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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -4
  3. data/Appraisals +0 -8
  4. data/Gemfile.lock +5 -5
  5. data/NEWS.md +7 -0
  6. data/capybara-webkit.gemspec +1 -1
  7. data/extconf.rb +18 -0
  8. data/gemfiles/2.3.gemfile.lock +2 -2
  9. data/gemfiles/2.4.gemfile.lock +2 -2
  10. data/lib/capybara/webkit/browser.rb +14 -0
  11. data/lib/capybara/webkit/driver.rb +12 -0
  12. data/lib/capybara/webkit/version.rb +1 -1
  13. data/lib/capybara_webkit_builder.rb +18 -2
  14. data/spec/driver_spec.rb +99 -28
  15. data/spec/support/app_runner.rb +4 -4
  16. data/spec/support/output_writer.rb +15 -0
  17. data/src/AllowUrl.cpp +16 -0
  18. data/src/AllowUrl.h +10 -0
  19. data/src/BlacklistedRequestHandler.cpp +56 -0
  20. data/src/BlacklistedRequestHandler.h +22 -0
  21. data/src/BlockUrl.cpp +16 -0
  22. data/src/BlockUrl.h +10 -0
  23. data/src/CommandFactory.cpp +3 -0
  24. data/src/CustomHeadersRequestHandler.cpp +37 -0
  25. data/src/CustomHeadersRequestHandler.h +21 -0
  26. data/src/Header.cpp +1 -2
  27. data/src/MissingContentHeaderRequestHandler.cpp +23 -0
  28. data/src/MissingContentHeaderRequestHandler.h +15 -0
  29. data/src/NetworkAccessManager.cpp +35 -53
  30. data/src/NetworkAccessManager.h +14 -9
  31. data/src/NetworkRequestFactory.cpp +15 -0
  32. data/src/NetworkRequestFactory.h +12 -0
  33. data/src/NoOpReply.cpp +1 -1
  34. data/src/NoOpReply.h +1 -1
  35. data/src/RequestHandler.cpp +4 -0
  36. data/src/RequestHandler.h +25 -0
  37. data/src/SetUnknownUrlMode.cpp +27 -0
  38. data/src/SetUnknownUrlMode.h +10 -0
  39. data/src/SetUrlBlacklist.cpp +1 -2
  40. data/src/SetUrlBlacklist.h +0 -2
  41. data/src/UnknownUrlHandler.cpp +70 -0
  42. data/src/UnknownUrlHandler.h +28 -0
  43. data/src/WebPageManager.cpp +41 -1
  44. data/src/WebPageManager.h +12 -1
  45. data/src/capybara.js +2 -1
  46. data/src/find_command.h +3 -0
  47. data/src/webkit_server.pro +20 -2
  48. metadata +23 -10
  49. data/gemfiles/2.0.gemfile +0 -7
  50. data/gemfiles/2.0.gemfile.lock +0 -76
  51. data/gemfiles/2.1.gemfile +0 -7
  52. data/gemfiles/2.1.gemfile.lock +0 -83
  53. data/gemfiles/2.2.gemfile +0 -7
  54. data/gemfiles/2.2.gemfile.lock +0 -77
data/src/NoOpReply.cpp CHANGED
@@ -1,7 +1,7 @@
1
1
  #include <QTimer>
2
2
  #include "NoOpReply.h"
3
3
 
