Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Try to detect when a command starts a page load and wait for it to fi…
Browse files Browse the repository at this point in the history
…nish
  • Loading branch information
jferris committed Jan 31, 2012
1 parent 0e32d3c commit 18607d0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
17 changes: 8 additions & 9 deletions spec/driver_spec.rb
Expand Up @@ -783,23 +783,22 @@

context "slow app" do
before(:all) do
@result = ""
@app = lambda do |env|
body = <<-HTML
<html><body>
<form action="/next"><input type="submit"/></form>
<p>#{env['PATH_INFO']}</p>
</body></html>
HTML
sleep(0.5)
if env["PATH_INFO"] == "/result"
sleep(0.5)
@result << "finished"
end
body = %{<html><body><a href="/result">Go</a></body></html>}
[200,
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
[body]]
end
end

it "waits for a request to load" do
subject.find("//input").first.click
subject.find("//p").first.text.should == "/next"
subject.find("//a").first.click
@result.should == "finished"
end
end

Expand Down
20 changes: 19 additions & 1 deletion src/Connection.cpp
Expand Up @@ -17,6 +17,8 @@ Connection::Connection(QTcpSocket *socket, WebPage *page, QObject *parent) :
m_command = NULL;
m_pageSuccess = true;
m_commandWaiting = false;
m_pageLoadingFromCommand = false;
m_pendingResponse = NULL;
connect(m_socket, SIGNAL(readyRead()), m_commandParser, SLOT(checkNext()));
connect(m_commandParser, SIGNAL(commandReady(QString, QStringList)), this, SLOT(commandReady(QString, QStringList)));
connect(m_page, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
Expand All @@ -38,6 +40,7 @@ void Connection::startCommand() {
if (m_pageSuccess) {
m_command = m_commandFactory->createCommand(m_commandName.toAscii().constData());
if (m_command) {
connect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
connect(m_command,
SIGNAL(finished(Response *)),
this,
Expand All @@ -55,16 +58,31 @@ void Connection::startCommand() {
}
}

void Connection::pageLoadingFromCommand() {
m_pageLoadingFromCommand = true;
}

void Connection::pendingLoadFinished(bool success) {
m_pageSuccess = success;
if (m_commandWaiting)
startCommand();
if (m_pageLoadingFromCommand) {
m_pageLoadingFromCommand = false;
if (m_pendingResponse) {
writeResponse(m_pendingResponse);
m_pendingResponse = NULL;
}
}
}

void Connection::finishCommand(Response *response) {
disconnect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
m_command->deleteLater();
m_command = NULL;
writeResponse(response);
if (m_pageLoadingFromCommand)
m_pendingResponse = response;
else
writeResponse(response);
}

void Connection::writeResponse(Response *response) {
Expand Down
3 changes: 3 additions & 0 deletions src/Connection.h
Expand Up @@ -18,6 +18,7 @@ class Connection : public QObject {
void commandReady(QString commandName, QStringList arguments);
void finishCommand(Response *response);
void pendingLoadFinished(bool success);
void pageLoadingFromCommand();

private:
void startCommand();
Expand All @@ -32,5 +33,7 @@ class Connection : public QObject {
CommandFactory *m_commandFactory;
bool m_pageSuccess;
bool m_commandWaiting;
bool m_pageLoadingFromCommand;
Response *m_pendingResponse;
};

0 comments on commit 18607d0

Please sign in to comment.