otherinbox-capybara-webkit 0.12.0 → 0.12.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/GOALS +9 -0
  2. data/README.md +1 -1
  3. data/capybara-webkit.gemspec +1 -1
  4. data/lib/capybara/webkit.rb +11 -4
  5. data/lib/capybara/{driver/webkit → webkit}/browser.rb +27 -3
  6. data/lib/capybara/{driver/webkit → webkit}/connection.rb +45 -47
  7. data/lib/capybara/{driver/webkit → webkit}/cookie_jar.rb +1 -1
  8. data/lib/capybara/webkit/driver.rb +150 -0
  9. data/lib/capybara/webkit/errors.rb +10 -0
  10. data/lib/capybara/{driver/webkit → webkit}/node.rb +2 -2
  11. data/lib/capybara/{driver/webkit → webkit}/socket_debugger.rb +1 -1
  12. data/lib/capybara/{driver/webkit → webkit}/version.rb +1 -1
  13. data/lib/capybara_webkit_builder.rb +17 -3
  14. data/spec/browser_spec.rb +38 -25
  15. data/spec/connection_spec.rb +5 -5
  16. data/spec/cookie_jar_spec.rb +3 -3
  17. data/spec/driver_rendering_spec.rb +19 -26
  18. data/spec/driver_resize_window_spec.rb +3 -3
  19. data/spec/driver_spec.rb +907 -829
  20. data/spec/integration/driver_spec.rb +4 -3
  21. data/spec/spec_helper.rb +14 -6
  22. data/spec/support/app_runner.rb +91 -0
  23. data/src/Authenticate.cpp +18 -0
  24. data/src/Authenticate.h +12 -0
  25. data/src/Body.h +3 -5
  26. data/src/ClearCookies.cpp +3 -5
  27. data/src/ClearCookies.h +3 -5
  28. data/src/Command.cpp +4 -15
  29. data/src/Command.h +3 -14
  30. data/src/CommandFactory.cpp +10 -6
  31. data/src/CommandFactory.h +3 -2
  32. data/src/CommandParser.cpp +1 -1
  33. data/src/Connection.cpp +22 -11
  34. data/src/Connection.h +4 -2
  35. data/src/ConsoleMessages.cpp +2 -1
  36. data/src/ConsoleMessages.h +3 -5
  37. data/src/CurrentUrl.cpp +2 -1
  38. data/src/CurrentUrl.h +3 -5
  39. data/src/EnableLogging.cpp +10 -0
  40. data/src/EnableLogging.h +12 -0
  41. data/src/Evaluate.cpp +2 -1
  42. data/src/Evaluate.h +3 -5
  43. data/src/Execute.cpp +2 -1
  44. data/src/Execute.h +3 -5
  45. data/src/Find.cpp +3 -2
  46. data/src/Find.h +3 -5
  47. data/src/FrameFocus.cpp +3 -2
  48. data/src/FrameFocus.h +3 -4
  49. data/src/GetCookies.cpp +3 -4
  50. data/src/GetCookies.h +3 -5
  51. data/src/GetWindowHandle.cpp +11 -0
  52. data/src/GetWindowHandle.h +10 -0
  53. data/src/GetWindowHandles.cpp +20 -0
  54. data/src/GetWindowHandles.h +10 -0
  55. data/src/Header.cpp +2 -1
  56. data/src/Header.h +3 -5
  57. data/src/Headers.cpp +2 -1
  58. data/src/Headers.h +3 -5
  59. data/src/IgnoreSslErrors.cpp +4 -3
  60. data/src/IgnoreSslErrors.h +3 -5
  61. data/src/JavascriptInvocation.cpp +1 -1
  62. data/src/JavascriptInvocation.h +1 -1
  63. data/src/NetworkAccessManager.cpp +19 -1
  64. data/src/NetworkAccessManager.h +10 -0
  65. data/src/Node.cpp +6 -1
  66. data/src/Node.h +4 -5
  67. data/src/NullCommand.cpp +5 -2
  68. data/src/NullCommand.h +4 -3
  69. data/src/PageLoadingCommand.cpp +12 -7
  70. data/src/PageLoadingCommand.h +6 -9
  71. data/src/Render.cpp +2 -1
  72. data/src/Render.h +3 -5
  73. data/src/RequestedUrl.cpp +2 -1
  74. data/src/RequestedUrl.h +3 -5
  75. data/src/Reset.cpp +3 -17
  76. data/src/Reset.h +3 -8
  77. data/src/ResizeWindow.cpp +2 -1
  78. data/src/ResizeWindow.h +3 -5
  79. data/src/Server.cpp +2 -3
  80. data/src/Server.h +0 -2
  81. data/src/SetCookie.cpp +3 -4
  82. data/src/SetCookie.h +3 -5
  83. data/src/SetProxy.cpp +2 -1
  84. data/src/SetProxy.h +3 -5
  85. data/src/SetSkipImageLoading.cpp +3 -2
  86. data/src/SetSkipImageLoading.h +3 -5
  87. data/src/SocketCommand.cpp +21 -0
  88. data/src/SocketCommand.h +29 -0
  89. data/src/Source.cpp +2 -1
  90. data/src/Source.h +3 -4
  91. data/src/Status.cpp +2 -1
  92. data/src/Status.h +3 -5
  93. data/src/UnsupportedContentHandler.cpp +1 -1
  94. data/src/Url.cpp +2 -1
  95. data/src/Url.h +3 -5
  96. data/src/Visit.cpp +3 -2
  97. data/src/Visit.h +3 -5
  98. data/src/WebPage.cpp +86 -39
  99. data/src/WebPage.h +22 -8
  100. data/src/WebPageManager.cpp +117 -0
  101. data/src/WebPageManager.h +56 -0
  102. data/src/WindowFocus.cpp +32 -0
  103. data/src/WindowFocus.h +15 -0
  104. data/src/body.cpp +2 -1
  105. data/src/find_command.h +6 -2
  106. data/src/webkit_server.pro +14 -0
  107. data/templates/Command.cpp +2 -4
  108. data/templates/Command.h +3 -3
  109. metadata +29 -10
  110. data/lib/capybara/driver/webkit.rb +0 -135