4
- NoOpReply::NoOpReply(QNetworkRequest &request, QObject *parent) : QNetworkReply(parent) {
4
+ NoOpReply::NoOpReply(const QNetworkRequest &request, QObject *parent) : QNetworkReply(parent) {
5
5
  open(ReadOnly | Unbuffered);
6
6
  setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200);
7
7
  setHeader(QNetworkRequest::ContentLengthHeader, QVariant(0));
data/src/NoOpReply.h CHANGED
@@ -5,7 +5,7 @@ class NoOpReply : public QNetworkReply {
5
5
  Q_OBJECT
6
6
 
7
7
  public:
8
- NoOpReply(QNetworkRequest &request, QObject *parent = 0);
8
+ NoOpReply(const QNetworkRequest &request, QObject *parent = 0);
9
9
 
10
10
  void abort();
11
11
  qint64 bytesAvailable() const;
@@ -0,0 +1,4 @@
1
+ #include "RequestHandler.h"
2
+
3
+ RequestHandler::RequestHandler(QObject *parent) : QObject(parent) {
4
+ }
@@ -0,0 +1,25 @@
1
+ #ifndef __REQUESTHANDLER_H
2
+ #define __REQUESTHANDLER_H
3
+
4
+ #include <QtNetwork/QNetworkAccessManager>
5
+ #include <QtNetwork/QNetworkRequest>
6
+ #include <QtNetwork/QNetworkReply>
7
+ #include <QStringList>
8
+
9
+ class NetworkAccessManager;
10
+
11
+ class RequestHandler : public QObject {
12
+ Q_OBJECT
13
+
14
+ public:
15
+ RequestHandler(QObject *parent = 0);
16
+
17
+ virtual QNetworkReply* handleRequest(
18
+ NetworkAccessManager *,
19
+ QNetworkAccessManager::Operation,
20
+ QNetworkRequest &,
21
+ QIODevice *
22
+ ) = 0;
23
+ };
24
+
25
+ #endif
@@ -0,0 +1,27 @@
1
+ #include "SetUnknownUrlMode.h"
2
+ #include "WebPage.h"
3
+ #include "WebPageManager.h"
4
+ #include "ErrorMessage.h"
5
+
6
+ SetUnknownUrlMode::SetUnknownUrlMode(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
7
+ }
8
+
9
+ void SetUnknownUrlMode::start() {
10
+ QString modeString = arguments()[0];
11
+ QStringList modes;
12
+ modes << "warn" << "block";
13
+
14
+ switch(modes.indexOf(modeString)) {
15
+ case 0:
16
+ manager()->setUnknownUrlMode(UnknownUrlHandler::WARN);
17
+ finish(true);
18
+ break;
19
+ case 1:
20
+ manager()->setUnknownUrlMode(UnknownUrlHandler::BLOCK);
21
+ finish(true);
22
+ break;
23
+ default:
24
+ QString error = QString("Invalid mode string:") + modeString;
25
+ finish(false, new ErrorMessage(error));
26
+ }
27
+ }
@@ -0,0 +1,10 @@
1
+ #include "SocketCommand.h"
2
+ #include "UnknownUrlHandler.h"
3
+
4
+ class SetUnknownUrlMode : public SocketCommand {
5
+ Q_OBJECT
6
+
7
+ public:
8
+ SetUnknownUrlMode(WebPageManager *, QStringList &arguments, QObject *parent = 0);
9
+ virtual void start();
10
+ };
@@ -8,8 +8,7 @@ SetUrlBlacklist::SetUrlBlacklist(WebPageManager *manager, QStringList &arguments
8
8
  }
9
9
 
10
10
  void SetUrlBlacklist::start() {
11
- NetworkAccessManager* networkAccessManager = manager()->networkAccessManager();
12
- networkAccessManager->setUrlBlacklist(arguments());
11
+ manager()->setUrlBlacklist(arguments());
13
12
  finish(true);
14
13
  }
15
14
 
@@ -1,4 +1,3 @@
1
-
2
1
  #include "SocketCommand.h"
3
2
 
4
3
  class SetUrlBlacklist : public SocketCommand {
@@ -8,4 +7,3 @@ class SetUrlBlacklist : public SocketCommand {
8
7
  SetUrlBlacklist(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
9
8
  virtual void start();
10
9
  };
11
-
@@ -0,0 +1,70 @@
1
+ #include "UnknownUrlHandler.h"
2
+ #include "NetworkReplyProxy.h"
3
+ #include "NoOpReply.h"
4
+
5
+ UnknownUrlHandler::UnknownUrlHandler(
6
+ RequestHandler *next,
7
+ QObject *parent
8
+ ) : RequestHandler(parent) {
9
+ m_next = next;
10
+ m_allowedUrls.append(QString("127.0.0.1"));
11
+ m_allowedUrls.append(QString("localhost"));
12
+ m_mode = WARN;
13
+ }
14
+
15
+ QNetworkReply* UnknownUrlHandler::handleRequest(
16
+ NetworkAccessManager *manager,
17
+ QNetworkAccessManager::Operation operation,
18
+ QNetworkRequest &request,
19
+ QIODevice *outgoingData
20
+ ) {
21
+ QUrl url(request.url());
22
+ if (this->isUnknown(url)) {
23
+ switch(m_mode) {
24
+ case WARN:
25
+ QTextStream(stderr) <<
26
+ "Request to unknown URL: " << url.toString() << endl <<
27
+ "To block requests to unknown URLs:" << endl <<
28
+ " page.driver.block_unknown_urls" << endl <<
29
+ "To allow just this URL:" << endl <<
30
+ " page.driver.allow_url(\"" << url.toString() << "\")" << endl <<
31
+ "To allow requests to URLs from this host:" << endl <<
32
+ " page.driver.allow_url(\"" << url.host() << "\")" << endl;
33
+ break;
34
+ case BLOCK:
35
+ return new NetworkReplyProxy(new NoOpReply(request), this);
36
+ }
37
+ }
38
+
39
+ return m_next->handleRequest(manager, operation, request, outgoingData);
40
+ }
41
+
42
+ void UnknownUrlHandler::allowUrl(const QString &url) {
43
+ m_allowedUrls << url;
44
+ }
45
+
46
+ void UnknownUrlHandler::setMode(Mode mode) {
47
+ m_mode = mode;
48
+ }
49
+
50
+ bool UnknownUrlHandler::isUnknown(QUrl url) {
51
+ QStringListIterator iterator(m_allowedUrls);
52
+ QString urlString = url.toString();
53
+
54
+ while (iterator.hasNext()) {
55
+ QRegExp allowedUrl = QRegExp(iterator.next());
56
+ allowedUrl.setPatternSyntax(QRegExp::Wildcard);
57
+
58
+ if(urlString.contains(allowedUrl)) {
59
+ return false;
60
+ }
61
+ }
62
+
63
+ return true;
64
+ }
65
+
66
+ void UnknownUrlHandler::reset() {
67
+ m_allowedUrls.clear();
68
+ m_allowedUrls.append(QString("127.0.0.1"));
69
+ m_allowedUrls.append(QString("localhost"));
70
+ }
@@ -0,0 +1,28 @@
1
+ #ifndef _REQUESTHANDLER_H
2
+ #define _REQUESTHANDLER_H
3
+
4
+ #include "RequestHandler.h"
5
+
6
+ class UnknownUrlHandler : public RequestHandler {
7
+ public:
8
+ enum Mode { WARN, BLOCK };
9
+
10
+ UnknownUrlHandler(RequestHandler *next, QObject *parent = 0);
11
+ virtual QNetworkReply* handleRequest(
12
+ NetworkAccessManager *,
13
+ QNetworkAccessManager::Operation,
14
+ QNetworkRequest &,
15
+ QIODevice *
16
+ );
17
+ void allowUrl(const QString &);
18
+ void setMode(Mode);
19
+ void reset();
20
+
21
+ private:
22
+ QStringList m_allowedUrls;
23
+ bool isUnknown(QUrl);
24
+ Mode m_mode;
25
+ RequestHandler *m_next;
26
+ };
27
+
28
+ #endif
@@ -2,6 +2,11 @@
2
2
  #include "WebPage.h"
3
3
  #include "NetworkCookieJar.h"
4
4
  #include "NetworkAccessManager.h"
5
+ #include "BlacklistedRequestHandler.h"
6
+ #include "CustomHeadersRequestHandler.h"
7
+ #include "MissingContentHeaderRequestHandler.h"
8
+ #include "UnknownUrlHandler.h"
9
+ #include "NetworkRequestFactory.h"
5
10
 
6
11
  WebPageManager::WebPageManager(QObject *parent) : QObject(parent) {
7
12
  m_ignoreSslErrors = false;
@@ -10,7 +15,19 @@ WebPageManager::WebPageManager(QObject *parent) : QObject(parent) {
10
15
  m_loggingEnabled = false;
11
16
  m_ignoredOutput = new QFile(this);
12
17
  m_timeout = -1;
13
- m_networkAccessManager = new NetworkAccessManager(this);
18
+ m_customHeadersRequestHandler = new CustomHeadersRequestHandler(
19
+ new MissingContentHeaderRequestHandler(
20
+ new NetworkRequestFactory(this),
21
+ this
22
+ ),
23
+ this
24
+ );
25
+ m_unknownUrlHandler =
26
+ new UnknownUrlHandler(m_customHeadersRequestHandler, this);
27
+ m_blacklistedRequestHandler =
28
+ new BlacklistedRequestHandler(m_unknownUrlHandler, this);
29
+ m_networkAccessManager =
30
+ new NetworkAccessManager(m_blacklistedRequestHandler, this);
14
31
  m_networkAccessManager->setCookieJar(m_cookieJar);
15
32
  createPage()->setFocus();
16
33
  }
@@ -119,7 +136,10 @@ void WebPageManager::reset() {
119
136
  m_timeout = -1;
120
137
  m_cookieJar->clearCookies();
121
138
  m_networkAccessManager->reset();
139
+ m_customHeadersRequestHandler->reset();
122
140
  m_currentPage->resetLocalStorage();
141
+ m_blacklistedRequestHandler->reset();
142
+ m_unknownUrlHandler->reset();
123
143
  while (!m_pages.isEmpty()) {
124
144
  WebPage *page = m_pages.takeFirst();
125
145
  page->deleteLater();
@@ -157,3 +177,23 @@ QDebug WebPageManager::logger() const {
157
177
  void WebPageManager::enableLogging() {
158
178
  m_loggingEnabled = true;
159
179
  }
180
+
181
+ void WebPageManager::setUrlBlacklist(const QStringList &urls) {
182
+ m_blacklistedRequestHandler->setUrlBlacklist(urls);
183
+ }
184
+
185
+ void WebPageManager::addHeader(QString key, QString value) {
186
+ m_customHeadersRequestHandler->addHeader(key, value);
187
+ }
188
+
189
+ void WebPageManager::setUnknownUrlMode(UnknownUrlHandler::Mode mode) {
190
+ m_unknownUrlHandler->setMode(mode);
191
+ }
192
+
193
+ void WebPageManager::allowUrl(const QString &url) {
194
+ m_unknownUrlHandler->allowUrl(url);
195
+ }
196
+
197
+ void WebPageManager::blockUrl(const QString &url) {
198
+ m_blacklistedRequestHandler->blockUrl(url);
199
+ }
data/src/WebPageManager.h CHANGED
@@ -7,9 +7,13 @@
7
7
  #include <QDebug>
8
8
  #include <QFile>
9
9
 
10
+ #include "UnknownUrlHandler.h"
11
+
10
12
  class WebPage;
11
13
  class NetworkCookieJar;
12
14
  class NetworkAccessManager;
15
+ class BlacklistedRequestHandler;
16
+ class CustomHeadersRequestHandler;
13
17
 
14
18
  class WebPageManager : public QObject {
15
19
  Q_OBJECT
@@ -33,6 +37,11 @@ class WebPageManager : public QObject {
33
37
  void enableLogging();
34
38
  void replyFinished(QNetworkReply *reply);
35
39
  NetworkAccessManager *networkAccessManager();
40
+ void setUrlBlacklist(const QStringList &);
41
+ void addHeader(QString, QString);
42
+ void setUnknownUrlMode(UnknownUrlHandler::Mode);
43
+ void allowUrl(const QString &);
44
+ void blockUrl(const QString &);
36
45
 
37
46
  public slots:
38
47
  void emitLoadStarted();
@@ -58,7 +67,9 @@ class WebPageManager : public QObject {
58
67
  QFile *m_ignoredOutput;
59
68
  int m_timeout;
60
69
  NetworkAccessManager *m_networkAccessManager;
70
+ BlacklistedRequestHandler *m_blacklistedRequestHandler;
71
+ CustomHeadersRequestHandler *m_customHeadersRequestHandler;
72
+ UnknownUrlHandler *m_unknownUrlHandler;
61
73
  };
62
74
 
63
75
  #endif // _WEBPAGEMANAGER_H
64
-
data/src/capybara.js CHANGED
@@ -71,7 +71,8 @@ Capybara = {
71
71
  } else if (type == "textarea") {
72
72
  return node.innerHTML;
73
73
  } else {
74
- return node.innerText || node.textContent;
74
+ visible_text = node.innerText;
75
+ return typeof visible_text === "string" ? visible_text : node.textContent;
75
76
  }
76
77
  },
77
78
 
data/src/find_command.h CHANGED
@@ -50,3 +50,6 @@ CHECK_COMMAND(GoBack)
50
50
  CHECK_COMMAND(GoForward)
51
51
  CHECK_COMMAND(AcceptAlert)
52
52
  CHECK_COMMAND(FindModal)
53
+ CHECK_COMMAND(SetUnknownUrlMode)
54
+ CHECK_COMMAND(AllowUrl)
55
+ CHECK_COMMAND(BlockUrl)
@@ -7,6 +7,9 @@ PRECOMPILED_DIR = $${BUILD_DIR}
7
7
  OBJECTS_DIR = $${BUILD_DIR}
8
8
  MOC_DIR = $${BUILD_DIR}
9
9
  HEADERS = \
10
+ BlockUrl.h \
11
+ AllowUrl.h \
12
+ SetUnknownUrlMode.h \
10
13
  FindModal.h \
11
14
  AcceptAlert.h \
12
15
  GoForward.h \
@@ -78,9 +81,18 @@ HEADERS = \
78
81
  FindXpath.h \
79
82
  NetworkReplyProxy.h \
80
83
  IgnoreDebugOutput.h \
81
- StdinNotifier.h
84
+ StdinNotifier.h \
85
+ RequestHandler.h \
86
+ BlacklistedRequestHandler.h \
87
+ MissingContentHeaderRequestHandler.h \
88
+ CustomHeadersRequestHandler.h \
89
+ NetworkRequestFactory.h \
90
+ UnknownUrlHandler.h
82
91
 
83
92
  SOURCES = \
93
+ BlockUrl.cpp \
94
+ AllowUrl.cpp \
95
+ SetUnknownUrlMode.cpp \
84
96
  FindModal.cpp \
85
97
  AcceptAlert.cpp \
86
98
  GoForward.cpp \
@@ -153,7 +165,13 @@ SOURCES = \
153
165
  FindXpath.cpp \
154
166
  NetworkReplyProxy.cpp \
155
167
  IgnoreDebugOutput.cpp \
156
- StdinNotifier.cpp
168
+ StdinNotifier.cpp \
169
+ RequestHandler.cpp \
170
+ BlacklistedRequestHandler.cpp \
171
+ MissingContentHeaderRequestHandler.cpp \
172
+ CustomHeadersRequestHandler.cpp \
173
+ NetworkRequestFactory.cpp \
174
+ UnknownUrlHandler.cpp
157
175
 
158
176
  RESOURCES = webkit_server.qrc
159
177
  QT += network
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-webkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoughtbot
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2014-10-22 00:00:00.000000000 Z
16
+ date: 2015-01-22 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: capybara
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 2.0.2
24
+ version: 2.3.0
25
25
  - - "<"
26
26
  - !ruby/object:Gem::Version
27
27
  version: 2.5.0
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 2.0.2
34
+ version: 2.3.0
35
35
  - - "<"
36
36
  - !ruby/object:Gem::Version
37
37
  version: 2.5.0
@@ -170,12 +170,6 @@ files:
170
170
  - bin/Info.plist
171
171
  - capybara-webkit.gemspec
172
172
  - extconf.rb
173
- - gemfiles/2.0.gemfile
174
- - gemfiles/2.0.gemfile.lock
175
- - gemfiles/2.1.gemfile
176
- - gemfiles/2.1.gemfile.lock
177
- - gemfiles/2.2.gemfile
178
- - gemfiles/2.2.gemfile.lock
179
173
  - gemfiles/2.3.gemfile
180
174
  - gemfiles/2.3.gemfile.lock
181
175
  - gemfiles/2.4.gemfile
@@ -206,10 +200,17 @@ files:
206
200
  - spec/spec_helper.rb
207
201
  - spec/support/app_runner.rb
208
202
  - spec/support/matchers/include_response.rb
203
+ - spec/support/output_writer.rb
209
204
  - src/AcceptAlert.cpp
210
205
  - src/AcceptAlert.h
206
+ - src/AllowUrl.cpp
207
+ - src/AllowUrl.h
211
208
  - src/Authenticate.cpp
212
209
  - src/Authenticate.h
210
+ - src/BlacklistedRequestHandler.cpp
211
+ - src/BlacklistedRequestHandler.h
212
+ - src/BlockUrl.cpp
213
+ - src/BlockUrl.h
213
214
  - src/Body.h
214
215
  - src/ClearCookies.cpp
215
216
  - src/ClearCookies.h
@@ -227,6 +228,8 @@ files:
227
228
  - src/ConsoleMessages.h
228
229
  - src/CurrentUrl.cpp
229
230
  - src/CurrentUrl.h
231
+ - src/CustomHeadersRequestHandler.cpp
232
+ - src/CustomHeadersRequestHandler.h
230
233
  - src/EnableLogging.cpp
231
234
  - src/EnableLogging.h
232
235
  - src/ErrorMessage.cpp
@@ -277,12 +280,16 @@ files:
277
280
  - src/JavascriptPromptMessages.h
278
281
  - src/JsonSerializer.cpp
279
282
  - src/JsonSerializer.h
283
+ - src/MissingContentHeaderRequestHandler.cpp
284
+ - src/MissingContentHeaderRequestHandler.h
280
285
  - src/NetworkAccessManager.cpp
281
286
  - src/NetworkAccessManager.h
282
287
  - src/NetworkCookieJar.cpp
283
288
  - src/NetworkCookieJar.h
284
289
  - src/NetworkReplyProxy.cpp
285
290
  - src/NetworkReplyProxy.h
291
+ - src/NetworkRequestFactory.cpp
292
+ - src/NetworkRequestFactory.h
286
293
  - src/NoOpReply.cpp
287
294
  - src/NoOpReply.h
288
295
  - src/Node.cpp
@@ -293,6 +300,8 @@ files:
293
300
  - src/PageLoadingCommand.h
294
301
  - src/Render.cpp
295
302
  - src/Render.h
303
+ - src/RequestHandler.cpp
304
+ - src/RequestHandler.h
296
305
  - src/Reset.cpp
297
306
  - src/Reset.h
298
307
  - src/Response.cpp
@@ -313,6 +322,8 @@ files:
313
322
  - src/SetSkipImageLoading.h
314
323
  - src/SetTimeout.cpp
315
324
  - src/SetTimeout.h
325
+ - src/SetUnknownUrlMode.cpp
326
+ - src/SetUnknownUrlMode.h
316
327
  - src/SetUrlBlacklist.cpp
317
328
  - src/SetUrlBlacklist.h
318
329
  - src/SocketCommand.cpp
@@ -325,6 +336,8 @@ files:
325
336
  - src/TimeoutCommand.h
326
337
  - src/Title.cpp
327
338
  - src/Title.h
339
+ - src/UnknownUrlHandler.cpp
340
+ - src/UnknownUrlHandler.h
328
341
  - src/UnsupportedContentHandler.cpp
329
342
  - src/UnsupportedContentHandler.h
330
343
  - src/Version.cpp