diff --git a/spec/browser_spec.rb b/spec/browser_spec.rb index 2bd379f..5cc0325 100644 --- a/spec/browser_spec.rb +++ b/spec/browser_spec.rb @@ -1,8 +1,7 @@ require 'spec_helper' require 'self_signed_ssl_cert' require 'stringio' -require 'capybara/driver/webkit/browser' -require 'capybara/driver/webkit/connection' +require 'capybara/driver/webkit' require 'socket' require 'base64' @@ -62,6 +61,18 @@ describe Capybara::Driver::Webkit::Browser do it 'accepts a self-signed certificate if configured to do so' do browser_ignore_ssl_err.visit "https://#{@host}:#{@port}/" end + + it "doesn't accept a self-signed certificate in a new window by default" do + browser.execute_script("window.open('about:blank')") + browser.window_focus(browser.get_window_handles.last) + lambda { browser.visit "https://#{@host}:#{@port}/" }.should raise_error + end + + it 'accepts a self-signed certificate in a new window if configured to do so' do + browser_ignore_ssl_err.execute_script("window.open('about:blank')") + browser_ignore_ssl_err.window_focus(browser_ignore_ssl_err.get_window_handles.last) + browser_ignore_ssl_err.visit "https://#{@host}:#{@port}/" + end end context "skip image loading" do diff --git a/src/IgnoreSslErrors.cpp b/src/IgnoreSslErrors.cpp index 2c71000..36f7279 100644 --- a/src/IgnoreSslErrors.cpp +++ b/src/IgnoreSslErrors.cpp @@ -7,7 +7,7 @@ IgnoreSslErrors::IgnoreSslErrors(WebPageManager *manager, QStringList &arguments } void IgnoreSslErrors::start() { - page()->ignoreSslErrors(); + manager()->setIgnoreSslErrors(true); emit finished(new Response(true)); } diff --git a/src/WebPage.cpp b/src/WebPage.cpp index c68c268..63955ed 100644 --- a/src/WebPage.cpp +++ b/src/WebPage.cpp @@ -10,14 +10,14 @@ #include WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) { + m_loading = false; m_manager = manager; + m_uuid = QUuid::createUuid().toString(); setForwardUnsupportedContent(true); loadJavascript(); setUserStylesheet(); - m_loading = false; - m_ignoreSslErrors = false; this->setCustomNetworkAccessManager(); connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted())); @@ -31,8 +31,6 @@ WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) { resetWindowSize(); settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true); - - m_uuid = QUuid::createUuid().toString(); } void WebPage::resetWindowSize() { @@ -219,14 +217,10 @@ void WebPage::replyFinished(QNetworkReply *reply) { } void WebPage::handleSslErrorsForReply(QNetworkReply *reply, const QList &errors) { - if (m_ignoreSslErrors) + if (m_manager->ignoreSslErrors()) reply->ignoreSslErrors(errors); } -void WebPage::ignoreSslErrors() { - m_ignoreSslErrors = true; -} - void WebPage::setSkipImageLoading(bool skip) { settings()->setAttribute(QWebSettings::AutoLoadImages, !skip); } diff --git a/src/WebPage.h b/src/WebPage.h index 8e525a2..c4e196e 100644 --- a/src/WebPage.h +++ b/src/WebPage.h @@ -19,7 +19,6 @@ class WebPage : public QWebPage { void setCustomNetworkAccessManager(); bool render(const QString &fileName); virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0); - void ignoreSslErrors(); void setSkipImageLoading(bool skip); QString consoleMessages(); void resetConsoleMessages(); @@ -61,7 +60,6 @@ class WebPage : public QWebPage { void setUserStylesheet(); int m_lastStatus; QString m_pageHeaders; - bool m_ignoreSslErrors; QStringList m_consoleMessages; QString m_uuid; WebPageManager *m_manager; diff --git a/src/WebPageManager.cpp b/src/WebPageManager.cpp index 40764f2..be70076 100644 --- a/src/WebPageManager.cpp +++ b/src/WebPageManager.cpp @@ -33,3 +33,11 @@ void WebPageManager::emitPageFinished(bool success) { if (currentPage() == sender()) emit pageFinished(success); } + +void WebPageManager::setIgnoreSslErrors(bool value) { + m_ignoreSslErrors = value; +} + +bool WebPageManager::ignoreSslErrors() { + return m_ignoreSslErrors; +} diff --git a/src/WebPageManager.h b/src/WebPageManager.h index d510387..1de830b 100644 --- a/src/WebPageManager.h +++ b/src/WebPageManager.h @@ -14,7 +14,9 @@ class WebPageManager : public QObject { QListIterator iterator(); void setCurrentPage(WebPage *); WebPage *currentPage(); - WebPage *createPage(QObject *); + WebPage *createPage(QObject *parent); + void setIgnoreSslErrors(bool); + bool ignoreSslErrors(); public slots: void emitPageFinished(bool);