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.
Files changed (141) hide show
  1. data/.gitignore +2 -1
  2. data/GOALS +9 -0
  3. data/Gemfile.lock +15 -12
  4. data/LICENSE +1 -1
  5. data/NEWS.md +18 -0
  6. data/README.md +81 -2
  7. data/capybara-webkit.gemspec +1 -1
  8. data/lib/capybara/webkit.rb +11 -6
  9. data/lib/capybara/{driver/webkit → webkit}/browser.rb +90 -4
  10. data/lib/capybara/{driver/webkit → webkit}/connection.rb +48 -47
  11. data/lib/capybara/{driver/webkit → webkit}/cookie_jar.rb +1 -1
  12. data/lib/capybara/webkit/driver.rb +186 -0
  13. data/lib/capybara/webkit/errors.rb +10 -0
  14. data/lib/capybara/{driver/webkit → webkit}/node.rb +12 -4
  15. data/lib/capybara/{driver/webkit → webkit}/socket_debugger.rb +4 -1
  16. data/lib/capybara/{driver/webkit → webkit}/version.rb +1 -1
  17. data/lib/capybara_webkit_builder.rb +17 -3
  18. data/spec/browser_spec.rb +95 -7
  19. data/spec/connection_spec.rb +16 -5
  20. data/spec/cookie_jar_spec.rb +3 -3
  21. data/spec/driver_rendering_spec.rb +19 -26
  22. data/spec/driver_resize_window_spec.rb +3 -3
  23. data/spec/driver_spec.rb +1200 -822
  24. data/spec/integration/driver_spec.rb +4 -3
  25. data/spec/selenium_compatibility_spec.rb +49 -0
  26. data/spec/spec_helper.rb +14 -6
  27. data/spec/support/app_runner.rb +94 -0
  28. data/src/Authenticate.cpp +18 -0
  29. data/src/Authenticate.h +12 -0
  30. data/src/Body.h +3 -5
  31. data/src/ClearCookies.cpp +3 -5
  32. data/src/ClearCookies.h +3 -5
  33. data/src/ClearPromptText.cpp +11 -0
  34. data/src/ClearPromptText.h +9 -0
  35. data/src/Command.cpp +4 -15
  36. data/src/Command.h +3 -14
  37. data/src/CommandFactory.cpp +20 -6
  38. data/src/CommandFactory.h +3 -2
  39. data/src/CommandParser.cpp +1 -1
  40. data/src/Connection.cpp +22 -21
  41. data/src/Connection.h +5 -6
  42. data/src/ConsoleMessages.cpp +2 -1
  43. data/src/ConsoleMessages.h +3 -5
  44. data/src/CurrentUrl.cpp +9 -48
  45. data/src/CurrentUrl.h +8 -8
  46. data/src/EnableLogging.cpp +10 -0
  47. data/src/EnableLogging.h +12 -0
  48. data/src/Evaluate.cpp +2 -1
  49. data/src/Evaluate.h +3 -5
  50. data/src/Execute.cpp +2 -1
  51. data/src/Execute.h +3 -5
  52. data/src/Find.cpp +3 -2
  53. data/src/Find.h +3 -5
  54. data/src/FrameFocus.cpp +3 -2
  55. data/src/FrameFocus.h +3 -4
  56. data/src/GetCookies.cpp +3 -4
  57. data/src/GetCookies.h +3 -5
  58. data/src/GetTimeout.cpp +9 -0
  59. data/src/GetTimeout.h +11 -0
  60. data/src/GetWindowHandle.cpp +11 -0
  61. data/src/GetWindowHandle.h +10 -0
  62. data/src/GetWindowHandles.cpp +20 -0
  63. data/src/GetWindowHandles.h +10 -0
  64. data/src/Header.cpp +2 -1
  65. data/src/Header.h +3 -5
  66. data/src/Headers.cpp +8 -2
  67. data/src/Headers.h +3 -5
  68. data/src/IgnoreSslErrors.cpp +4 -3
  69. data/src/IgnoreSslErrors.h +3 -5
  70. data/src/JavascriptAlertMessages.cpp +10 -0
  71. data/src/JavascriptAlertMessages.h +9 -0
  72. data/src/JavascriptConfirmMessages.cpp +10 -0
  73. data/src/JavascriptConfirmMessages.h +9 -0
  74. data/src/JavascriptInvocation.cpp +1 -1
  75. data/src/JavascriptInvocation.h +1 -1
  76. data/src/JavascriptPromptMessages.cpp +10 -0
  77. data/src/JavascriptPromptMessages.h +9 -0
  78. data/src/NetworkAccessManager.cpp +38 -5
  79. data/src/NetworkAccessManager.h +20 -0
  80. data/src/Node.cpp +6 -1
  81. data/src/Node.h +4 -5
  82. data/src/NullCommand.cpp +5 -2
  83. data/src/NullCommand.h +4 -3
  84. data/src/PageLoadingCommand.cpp +12 -7
  85. data/src/PageLoadingCommand.h +6 -9
  86. data/src/Render.cpp +2 -1
  87. data/src/Render.h +3 -5
  88. data/src/RequestedUrl.cpp +2 -1
  89. data/src/RequestedUrl.h +3 -5
  90. data/src/Reset.cpp +3 -17
  91. data/src/Reset.h +3 -8
  92. data/src/ResizeWindow.cpp +2 -1
  93. data/src/ResizeWindow.h +3 -5
  94. data/src/Response.cpp +4 -0
  95. data/src/Response.h +1 -0
  96. data/src/Server.cpp +2 -3
  97. data/src/Server.h +0 -2
  98. data/src/SetConfirmAction.cpp +11 -0
  99. data/src/SetConfirmAction.h +9 -0
  100. data/src/SetCookie.cpp +3 -4
  101. data/src/SetCookie.h +3 -5
  102. data/src/SetPromptAction.cpp +11 -0
  103. data/src/SetPromptAction.h +9 -0
  104. data/src/SetPromptText.cpp +11 -0
  105. data/src/SetPromptText.h +9 -0
  106. data/src/SetProxy.cpp +2 -1
  107. data/src/SetProxy.h +3 -5
  108. data/src/SetSkipImageLoading.cpp +12 -0
  109. data/src/SetSkipImageLoading.h +9 -0
  110. data/src/SetTimeout.cpp +19 -0
  111. data/src/SetTimeout.h +9 -0
  112. data/src/SocketCommand.cpp +21 -0
  113. data/src/SocketCommand.h +29 -0
  114. data/src/Source.cpp +3 -2
  115. data/src/Source.h +3 -4
  116. data/src/Status.cpp +2 -1
  117. data/src/Status.h +3 -5
  118. data/src/TimeoutCommand.cpp +69 -0
  119. data/src/TimeoutCommand.h +41 -0
  120. data/src/UnsupportedContentHandler.cpp +11 -17
  121. data/src/UnsupportedContentHandler.h +5 -3
  122. data/src/Url.cpp +2 -1
  123. data/src/Url.h +3 -5
  124. data/src/Visit.cpp +3 -2
  125. data/src/Visit.h +3 -5
  126. data/src/WebPage.cpp +129 -44
  127. data/src/WebPage.h +37 -11
  128. data/src/WebPageManager.cpp +127 -0
  129. data/src/WebPageManager.h +59 -0
  130. data/src/WindowFocus.cpp +32 -0
  131. data/src/WindowFocus.h +15 -0
  132. data/src/body.cpp +2 -1
  133. data/src/capybara.js +38 -10
  134. data/src/find_command.h +17 -2
  135. data/src/main.cpp +0 -2
  136. data/src/webkit_server.pro +36 -0
  137. data/templates/Command.cpp +2 -4
  138. data/templates/Command.h +3 -3
  139. metadata +106 -27
  140. data/ChangeLog +0 -70
  141. data/lib/capybara/driver/webkit.rb +0 -136
