capybara-webkit 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -4
- data/Appraisals +0 -8
- data/Gemfile.lock +5 -5
- data/NEWS.md +7 -0
- data/capybara-webkit.gemspec +1 -1
- data/extconf.rb +18 -0
- data/gemfiles/2.3.gemfile.lock +2 -2
- data/gemfiles/2.4.gemfile.lock +2 -2
- data/lib/capybara/webkit/browser.rb +14 -0
- data/lib/capybara/webkit/driver.rb +12 -0
- data/lib/capybara/webkit/version.rb +1 -1
- data/lib/capybara_webkit_builder.rb +18 -2
- data/spec/driver_spec.rb +99 -28
- data/spec/support/app_runner.rb +4 -4
- data/spec/support/output_writer.rb +15 -0
- data/src/AllowUrl.cpp +16 -0
- data/src/AllowUrl.h +10 -0
- data/src/BlacklistedRequestHandler.cpp +56 -0
- data/src/BlacklistedRequestHandler.h +22 -0
- data/src/BlockUrl.cpp +16 -0
- data/src/BlockUrl.h +10 -0
- data/src/CommandFactory.cpp +3 -0
- data/src/CustomHeadersRequestHandler.cpp +37 -0
- data/src/CustomHeadersRequestHandler.h +21 -0
- data/src/Header.cpp +1 -2
- data/src/MissingContentHeaderRequestHandler.cpp +23 -0
- data/src/MissingContentHeaderRequestHandler.h +15 -0
- data/src/NetworkAccessManager.cpp +35 -53
- data/src/NetworkAccessManager.h +14 -9
- data/src/NetworkRequestFactory.cpp +15 -0
- data/src/NetworkRequestFactory.h +12 -0
- data/src/NoOpReply.cpp +1 -1
- data/src/NoOpReply.h +1 -1
- data/src/RequestHandler.cpp +4 -0
- data/src/RequestHandler.h +25 -0
- data/src/SetUnknownUrlMode.cpp +27 -0
- data/src/SetUnknownUrlMode.h +10 -0
- data/src/SetUrlBlacklist.cpp +1 -2
- data/src/SetUrlBlacklist.h +0 -2
- data/src/UnknownUrlHandler.cpp +70 -0
- data/src/UnknownUrlHandler.h +28 -0
- data/src/WebPageManager.cpp +41 -1
- data/src/WebPageManager.h +12 -1
- data/src/capybara.js +2 -1
- data/src/find_command.h +3 -0
- data/src/webkit_server.pro +20 -2
- metadata +23 -10
- data/gemfiles/2.0.gemfile +0 -7
- data/gemfiles/2.0.gemfile.lock +0 -76
- data/gemfiles/2.1.gemfile +0 -7
- data/gemfiles/2.1.gemfile.lock +0 -83
- data/gemfiles/2.2.gemfile +0 -7
- data/gemfiles/2.2.gemfile.lock +0 -77
data/src/AllowUrl.h
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#include "BlacklistedRequestHandler.h"
|
2
|
+
#include "NetworkReplyProxy.h"
|
3
|
+
#include "NoOpReply.h"
|
4
|
+
|
5
|
+
BlacklistedRequestHandler::BlacklistedRequestHandler(
|
6
|
+
RequestHandler *next,
|
7
|
+
QObject *parent
|
8
|
+
) : RequestHandler(parent) {
|
9
|
+
m_next = next;
|
10
|
+
}
|
11
|
+
|
12
|
+
QNetworkReply* BlacklistedRequestHandler::handleRequest(
|
13
|
+
NetworkAccessManager *manager,
|
14
|
+
QNetworkAccessManager::Operation operation,
|
15
|
+
QNetworkRequest &request,
|
16
|
+
QIODevice *outgoingData
|
17
|
+
) {
|
18
|
+
if (this->isBlacklisted(request.url())) {
|
19
|
+
return new NetworkReplyProxy(new NoOpReply(request), this);
|
20
|
+
} else {
|
21
|
+
return m_next->handleRequest(manager, operation, request, outgoingData);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
void BlacklistedRequestHandler::setUrlBlacklist(QStringList urlBlacklist) {
|
26
|
+
m_urlBlacklist.clear();
|
27
|
+
|
28
|
+
QStringListIterator iter(urlBlacklist);
|
29
|
+
while (iter.hasNext()) {
|
30
|
+
m_urlBlacklist << iter.next();
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
bool BlacklistedRequestHandler::isBlacklisted(QUrl url) {
|
35
|
+
QString urlString = url.toString();
|
36
|
+
QStringListIterator iter(m_urlBlacklist);
|
37
|
+
|
38
|
+
while (iter.hasNext()) {
|
39
|
+
QRegExp blacklisted = QRegExp(iter.next());
|
40
|
+
blacklisted.setPatternSyntax(QRegExp::Wildcard);
|
41
|
+
|
42
|
+
if(urlString.contains(blacklisted)) {
|
43
|
+
return true;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
return false;
|
48
|
+
}
|
49
|
+
|
50
|
+
void BlacklistedRequestHandler::blockUrl(const QString &url) {
|
51
|
+
m_urlBlacklist.append(url);
|
52
|
+
}
|
53
|
+
|
54
|
+
void BlacklistedRequestHandler::reset() {
|
55
|
+
m_urlBlacklist.clear();
|
56
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#include <QStringList>
|
2
|
+
|
3
|
+
#include "RequestHandler.h"
|
4
|
+
|
5
|
+
class BlacklistedRequestHandler : public RequestHandler {
|
6
|
+
public:
|
7
|
+
BlacklistedRequestHandler(RequestHandler *next, QObject *parent = 0);
|
8
|
+
virtual QNetworkReply* handleRequest(
|
9
|
+
NetworkAccessManager *,
|
10
|
+
QNetworkAccessManager::Operation,
|
11
|
+
QNetworkRequest &,
|
12
|
+
QIODevice *
|
13
|
+
);
|
14
|
+
void setUrlBlacklist(QStringList urlBlacklist);
|
15
|
+
void blockUrl(const QString &);
|
16
|
+
void reset();
|
17
|
+
|
18
|
+
private:
|
19
|
+
RequestHandler *m_next;
|
20
|
+
QStringList m_urlBlacklist;
|
21
|
+
bool isBlacklisted(QUrl url);
|
22
|
+
};
|
data/src/BlockUrl.cpp
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#include "BlockUrl.h"
|
2
|
+
#include "SocketCommand.h"
|
3
|
+
#include "WebPage.h"
|
4
|
+
#include "WebPageManager.h"
|
5
|
+
|
6
|
+
BlockUrl::BlockUrl(
|
7
|
+
WebPageManager *manager,
|
8
|
+
QStringList &arguments,
|
9
|
+
QObject *parent
|
10
|
+
) : SocketCommand(manager, arguments, parent) {
|
11
|
+
}
|
12
|
+
|
13
|
+
void BlockUrl::start() {
|
14
|
+
manager()->blockUrl(arguments()[0]);
|
15
|
+
finish(true);
|
16
|
+
}
|
data/src/BlockUrl.h
ADDED
data/src/CommandFactory.cpp
CHANGED
@@ -48,6 +48,9 @@
|
|
48
48
|
#include "GoForward.h"
|
49
49
|
#include "AcceptAlert.h"
|
50
50
|
#include "FindModal.h"
|
51
|
+
#include "SetUnknownUrlMode.h"
|
52
|
+
#include "AllowUrl.h"
|
53
|
+
#include "BlockUrl.h"
|
51
54
|
|
52
55
|
CommandFactory::CommandFactory(WebPageManager *manager, QObject *parent) : QObject(parent) {
|
53
56
|
m_manager = manager;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#include "CustomHeadersRequestHandler.h"
|
2
|
+
#include "NetworkReplyProxy.h"
|
3
|
+
#include "NoOpReply.h"
|
4
|
+
|
5
|
+
CustomHeadersRequestHandler::CustomHeadersRequestHandler(
|
6
|
+
RequestHandler *next,
|
7
|
+
QObject *parent
|
8
|
+
) : RequestHandler(parent) {
|
9
|
+
m_next = next;
|
10
|
+
}
|
11
|
+
|
12
|
+
QNetworkReply* CustomHeadersRequestHandler::handleRequest(
|
13
|
+
NetworkAccessManager *manager,
|
14
|
+
QNetworkAccessManager::Operation operation,
|
15
|
+
QNetworkRequest &request,
|
16
|
+
QIODevice *outgoingData
|
17
|
+
) {
|
18
|
+
Q_UNUSED(manager)
|
19
|
+
Q_UNUSED(operation)
|
20
|
+
Q_UNUSED(outgoingData)
|
21
|
+
|
22
|
+
QHashIterator<QString, QString> item(m_headers);
|
23
|
+
while (item.hasNext()) {
|
24
|
+
item.next();
|
25
|
+
request.setRawHeader(item.key().toLatin1(), item.value().toLatin1());
|
26
|
+
}
|
27
|
+
|
28
|
+
return m_next->handleRequest(manager, operation, request, outgoingData);
|
29
|
+
}
|
30
|
+
|
31
|
+
void CustomHeadersRequestHandler::addHeader(QString key, QString value) {
|
32
|
+
m_headers.insert(key, value);
|
33
|
+
}
|
34
|
+
|
35
|
+
void CustomHeadersRequestHandler::reset() {
|
36
|
+
m_headers.clear();
|
37
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#include <QHash>
|
2
|
+
#include <QString>
|
3
|
+
|
4
|
+
#include "RequestHandler.h"
|
5
|
+
|
6
|
+
class CustomHeadersRequestHandler : public RequestHandler {
|
7
|
+
public:
|
8
|
+
CustomHeadersRequestHandler(RequestHandler *next, QObject *parent = 0);
|
9
|
+
virtual QNetworkReply* handleRequest(
|
10
|
+
NetworkAccessManager *,
|
11
|
+
QNetworkAccessManager::Operation,
|
12
|
+
QNetworkRequest &,
|
13
|
+
QIODevice *
|
14
|
+
);
|
15
|
+
void addHeader(QString, QString);
|
16
|
+
virtual void reset();
|
17
|
+
|
18
|
+
private:
|
19
|
+
RequestHandler *m_next;
|
20
|
+
QHash<QString, QString> m_headers;
|
21
|
+
};
|
data/src/Header.cpp
CHANGED
@@ -9,11 +9,10 @@ Header::Header(WebPageManager *manager, QStringList &arguments, QObject *parent)
|
|
9
9
|
void Header::start() {
|
10
10
|
QString key = arguments()[0];
|
11
11
|
QString value = arguments()[1];
|
12
|
-
NetworkAccessManager* networkAccessManager = manager()->networkAccessManager();
|
13
12
|
if (key.toLower().replace("-", "_") == "user_agent") {
|
14
13
|
page()->setUserAgent(value);
|
15
14
|
} else {
|
16
|
-
|
15
|
+
manager()->addHeader(key, value);
|
17
16
|
}
|
18
17
|
finish(true);
|
19
18
|
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#include "MissingContentHeaderRequestHandler.h"
|
2
|
+
#include "NetworkReplyProxy.h"
|
3
|
+
#include "NoOpReply.h"
|
4
|
+
|
5
|
+
MissingContentHeaderRequestHandler::MissingContentHeaderRequestHandler(
|
6
|
+
RequestHandler *next,
|
7
|
+
QObject *parent
|
8
|
+
) : RequestHandler(parent) {
|
9
|
+
m_next = next;
|
10
|
+
}
|
11
|
+
|
12
|
+
QNetworkReply* MissingContentHeaderRequestHandler::handleRequest(
|
13
|
+
NetworkAccessManager *manager,
|
14
|
+
QNetworkAccessManager::Operation operation,
|
15
|
+
QNetworkRequest &request,
|
16
|
+
QIODevice *outgoingData
|
17
|
+
) {
|
18
|
+
if (operation != QNetworkAccessManager::PostOperation && operation != QNetworkAccessManager::PutOperation) {
|
19
|
+
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant());
|
20
|
+
}
|
21
|
+
|
22
|
+
return m_next->handleRequest(manager, operation, request, outgoingData);
|
23
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#include "RequestHandler.h"
|
2
|
+
|
3
|
+
class MissingContentHeaderRequestHandler : public RequestHandler {
|
4
|
+
public:
|
5
|
+
MissingContentHeaderRequestHandler(RequestHandler *next, QObject *parent = 0);
|
6
|
+
virtual QNetworkReply* handleRequest(
|
7
|
+
NetworkAccessManager *,
|
8
|
+
QNetworkAccessManager::Operation,
|
9
|
+
QNetworkRequest &,
|
10
|
+
QIODevice *
|
11
|
+
);
|
12
|
+
|
13
|
+
private:
|
14
|
+
RequestHandler *m_next;
|
15
|
+
};
|
@@ -1,34 +1,46 @@
|
|
1
1
|
#include "NetworkAccessManager.h"
|
2
2
|
#include "WebPage.h"
|
3
|
-
#include <iostream>
|
4
|
-
#include <fstream>
|
5
|
-
#include "NoOpReply.h"
|
6
3
|
#include "NetworkReplyProxy.h"
|
4
|
+
#include "RequestHandler.h"
|
7
5
|
|
8
|
-
NetworkAccessManager::NetworkAccessManager(
|
6
|
+
NetworkAccessManager::NetworkAccessManager(
|
7
|
+
RequestHandler * requestHandler,
|
8
|
+
QObject *parent
|
9
|
+
) : QNetworkAccessManager(parent) {
|
10
|
+
m_requestHandler = requestHandler;
|
9
11
|
connect(this, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), SLOT(provideAuthentication(QNetworkReply*,QAuthenticator*)));
|
10
12
|
connect(this, SIGNAL(finished(QNetworkReply *)), this, SLOT(finished(QNetworkReply *)));
|
11
13
|
disableKeyChainLookup();
|
12
14
|
}
|
13
15
|
|
14
|
-
QNetworkReply* NetworkAccessManager::
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
16
|
+
QNetworkReply* NetworkAccessManager::sendRequest(
|
17
|
+
QNetworkAccessManager::Operation operation,
|
18
|
+
const QNetworkRequest &request,
|
19
|
+
QIODevice * outgoingData
|
20
|
+
) {
|
21
|
+
QNetworkReply *reply = new NetworkReplyProxy(
|
22
|
+
QNetworkAccessManager::createRequest(operation,
|
23
|
+
request,
|
24
|
+
outgoingData
|
25
|
+
),
|
26
|
+
this
|
27
|
+
);
|
28
|
+
|
29
|
+
QByteArray url = reply->request().url().toEncoded();
|
30
|
+
emit requestCreated(url, reply);
|
31
|
+
|
32
|
+
return reply;
|
33
|
+
}
|
34
|
+
|
35
|
+
QNetworkReply* NetworkAccessManager::createRequest(
|
36
|
+
QNetworkAccessManager::Operation operation,
|
37
|
+
const QNetworkRequest &unsafeRequest,
|
38
|
+
QIODevice * outgoingData = 0
|
39
|
+
) {
|
40
|
+
QNetworkRequest request(unsafeRequest);
|
41
|
+
QNetworkReply *reply =
|
42
|
+
m_requestHandler->handleRequest(this, operation, request, outgoingData);
|
43
|
+
return reply;
|
32
44
|
};
|
33
45
|
|
34
46
|
void NetworkAccessManager::finished(QNetworkReply *reply) {
|
@@ -43,12 +55,7 @@ void NetworkAccessManager::finished(QNetworkReply *reply) {
|
|
43
55
|
}
|
44
56
|
}
|
45
57
|
|
46
|
-
void NetworkAccessManager::addHeader(QString key, QString value) {
|
47
|
-
m_headers.insert(key, value);
|
48
|
-
}
|
49
|
-
|
50
58
|
void NetworkAccessManager::reset() {
|
51
|
-
m_headers.clear();
|
52
59
|
m_userName = QString();
|
53
60
|
m_password = QString();
|
54
61
|
}
|
@@ -63,37 +70,12 @@ void NetworkAccessManager::setPassword(const QString &password) {
|
|
63
70
|
|
64
71
|
void NetworkAccessManager::provideAuthentication(QNetworkReply *reply, QAuthenticator *authenticator) {
|
65
72
|
Q_UNUSED(reply);
|
66
|
-
if (m_userName != authenticator->user())
|
73
|
+
if (m_userName != authenticator->user())
|
67
74
|
authenticator->setUser(m_userName);
|
68
75
|
if (m_password != authenticator->password())
|
69
76
|
authenticator->setPassword(m_password);
|
70
77
|
}
|
71
78
|
|
72
|
-
void NetworkAccessManager::setUrlBlacklist(QStringList urlBlacklist) {
|
73
|
-
m_urlBlacklist.clear();
|
74
|
-
|
75
|
-
QStringListIterator iter(urlBlacklist);
|
76
|
-
while (iter.hasNext()) {
|
77
|
-
m_urlBlacklist << iter.next();
|
78
|
-
}
|
79
|
-
};
|
80
|
-
|
81
|
-
bool NetworkAccessManager::isBlacklisted(QUrl url) {
|
82
|
-
QString urlString = url.toString();
|
83
|
-
QStringListIterator iter(m_urlBlacklist);
|
84
|
-
|
85
|
-
while (iter.hasNext()) {
|
86
|
-
QRegExp blacklisted = QRegExp(iter.next());
|
87
|
-
blacklisted.setPatternSyntax(QRegExp::Wildcard);
|
88
|
-
|
89
|
-
if(urlString.contains(blacklisted)) {
|
90
|
-
return true;
|
91
|
-
}
|
92
|
-
}
|
93
|
-
|
94
|
-
return false;
|
95
|
-
};
|
96
|
-
|
97
79
|
/*
|
98
80
|
* This is a workaround for a Qt 5/OS X bug:
|
99
81
|
* https://bugreports.qt-project.org/browse/QTBUG-30434
|
data/src/NetworkAccessManager.h
CHANGED
@@ -3,32 +3,37 @@
|
|
3
3
|
#include <QtNetwork/QNetworkAccessManager>
|
4
4
|
#include <QtNetwork/QNetworkRequest>
|
5
5
|
#include <QtNetwork/QNetworkReply>
|
6
|
-
#include <QStringList>
|
7
6
|
|
8
|
-
class
|
7
|
+
class RequestHandler;
|
9
8
|
|
9
|
+
class NetworkAccessManager : public QNetworkAccessManager {
|
10
10
|
Q_OBJECT
|
11
11
|
|
12
12
|
public:
|
13
|
-
NetworkAccessManager(QObject *parent = 0);
|
14
|
-
void addHeader(QString key, QString value);
|
13
|
+
NetworkAccessManager(RequestHandler *, QObject *parent = 0);
|
15
14
|
void reset();
|
16
15
|
void setUserName(const QString &userName);
|
17
16
|
void setPassword(const QString &password);
|
18
|
-
|
17
|
+
QNetworkReply* sendRequest(
|
18
|
+
QNetworkAccessManager::Operation,
|
19
|
+
const QNetworkRequest &,
|
20
|
+
QIODevice *
|
21
|
+
);
|
19
22
|
|
20
23
|
protected:
|
21
|
-
QNetworkReply* createRequest(
|
24
|
+
QNetworkReply* createRequest(
|
25
|
+
QNetworkAccessManager::Operation,
|
26
|
+
const QNetworkRequest &,
|
27
|
+
QIODevice *
|
28
|
+
);
|
22
29
|
QString m_userName;
|
23
30
|
QString m_password;
|
24
|
-
QStringList m_urlBlacklist;
|
25
31
|
|
26
32
|
private:
|
27
33
|
void disableKeyChainLookup();
|
28
34
|
|
29
|
-
QHash<QString, QString> m_headers;
|
30
|
-
bool isBlacklisted(QUrl url);
|
31
35
|
QHash<QUrl, QUrl> m_redirectMappings;
|
36
|
+
RequestHandler * m_requestHandler;
|
32
37
|
|
33
38
|
private slots:
|
34
39
|
void provideAuthentication(QNetworkReply *reply, QAuthenticator *authenticator);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#include "NetworkRequestFactory.h"
|
2
|
+
#include "NetworkAccessManager.h"
|
3
|
+
|
4
|
+
NetworkRequestFactory::NetworkRequestFactory(QObject *parent) :
|
5
|
+
RequestHandler(parent) {
|
6
|
+
}
|
7
|
+
|
8
|
+
QNetworkReply* NetworkRequestFactory::handleRequest(
|
9
|
+
NetworkAccessManager *manager,
|
10
|
+
QNetworkAccessManager::Operation operation,
|
11
|
+
QNetworkRequest &request,
|
12
|
+
QIODevice *outgoingData
|
13
|
+
) {
|
14
|
+
return manager->sendRequest(operation, request, outgoingData);
|
15
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#include "RequestHandler.h"
|
2
|
+
|
3
|
+
class NetworkRequestFactory : public RequestHandler {
|
4
|
+
public:
|
5
|
+
NetworkRequestFactory(QObject *parent = 0);
|
6
|
+
virtual QNetworkReply* handleRequest(
|
7
|
+
NetworkAccessManager *,
|
8
|
+
QNetworkAccessManager::Operation,
|
9
|
+
QNetworkRequest &,
|
10
|
+
QIODevice *
|
11
|
+
);
|
12
|
+
};
|