Page succeeds only when all loadFinished events succeed.

This commit is contained in:
Joshua Napoli 2012-04-26 16:05:19 -04:00 committed by Joe Ferris
parent 18655cb4e0
commit 7a1dbe26eb
3 changed files with 54 additions and 10 deletions

View File

@ -1670,4 +1670,45 @@ describe Capybara::Driver::Webkit do
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 File

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

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