@@ -1,7 +1,8 @@
1
1
  #include "RequestedUrl.h"
2
2
  #include "WebPage.h"
3
+ #include "WebPageManager.h"
3
4
 
4
- RequestedUrl::RequestedUrl(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
5
+ RequestedUrl::RequestedUrl(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
5
6
  }
6
7
 
7
8
  void RequestedUrl::start() {
@@ -1,12 +1,10 @@
1
- #include "Command.h"
1
+ #include "SocketCommand.h"
2
2
 
3
- class WebPage;
4
-
5
- class RequestedUrl : public Command {
3
+ class RequestedUrl : public SocketCommand {
6
4
  Q_OBJECT
7
5
 
8
6
  public:
9
- RequestedUrl(WebPage *page, QStringList &arguments, QObject *parent = 0);
7
+ RequestedUrl(WebPageManager *, QStringList &arguments, QObject *parent = 0);
10
8
  virtual void start();
11
9
  };
12
10
 
@@ -1,29 +1,15 @@
1
1
  #include "Reset.h"
2
2
  #include "WebPage.h"
3
- #include "NetworkAccessManager.h"
4
- #include "NetworkCookieJar.h"
3
+ #include "WebPageManager.h"
5
4
 
6
- Reset::Reset(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
5
+ Reset::Reset(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
7
6
  }
8
7
 
9
8
  void Reset::start() {
10
9
  page()->triggerAction(QWebPage::Stop);
11
10
 
12
- NetworkAccessManager* networkAccessManager = qobject_cast<NetworkAccessManager*>(page()->networkAccessManager());
13
- networkAccessManager->setCookieJar(new NetworkCookieJar());
14
- networkAccessManager->resetHeaders();
11
+ manager()->reset();
15
12
 
16
- page()->setUserAgent(NULL);
17
- page()->resetResponseHeaders();
18
- page()->resetConsoleMessages();
19
- page()->resetWindowSize();
20
- resetHistory();
21
13
  emit finished(new Response(true));
22
14
  }
23
15
 
24
- void Reset::resetHistory() {
25
- // Clearing the history preserves the current history item, so set it to blank first.
26
- page()->currentFrame()->setUrl(QUrl("about:blank"));
27
- page()->history()->clear();
28
- }
29
-
@@ -1,15 +1,10 @@
1
- #include "Command.h"
1
+ #include "SocketCommand.h"
2
2
 
3
- class WebPage;
4
-
5
- class Reset : public Command {
3
+ class Reset : public SocketCommand {
6
4
  Q_OBJECT
7
5
 
8
6
  public:
9
- Reset(WebPage *page, QStringList &arguments, QObject *parent = 0);
7
+ Reset(WebPageManager *, QStringList &arguments, QObject *parent = 0);
10
8
  virtual void start();
11
-
12
- private:
13
- void resetHistory();
14
9
  };
15
10
 
@@ -1,7 +1,8 @@
1
1
  #include "ResizeWindow.h"
2
2
  #include "WebPage.h"
3
+ #include "WebPageManager.h"
3
4
 
4
- ResizeWindow::ResizeWindow(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
5
+ ResizeWindow::ResizeWindow(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
5
6
  }
6
7
 
7
8
  void ResizeWindow::start() {
@@ -1,12 +1,10 @@
1
- #include "Command.h"
1
+ #include "SocketCommand.h"
2
2
 
3
- class WebPage;
4
-
5
- class ResizeWindow : public Command {
3
+ class ResizeWindow : public SocketCommand {
6
4
  Q_OBJECT
7
5
 
8
6
  public:
9
- ResizeWindow(WebPage *page, QStringList &arguments, QObject *parent = 0);
7
+ ResizeWindow(WebPageManager *, QStringList &arguments, QObject *parent = 0);
10
8
  virtual void start();
11
9
  };
12
10
 
@@ -22,3 +22,7 @@ bool Response::isSuccess() const {
22
22
  QByteArray Response::message() const {
23
23
  return m_message;
24
24
  }
25
+
26
+ QString Response::toString() const {
27
+ return QString(m_success ? "Success(" : "Failure(") + m_message + ")";
28
+ }
@@ -8,6 +8,7 @@ class Response {
8
8
  Response(bool success);
9
9
  bool isSuccess() const;
10
10
  QByteArray message() const;
11
+ QString toString() const;
11
12
 
12
13
  private:
13
14
  bool m_success;
@@ -1,12 +1,11 @@
1
1
  #include "Server.h"
2
- #include "WebPage.h"
3
2
  #include "Connection.h"
3
+ #include "WebPageManager.h"
4
4
 
5
5
  #include <QTcpServer>
6
6
 
7
7
  Server::Server(QObject *parent) : QObject(parent) {
8
8
  m_tcp_server = new QTcpServer(this);
9
- m_page = new WebPage(this);
10
9
  }
11
10
 
12
11
  bool Server::start() {
@@ -20,5 +19,5 @@ quint16 Server::server_port() const {
20
19
 
21
20
  void Server::handleConnection() {
22
21
  QTcpSocket *socket = m_tcp_server->nextPendingConnection();
23
- new Connection(socket, m_page, this);
22
+ new Connection(socket, new WebPageManager(this), this);
24
23
  }
@@ -1,7 +1,6 @@
1
1
  #include <QObject>
2
2
 
3
3
  class QTcpServer;
4
- class WebPage;
5
4
 
6
5
  class Server : public QObject {
7
6
  Q_OBJECT
@@ -16,6 +15,5 @@ class Server : public QObject {
16
15
 
17
16
  private:
18
17
  QTcpServer *m_tcp_server;
19
- WebPage *m_page;
20
18
  };
21
19
 
@@ -0,0 +1,11 @@
1
+ #include "SetConfirmAction.h"
2
+ #include "WebPage.h"
3
+ #include "WebPageManager.h"
4
+
5
+ SetConfirmAction::SetConfirmAction(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
6
+
7
+ void SetConfirmAction::start()
8
+ {
9
+ page()->setConfirmAction(arguments()[0]);
10
+ emit finished(new Response(true));
11
+ }
@@ -0,0 +1,9 @@
1
+ #include "SocketCommand.h"
2
+
3
+ class SetConfirmAction : public SocketCommand {
4
+ Q_OBJECT;
5
+
6
+ public:
7
+ SetConfirmAction(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
8
+ virtual void start();
9
+ };
@@ -1,16 +1,15 @@
1
1
  #include "SetCookie.h"
2
2
  #include "WebPage.h"
3
+ #include "WebPageManager.h"
3
4
  #include "NetworkCookieJar.h"
4
5
  #include <QNetworkCookie>
5
6
 
6
- SetCookie::SetCookie(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
7
+ SetCookie::SetCookie(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
7
8
 
8
9
  void SetCookie::start()
9
10
  {
10
11
  QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(arguments()[0].toAscii());
11
- NetworkCookieJar *jar = qobject_cast<NetworkCookieJar*>(page()
12
- ->networkAccessManager()
13
- ->cookieJar());
12
+ NetworkCookieJar *jar = manager()->cookieJar();
14
13
  jar->overwriteCookies(cookies);
15
14
  emit finished(new Response(true));
16
15
  }
@@ -1,11 +1,9 @@
1
- #include "Command.h"
1
+ #include "SocketCommand.h"
2
2
 
3
- class WebPage;
4
-
5
- class SetCookie : public Command {
3
+ class SetCookie : public SocketCommand {
6
4
  Q_OBJECT;
7
5
 
8
6
  public:
9
- SetCookie(WebPage *page, QStringList &arguments, QObject *parent = 0);
7
+ SetCookie(WebPageManager *, QStringList &arguments, QObject *parent = 0);
10
8
  virtual void start();
11
9
  };
@@ -0,0 +1,11 @@
1
+ #include "SetPromptAction.h"
2
+ #include "WebPage.h"
3
+ #include "WebPageManager.h"
4
+
5
+ SetPromptAction::SetPromptAction(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
6
+
7
+ void SetPromptAction::start()
8
+ {
9
+ page()->setPromptAction(arguments()[0]);
10
+ emit finished(new Response(true));
11
+ }
@@ -0,0 +1,9 @@
1
+ #include "SocketCommand.h"
2
+
3
+ class SetPromptAction : public SocketCommand {
4
+ Q_OBJECT;
5
+
6
+ public:
7
+ SetPromptAction(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
8
+ virtual void start();
9
+ };
@@ -0,0 +1,11 @@
1
+ #include "SetPromptText.h"
2
+ #include "WebPage.h"
3
+ #include "WebPageManager.h"
4
+
5
+ SetPromptText::SetPromptText(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
6
+
7
+ void SetPromptText::start()
8
+ {
9
+ page()->setPromptText(arguments()[0]);
10
+ emit finished(new Response(true));
11
+ }
@@ -0,0 +1,9 @@
1
+ #include "SocketCommand.h"
2
+
3
+ class SetPromptText : public SocketCommand {
4
+ Q_OBJECT;
5
+
6
+ public:
7
+ SetPromptText(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
8
+ virtual void start();
9
+ };
@@ -1,9 +1,10 @@
1
1
  #include "SetProxy.h"
2
2
  #include "WebPage.h"
3
+ #include "WebPageManager.h"
3
4
  #include <QNetworkAccessManager>
4
5
  #include <QNetworkProxy>
5
6
 
6
- SetProxy::SetProxy(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
7
+ SetProxy::SetProxy(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
7
8
 
8
9
  void SetProxy::start()
9
10
  {
@@ -1,11 +1,9 @@
1
- #include "Command.h"
1
+ #include "SocketCommand.h"
2
2
 
3
- class WebPage;
4
-
5
- class SetProxy : public Command {
3
+ class SetProxy : public SocketCommand {
6
4
  Q_OBJECT;
7
5
 
8
6
  public:
9
- SetProxy(WebPage *page, QStringList &arguments, QObject *parent = 0);
7
+ SetProxy(WebPageManager *, QStringList &arguments, QObject *parent = 0);
10
8
  virtual void start();
11
9
  };
@@ -0,0 +1,12 @@
1
+ #include "SetSkipImageLoading.h"
2
+ #include "WebPage.h"
3
+ #include "WebPageManager.h"
4
+
5
+ SetSkipImageLoading::SetSkipImageLoading(WebPageManager *manager, QStringList &arguments, QObject *parent) :
6
+ SocketCommand(manager, arguments, parent) {
7
+ }
8
+
9
+ void SetSkipImageLoading::start() {
10
+ page()->setSkipImageLoading(arguments().contains("true"));
11
+ emit finished(new Response(true));
12
+ }
@@ -0,0 +1,9 @@
1
+ #include "SocketCommand.h"
2
+
3
+ class SetSkipImageLoading : public SocketCommand {
4
+ Q_OBJECT
5
+
6
+ public:
7
+ SetSkipImageLoading(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
8
+ virtual void start();
9
+ };
@@ -0,0 +1,19 @@
1
+ #include "SetTimeout.h"
2
+ #include "WebPageManager.h"
3
+
4
+ SetTimeout::SetTimeout(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
5
+ }
6
+
7
+ void SetTimeout::start() {
8
+ QString timeoutString = arguments()[0];
9
+ bool ok;
10
+ int timeout = timeoutString.toInt(&ok);
11
+
12
+ if (ok) {
13
+ manager()->setTimeout(timeout);
14
+ emit finished(new Response(true));
15
+ } else {
16
+ emit finished(new Response(false, QString("Invalid value for timeout")));
17
+ }
18
+ }
19
+
@@ -0,0 +1,9 @@
1
+ #include "SocketCommand.h"
2
+
3
+ class SetTimeout : public SocketCommand {
4
+ Q_OBJECT
5
+
6
+ public:
7
+ SetTimeout(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
8
+ virtual void start();
9
+ };
@@ -0,0 +1,21 @@
1
+ #include "SocketCommand.h"
2
+ #include "WebPage.h"
3
+ #include "WebPageManager.h"
4
+
5
+ SocketCommand::SocketCommand(WebPageManager *manager, QStringList &arguments, QObject *parent) : Command(parent) {
6
+ m_manager = manager;
7
+ m_arguments = arguments;
8
+ }
9
+
10
+ WebPage *SocketCommand::page() const {
11
+ return m_manager->currentPage();
12
+ }
13
+
14
+ const QStringList &SocketCommand::arguments() const {
15
+ return m_arguments;
16
+ }
17
+
18
+ WebPageManager *SocketCommand::manager() const {
19
+ return m_manager;
20
+ }
21
+
@@ -0,0 +1,29 @@
1
+ #ifndef SOCKET_COMMAND_H
2
+ #define SOCKET_COMMAND_H
3
+
4
+ #include <QObject>
5
+ #include <QStringList>
6
+ #include "Command.h"
7
+
8
+ class WebPage;
9
+ class WebPageManager;
10
+ class Response;
11
+
12
+ class SocketCommand : public Command {
13
+ Q_OBJECT
14
+
15
+ public:
16
+ SocketCommand(WebPageManager *, QStringList &arguments, QObject *parent = 0);
17
+
18
+ protected:
19
+ WebPage *page() const;
20
+ const QStringList &arguments() const;
21
+ WebPageManager *manager() const;
22
+
23
+ private:
24
+ QStringList m_arguments;
25
+ WebPageManager *m_manager;
26
+
27
+ };
28
+
29
+ #endif
@@ -1,12 +1,13 @@
1
1
  #include "Source.h"
2
2
  #include "WebPage.h"
3
+ #include "WebPageManager.h"
3
4
 
4
- Source::Source(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
5
+ Source::Source(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
5
6
  }
6
7
 
7
8
  void Source::start() {
8
9
  QNetworkAccessManager* accessManager = page()->networkAccessManager();
9
- QNetworkRequest request(page()->currentFrame()->url());
10
+ QNetworkRequest request(page()->currentFrame()->requestedUrl());
10
11
  reply = accessManager->get(request);
11
12
 
12
13
  connect(reply, SIGNAL(finished()), this, SLOT(sourceLoaded()));
@@ -1,13 +1,12 @@
1
- #include "Command.h"
1
+ #include "SocketCommand.h"
2
2
 
3
- class WebPage;
4
3
  class QNetworkReply;
5
4
 
6
- class Source : public Command {
5
+ class Source : public SocketCommand {
7
6
  Q_OBJECT
8
7
 
9
8
  public:
10
- Source(WebPage *page, QStringList &arguments, QObject *parent = 0);
9
+ Source(WebPageManager *, QStringList &arguments, QObject *parent = 0);
11
10
  virtual void start();
12
11
 
13
12
  public slots:
@@ -1,8 +1,9 @@
1
1
  #include "Status.h"
2
2
  #include "WebPage.h"
3
+ #include "WebPageManager.h"
3
4
  #include <sstream>
4
5
 
5
- Status::Status(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
6
+ Status::Status(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
6
7
  }
7
8
 
8
9
  void Status::start() {