diff --git a/.travis.yml b/.travis.yml index f7d62b92..98b41d1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,17 +11,11 @@ env: global: - BUNDLE_JOBS=4 - NOKOGIRI_USE_SYSTEM_LIBRARIES=true -matrix: - include: - - rvm: 1.9.3 - gemfile: gemfiles/2.3.gemfile - env: QMAKE=/usr/lib/x86_64-linux-gnu/qt5/bin/qmake - - rvm: 1.9.3 - gemfile: gemfiles/2.4.gemfile - env: QMAKE=/usr/lib/x86_64-linux-gnu/qt5/bin/qmake gemfile: - gemfiles/2.3.gemfile - gemfiles/2.4.gemfile before_install: - - sh -c 'if [ -n "$QMAKE" ]; then sudo apt-add-repository -y ppa:ubuntu-sdk-team/ppa && sudo apt-get update && sudo apt-get install libqt5webkit5-dev qtdeclarative5-dev; fi' + - sudo apt-add-repository -y ppa:ubuntu-sdk-team/ppa + - sudo apt-get update + - sudo apt-get install libqt5webkit5-dev qtdeclarative5-dev qt5-default install: bundle diff --git a/lib/capybara/webkit/browser.rb b/lib/capybara/webkit/browser.rb index dc145331..83e00f5a 100644 --- a/lib/capybara/webkit/browser.rb +++ b/lib/capybara/webkit/browser.rb @@ -59,18 +59,6 @@ def error_messages end end - def alert_messages - JSON.parse(command("JavascriptAlertMessages")) - end - - def confirm_messages - JSON.parse(command("JavascriptConfirmMessages")) - end - - def prompt_messages - JSON.parse(command("JavascriptPromptMessages")) - end - def response_headers JSON.parse(command("Headers")) end @@ -127,38 +115,18 @@ def get_window_handles JSON.parse(command('GetWindowHandles')) end - def window_handles - warn '[DEPRECATION] Capybara::Webkit::Browser#window_handles ' \ - 'is deprecated. Please use Capybara::Session#windows instead.' - get_window_handles - end - def get_window_handle command('GetWindowHandle') end - def window_handle - warn '[DEPRECATION] Capybara::Webkit::Browser#window_handle ' \ - 'is deprecated. Please use Capybara::Session#current_window instead.' - get_window_handle - end - def accept_confirm(options) command("SetConfirmAction", "Yes", options[:text]) end - def accept_js_confirms - command("SetConfirmAction", "Yes") - end - def reject_confirm(options) command("SetConfirmAction", "No", options[:text]) end - def reject_js_confirms - command("SetConfirmAction", "No") - end - def accept_prompt(options) if options[:with] command("SetPromptAction", "Yes", options[:text], options[:with]) @@ -167,26 +135,10 @@ def accept_prompt(options) end end - def accept_js_prompts - command("SetPromptAction", "Yes") - end - def reject_prompt(options) command("SetPromptAction", "No", options[:text]) end - def reject_js_prompts - command("SetPromptAction", "No") - end - - def set_prompt_text_to(string) - command("SetPromptText", string) - end - - def clear_prompt_text - command("ClearPromptText") - end - def accept_alert(options) command("AcceptAlert", options[:text]) end @@ -195,12 +147,6 @@ def find_modal(id) command("FindModal", id) end - def url_blacklist=(black_list) - warn '[DEPRECATION] Capybara::Webkit::Browser#url_blacklist= ' \ - 'is deprecated. Please use page.driver.block_url instead.' - command("SetUrlBlacklist", *Array(black_list)) - end - def command(name, *args) @connection.puts name @connection.puts args.size diff --git a/lib/capybara/webkit/connection.rb b/lib/capybara/webkit/connection.rb index 0c9f22a1..8e409b4c 100644 --- a/lib/capybara/webkit/connection.rb +++ b/lib/capybara/webkit/connection.rb @@ -12,22 +12,7 @@ class Connection def initialize(options = {}) @socket = nil - if options.has_key?(:socket_class) - warn '[DEPRECATION] The Capybara::Webkit::Connection `socket_class` ' \ - 'option is deprecated without replacement.' - @socket_class = options[:socket_class] - else - @socket_class = TCPSocket - end - if options.has_key?(:stderr) - @output_target = options[:stderr] - elsif options.has_key?(:stdout) - warn '[DEPRECATION] The Capybara::Webkit::Connection `stdout` option ' \ - 'is deprecated. Please use `stderr` instead.' - @output_target = options[:stdout] - else - @output_target = $stderr - end + @output_target = options.fetch(:stderr) { $stderr } start_server connect end @@ -116,7 +101,7 @@ def connect end def attempt_connect - @socket = @socket_class.open("127.0.0.1", @port) + @socket = TCPSocket.open("127.0.0.1", @port) if defined?(Socket::TCP_NODELAY) @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true) end diff --git a/lib/capybara/webkit/driver.rb b/lib/capybara/webkit/driver.rb index b480a8f7..c90348be 100644 --- a/lib/capybara/webkit/driver.rb +++ b/lib/capybara/webkit/driver.rb @@ -15,31 +15,6 @@ def initialize(app, options={}) apply_options end - def enable_logging - deprecate_and_replace_with_config "enable_logging", "debug = true" - @browser.enable_logging - end - - def allow_url(url) - deprecate_and_replace_with_config "allow_url", "allow_url(#{url.inspect})" - @browser.allow_url(url) - end - - def block_url(url) - deprecate_and_replace_with_config "block_url", "block_url(#{url.inspect})" - @browser.block_url(url) - end - - def block_unknown_urls - deprecate_and_replace_with_config "block_unknown_urls" - @browser.block_unknown_urls - end - - def allow_unknown_urls - deprecate_and_replace_with_config "allow_unknown_urls" - @browser.allow_url("*") - end - def current_url @browser.current_url end @@ -91,26 +66,6 @@ def error_messages @browser.error_messages end - def alert_messages - warn '[DEPRECATION] Capybara::Webkit::Driver#alert_messages ' \ - 'is deprecated. Please use Capybara::Session#accept_alert instead.' - @browser.alert_messages - end - - def confirm_messages - warn '[DEPRECATION] Capybara::Webkit::Driver#confirm_messages ' \ - 'is deprecated. Please use Capybara::Session#accept_confirm ' \ - 'or Capybara::Session#dismiss_confirm instead.' - @browser.confirm_messages - end - - def prompt_messages - warn '[DEPRECATION] Capybara::Webkit::Driver#prompt_messages ' \ - 'is deprecated. Please use Capybara::Session#accept_prompt ' \ - 'or Capybara::Session#dismiss_prompt instead.' - @browser.prompt_messages - end - def response_headers @browser.response_headers end @@ -119,12 +74,6 @@ def status_code @browser.status_code end - def resize_window(width, height) - warn '[DEPRECATION] Capybara::Webkit::Driver#resize_window ' \ - 'is deprecated. Please use Capybara::Window#resize_to instead.' - resize_window_to(current_window_handle, width, height) - end - def resize_window_to(handle, width, height) @browser.window_resize(handle, width, height) end @@ -176,40 +125,6 @@ def maximize_window(selector) @browser.window_maximize(selector) end - def accept_js_confirms! - warn '[DEPRECATION] Capybara::Webkit::Driver#accept_js_confirms! ' \ - 'is deprecated. Please use Capybara::Session#accept_confirm instead.' - @browser.accept_js_confirms - end - - def dismiss_js_confirms! - warn '[DEPRECATION] Capybara::Webkit::Driver#dismiss_js_confirms! ' \ - 'is deprecated. Please use Capybara::Session#dismiss_confirm instead.' - @browser.reject_js_confirms - end - - def accept_js_prompts! - warn '[DEPRECATION] Capybara::Webkit::Driver#accept_js_prompts! ' \ - 'is deprecated. Please use Capybara::Session#accept_prompt instead.' - @browser.accept_js_prompts - end - - def dismiss_js_prompts! - warn '[DEPRECATION] Capybara::Webkit::Driver#dismiss_js_prompts! ' \ - 'is deprecated. Please use Capybara::Session#dismiss_prompt instead.' - @browser.reject_js_prompts - end - - def js_prompt_input=(value) - warn '[DEPRECATION] Capybara::Webkit::Driver#js_prompt_input= ' \ - 'is deprecated. Please use Capybara::Session#accept_prompt instead.' - if value.nil? - @browser.clear_prompt_text - else - @browser.set_prompt_text_to(value) - end - end - def go_back @browser.go_back end @@ -306,24 +221,6 @@ def authenticate(username, password) @browser.authenticate(username, password) end - def timeout - deprecate_and_replace_with_config "timeout" - @browser.timeout - end - - def timeout=(timeout) - deprecate_and_replace_with_config( - "timeout=", - "timeout = #{timeout.inspect}" - ) - @browser.timeout = timeout - end - - def browser - warn "[DEPRECATION] Capybara::Webkit::Driver#browser is deprecated." - @browser - end - private def modal_action_options_for_browser(options) @@ -374,15 +271,5 @@ def apply_options Array(@options[:allowed_urls]).each { |url| @browser.allow_url(url) } Array(@options[:blocked_urls]).each { |url| @browser.block_url(url) } end - - def deprecate_and_replace_with_config(deprecated_method, config_syntax = deprecated_method) - warn "[DEPRECATION] #{deprecated_method} is deprecated. " \ - "Please use Capybara::Webkit.configure instead:\n\n" \ - " Capybara::Webkit.configure do |config|\n" \ - " config.#{config_syntax}\n" \ - " end\n\n" \ - "This option is global and can be configured once" \ - " (not in a `before` or `setup` block)." - end end end diff --git a/lib/capybara/webkit/errors.rb b/lib/capybara/webkit/errors.rb index 06681faa..a20ea1c2 100644 --- a/lib/capybara/webkit/errors.rb +++ b/lib/capybara/webkit/errors.rb @@ -26,6 +26,9 @@ class ModalNotFound < StandardError class CrashError < StandardError end + class UnhandledModalError < StandardError + end + class JsonError def initialize(response) error = JSON.parse response diff --git a/spec/connection_spec.rb b/spec/connection_spec.rb index a8bc77ab..977c45ec 100644 --- a/spec/connection_spec.rb +++ b/spec/connection_spec.rb @@ -99,17 +99,6 @@ def eventually Capybara::Webkit::Connection.new(:stderr => nil) end - it 'prints a deprecation warning if the stdout option is used' do - Capybara::Webkit::Connection.any_instance.should_receive(:warn) - Capybara::Webkit::Connection.new(:stdout => nil) - end - - it 'does not forward stdout to nil if the stdout option is used' do - Capybara::Webkit::Connection.any_instance.stub(:warn) - IO.should_not_receive(:copy_stream) - Capybara::Webkit::Connection.new(:stdout => nil) - end - it "returns the server port" do connection.port.should be_between 0x400, 0xffff end diff --git a/spec/driver_rendering_spec.rb b/spec/driver_rendering_spec.rb index 8ebded2c..43b2d773 100644 --- a/spec/driver_rendering_spec.rb +++ b/spec/driver_rendering_spec.rb @@ -82,7 +82,7 @@ def render(options) end context "with a custom viewport size" do - before { driver.resize_window(800, 600) } + before { driver.resize_window_to(driver.current_window_handle, 800, 600) } it "should restore viewport dimensions after rendering" do render({}) diff --git a/spec/driver_resize_window_spec.rb b/spec/driver_resize_window_spec.rb index 88168c5e..9ccfb8de 100644 --- a/spec/driver_resize_window_spec.rb +++ b/spec/driver_resize_window_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'capybara/webkit/driver' -describe Capybara::Webkit::Driver, "#resize_window(width, height)" do +describe Capybara::Webkit::Driver, "#resize_window_to(handle, width, height)" do include AppRunner let(:driver) do @@ -26,21 +26,21 @@ it "resizes the window to the specified size" do driver.visit("#{AppRunner.app_host}/") - driver.resize_window(800, 600) + driver.resize_window_to(driver.current_window_handle, 800, 600) driver.html.should include("[800x600]") - driver.resize_window(300, 100) + driver.resize_window_to(driver.current_window_handle, 300, 100) driver.html.should include("[300x100]") end it "resizes the window to the specified size even before the document has loaded" do - driver.resize_window(800, 600) + driver.resize_window_to(driver.current_window_handle, 800, 600) driver.visit("#{AppRunner.app_host}/") driver.html.should include("[800x600]") end it "resets the window to the default size when the driver is reset" do - driver.resize_window(800, 600) + driver.resize_window_to(driver.current_window_handle, 800, 600) driver.reset! driver.visit("#{AppRunner.app_host}/") driver.html.should include(DEFAULT_DIMENTIONS) @@ -60,7 +60,7 @@ it "maximizes a window" do driver.visit("#{AppRunner.app_host}/") - driver.resize_window(400, 300) + driver.resize_window_to(driver.current_window_handle, 400, 300) driver.maximize_window(driver.current_window_handle) width, height = *driver.window_size(driver.current_window_handle) diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index f952cf23..b09c039d 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -712,7 +712,7 @@ def url(path)
@@ -755,7 +755,7 @@ def url(path) end expect { - driver.accept_modal(:alert, text: 'Boom') do + driver.accept_modal(:alert, text: 'Boom') do driver.find_xpath("//input").first.click end }.to raise_error Capybara::ModalNotFound, "Unable to find modal dialog with Boom" @@ -786,25 +786,12 @@ def url(path) }.to raise_error Capybara::ModalNotFound, "Unable to find modal dialog" end - it "should let me read my alert messages" do - visit("/") - driver.alert_messages.first.should eq "Alert Text\nGoes Here" - end - - it "empties the array when reset" do - visit("/") - driver.reset! - driver.alert_messages.should be_empty + it "should raise an error for an unexpected alert modal" do + expect { + visit("/") + }.to raise_error(Capybara::Webkit::UnhandledModalError) end - it "clears alerts from ajax requests in between sessions" do - visit("/ajax") - driver.find("//input").first.click - driver.reset! - sleep 0.5 - driver.alert_messages.should eq([]) - expect { visit("/") }.not_to raise_error - end end context "on a confirm app" do @@ -922,48 +909,33 @@ def url(path) end end - it "should default to accept the confirm" do - driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "hello" + it "should raise an error for an unexpected confirm modal" do + expect { + driver.find_xpath("//input").first.click + }.to raise_error(Capybara::Webkit::UnhandledModalError) end it "can dismiss the confirm" do - driver.dismiss_js_confirms! - driver.find_xpath("//input").first.click + driver.dismiss_modal :confirm do + driver.find_xpath("//input").first.click + end + driver.console_messages.first[:message].should eq "goodbye" end it "can accept the confirm explicitly" do - driver.dismiss_js_confirms! - driver.accept_js_confirms! - driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "hello" - end - - it "should collect the javascript confirm dialog contents" do - driver.find_xpath("//input").first.click - driver.confirm_messages.first.should eq "Yes?" - end - - it "empties the array when reset" do - driver.find_xpath("//input").first.click - driver.reset! - driver.confirm_messages.should be_empty - end + driver.accept_modal :confirm do + driver.find_xpath("//input").first.click + end - it "resets to the default of accepting confirms" do - driver.dismiss_js_confirms! - driver.reset! - visit("/") - driver.find_xpath("//input").first.click driver.console_messages.first[:message].should eq "hello" end it "supports multi-line confirmation messages" do - driver.execute_script("confirm('Hello\\nnewline')") - driver.confirm_messages.first.should eq "Hello\nnewline" + driver.accept_modal :confirm, text: "Hello\nnewline" do + driver.execute_script("confirm('Hello\\nnewline')") + end end - end context "on a prompt app" do @@ -1087,65 +1059,37 @@ def url(path) end end - it "should default to dismiss the prompt" do - driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "goodbye" + it "should raise an error for an unexpected prompt modal" do + expect { + driver.find_xpath("//input").first.click + }.to raise_error(Capybara::Webkit::UnhandledModalError) end it "can accept the prompt without providing text" do - driver.accept_js_prompts! - driver.find_xpath("//input").first.click + driver.accept_modal :prompt do + driver.find_xpath("//input").first.click + end driver.console_messages.first[:message].should eq "hello John Smith" end it "can accept the prompt with input" do - driver.js_prompt_input = "Capy" - driver.accept_js_prompts! - driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "hello Capy" - end - - it "can return to dismiss the prompt after accepting prompts" do - driver.accept_js_prompts! - driver.dismiss_js_prompts! - driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "goodbye" - end - - it "should let me remove the prompt input text" do - driver.js_prompt_input = "Capy" - driver.accept_js_prompts! - driver.find_xpath("//input").first.click + driver.accept_modal :prompt, with: "Capy" do + driver.find_xpath("//input").first.click + end driver.console_messages.first[:message].should eq "hello Capy" - driver.js_prompt_input = nil - driver.find_xpath("//input").first.click - driver.console_messages.last[:message].should eq "hello John Smith" end it "should collect the javascript prompt dialog contents" do - driver.find_xpath("//input").first.click - driver.prompt_messages.first.should eq "Your name?" - end - - it "empties the array when reset" do - driver.find_xpath("//input").first.click - driver.reset! - driver.prompt_messages.should be_empty - end - - it "returns the prompt action to dismiss on reset" do - driver.accept_js_prompts! - driver.reset! - visit("/") - driver.find_xpath("//input").first.click - driver.console_messages.first[:message].should eq "goodbye" + driver.accept_modal :prompt, text: "Your name?" do + driver.find_xpath("//input").first.click + end end it "supports multi-line prompt messages" do - driver.execute_script("prompt('Hello\\nnewline')") - driver.prompt_messages.first.should eq "Hello\nnewline" + driver.accept_modal :prompt, text: "Hello\nnewline" do + driver.execute_script("prompt('Hello\\nnewline')") + end end - end end @@ -1575,7 +1519,7 @@ def url(path) end it "hovers an element off the screen" do - driver.resize_window(200, 200) + driver.resize_window_to(driver.window_handles.first, 200, 200) driver.evaluate_script(<<-JS) var element = document.getElementById('hover'); element.style.position = 'absolute'; @@ -1727,32 +1671,6 @@ def wait_for_error_to_complete end end - context "popup app" do - let(:driver) do - driver_for_app do - get "/" do - sleep(0.5) - return <<-HTML - - -success
- - HTML - end - end - end - - before { visit("/") } - - it "doesn't crash from alerts" do - driver.find_xpath("//p").first.visible_text.should eq "success" - end - end - context "custom header" do let(:driver) do driver_for_app do @@ -2755,15 +2673,6 @@ def which_for(character) end end - it "resets allowed hosts on reset" do - driver.allow_unknown_urls - driver.reset! - visit("/") - - expect(stderr).to include("http://example.com/path") - expect(stderr).not_to include(driver.current_url) - end - it "can block unknown hosts" do configure(&:block_unknown_urls) visit("/") @@ -2840,34 +2749,13 @@ def which_for(character) lambda { visit("/") }.should_not raise_error end - it "should set the timeout for each request" do - configure { |config| config.timeout = 10 } - lambda { visit("/") }.should_not raise_error - driver.timeout = 1 - lambda { visit("/") }.should raise_error(Timeout::Error) - end - - it "should set the timeout for each request" do - configure { |config| config.timeout = 1 } - lambda { visit("/") }.should raise_error(Timeout::Error) - driver.reset! - driver.timeout = 10 - lambda { visit("/") }.should_not raise_error - end - it "should raise a timeout on a slow form" do configure { |config| config.timeout = 3 } visit("/") driver.status_code.should eq 200 - driver.timeout = 1 driver.find_xpath("//input").first.click lambda { driver.status_code }.should raise_error(Timeout::Error) end - - it "get timeout" do - configure { |config| config.timeout = 10 } - driver.browser.timeout.should eq 10 - end end describe "logger app" do @@ -3081,7 +2969,7 @@ def which_for(character) end it "aborts unfinished responses" do - driver.enable_logging + configure { |config| config.debug = true } visit "/" sleep 0.5 visit "/" @@ -3325,13 +3213,6 @@ def abort_request_to(path) driver.execute_script %{window.history.pushState("", "", "/blah")} driver.current_url.should eq "http://example.org/blah" end - - it "is possible to disable proxy again" do - @proxy_requests.clear - driver.browser.clear_proxy - driver.visit "http://#{@host}:#{@port}/" - @proxy_requests.size.should eq 0 - end end def driver_url(driver, path) diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index 106edfeb..578b8eff 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -386,7 +386,7 @@ module TestSessions it 'clicks in the center of the viewable area of an element' do subject.visit('/') - subject.driver.resize_window(200, 200) + subject.current_window.resize_to(200, 200) subject.find(:css, '#one').click subject.find(:css, '#one')['data-click-x'].should eq '149' subject.find(:css, '#one')['data-click-y'].should eq '99' @@ -399,7 +399,7 @@ module TestSessions it 'scrolls an element into view when clicked' do subject.visit('/') - subject.driver.resize_window(200, 200) + subject.current_window.resize_to(200, 200) subject.find(:css, '#two').click subject.find(:css, '#two')['data-click-x'].should_not be_nil subject.find(:css, '#two')['data-click-y'].should_not be_nil diff --git a/src/ClearPromptText.cpp b/src/ClearPromptText.cpp deleted file mode 100644 index cae1936f..00000000 --- a/src/ClearPromptText.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "ClearPromptText.h" -#include "WebPage.h" -#include "WebPageManager.h" - -ClearPromptText::ClearPromptText(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {} - -void ClearPromptText::start() -{ - page()->setPromptText(QString()); - finish(true); -} diff --git a/src/ClearPromptText.h b/src/ClearPromptText.h deleted file mode 100644 index afc3244b..00000000 --- a/src/ClearPromptText.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "SocketCommand.h" - -class ClearPromptText : public SocketCommand { - Q_OBJECT; - - public: - ClearPromptText(WebPageManager *manager, QStringList &arguments, QObject *parent = 0); - virtual void start(); -}; diff --git a/src/CommandFactory.cpp b/src/CommandFactory.cpp index 9519969d..7fbc2d88 100644 --- a/src/CommandFactory.cpp +++ b/src/CommandFactory.cpp @@ -31,12 +31,6 @@ #include "EnableLogging.h" #include "SetConfirmAction.h" #include "SetPromptAction.h" -#include "SetPromptText.h" -#include "ClearPromptText.h" -#include "JavascriptAlertMessages.h" -#include "JavascriptConfirmMessages.h" -#include "JavascriptPromptMessages.h" -#include "SetUrlBlacklist.h" #include "Version.h" #include "Title.h" #include "FindCss.h" diff --git a/src/Connection.cpp b/src/Connection.cpp index ba16338c..e9a1cfdb 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -3,6 +3,7 @@ #include "WebPageManager.h" #include "CommandParser.h" #include "CommandFactory.h" +#include "UnhandledModalCommand.h" #include "PageLoadingCommand.h" #include "TimeoutCommand.h" #include "SocketCommand.h" @@ -33,7 +34,11 @@ void Connection::startCommand(Command *command) { m_pendingCommand->deleteLater(); } if (m_pageSuccess) { - m_pendingCommand = new TimeoutCommand(new PageLoadingCommand(command, m_manager, this), m_manager, this); + m_pendingCommand = new UnhandledModalCommand( + new TimeoutCommand( + new PageLoadingCommand(command, m_manager, this), + m_manager, this), + m_manager, this); connect(m_pendingCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *))); m_pendingCommand->start(); } else { diff --git a/src/JavascriptAlertMessages.cpp b/src/JavascriptAlertMessages.cpp deleted file mode 100644 index b94bdc60..00000000 --- a/src/JavascriptAlertMessages.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "JavascriptAlertMessages.h" -#include "WebPage.h" -#include "WebPageManager.h" -#include "JsonSerializer.h" - -JavascriptAlertMessages::JavascriptAlertMessages(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {} - -void JavascriptAlertMessages::start() -{ - JsonSerializer serializer; - QByteArray json = serializer.serialize(page()->alertMessages()); - finish(true, json); -} diff --git a/src/JavascriptAlertMessages.h b/src/JavascriptAlertMessages.h deleted file mode 100644 index 4f275bef..00000000 --- a/src/JavascriptAlertMessages.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "SocketCommand.h" - -class JavascriptAlertMessages : public SocketCommand { - Q_OBJECT - - public: - JavascriptAlertMessages(WebPageManager *manager, QStringList &arguments, QObject *parent = 0); - virtual void start(); -}; diff --git a/src/JavascriptConfirmMessages.cpp b/src/JavascriptConfirmMessages.cpp deleted file mode 100644 index d9697021..00000000 --- a/src/JavascriptConfirmMessages.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "JavascriptConfirmMessages.h" -#include "WebPage.h" -#include "WebPageManager.h" -#include "JsonSerializer.h" - -JavascriptConfirmMessages::JavascriptConfirmMessages(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {} - -void JavascriptConfirmMessages::start() -{ - JsonSerializer serializer; - QByteArray json = serializer.serialize(page()->confirmMessages()); - finish(true, json); -} diff --git a/src/JavascriptPromptMessages.cpp b/src/JavascriptPromptMessages.cpp deleted file mode 100644 index 9fa53569..00000000 --- a/src/JavascriptPromptMessages.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "JavascriptPromptMessages.h" -#include "WebPage.h" -#include "WebPageManager.h" -#include "JsonSerializer.h" - -JavascriptPromptMessages::JavascriptPromptMessages(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {} - -void JavascriptPromptMessages::start() -{ - JsonSerializer serializer; - QByteArray json = serializer.serialize(page()->promptMessages()); - finish(true, json); -} diff --git a/src/JavascriptPromptMessages.h b/src/JavascriptPromptMessages.h deleted file mode 100644 index b9e3e6da..00000000 --- a/src/JavascriptPromptMessages.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "SocketCommand.h" - -class JavascriptPromptMessages : public SocketCommand { - Q_OBJECT - - public: - JavascriptPromptMessages(WebPageManager *manager, QStringList &arguments, QObject *parent = 0); - virtual void start(); -}; diff --git a/src/Server.cpp b/src/Server.cpp index 434c5b67..9dc1536f 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -9,13 +9,6 @@ Server::Server(QObject *parent) : QObject(parent) { } bool Server::start() { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QTextStream(stderr) << - "WARNING: The next major version of capybara-webkit " << - "will require at least version 5.0 of Qt. " << - "You're using version " << QT_VERSION_STR << "." << endl; -#endif - connect(m_tcp_server, SIGNAL(newConnection()), this, SLOT(handleConnection())); return m_tcp_server->listen(QHostAddress::LocalHost, 0); } diff --git a/src/SetConfirmAction.cpp b/src/SetConfirmAction.cpp index 244fc37c..21c0b92d 100644 --- a/src/SetConfirmAction.cpp +++ b/src/SetConfirmAction.cpp @@ -6,14 +6,7 @@ SetConfirmAction::SetConfirmAction(WebPageManager *manager, QStringList &argumen void SetConfirmAction::start() { - QString index; - switch (arguments().length()) { - case 2: - index = page()->setConfirmAction(arguments()[0], arguments()[1]); - break; - default: - page()->setConfirmAction(arguments()[0]); - } + QString index = page()->setConfirmAction(arguments()[0], arguments()[1]); finish(true, index); } diff --git a/src/SetPromptAction.cpp b/src/SetPromptAction.cpp index 3a9f874e..9483ae25 100644 --- a/src/SetPromptAction.cpp +++ b/src/SetPromptAction.cpp @@ -11,11 +11,8 @@ void SetPromptAction::start() case 3: index = page()->setPromptAction(arguments()[0], arguments()[1], arguments()[2]); break; - case 2: - index = page()->setPromptAction(arguments()[0], arguments()[1]); - break; default: - page()->setPromptAction(arguments()[0]); + index = page()->setPromptAction(arguments()[0], arguments()[1]); } finish(true, index); diff --git a/src/SetPromptText.cpp b/src/SetPromptText.cpp deleted file mode 100644 index fd2a768d..00000000 --- a/src/SetPromptText.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "SetPromptText.h" -#include "WebPage.h" -#include "WebPageManager.h" - -SetPromptText::SetPromptText(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {} - -void SetPromptText::start() -{ - page()->setPromptText(arguments()[0]); - finish(true); -} diff --git a/src/SetPromptText.h b/src/SetPromptText.h deleted file mode 100644 index 67467dd6..00000000 --- a/src/SetPromptText.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "SocketCommand.h" - -class SetPromptText : public SocketCommand { - Q_OBJECT; - - public: - SetPromptText(WebPageManager *manager, QStringList &arguments, QObject *parent = 0); - virtual void start(); -}; diff --git a/src/SetUrlBlacklist.cpp b/src/SetUrlBlacklist.cpp deleted file mode 100644 index c0cae3cc..00000000 --- a/src/SetUrlBlacklist.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -#include "SetUrlBlacklist.h" -#include "WebPageManager.h" -#include "WebPage.h" -#include "NetworkAccessManager.h" - -SetUrlBlacklist::SetUrlBlacklist(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) { -} - -void SetUrlBlacklist::start() { - manager()->setUrlBlacklist(arguments()); - finish(true); -} - diff --git a/src/SetUrlBlacklist.h b/src/SetUrlBlacklist.h deleted file mode 100644 index 7a52f0dc..00000000 --- a/src/SetUrlBlacklist.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "SocketCommand.h" - -class SetUrlBlacklist : public SocketCommand { - Q_OBJECT - - public: - SetUrlBlacklist(WebPageManager *manager, QStringList &arguments, QObject *parent = 0); - virtual void start(); -}; diff --git a/src/UnhandledModalCommand.cpp b/src/UnhandledModalCommand.cpp new file mode 100644 index 00000000..a022f68b --- /dev/null +++ b/src/UnhandledModalCommand.cpp @@ -0,0 +1,24 @@ +#include "UnhandledModalCommand.h" +#include "SocketCommand.h" +#include "WebPage.h" +#include "WebPageManager.h" +#include "ErrorMessage.h" + +UnhandledModalCommand::UnhandledModalCommand(Command *command, WebPageManager *manager, QObject *parent) : Command(parent) { + m_manager = manager; + m_command = command; + m_command->setParent(this); +} + +void UnhandledModalCommand::start() { + connect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *))); + m_command->start(); +}; + +void UnhandledModalCommand::commandFinished(Response *response) { + if (m_manager->currentPage()->hasUnexpectedModal()) { + finish(false, new ErrorMessage("UnhandledModalError", "")); + } else { + emit finished(response); + } +} diff --git a/src/UnhandledModalCommand.h b/src/UnhandledModalCommand.h new file mode 100644 index 00000000..d8e161f8 --- /dev/null +++ b/src/UnhandledModalCommand.h @@ -0,0 +1,22 @@ +#include