diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index 115a944..1dd1f5d 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -104,6 +104,35 @@ describe Capybara::Driver::Webkit do end end + context "error iframe app" do + before(:all) do + @app = lambda do |env| + case env["PATH_INFO"] + when "/inner-not-found" + [404, {}, []] + when "/outer" + body = <<-HTML + + + + + + HTML + [200, + { 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s }, + [body]] + else + body = "" + return [200, {'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s}, [body]] + end + end + end + + it "raises error whose message references the actual missing url" do + expect { subject.visit("/outer") }.to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError, /inner-not-found/) + end + end + context "redirect app" do before(:all) do @app = lambda do |env| diff --git a/src/WebPage.cpp b/src/WebPage.cpp index c0f3469..b269fb5 100644 --- a/src/WebPage.cpp +++ b/src/WebPage.cpp @@ -141,6 +141,7 @@ bool WebPage::javaScriptPrompt(QWebFrame *frame, const QString &message, const Q void WebPage::loadStarted() { m_loading = true; + m_errorPageMessage = QString(); } void WebPage::loadFinished(bool success) { @@ -153,7 +154,11 @@ bool WebPage::isLoading() const { } QString WebPage::failureString() { - return QString("Unable to load URL: ") + currentFrame()->requestedUrl().toString(); + QString message = QString("Unable to load URL: ") + currentFrame()->requestedUrl().toString(); + if(m_errorPageMessage.isEmpty()) + return message; + else + return message + ": " + m_errorPageMessage; } bool WebPage::render(const QString &fileName) { @@ -191,12 +196,16 @@ QString WebPage::chooseFile(QWebFrame *parentFrame, const QString &suggestedFile } bool WebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) { - Q_UNUSED(option); if (extension == ChooseMultipleFilesExtension) { QStringList names = QStringList() << getLastAttachedFileName(); static_cast(output)->fileNames = names; return true; } + else if (extension == QWebPage::ErrorPageExtension) { + ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option; + m_errorPageMessage = "Because of error loading " + errorOption->url.toString() + ": " + errorOption->errorString; + return false; + } return false; } @@ -269,3 +278,9 @@ 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; +} diff --git a/src/WebPage.h b/src/WebPage.h index f350bb2..b083ee6 100644 --- a/src/WebPage.h +++ b/src/WebPage.h @@ -48,6 +48,7 @@ class WebPage : public QWebPage { virtual bool javaScriptConfirm(QWebFrame *frame, const QString &message); virtual bool javaScriptPrompt(QWebFrame *frame, const QString &message, const QString &defaultValue, QString *result); virtual QString chooseFile(QWebFrame * parentFrame, const QString &suggestedFile); + virtual bool supportsExtension(Extension extension) const; private: QString m_capybaraJavascript; @@ -61,6 +62,7 @@ class WebPage : public QWebPage { QStringList m_consoleMessages; QString m_uuid; WebPageManager *m_manager; + QString m_errorPageMessage; }; #endif //_WEBPAGE_H