From b1b3a4c390031a47e74a35eae0a7a6eebb7697e7 Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Mon, 22 Oct 2012 20:53:13 -0400 Subject: [PATCH] Revert "Add configurable timeouts to commands." This reverts commit da93136a9c6fab730706a6d86b3b11f263b6046f. Conflicts: src/TimeoutCommand.cpp --- lib/capybara/webkit/browser.rb | 24 +----------- spec/driver_spec.rb | 72 ---------------------------------- src/CommandFactory.cpp | 2 - src/Connection.cpp | 12 ++++-- src/Connection.h | 2 +- src/GetTimeout.cpp | 9 ----- src/GetTimeout.h | 11 ------ src/SetTimeout.cpp | 19 --------- src/SetTimeout.h | 9 ----- src/TimeoutCommand.cpp | 59 ---------------------------- src/TimeoutCommand.h | 41 ------------------- src/WebPageManager.cpp | 10 ----- src/WebPageManager.h | 3 -- src/find_command.h | 3 -- src/webkit_server.pro | 6 --- 15 files changed, 11 insertions(+), 271 deletions(-) delete mode 100644 src/GetTimeout.cpp delete mode 100644 src/GetTimeout.h delete mode 100644 src/SetTimeout.cpp delete mode 100644 src/SetTimeout.h delete mode 100644 src/TimeoutCommand.cpp delete mode 100644 src/TimeoutCommand.h diff --git a/lib/capybara/webkit/browser.rb b/lib/capybara/webkit/browser.rb index e9ab44f..0f33114 100644 --- a/lib/capybara/webkit/browser.rb +++ b/lib/capybara/webkit/browser.rb @@ -165,14 +165,6 @@ module Capybara::Webkit command "Render", path, width, height end - def timeout=(timeout_in_seconds) - command "SetTimeout", timeout_in_seconds - end - - def timeout - command("GetTimeout").to_i - end - def set_cookie(cookie) command "SetCookie", cookie end @@ -207,26 +199,12 @@ module Capybara::Webkit if result.nil? raise NoResponseError, "No response received from the server." elsif result != 'ok' - case response = read_response - when "timeout" - raise Capybara::TimeoutError, "Request timed out after #{timeout_seconds}" - else - raise InvalidResponseError, response - end + raise InvalidResponseError, read_response end result end - def timeout_seconds - seconds = timeout - if seconds > 1 - "#{seconds} seconds" - else - "1 second" - end - end - def read_response response_length = @connection.gets.to_i if response_length > 0 diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index 87ac5ac..ee41abf 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -1825,78 +1825,6 @@ describe Capybara::Webkit::Driver do end end - describe "timeout for long requests" do - let(:driver) do - driver_for_app do - html = <<-HTML - - -
- -
- - - HTML - - get "/" do - sleep(2) - html - end - - post "/form" do - sleep(4) - html - end - end - end - - it "should not raise a timeout error when zero" do - driver.browser.timeout = 0 - lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError) - end - - it "should raise a timeout error" do - driver.browser.timeout = 1 - lambda { driver.visit("/") }.should raise_error(Capybara::TimeoutError, "Request timed out after 1 second") - end - - it "should not raise an error when the timeout is high enough" do - driver.browser.timeout = 10 - lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError) - end - - it "should set the timeout for each request" do - driver.browser.timeout = 10 - lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError) - driver.browser.timeout = 1 - lambda { driver.visit("/") }.should raise_error(Capybara::TimeoutError) - end - - it "should set the timeout for each request" do - driver.browser.timeout = 1 - lambda { driver.visit("/") }.should raise_error(Capybara::TimeoutError) - driver.reset! - driver.browser.timeout = 10 - lambda { driver.visit("/") }.should_not raise_error(Capybara::TimeoutError) - end - - it "should raise a timeout on a slow form" do - driver.browser.timeout = 3 - driver.visit("/") - driver.status_code.should == 200 - driver.browser.timeout = 1 - driver.find("//input").first.click - lambda { driver.status_code }.should raise_error(Capybara::TimeoutError) - end - - it "get timeout" do - driver.browser.timeout = 10 - driver.browser.timeout.should == 10 - driver.browser.timeout = 3 - driver.browser.timeout.should == 3 - end - end - describe "logger app" do it "logs nothing before turning on the logger" do driver.visit("/") diff --git a/src/CommandFactory.cpp b/src/CommandFactory.cpp index d4f58a9..e1b6baa 100644 --- a/src/CommandFactory.cpp +++ b/src/CommandFactory.cpp @@ -22,8 +22,6 @@ #include "ConsoleMessages.h" #include "RequestedUrl.h" #include "CurrentUrl.h" -#include "SetTimeout.h" -#include "GetTimeout.h" #include "ResizeWindow.h" #include "IgnoreSslErrors.h" #include "SetSkipImageLoading.h" diff --git a/src/Connection.cpp b/src/Connection.cpp index 90298f8..c00e977 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -4,7 +4,6 @@ #include "CommandParser.h" #include "CommandFactory.h" #include "PageLoadingCommand.h" -#include "TimeoutCommand.h" #include "SocketCommand.h" #include @@ -25,14 +24,18 @@ Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *par void Connection::commandReady(Command *command) { m_queuedCommand = command; m_manager->logger() << "Received" << command->toString(); - startCommand(); + if (m_manager->isLoading()) { + m_manager->logger() << command->toString() << "waiting for load to finish"; + m_commandWaiting = true; + } else { + startCommand(); + } } void Connection::startCommand() { m_commandWaiting = false; if (m_pageSuccess) { m_runningCommand = new PageLoadingCommand(m_queuedCommand, m_manager, this); - m_runningCommand = new TimeoutCommand(m_runningCommand, m_manager, this); connect(m_runningCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *))); m_runningCommand->start(); } else { @@ -42,6 +45,9 @@ void Connection::startCommand() { void Connection::pendingLoadFinished(bool success) { m_pageSuccess = m_pageSuccess && success; + if (m_commandWaiting) { + startCommand(); + } } void Connection::writePageLoadFailure() { diff --git a/src/Connection.h b/src/Connection.h index 59b3b70..244ddb6 100644 --- a/src/Connection.h +++ b/src/Connection.h @@ -31,7 +31,7 @@ class Connection : public QObject { WebPageManager *m_manager; CommandParser *m_commandParser; CommandFactory *m_commandFactory; - Command *m_runningCommand; + PageLoadingCommand *m_runningCommand; bool m_pageSuccess; bool m_commandWaiting; WebPage *currentPage(); diff --git a/src/GetTimeout.cpp b/src/GetTimeout.cpp deleted file mode 100644 index 844d441..0000000 --- a/src/GetTimeout.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "GetTimeout.h" -#include "WebPageManager.h" - -GetTimeout::GetTimeout(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) { -} - -void GetTimeout::start() { - emit finished(new Response(true, QString::number(manager()->getTimeout()))); -} diff --git a/src/GetTimeout.h b/src/GetTimeout.h deleted file mode 100644 index 1b96ab7..0000000 --- a/src/GetTimeout.h +++ /dev/null @@ -1,11 +0,0 @@ -#include "SocketCommand.h" - -class WebPageManager; - -class GetTimeout : public SocketCommand { - Q_OBJECT; - - public: - GetTimeout(WebPageManager *page, QStringList &arguments, QObject *parent = 0); - virtual void start(); -}; diff --git a/src/SetTimeout.cpp b/src/SetTimeout.cpp deleted file mode 100644 index 364cc49..0000000 --- a/src/SetTimeout.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "SetTimeout.h" -#include "WebPageManager.h" - -SetTimeout::SetTimeout(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) { -} - -void SetTimeout::start() { - QString timeoutString = arguments()[0]; - bool ok; - int timeout = timeoutString.toInt(&ok); - - if (ok) { - manager()->setTimeout(timeout); - emit finished(new Response(true)); - } else { - emit finished(new Response(false, QString("Invalid value for timeout"))); - } -} - diff --git a/src/SetTimeout.h b/src/SetTimeout.h deleted file mode 100644 index 390c117..0000000 --- a/src/SetTimeout.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "SocketCommand.h" - -class SetTimeout : public SocketCommand { - Q_OBJECT - - public: - SetTimeout(WebPageManager *manager, QStringList &arguments, QObject *parent = 0); - virtual void start(); -}; diff --git a/src/TimeoutCommand.cpp b/src/TimeoutCommand.cpp deleted file mode 100644 index ab44a8b..0000000 --- a/src/TimeoutCommand.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "TimeoutCommand.h" -#include "Command.h" -#include "WebPageManager.h" -#include "WebPage.h" -#include - -TimeoutCommand::TimeoutCommand(Command *command, WebPageManager *manager, QObject *parent) : Command(parent) { - m_command = command; - m_manager = manager; - m_timer = new QTimer(this); - m_timer->setSingleShot(true); - connect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout())); - connect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand())); -} - -void TimeoutCommand::start() { - if (m_manager->isLoading()) { - connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool))); - startTimeout(); - } else { - startCommand(); - } -} - -void TimeoutCommand::startCommand() { - connect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *))); - m_command->start(); -} - -void TimeoutCommand::startTimeout() { - int timeout = m_manager->getTimeout(); - if (timeout > 0) { - m_timer->start(timeout * 1000); - } -} - -void TimeoutCommand::pendingLoadFinished(bool success) { - if (success) { - startCommand(); - } else { - emit finished(new Response(false, m_manager->currentPage()->failureString())); - } -} - -void TimeoutCommand::pageLoadingFromCommand() { - startTimeout(); -} - -void TimeoutCommand::commandTimeout() { - m_manager->currentPage()->triggerAction(QWebPage::Stop); - m_command->deleteLater(); - emit finished(new Response(false, QString("timeout"))); -} - -void TimeoutCommand::commandFinished(Response *response) { - m_command->deleteLater(); - emit finished(response); -} - diff --git a/src/TimeoutCommand.h b/src/TimeoutCommand.h deleted file mode 100644 index 6ec4c2b..0000000 --- a/src/TimeoutCommand.h +++ /dev/null @@ -1,41 +0,0 @@ -#include "Command.h" -#include -#include - -class Response; -class WebPageManager; -class QTimer; - -/* Decorates a command with a timeout. - * - * If the timeout, using a QTimer is reached before - * the command is finished, the load page load will - * be stopped and failure response will be issued. - * - */ -class TimeoutCommand : public Command { - Q_OBJECT - - public: - TimeoutCommand(Command *command, WebPageManager *page, QObject *parent = 0); - virtual void start(); - - public slots: - void commandTimeout(); - void commandFinished(Response *response); - void pageLoadingFromCommand(); - void pendingLoadFinished(bool); - - signals: - void finished(Response *response); - - protected: - void startCommand(); - void startTimeout(); - - private: - WebPageManager *m_manager; - QTimer *m_timer; - Command *m_command; -}; - diff --git a/src/WebPageManager.cpp b/src/WebPageManager.cpp index d2ed1fa..fcae551 100644 --- a/src/WebPageManager.cpp +++ b/src/WebPageManager.cpp @@ -8,7 +8,6 @@ WebPageManager::WebPageManager(QObject *parent) : QObject(parent) { m_success = true; m_loggingEnabled = false; m_ignoredOutput = new QString(); - m_timeout = -1; createPage(this)->setFocus(); } @@ -86,16 +85,7 @@ bool WebPageManager::ignoreSslErrors() { return m_ignoreSslErrors; } -int WebPageManager::getTimeout() { - return m_timeout; -} - -void WebPageManager::setTimeout(int timeout) { - m_timeout = timeout; -} - void WebPageManager::reset() { - m_timeout = -1; m_cookieJar->clearCookies(); m_pages.first()->deleteLater(); m_pages.clear(); diff --git a/src/WebPageManager.h b/src/WebPageManager.h index b2f532c..b0002b0 100644 --- a/src/WebPageManager.h +++ b/src/WebPageManager.h @@ -22,8 +22,6 @@ class WebPageManager : public QObject { WebPage *createPage(QObject *parent); void setIgnoreSslErrors(bool); bool ignoreSslErrors(); - void setTimeout(int); - int getTimeout(); void reset(); NetworkCookieJar *cookieJar(); bool isLoading() const; @@ -52,7 +50,6 @@ class WebPageManager : public QObject { bool m_success; bool m_loggingEnabled; QString *m_ignoredOutput; - int m_timeout; }; #endif // _WEBPAGEMANAGER_H diff --git a/src/find_command.h b/src/find_command.h index a31cf60..c74913b 100644 --- a/src/find_command.h +++ b/src/find_command.h @@ -39,6 +39,3 @@ CHECK_COMMAND(ClearPromptText) CHECK_COMMAND(JavascriptAlertMessages) CHECK_COMMAND(JavascriptConfirmMessages) CHECK_COMMAND(JavascriptPromptMessages) -CHECK_COMMAND(GetTimeout) -CHECK_COMMAND(SetTimeout) - diff --git a/src/webkit_server.pro b/src/webkit_server.pro index 404c0e8..f6697dd 100644 --- a/src/webkit_server.pro +++ b/src/webkit_server.pro @@ -53,9 +53,6 @@ HEADERS = \ WindowFocus.h \ GetWindowHandles.h \ GetWindowHandle.h \ - GetTimeout.h \ - SetTimeout.h \ - TimeoutCommand.h \ SOURCES = \ EnableLogging.cpp \ @@ -105,14 +102,11 @@ SOURCES = \ SetProxy.cpp \ NullCommand.cpp \ PageLoadingCommand.cpp \ - SetTimeout.cpp \ - GetTimeout.cpp \ SetSkipImageLoading.cpp \ WebPageManager.cpp \ WindowFocus.cpp \ GetWindowHandles.cpp \ GetWindowHandle.cpp \ - TimeoutCommand.cpp \ RESOURCES = webkit_server.qrc QT += network webkit