Skip to content
Browse files

Page succeeds only when all loadFinished events succeed.

  • Loading branch information...
1 parent 18655cb commit 7a1dbe26eb943ee47518018c2edb79e8f9035b9a Joshua Napoli committed with jferris Apr 26, 2012
Showing with 54 additions and 10 deletions.
  1. +41 −0 spec/driver_spec.rb
  2. +1 −1 src/Connection.cpp
  3. +12 −9 src/WebPage.cpp
View
41 spec/driver_spec.rb
@@ -1670,4 +1670,45 @@ def which_for(character)
subject.window_handles.should_not include(last_handle)
end
end
+
+ context "timers app" do
+ before(:all) do
+ @app = lambda do |env|
+ case env["PATH_INFO"]
+ when "/success"
+ [200, {'Content-Type' => 'text/html'}, ['<html><body></body></html>']]
+ when "/not-found"
+ [404, {}, []]
+ when "/outer"
+ body = <<-HTML
+ <html>
+ <head>
+ <script>
+ function emit_true_load_finished(){var divTag = document.createElement("div");divTag.innerHTML = "<iframe src='/success'></iframe>";document.body.appendChild(divTag);};
+ function emit_false_load_finished(){var divTag = document.createElement("div");divTag.innerHTML = "<iframe src='/not-found'></iframe>";document.body.appendChild(divTag);};
+ function emit_false_true_load_finished() { emit_false_load_finished(); setTimeout('emit_true_load_finished()',100); };
+ </script>
+ </head>
+ <body onload="setTimeout('emit_false_true_load_finished()',100)">
+ </body>
+ </html>
+ HTML
+ [200,
+ { 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
+ [body]]
+ else
+ body = "<html><body></body></html>"
+ return [200, {'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s}, [body]]
+ end
+ end
+ end
+
+ it "raises error for any loadFinished failure" do
+ expect do
+ subject.visit("/outer")
+ sleep 1
+ subject.find("//body")
+ end.to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError)
+ end
+ end
end
View
2 src/Connection.cpp
@@ -41,7 +41,7 @@ void Connection::startCommand() {
}
void Connection::pendingLoadFinished(bool success) {
- m_pageSuccess = success;
+ m_pageSuccess = m_pageSuccess && success;
if (m_commandWaiting)
startCommand();
}
View
21 src/WebPage.cpp
@@ -155,10 +155,10 @@ bool WebPage::isLoading() const {
QString WebPage::failureString() {
QString message = QString("Unable to load URL: ") + currentFrame()->requestedUrl().toString();
- if(m_errorPageMessage.isEmpty())
+ if (m_errorPageMessage.isEmpty())
return message;
else
- return message + ": " + m_errorPageMessage;
+ return message + m_errorPageMessage;
}
bool WebPage::render(const QString &fileName) {
@@ -203,7 +203,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption *option, Exte
}
else if (extension == QWebPage::ErrorPageExtension) {
ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option;
- m_errorPageMessage = "Because of error loading " + errorOption->url.toString() + ": " + errorOption->errorString;
+ m_errorPageMessage = " because of error loading " + errorOption->url.toString() + ": " + errorOption->errorString;
return false;
}
return false;
@@ -250,6 +250,15 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
Q_UNUSED(handler);
}
+bool WebPage::supportsExtension(Extension extension) const {
+ if (extension == ErrorPageExtension)
+ return true;
+ else if (extension == ChooseMultipleFilesExtension)
+ return true;
+ else
+ return false;
+}
+
QWebPage *WebPage::createWindow(WebWindowType type) {
Q_UNUSED(type);
return m_manager->createPage(this);
@@ -278,9 +287,3 @@ bool WebPage::matchesWindowSelector(QString selector) {
void WebPage::setFocus() {
m_manager->setCurrentPage(this);
}
-
-bool WebPage::supportsExtension(Extension extension) const {
- if(extension == ErrorPageExtension) { return true; }
- else if(extension == ChooseMultipleFilesExtension) { return true; }
- else return false;
-}

0 comments on commit 7a1dbe2

Please sign in to comment.
Something went wrong with that request. Please try again.