From 728feeeff7136a8c0968eccbc8b3c2a6e3fe2254 Mon Sep 17 00:00:00 2001 From: Joe Ferris Date: Thu, 5 May 2011 18:27:04 -0400 Subject: [PATCH] Fixed subsequent failures when a page fails quickly before the next command begins --- spec/driver_spec.rb | 8 ++++++-- src/Connection.cpp | 40 +++++++++++++++++++++++----------------- src/Connection.h | 2 ++ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index a88b4c5..6eb29ef 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -550,7 +550,6 @@ describe Capybara::Driver::Webkit do before(:all) do @app = lambda do |env| if env['PATH_INFO'] == "/error" - body = "error" [404, {}, []] else body = <<-HTML @@ -568,10 +567,15 @@ describe Capybara::Driver::Webkit do it "raises a webkit error for the requested url" do expect { subject.find("//input").first.click - subject.find("//p") + wait_for_error_to_complete + subject.find("//body") }. to raise_error(Capybara::Driver::Webkit::WebkitError, %r{/error}) end + + def wait_for_error_to_complete + sleep(0.5) + end end context "slow error app" do diff --git a/src/Connection.cpp b/src/Connection.cpp index a729a8d..f63b9a3 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -20,7 +20,10 @@ Connection::Connection(QTcpSocket *socket, WebPage *page, QObject *parent) : m_page = page; m_command = NULL; m_expectingDataSize = -1; + m_pageSuccess = true; + m_commandWaiting = false; connect(m_socket, SIGNAL(readyRead()), this, SLOT(checkNext())); + connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(pendingLoadFinished(bool))); } void Connection::checkNext() { @@ -75,25 +78,32 @@ void Connection::processArgument(const char *data) { if (m_arguments.length() == m_argumentsExpected) { if (m_page->isLoading()) - connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(pendingLoadFinished(bool))); + m_commandWaiting = true; else startCommand(); } } void Connection::startCommand() { - m_command = createCommand(m_commandName.toAscii().constData()); - if (m_command) { - connect(m_command, - SIGNAL(finished(Response *)), - this, - SLOT(finishCommand(Response *))); - m_command->start(m_arguments); + m_commandWaiting = false; + if (m_pageSuccess) { + m_command = createCommand(m_commandName.toAscii().constData()); + if (m_command) { + connect(m_command, + SIGNAL(finished(Response *)), + this, + SLOT(finishCommand(Response *))); + m_command->start(m_arguments); + } else { + QString failure = QString("Unknown command: ") + m_commandName + "\n"; + writeResponse(new Response(false, failure)); + } + m_commandName = QString(); } else { - QString failure = QString("Unknown command: ") + m_commandName + "\n"; - writeResponse(new Response(false, failure)); + m_pageSuccess = true; + QString message = m_page->failureString(); + writeResponse(new Response(false, message)); } - m_commandName = QString(); } Command *Connection::createCommand(const char *name) { @@ -102,13 +112,9 @@ Command *Connection::createCommand(const char *name) { } void Connection::pendingLoadFinished(bool success) { - m_page->disconnect(this, SLOT(pendingLoadFinished(bool))); - if (success) { + m_pageSuccess = success; + if (m_commandWaiting) startCommand(); - } else { - QString message = m_page->failureString(); - writeResponse(new Response(false, message)); - } } void Connection::finishCommand(Response *response) { diff --git a/src/Connection.h b/src/Connection.h index ceebeea..12f4f53 100644 --- a/src/Connection.h +++ b/src/Connection.h @@ -33,5 +33,7 @@ class Connection : public QObject { int m_argumentsExpected; WebPage *m_page; int m_expectingDataSize; + bool m_pageSuccess; + bool m_commandWaiting; };