@@ -0,0 +1,117 @@
1
+ #include "WebPageManager.h"
2
+ #include "WebPage.h"
3
+ #include "NetworkCookieJar.h"
4
+
5
+ WebPageManager::WebPageManager(QObject *parent) : QObject(parent) {
6
+ m_ignoreSslErrors = false;
7
+ m_cookieJar = new NetworkCookieJar(this);
8
+ m_success = true;
9
+ m_loggingEnabled = false;
10
+ m_ignoredOutput = new QString();
11
+ createPage(this)->setFocus();
12
+ }
13
+
14
+ void WebPageManager::append(WebPage *value) {
15
+ m_pages.append(value);
16
+ }
17
+
18
+ QList<WebPage *> WebPageManager::pages() const {
19
+ return m_pages;
20
+ }
21
+
22
+ void WebPageManager::setCurrentPage(WebPage *page) {
23
+ m_currentPage = page;
24
+ }
25
+
26
+ WebPage *WebPageManager::currentPage() const {
27
+ return m_currentPage;
28
+ }
29
+
30
+ WebPage *WebPageManager::createPage(QObject *parent) {
31
+ WebPage *page = new WebPage(this, parent);
32
+ connect(page, SIGNAL(loadStarted()),
33
+ this, SLOT(emitLoadStarted()));
34
+ connect(page, SIGNAL(pageFinished(bool)),
35
+ this, SLOT(setPageStatus(bool)));
36
+ connect(page, SIGNAL(requestCreated(QNetworkReply *)),
37
+ this, SLOT(requestCreated(QNetworkReply *)));
38
+ connect(page, SIGNAL(replyFinished(QNetworkReply *)),
39
+ this, SLOT(replyFinished(QNetworkReply *)));
40
+ append(page);
41
+ return page;
42
+ }
43
+
44
+ void WebPageManager::emitLoadStarted() {
45
+ if (m_started.empty()) {
46
+ logger() << "Load started";
47
+ emit loadStarted();
48
+ }
49
+ }
50
+
51
+ void WebPageManager::requestCreated(QNetworkReply *reply) {
52
+ logger() << "Started request to" << reply->url().toString();
53
+ m_started += reply;
54
+ }
55
+
56
+ void WebPageManager::replyFinished(QNetworkReply *reply) {
57
+ int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
58
+ logger() << "Received" << status << "from" << reply->url().toString();
59
+ m_started.remove(reply);
60
+ logger() << m_started.size() << "requests remaining";
61
+ if (m_started.empty() && !m_success) {
62
+ emitPageFinished();
63
+ }
64
+ }
65
+
66
+ void WebPageManager::setPageStatus(bool success) {
67
+ logger() << "Page finished with" << success;
68
+ m_success = success && m_success;
69
+ if (m_started.empty()) {
70
+ emitPageFinished();
71
+ }
72
+ }
73
+
74
+ void WebPageManager::emitPageFinished() {
75
+ logger() << "Load finished";
76
+ emit pageFinished(m_success);
77
+ m_success = true;
78
+ }
79
+
80
+ void WebPageManager::setIgnoreSslErrors(bool value) {
81
+ m_ignoreSslErrors = value;
82
+ }
83
+
84
+ bool WebPageManager::ignoreSslErrors() {
85
+ return m_ignoreSslErrors;
86
+ }
87
+
88
+ void WebPageManager::reset() {
89
+ m_cookieJar->clearCookies();
90
+ m_pages.first()->deleteLater();
91
+ m_pages.clear();
92
+ createPage(this)->setFocus();
93
+ }
94
+
95
+ NetworkCookieJar *WebPageManager::cookieJar() {
96
+ return m_cookieJar;
97
+ }
98
+
99
+ bool WebPageManager::isLoading() const {
100
+ foreach(WebPage *page, pages()) {
101
+ if (page->isLoading()) {
102
+ return true;
103
+ }
104
+ }
105
+ return false;
106
+ }
107
+
108
+ QDebug WebPageManager::logger() const {
109
+ if (m_loggingEnabled)
110
+ return qDebug();
111
+ else
112
+ return QDebug(m_ignoredOutput);
113
+ }
114
+
115
+ void WebPageManager::enableLogging() {
116
+ m_loggingEnabled = true;
117
+ }
@@ -0,0 +1,56 @@
1
+ #ifndef _WEBPAGEMANAGER_H
2
+ #define _WEBPAGEMANAGER_H
3
+ #include <QList>
4
+ #include <QSet>
5
+ #include <QObject>
6
+ #include <QNetworkReply>
7
+ #include <QDebug>
8
+ #include <QFile>
9
+
10
+ class WebPage;
11
+ class NetworkCookieJar;
12
+
13
+ class WebPageManager : public QObject {
14
+ Q_OBJECT
15
+
16
+ public:
17
+ WebPageManager(QObject *parent = 0);
18
+ void append(WebPage *value);
19
+ QList<WebPage *> pages() const;
20
+ void setCurrentPage(WebPage *);
21
+ WebPage *currentPage() const;
22
+ WebPage *createPage(QObject *parent);
23
+ void setIgnoreSslErrors(bool);
24
+ bool ignoreSslErrors();
25
+ void reset();
26
+ NetworkCookieJar *cookieJar();
27
+ bool isLoading() const;
28
+ QDebug logger() const;
29
+ void enableLogging();
30
+
31
+ public slots:
32
+ void emitLoadStarted();
33
+ void setPageStatus(bool);
34
+ void requestCreated(QNetworkReply *reply);
35
+ void replyFinished(QNetworkReply *reply);
36
+
37
+ signals:
38
+ void pageFinished(bool);
39
+ void loadStarted();
40
+
41
+ private:
42
+ void emitPageFinished();
43
+ static void handleDebugMessage(QtMsgType type, const char *message);
44
+
45
+ QList<WebPage *> m_pages;
46
+ WebPage *m_currentPage;
47
+ bool m_ignoreSslErrors;
48
+ NetworkCookieJar *m_cookieJar;
49
+ QSet<QNetworkReply*> m_started;
50
+ bool m_success;
51
+ bool m_loggingEnabled;
52
+ QString *m_ignoredOutput;
53
+ };
54
+
55
+ #endif // _WEBPAGEMANAGER_H
56
+
@@ -0,0 +1,32 @@
1
+ #include "WindowFocus.h"
2
+ #include "SocketCommand.h"
3
+ #include "WebPage.h"
4
+ #include "CommandFactory.h"
5
+ #include "WebPageManager.h"
6
+
7
+ WindowFocus::WindowFocus(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
8
+ }
9
+
10
+ void WindowFocus::start() {
11
+ focusWindow(arguments()[0]);
12
+ }
13
+
14
+ void WindowFocus::windowNotFound() {
15
+ emit finished(new Response(false, QString("Unable to locate window. ")));
16
+ }
17
+
18
+ void WindowFocus::success(WebPage *page) {
19
+ page->setFocus();
20
+ emit finished(new Response(true));
21
+ }
22
+
23
+ void WindowFocus::focusWindow(QString selector) {
24
+ foreach(WebPage *page, manager()->pages()) {
25
+ if (page->matchesWindowSelector(selector)) {
26
+ success(page);
27
+ return;
28
+ }
29
+ }
30
+
31
+ windowNotFound();
32
+ }
data/src/WindowFocus.h ADDED
@@ -0,0 +1,15 @@
1
+ #include "SocketCommand.h"
2
+
3
+ class WindowFocus : public SocketCommand {
4
+ Q_OBJECT
5
+
6
+ public:
7
+ WindowFocus(WebPageManager *, QStringList &arguments, QObject *parent = 0);
8
+ virtual void start();
9
+
10
+ private:
11
+ void success(WebPage *);
12
+ void windowNotFound();
13
+ void focusWindow(QString);
14
+ };
15
+
data/src/body.cpp CHANGED
@@ -1,7 +1,8 @@
1
1
  #include "Body.h"
