capybara-webkit 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/GOALS +9 -0
- data/Gemfile.lock +15 -12
- data/LICENSE +1 -1
- data/NEWS.md +18 -0
- data/README.md +81 -2
- data/capybara-webkit.gemspec +1 -1
- data/lib/capybara/webkit.rb +11 -6
- data/lib/capybara/{driver/webkit → webkit}/browser.rb +90 -4
- data/lib/capybara/{driver/webkit → webkit}/connection.rb +48 -47
- data/lib/capybara/{driver/webkit → webkit}/cookie_jar.rb +1 -1
- data/lib/capybara/webkit/driver.rb +186 -0
- data/lib/capybara/webkit/errors.rb +10 -0
- data/lib/capybara/{driver/webkit → webkit}/node.rb +12 -4
- data/lib/capybara/{driver/webkit → webkit}/socket_debugger.rb +4 -1
- data/lib/capybara/{driver/webkit → webkit}/version.rb +1 -1
- data/lib/capybara_webkit_builder.rb +17 -3
- data/spec/browser_spec.rb +95 -7
- data/spec/connection_spec.rb +16 -5
- data/spec/cookie_jar_spec.rb +3 -3
- data/spec/driver_rendering_spec.rb +19 -26
- data/spec/driver_resize_window_spec.rb +3 -3
- data/spec/driver_spec.rb +1200 -822
- data/spec/integration/driver_spec.rb +4 -3
- data/spec/selenium_compatibility_spec.rb +49 -0
- data/spec/spec_helper.rb +14 -6
- data/spec/support/app_runner.rb +94 -0
- data/src/Authenticate.cpp +18 -0
- data/src/Authenticate.h +12 -0
- data/src/Body.h +3 -5
- data/src/ClearCookies.cpp +3 -5
- data/src/ClearCookies.h +3 -5
- data/src/ClearPromptText.cpp +11 -0
- data/src/ClearPromptText.h +9 -0
- data/src/Command.cpp +4 -15
- data/src/Command.h +3 -14
- data/src/CommandFactory.cpp +20 -6
- data/src/CommandFactory.h +3 -2
- data/src/CommandParser.cpp +1 -1
- data/src/Connection.cpp +22 -21
- data/src/Connection.h +5 -6
- data/src/ConsoleMessages.cpp +2 -1
- data/src/ConsoleMessages.h +3 -5
- data/src/CurrentUrl.cpp +9 -48
- data/src/CurrentUrl.h +8 -8
- data/src/EnableLogging.cpp +10 -0
- data/src/EnableLogging.h +12 -0
- data/src/Evaluate.cpp +2 -1
- data/src/Evaluate.h +3 -5
- data/src/Execute.cpp +2 -1
- data/src/Execute.h +3 -5
- data/src/Find.cpp +3 -2
- data/src/Find.h +3 -5
- data/src/FrameFocus.cpp +3 -2
- data/src/FrameFocus.h +3 -4
- data/src/GetCookies.cpp +3 -4
- data/src/GetCookies.h +3 -5
- data/src/GetTimeout.cpp +9 -0
- data/src/GetTimeout.h +11 -0
- data/src/GetWindowHandle.cpp +11 -0
- data/src/GetWindowHandle.h +10 -0
- data/src/GetWindowHandles.cpp +20 -0
- data/src/GetWindowHandles.h +10 -0
- data/src/Header.cpp +2 -1
- data/src/Header.h +3 -5
- data/src/Headers.cpp +8 -2
- data/src/Headers.h +3 -5
- data/src/IgnoreSslErrors.cpp +4 -3
- data/src/IgnoreSslErrors.h +3 -5
- data/src/JavascriptAlertMessages.cpp +10 -0
- data/src/JavascriptAlertMessages.h +9 -0
- data/src/JavascriptConfirmMessages.cpp +10 -0
- data/src/JavascriptConfirmMessages.h +9 -0
- data/src/JavascriptInvocation.cpp +1 -1
- data/src/JavascriptInvocation.h +1 -1
- data/src/JavascriptPromptMessages.cpp +10 -0
- data/src/JavascriptPromptMessages.h +9 -0
- data/src/NetworkAccessManager.cpp +38 -5
- data/src/NetworkAccessManager.h +20 -0
- data/src/Node.cpp +6 -1
- data/src/Node.h +4 -5
- data/src/NullCommand.cpp +5 -2
- data/src/NullCommand.h +4 -3
- data/src/PageLoadingCommand.cpp +12 -7
- data/src/PageLoadingCommand.h +6 -9
- data/src/Render.cpp +2 -1
- data/src/Render.h +3 -5
- data/src/RequestedUrl.cpp +2 -1
- data/src/RequestedUrl.h +3 -5
- data/src/Reset.cpp +3 -17
- data/src/Reset.h +3 -8
- data/src/ResizeWindow.cpp +2 -1
- data/src/ResizeWindow.h +3 -5
- data/src/Response.cpp +4 -0
- data/src/Response.h +1 -0
- data/src/Server.cpp +2 -3
- data/src/Server.h +0 -2
- data/src/SetConfirmAction.cpp +11 -0
- data/src/SetConfirmAction.h +9 -0
- data/src/SetCookie.cpp +3 -4
- data/src/SetCookie.h +3 -5
- data/src/SetPromptAction.cpp +11 -0
- data/src/SetPromptAction.h +9 -0
- data/src/SetPromptText.cpp +11 -0
- data/src/SetPromptText.h +9 -0
- data/src/SetProxy.cpp +2 -1
- data/src/SetProxy.h +3 -5
- data/src/SetSkipImageLoading.cpp +12 -0
- data/src/SetSkipImageLoading.h +9 -0
- data/src/SetTimeout.cpp +19 -0
- data/src/SetTimeout.h +9 -0
- data/src/SocketCommand.cpp +21 -0
- data/src/SocketCommand.h +29 -0
- data/src/Source.cpp +3 -2
- data/src/Source.h +3 -4
- data/src/Status.cpp +2 -1
- data/src/Status.h +3 -5
- data/src/TimeoutCommand.cpp +69 -0
- data/src/TimeoutCommand.h +41 -0
- data/src/UnsupportedContentHandler.cpp +11 -17
- data/src/UnsupportedContentHandler.h +5 -3
- data/src/Url.cpp +2 -1
- data/src/Url.h +3 -5
- data/src/Visit.cpp +3 -2
- data/src/Visit.h +3 -5
- data/src/WebPage.cpp +129 -44
- data/src/WebPage.h +37 -11
- data/src/WebPageManager.cpp +127 -0
- data/src/WebPageManager.h +59 -0
- data/src/WindowFocus.cpp +32 -0
- data/src/WindowFocus.h +15 -0
- data/src/body.cpp +2 -1
- data/src/capybara.js +38 -10
- data/src/find_command.h +17 -2
- data/src/main.cpp +0 -2
- data/src/webkit_server.pro +36 -0
- data/templates/Command.cpp +2 -4
- data/templates/Command.h +3 -3
- metadata +106 -27
- data/ChangeLog +0 -70
- data/lib/capybara/driver/webkit.rb +0 -136
data/src/Status.h
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
#include "
|
1
|
+
#include "SocketCommand.h"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
5
|
-
class Status : public Command {
|
3
|
+
class Status : public SocketCommand {
|
6
4
|
Q_OBJECT
|
7
5
|
|
8
6
|
public:
|
9
|
-
Status(
|
7
|
+
Status(WebPageManager *, QStringList &arguments, QObject *parent = 0);
|
10
8
|
virtual void start();
|
11
9
|
};
|
12
10
|
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#include "TimeoutCommand.h"
|
2
|
+
#include "Command.h"
|
3
|
+
#include "WebPageManager.h"
|
4
|
+
#include "WebPage.h"
|
5
|
+
#include <QTimer>
|
6
|
+
|
7
|
+
TimeoutCommand::TimeoutCommand(Command *command, WebPageManager *manager, QObject *parent) : Command(parent) {
|
8
|
+
m_command = command;
|
9
|
+
m_manager = manager;
|
10
|
+
m_timer = new QTimer(this);
|
11
|
+
m_timer->setSingleShot(true);
|
12
|
+
connect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
|
13
|
+
connect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
|
14
|
+
}
|
15
|
+
|
16
|
+
void TimeoutCommand::start() {
|
17
|
+
if (m_manager->isLoading()) {
|
18
|
+
m_manager->logger() << this->toString() << "waiting for load to finish";
|
19
|
+
connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
20
|
+
startTimeout();
|
21
|
+
} else {
|
22
|
+
startCommand();
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
void TimeoutCommand::startCommand() {
|
27
|
+
connect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
|
28
|
+
m_command->start();
|
29
|
+
}
|
30
|
+
|
31
|
+
void TimeoutCommand::startTimeout() {
|
32
|
+
int timeout = m_manager->getTimeout();
|
33
|
+
if (timeout > 0) {
|
34
|
+
m_timer->start(timeout * 1000);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
void TimeoutCommand::pendingLoadFinished(bool success) {
|
39
|
+
if (success) {
|
40
|
+
startCommand();
|
41
|
+
} else {
|
42
|
+
disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
|
43
|
+
disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
|
44
|
+
disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
45
|
+
emit finished(new Response(false, m_manager->currentPage()->failureString()));
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
void TimeoutCommand::pageLoadingFromCommand() {
|
50
|
+
startTimeout();
|
51
|
+
}
|
52
|
+
|
53
|
+
void TimeoutCommand::commandTimeout() {
|
54
|
+
disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
|
55
|
+
disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
56
|
+
disconnect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
|
57
|
+
m_manager->currentPage()->triggerAction(QWebPage::Stop);
|
58
|
+
m_command->deleteLater();
|
59
|
+
emit finished(new Response(false, QString("timeout")));
|
60
|
+
}
|
61
|
+
|
62
|
+
void TimeoutCommand::commandFinished(Response *response) {
|
63
|
+
disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
|
64
|
+
disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
|
65
|
+
disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
66
|
+
m_command->deleteLater();
|
67
|
+
emit finished(response);
|
68
|
+
}
|
69
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#include "Command.h"
|
2
|
+
#include <QObject>
|
3
|
+
#include <QStringList>
|
4
|
+
|
5
|
+
class Response;
|
6
|
+
class WebPageManager;
|
7
|
+
class QTimer;
|
8
|
+
|
9
|
+
/* Decorates a command with a timeout.
|
10
|
+
*
|
11
|
+
* If the timeout, using a QTimer is reached before
|
12
|
+
* the command is finished, the load page load will
|
13
|
+
* be stopped and failure response will be issued.
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
class TimeoutCommand : public Command {
|
17
|
+
Q_OBJECT
|
18
|
+
|
19
|
+
public:
|
20
|
+
TimeoutCommand(Command *command, WebPageManager *page, QObject *parent = 0);
|
21
|
+
virtual void start();
|
22
|
+
|
23
|
+
public slots:
|
24
|
+
void commandTimeout();
|
25
|
+
void commandFinished(Response *response);
|
26
|
+
void pageLoadingFromCommand();
|
27
|
+
void pendingLoadFinished(bool);
|
28
|
+
|
29
|
+
signals:
|
30
|
+
void finished(Response *response);
|
31
|
+
|
32
|
+
protected:
|
33
|
+
void startCommand();
|
34
|
+
void startTimeout();
|
35
|
+
|
36
|
+
private:
|
37
|
+
WebPageManager *m_manager;
|
38
|
+
QTimer *m_timer;
|
39
|
+
Command *m_command;
|
40
|
+
};
|
41
|
+
|
@@ -5,28 +5,22 @@
|
|
5
5
|
UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkReply *reply, QObject *parent) : QObject(parent) {
|
6
6
|
m_page = page;
|
7
7
|
m_reply = reply;
|
8
|
-
connect(m_reply, SIGNAL(finished()), this, SLOT(handleUnsupportedContent()));
|
9
|
-
disconnect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
|
10
8
|
}
|
11
9
|
|
12
|
-
void UnsupportedContentHandler::
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
this->loadUnsupportedContent();
|
18
|
-
this->finish(true);
|
19
|
-
}
|
10
|
+
void UnsupportedContentHandler::renderNonHtmlContent() {
|
11
|
+
QByteArray text = m_reply->readAll();
|
12
|
+
m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
|
13
|
+
m_page->networkAccessManagerFinishedReply(m_reply);
|
14
|
+
m_page->loadFinished(true);
|
20
15
|
this->deleteLater();
|
21
16
|
}
|
22
17
|
|
23
|
-
void UnsupportedContentHandler::
|
24
|
-
|
25
|
-
|
18
|
+
void UnsupportedContentHandler::waitForReplyToFinish() {
|
19
|
+
connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
|
20
|
+
disconnect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
|
26
21
|
}
|
27
22
|
|
28
|
-
void UnsupportedContentHandler::
|
29
|
-
|
30
|
-
|
31
|
-
m_page->loadFinished(success);
|
23
|
+
void UnsupportedContentHandler::replyFinished() {
|
24
|
+
renderNonHtmlContent();
|
25
|
+
connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
|
32
26
|
}
|
@@ -1,18 +1,20 @@
|
|
1
1
|
#include <QObject>
|
2
|
+
|
2
3
|
class WebPage;
|
3
4
|
class QNetworkReply;
|
5
|
+
|
4
6
|
class UnsupportedContentHandler : public QObject {
|
5
7
|
Q_OBJECT
|
6
8
|
|
7
9
|
public:
|
8
10
|
UnsupportedContentHandler(WebPage *page, QNetworkReply *reply, QObject *parent = 0);
|
11
|
+
void waitForReplyToFinish();
|
12
|
+
void renderNonHtmlContent();
|
9
13
|
|
10
14
|
public slots:
|
11
|
-
void
|
15
|
+
void replyFinished();
|
12
16
|
|
13
17
|
private:
|
14
18
|
WebPage *m_page;
|
15
19
|
QNetworkReply *m_reply;
|
16
|
-
void loadUnsupportedContent();
|
17
|
-
void finish(bool success);
|
18
20
|
};
|
data/src/Url.cpp
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#include "Url.h"
|
2
2
|
#include "WebPage.h"
|
3
|
+
#include "WebPageManager.h"
|
3
4
|
|
4
|
-
Url::Url(
|
5
|
+
Url::Url(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
|
5
6
|
}
|
6
7
|
|
7
8
|
void Url::start() {
|
data/src/Url.h
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
#include "
|
1
|
+
#include "SocketCommand.h"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
5
|
-
class Url : public Command {
|
3
|
+
class Url : public SocketCommand {
|
6
4
|
Q_OBJECT
|
7
5
|
|
8
6
|
public:
|
9
|
-
Url(
|
7
|
+
Url(WebPageManager *, QStringList &arguments, QObject *parent = 0);
|
10
8
|
virtual void start();
|
11
9
|
};
|
12
10
|
|
data/src/Visit.cpp
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
#include "Visit.h"
|
2
|
-
#include "
|
2
|
+
#include "SocketCommand.h"
|
3
3
|
#include "WebPage.h"
|
4
|
+
#include "WebPageManager.h"
|
4
5
|
|
5
|
-
Visit::Visit(
|
6
|
+
Visit::Visit(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
|
6
7
|
}
|
7
8
|
|
8
9
|
void Visit::start() {
|
data/src/Visit.h
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
#include "
|
1
|
+
#include "SocketCommand.h"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
5
|
-
class Visit : public Command {
|
3
|
+
class Visit : public SocketCommand {
|
6
4
|
Q_OBJECT
|
7
5
|
|
8
6
|
public:
|
9
|
-
Visit(
|
7
|
+
Visit(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
|
10
8
|
virtual void start();
|
11
9
|
};
|
12
10
|
|
data/src/WebPage.cpp
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
#include "WebPage.h"
|
2
|
+
#include "WebPageManager.h"
|
2
3
|
#include "JavascriptInvocation.h"
|
3
4
|
#include "NetworkAccessManager.h"
|
4
5
|
#include "NetworkCookieJar.h"
|
5
6
|
#include "UnsupportedContentHandler.h"
|
6
7
|
#include <QResource>
|
7
8
|
#include <iostream>
|
9
|
+
#include <QWebSettings>
|
10
|
+
#include <QUuid>
|
11
|
+
|
12
|
+
WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
|
13
|
+
m_loading = false;
|
14
|
+
m_failed = false;
|
15
|
+
m_manager = manager;
|
16
|
+
m_uuid = QUuid::createUuid().toString();
|
8
17
|
|
9
|
-
WebPage::WebPage(QObject *parent) : QWebPage(parent) {
|
10
18
|
setForwardUnsupportedContent(true);
|
11
19
|
loadJavascript();
|
12
20
|
setUserStylesheet();
|
13
21
|
|
14
|
-
|
15
|
-
|
22
|
+
m_confirm = true;
|
23
|
+
m_prompt = false;
|
24
|
+
m_prompt_text = QString();
|
16
25
|
this->setCustomNetworkAccessManager();
|
17
26
|
|
18
27
|
connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
|
@@ -22,6 +31,9 @@ WebPage::WebPage(QObject *parent) : QWebPage(parent) {
|
|
22
31
|
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)),
|
23
32
|
this, SLOT(handleUnsupportedContent(QNetworkReply*)));
|
24
33
|
resetWindowSize();
|
34
|
+
|
35
|
+
settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
|
36
|
+
currentFrame()->setUrl(QUrl("about:blank"));
|
25
37
|
}
|
26
38
|
|
27
39
|
void WebPage::resetWindowSize() {
|
@@ -30,12 +42,21 @@ void WebPage::resetWindowSize() {
|
|
30
42
|
}
|
31
43
|
|
32
44
|
void WebPage::setCustomNetworkAccessManager() {
|
33
|
-
NetworkAccessManager *manager = new NetworkAccessManager();
|
34
|
-
manager->setCookieJar(
|
45
|
+
NetworkAccessManager *manager = new NetworkAccessManager(this);
|
46
|
+
manager->setCookieJar(m_manager->cookieJar());
|
35
47
|
this->setNetworkAccessManager(manager);
|
36
|
-
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(
|
48
|
+
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(networkAccessManagerFinishedReply(QNetworkReply *)));
|
37
49
|
connect(manager, SIGNAL(sslErrors(QNetworkReply *, QList<QSslError>)),
|
38
50
|
this, SLOT(handleSslErrorsForReply(QNetworkReply *, QList<QSslError>)));
|
51
|
+
connect(manager, SIGNAL(requestCreated(QByteArray &, QNetworkReply *)), this, SLOT(networkAccessManagerCreatedRequest(QByteArray &, QNetworkReply *)));
|
52
|
+
}
|
53
|
+
|
54
|
+
void WebPage::networkAccessManagerCreatedRequest(QByteArray &url, QNetworkReply *reply) {
|
55
|
+
emit requestCreated(url, reply);
|
56
|
+
}
|
57
|
+
|
58
|
+
void WebPage::networkAccessManagerFinishedReply(QNetworkReply *reply) {
|
59
|
+
emit replyFinished(reply);
|
39
60
|
}
|
40
61
|
|
41
62
|
void WebPage::loadJavascript() {
|
@@ -69,6 +90,18 @@ QString WebPage::consoleMessages() {
|
|
69
90
|
return m_consoleMessages.join("\n");
|
70
91
|
}
|
71
92
|
|
93
|
+
QString WebPage::alertMessages() {
|
94
|
+
return m_alertMessages.join("\n");
|
95
|
+
}
|
96
|
+
|
97
|
+
QString WebPage::confirmMessages() {
|
98
|
+
return m_confirmMessages.join("\n");
|
99
|
+
}
|
100
|
+
|
101
|
+
QString WebPage::promptMessages() {
|
102
|
+
return m_promptMessages.join("\n");
|
103
|
+
}
|
104
|
+
|
72
105
|
void WebPage::setUserAgent(QString userAgent) {
|
73
106
|
m_userAgent = userAgent;
|
74
107
|
}
|
@@ -87,7 +120,7 @@ bool WebPage::shouldInterruptJavaScript() {
|
|
87
120
|
return false;
|
88
121
|
}
|
89
122
|
|
90
|
-
QVariant WebPage::invokeCapybaraFunction(const char *name, QStringList &arguments) {
|
123
|
+
QVariant WebPage::invokeCapybaraFunction(const char *name, const QStringList &arguments) {
|
91
124
|
QString qname(name);
|
92
125
|
QString objectName("CapybaraInvocation");
|
93
126
|
JavascriptInvocation invocation(qname, arguments);
|
@@ -96,7 +129,7 @@ QVariant WebPage::invokeCapybaraFunction(const char *name, QStringList &argument
|
|
96
129
|
return currentFrame()->evaluateJavaScript(javascript);
|
97
130
|
}
|
98
131
|
|
99
|
-
QVariant WebPage::invokeCapybaraFunction(QString &name, QStringList &arguments) {
|
132
|
+
QVariant WebPage::invokeCapybaraFunction(QString &name, const QStringList &arguments) {
|
100
133
|
return invokeCapybaraFunction(name.toAscii().data(), arguments);
|
101
134
|
}
|
102
135
|
|
@@ -110,30 +143,39 @@ void WebPage::javaScriptConsoleMessage(const QString &message, int lineNumber, c
|
|
110
143
|
|
111
144
|
void WebPage::javaScriptAlert(QWebFrame *frame, const QString &message) {
|
112
145
|
Q_UNUSED(frame);
|
146
|
+
m_alertMessages.append(message);
|
113
147
|
std::cout << "ALERT: " << qPrintable(message) << std::endl;
|
114
148
|
}
|
115
149
|
|
116
150
|
bool WebPage::javaScriptConfirm(QWebFrame *frame, const QString &message) {
|
117
151
|
Q_UNUSED(frame);
|
118
|
-
|
119
|
-
return
|
152
|
+
m_confirmMessages.append(message);
|
153
|
+
return m_confirm;
|
120
154
|
}
|
121
155
|
|
122
156
|
bool WebPage::javaScriptPrompt(QWebFrame *frame, const QString &message, const QString &defaultValue, QString *result) {
|
123
157
|
Q_UNUSED(frame)
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
158
|
+
m_promptMessages.append(message);
|
159
|
+
if (m_prompt) {
|
160
|
+
if (m_prompt_text.isNull()) {
|
161
|
+
*result = defaultValue;
|
162
|
+
} else {
|
163
|
+
*result = m_prompt_text;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
return m_prompt;
|
128
167
|
}
|
129
168
|
|
130
169
|
void WebPage::loadStarted() {
|
131
170
|
m_loading = true;
|
171
|
+
m_errorPageMessage = QString();
|
132
172
|
}
|
133
173
|
|
134
174
|
void WebPage::loadFinished(bool success) {
|
175
|
+
Q_UNUSED(success);
|
135
176
|
m_loading = false;
|
136
|
-
emit pageFinished(
|
177
|
+
emit pageFinished(!m_failed);
|
178
|
+
m_failed = false;
|
137
179
|
}
|
138
180
|
|
139
181
|
bool WebPage::isLoading() const {
|
@@ -141,7 +183,11 @@ bool WebPage::isLoading() const {
|
|
141
183
|
}
|
142
184
|
|
143
185
|
QString WebPage::failureString() {
|
144
|
-
|
186
|
+
QString message = QString("Unable to load URL: ") + currentFrame()->requestedUrl().toString();
|
187
|
+
if (m_errorPageMessage.isEmpty())
|
188
|
+
return message;
|
189
|
+
else
|
190
|
+
return message + m_errorPageMessage;
|
145
191
|
}
|
146
192
|
|
147
193
|
bool WebPage::render(const QString &fileName) {
|
@@ -179,12 +225,17 @@ QString WebPage::chooseFile(QWebFrame *parentFrame, const QString &suggestedFile
|
|
179
225
|
}
|
180
226
|
|
181
227
|
bool WebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) {
|
182
|
-
Q_UNUSED(option);
|
183
228
|
if (extension == ChooseMultipleFilesExtension) {
|
184
229
|
QStringList names = QStringList() << getLastAttachedFileName();
|
185
230
|
static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = names;
|
186
231
|
return true;
|
187
232
|
}
|
233
|
+
else if (extension == QWebPage::ErrorPageExtension) {
|
234
|
+
ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option;
|
235
|
+
m_errorPageMessage = " because of error loading " + errorOption->url.toString() + ": " + errorOption->errorString;
|
236
|
+
m_failed = true;
|
237
|
+
return false;
|
238
|
+
}
|
188
239
|
return false;
|
189
240
|
}
|
190
241
|
|
@@ -192,48 +243,82 @@ QString WebPage::getLastAttachedFileName() {
|
|
192
243
|
return currentFrame()->evaluateJavaScript(QString("Capybara.lastAttachedFile")).toString();
|
193
244
|
}
|
194
245
|
|
195
|
-
void WebPage::
|
196
|
-
if (
|
197
|
-
|
198
|
-
|
199
|
-
QList<QByteArray> list = reply->rawHeaderList();
|
246
|
+
void WebPage::handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &errors) {
|
247
|
+
if (m_manager->ignoreSslErrors())
|
248
|
+
reply->ignoreSslErrors(errors);
|
249
|
+
}
|
200
250
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
251
|
+
void WebPage::setSkipImageLoading(bool skip) {
|
252
|
+
settings()->setAttribute(QWebSettings::AutoLoadImages, !skip);
|
253
|
+
}
|
254
|
+
|
255
|
+
int WebPage::getLastStatus() {
|
256
|
+
return qobject_cast<NetworkAccessManager *>(networkAccessManager())->statusFor(currentFrame()->url());
|
257
|
+
}
|
205
258
|
|
206
|
-
|
259
|
+
const QList<QNetworkReply::RawHeaderPair> &WebPage::pageHeaders() {
|
260
|
+
return qobject_cast<NetworkAccessManager *>(networkAccessManager())->headersFor(currentFrame()->url());
|
261
|
+
}
|
262
|
+
|
263
|
+
void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
|
264
|
+
QVariant contentMimeType = reply->header(QNetworkRequest::ContentTypeHeader);
|
265
|
+
if(!contentMimeType.isNull()) {
|
266
|
+
triggerAction(QWebPage::Stop);
|
267
|
+
UnsupportedContentHandler *handler = new UnsupportedContentHandler(this, reply);
|
268
|
+
if (reply->isFinished())
|
269
|
+
handler->renderNonHtmlContent();
|
270
|
+
else
|
271
|
+
handler->waitForReplyToFinish();
|
207
272
|
}
|
208
273
|
}
|
209
274
|
|
210
|
-
|
211
|
-
if (
|
212
|
-
|
275
|
+
bool WebPage::supportsExtension(Extension extension) const {
|
276
|
+
if (extension == ErrorPageExtension)
|
277
|
+
return true;
|
278
|
+
else if (extension == ChooseMultipleFilesExtension)
|
279
|
+
return true;
|
280
|
+
else
|
281
|
+
return false;
|
213
282
|
}
|
214
283
|
|
215
|
-
|
216
|
-
|
284
|
+
QWebPage *WebPage::createWindow(WebWindowType type) {
|
285
|
+
Q_UNUSED(type);
|
286
|
+
return m_manager->createPage(this);
|
217
287
|
}
|
218
288
|
|
219
|
-
|
220
|
-
return
|
289
|
+
QString WebPage::uuid() {
|
290
|
+
return m_uuid;
|
221
291
|
}
|
222
292
|
|
223
|
-
|
224
|
-
|
225
|
-
|
293
|
+
QString WebPage::getWindowName() {
|
294
|
+
QVariant windowName = mainFrame()->evaluateJavaScript("window.name");
|
295
|
+
|
296
|
+
if (windowName.isValid())
|
297
|
+
return windowName.toString();
|
298
|
+
else
|
299
|
+
return "";
|
226
300
|
}
|
227
301
|
|
228
|
-
|
229
|
-
|
302
|
+
bool WebPage::matchesWindowSelector(QString selector) {
|
303
|
+
return (selector == getWindowName() ||
|
304
|
+
selector == mainFrame()->title() ||
|
305
|
+
selector == mainFrame()->url().toString() ||
|
306
|
+
selector == uuid());
|
230
307
|
}
|
231
308
|
|
232
|
-
|
233
|
-
|
309
|
+
void WebPage::setFocus() {
|
310
|
+
m_manager->setCurrentPage(this);
|
234
311
|
}
|
235
312
|
|
236
|
-
void WebPage::
|
237
|
-
|
238
|
-
Q_UNUSED(handler);
|
313
|
+
void WebPage::setConfirmAction(QString action) {
|
314
|
+
m_confirm = (action == "Yes");
|
239
315
|
}
|
316
|
+
|
317
|
+
void WebPage::setPromptAction(QString action) {
|
318
|
+
m_prompt = (action == "Yes");
|
319
|
+
}
|
320
|
+
|
321
|
+
void WebPage::setPromptText(QString text) {
|
322
|
+
m_prompt_text = text;
|
323
|
+
}
|
324
|
+
|