Fixed subsequent failures when a page fails quickly before the next command begins

This commit is contained in:
Joe Ferris 2011-05-05 18:27:04 -04:00
parent cc74875e4b
commit 728feeeff7
3 changed files with 31 additions and 19 deletions

View File

@ -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

View File

@ -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) {

View File

@ -33,5 +33,7 @@ class Connection : public QObject {
int m_argumentsExpected;
WebPage *m_page;
int m_expectingDataSize;
bool m_pageSuccess;
bool m_commandWaiting;
};