2
2
  #include "WebPage.h"
3
+ #include "WebPageManager.h"
3
4
 
4
- Body::Body(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
5
+ Body::Body(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
5
6
  }
6
7
 
7
8
  void Body::start() {
data/src/find_command.h CHANGED
@@ -1,6 +1,6 @@
1
1
  #define CHECK_COMMAND(expectedName) \
2
2
  if (strcmp(#expectedName, name) == 0) { \
3
- return new expectedName(m_page, arguments, this); \
3
+ return new expectedName(m_manager, arguments, this); \
4
4
  }
5
5
 
6
6
  CHECK_COMMAND(Visit)
@@ -20,7 +20,6 @@ CHECK_COMMAND(Headers)
20
20
  CHECK_COMMAND(SetCookie)
21
21
  CHECK_COMMAND(ClearCookies)
22
22
  CHECK_COMMAND(GetCookies)
23
- CHECK_COMMAND(Headers)
24
23
  CHECK_COMMAND(SetProxy)
25
24
  CHECK_COMMAND(ConsoleMessages)
26
25
  CHECK_COMMAND(RequestedUrl)
@@ -28,3 +27,8 @@ CHECK_COMMAND(CurrentUrl)
28
27
  CHECK_COMMAND(ResizeWindow)
29
28
  CHECK_COMMAND(IgnoreSslErrors)
30
29
  CHECK_COMMAND(SetSkipImageLoading)
30
+ CHECK_COMMAND(WindowFocus)
31
+ CHECK_COMMAND(GetWindowHandles)
32
+ CHECK_COMMAND(GetWindowHandle)
33
+ CHECK_COMMAND(Authenticate)
34
+ CHECK_COMMAND(EnableLogging)
@@ -2,6 +2,8 @@ TEMPLATE = app
2
2
  TARGET = webkit_server
3
3
  DESTDIR = .
4
4
  HEADERS = \
5
+ EnableLogging.h \
6
+ Authenticate.h \
5
7
  IgnoreSslErrors.h \
6
8
  ResizeWindow.h \
7
9
  CurrentUrl.h \
@@ -11,6 +13,7 @@ HEADERS = \
11
13
  Server.h \
12
14
  Connection.h \
13
15
  Command.h \
16
+ SocketCommand.h \
14
17
  Visit.h \
15
18
  Find.h \
16
19
  Reset.h \
@@ -39,8 +42,14 @@ HEADERS = \
39
42
  NullCommand.h \
40
43
  PageLoadingCommand.h \
41
44
  SetSkipImageLoading.h \
45
+ WebPageManager.h \
46
+ WindowFocus.h \
47
+ GetWindowHandles.h \
48
+ GetWindowHandle.h \
42
49
 
43
50
  SOURCES = \
51
+ EnableLogging.cpp \
52
+ Authenticate.cpp \
44
53
  IgnoreSslErrors.cpp \
45
54
  ResizeWindow.cpp \
46
55
  CurrentUrl.cpp \
@@ -51,6 +60,7 @@ SOURCES = \
51
60
  Server.cpp \
52
61
  Connection.cpp \
53
62
  Command.cpp \
63
+ SocketCommand.cpp \
54
64
  Visit.cpp \
55
65
  Find.cpp \
56
66
  Reset.cpp \
@@ -79,6 +89,10 @@ SOURCES = \
79
89
  NullCommand.cpp \
80
90
  PageLoadingCommand.cpp \
81
91
  SetSkipImageLoading.cpp \
92
+ WebPageManager.cpp \
93
+ WindowFocus.cpp \
94
+ GetWindowHandles.cpp \
95
+ GetWindowHandle.cpp \
82
96
 
83
97
  RESOURCES = webkit_server.qrc
84
98
  QT += network webkit
@@ -1,10 +1,8 @@
1
1
  #include "NAME.h"
2
2
  #include "WebPage.h"
3
3
 
4
- NAME::NAME(WebPage *page, QObject *parent) : Command(page, parent) {
4
+ NAME::NAME(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
5
5
  }
6
6
 
7
- void NAME::start(QStringList &arguments) {
8
- Q_UNUSED(arguments);
7
+ void NAME::start() {
9
8
  }
10
-
data/templates/Command.h CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  class WebPage;
4
4
 
5
- class NAME : public Command {
5
+ class NAME : public SocketCommand {
6
6
  Q_OBJECT
7
7
 
8
8
  public:
9
- NAME(WebPage *page, QObject *parent = 0);
10
- virtual void start(QStringList &arguments);
9
+ NAME(WebPageManager *, QStringList &arguments, QObject *parent = 0);
10
+ virtual void start();
11
11
  };
12
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: otherinbox-capybara-webkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2012-05-18 00:00:00.000000000 Z
16
+ date: 2012-07-10 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: capybara
@@ -145,6 +145,7 @@ files:
145
145
  - Appraisals
146
146
  - CONTRIBUTING.md
147
147
  - ChangeLog
148
+ - GOALS
148
149
  - Gemfile
149
150
  - Gemfile.lock
150
151
  - LICENSE
@@ -159,15 +160,16 @@ files:
159
160
  - gemfiles/1.1.gemfile
160
161
  - gemfiles/1.1.gemfile.lock
161
162
  - lib/capybara-webkit.rb
162
- - lib/capybara/driver/webkit.rb
163
- - lib/capybara/driver/webkit/browser.rb
164
- - lib/capybara/driver/webkit/connection.rb
165
- - lib/capybara/driver/webkit/cookie_jar.rb
166
- - lib/capybara/driver/webkit/node.rb
167
- - lib/capybara/driver/webkit/socket_debugger.rb
168
- - lib/capybara/driver/webkit/version.rb
169
163
  - lib/capybara/webkit.rb
164
+ - lib/capybara/webkit/browser.rb
165
+ - lib/capybara/webkit/connection.rb
166
+ - lib/capybara/webkit/cookie_jar.rb
167
+ - lib/capybara/webkit/driver.rb
168
+ - lib/capybara/webkit/errors.rb
170
169
  - lib/capybara/webkit/matchers.rb
170
+ - lib/capybara/webkit/node.rb
171
+ - lib/capybara/webkit/socket_debugger.rb
172
+ - lib/capybara/webkit/version.rb
171
173
  - lib/capybara_webkit_builder.rb
172
174
  - spec/browser_spec.rb
173
175
  - spec/capybara_webkit_builder_spec.rb
@@ -180,6 +182,9 @@ files:
180
182
  - spec/integration/session_spec.rb
181
183
  - spec/self_signed_ssl_cert.rb
182
184
  - spec/spec_helper.rb
185
+ - spec/support/app_runner.rb
186
+ - src/Authenticate.cpp
187
+ - src/Authenticate.h
183
188
  - src/Body.h
184
189
  - src/ClearCookies.cpp
185
190
  - src/ClearCookies.h
@@ -195,6 +200,8 @@ files:
195
200
  - src/ConsoleMessages.h
196
201
  - src/CurrentUrl.cpp
197
202
  - src/CurrentUrl.h
203
+ - src/EnableLogging.cpp
204
+ - src/EnableLogging.h
198
205
  - src/Evaluate.cpp
199
206
  - src/Evaluate.h
200
207
  - src/Execute.cpp
@@ -205,6 +212,10 @@ files:
205
212
  - src/FrameFocus.h
206
213
  - src/GetCookies.cpp
207
214
  - src/GetCookies.h
215
+ - src/GetWindowHandle.cpp
216
+ - src/GetWindowHandle.h
217
+ - src/GetWindowHandles.cpp
218
+ - src/GetWindowHandles.h
208
219
  - src/Header.cpp
209
220
  - src/Header.h
210
221
  - src/Headers.cpp
@@ -241,6 +252,8 @@ files:
241
252
  - src/SetProxy.h
242
253
  - src/SetSkipImageLoading.cpp
243
254
  - src/SetSkipImageLoading.h
255
+ - src/SocketCommand.cpp
256
+ - src/SocketCommand.h
244
257
  - src/Source.cpp
245
258
  - src/Source.h
246
259
  - src/Status.cpp
@@ -253,6 +266,10 @@ files:
253
266
  - src/Visit.h
254
267
  - src/WebPage.cpp
255
268
  - src/WebPage.h
269
+ - src/WebPageManager.cpp
270
+ - src/WebPageManager.h
271
+ - src/WindowFocus.cpp
272
+ - src/WindowFocus.h
256
273
  - src/body.cpp
257
274
  - src/capybara.js
258
275
  - src/find_command.h
@@ -282,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
299
  version: '0'
283
300
  requirements: []
284
301
  rubyforge_project:
285
- rubygems_version: 1.8.21
302
+ rubygems_version: 1.8.24
286
303
  signing_key:
287
304
  specification_version: 3
288
305
  summary: Headless Webkit driver for Capybara
@@ -298,3 +315,5 @@ test_files:
298
315
  - spec/integration/session_spec.rb
299
316
  - spec/self_signed_ssl_cert.rb
300
317
  - spec/spec_helper.rb
318
+ - spec/support/app_runner.rb
319
+ has_rdoc: