New windows should respect ignore_ssl_errors

This commit is contained in:
Matthew Horan 2012-03-30 15:00:51 -04:00
parent f80125e6cb
commit 8f8c95d980
6 changed files with 28 additions and 15 deletions

View File

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

View File

@ -7,7 +7,7 @@ IgnoreSslErrors::IgnoreSslErrors(WebPageManager *manager, QStringList &arguments
}
void IgnoreSslErrors::start() {
page()->ignoreSslErrors();
manager()->setIgnoreSslErrors(true);
emit finished(new Response(true));
}

View File

@ -10,14 +10,14 @@
#include <QUuid>
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<QSslError> &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);
}

View File

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

View File

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

View File

@ -14,7 +14,9 @@ class WebPageManager : public QObject {
QListIterator<WebPage *> iterator();
void setCurrentPage(WebPage *);
WebPage *currentPage();
WebPage *createPage(QObject *);
WebPage *createPage(QObject *parent);
void setIgnoreSslErrors(bool);
bool ignoreSslErrors();
public slots:
void emitPageFinished(bool);