capybara-webkit 0.13.2 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.travis.yml +10 -0
  2. data/Gemfile.lock +20 -18
  3. data/NEWS.md +20 -1
  4. data/README.md +12 -10
  5. data/capybara-webkit.gemspec +3 -2
  6. data/lib/capybara/webkit/browser.rb +10 -19
  7. data/lib/capybara/webkit/connection.rb +13 -34
  8. data/lib/capybara/webkit/driver.rb +5 -22
  9. data/lib/capybara/webkit/node.rb +10 -2
  10. data/lib/capybara/webkit/version.rb +1 -1
  11. data/lib/capybara_webkit_builder.rb +10 -1
  12. data/spec/browser_spec.rb +1 -1
  13. data/spec/connection_spec.rb +4 -2
  14. data/spec/driver_rendering_spec.rb +2 -2
  15. data/spec/driver_resize_window_spec.rb +29 -40
  16. data/spec/driver_spec.rb +368 -125
  17. data/spec/integration/session_spec.rb +100 -6
  18. data/spec/spec_helper.rb +6 -9
  19. data/spec/support/app_runner.rb +2 -12
  20. data/src/Authenticate.cpp +2 -2
  21. data/src/ClearCookies.cpp +1 -1
  22. data/src/ClearPromptText.cpp +1 -1
  23. data/src/Command.cpp +13 -0
  24. data/src/Command.h +6 -0
  25. data/src/CommandFactory.cpp +1 -3
  26. data/src/Connection.cpp +4 -3
  27. data/src/ConsoleMessages.cpp +4 -1
  28. data/src/CurrentUrl.cpp +1 -16
  29. data/src/CurrentUrl.h +0 -6
  30. data/src/EnableLogging.cpp +1 -1
  31. data/src/Evaluate.cpp +3 -74
  32. data/src/Evaluate.h +0 -8
  33. data/src/Execute.cpp +2 -2
  34. data/src/Find.cpp +2 -2
  35. data/src/FrameFocus.cpp +3 -3
  36. data/src/GetCookies.cpp +1 -1
  37. data/src/GetTimeout.cpp +1 -1
  38. data/src/GetWindowHandle.cpp +1 -1
  39. data/src/GetWindowHandles.cpp +6 -5
  40. data/src/Header.cpp +2 -2
  41. data/src/Headers.cpp +1 -1
  42. data/src/IgnoreSslErrors.cpp +1 -1
  43. data/src/JavascriptAlertMessages.cpp +4 -1
  44. data/src/JavascriptConfirmMessages.cpp +4 -1
  45. data/src/JavascriptPromptMessages.cpp +4 -1
  46. data/src/JsonSerializer.cpp +116 -0
  47. data/src/JsonSerializer.h +20 -0
  48. data/src/NetworkAccessManager.cpp +58 -17
  49. data/src/NetworkAccessManager.h +6 -0
  50. data/src/NoOpReply.cpp +32 -0
  51. data/src/NoOpReply.h +18 -0
  52. data/src/Node.cpp +1 -1
  53. data/src/NullCommand.cpp +1 -1
  54. data/src/PageLoadingCommand.cpp +5 -4
  55. data/src/Render.cpp +1 -1
  56. data/src/Reset.cpp +1 -1
  57. data/src/ResizeWindow.cpp +1 -1
  58. data/src/Response.cpp +3 -3
  59. data/src/Response.h +13 -4
  60. data/src/SetConfirmAction.cpp +1 -1
  61. data/src/SetCookie.cpp +1 -1
  62. data/src/SetPromptAction.cpp +1 -1
  63. data/src/SetPromptText.cpp +1 -1
  64. data/src/SetProxy.cpp +2 -2
  65. data/src/SetSkipImageLoading.cpp +1 -1
  66. data/src/SetTimeout.cpp +2 -2
  67. data/src/SetUrlBlacklist.cpp +15 -0
  68. data/src/SetUrlBlacklist.h +11 -0
  69. data/src/Status.cpp +1 -1
  70. data/src/TimeoutCommand.cpp +6 -6
  71. data/src/TimeoutCommand.h +0 -3
  72. data/src/UnsupportedContentHandler.cpp +1 -4
  73. data/src/Visit.cpp +1 -1
  74. data/src/WebPage.cpp +41 -31
  75. data/src/WebPage.h +14 -12
  76. data/src/WebPageManager.cpp +13 -8
  77. data/src/WebPageManager.h +3 -2
  78. data/src/WindowFocus.cpp +2 -2
  79. data/src/body.cpp +7 -2
  80. data/src/capybara.js +10 -2
  81. data/src/find_command.h +1 -3
  82. data/src/webkit_server.pro +7 -7
  83. metadata +47 -82
  84. checksums.yaml +0 -7
  85. data/spec/integration/driver_spec.rb +0 -21
  86. data/src/RequestedUrl.cpp +0 -13
  87. data/src/RequestedUrl.h +0 -10
  88. data/src/Source.cpp +0 -19
  89. data/src/Source.h +0 -18
  90. data/src/Url.cpp +0 -13
  91. data/src/Url.h +0 -10
@@ -0,0 +1,32 @@
1
+ #include <QTimer>
2
+ #include "NoOpReply.h"
3
+
4
+ NoOpReply::NoOpReply(QNetworkRequest &request, QObject *parent) : QNetworkReply(parent) {
5
+ open(ReadOnly | Unbuffered);
6
+ setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200);
7
+ setHeader(QNetworkRequest::ContentLengthHeader, QVariant(0));
8
+ setHeader(QNetworkRequest::ContentTypeHeader, QVariant(QString("text/plain")));
9
+ setUrl(request.url());
10
+
11
+ QTimer::singleShot( 0, this, SIGNAL(readyRead()) );
12
+ QTimer::singleShot( 0, this, SIGNAL(finished()) );
13
+ }
14
+
15
+ void NoOpReply::abort() {
16
+ // NO-OP
17
+ }
18
+
19
+ qint64 NoOpReply::bytesAvailable() const {
20
+ return 0;
21
+ }
22
+
23
+ bool NoOpReply::isSequential() const {
24
+ return true;
25
+ }
26
+
27
+ qint64 NoOpReply::readData(char *data, qint64 maxSize) {
28
+ Q_UNUSED(data);
29
+ Q_UNUSED(maxSize);
30
+ return 0;
31
+ }
32
+
@@ -0,0 +1,18 @@
1
+ #include <QNetworkReply>
2
+ #include <QNetworkRequest>
3
+
4
+ class NoOpReply : public QNetworkReply {
5
+ Q_OBJECT
6
+
7
+ public:
8
+ NoOpReply(QNetworkRequest &request, QObject *parent = 0);
9
+
10
+ void abort();
11
+ qint64 bytesAvailable() const;
12
+ bool isSequential() const;
13
+
14
+ protected:
15
+ qint64 readData(char *data, qint64 maxSize);
16
+
17
+ };
18
+
@@ -10,7 +10,7 @@ void Node::start() {
10
10
  QString functionName = functionArguments.takeFirst();
11
11
  QVariant result = page()->invokeCapybaraFunction(functionName, functionArguments);
12
12
  QString attributeValue = result.toString();
13
- emit finished(new Response(true, attributeValue));
13
+ emitFinished(true, attributeValue);
14
14
  }
15
15
 
16
16
  QString Node::toString() const {
@@ -8,6 +8,6 @@ NullCommand::NullCommand(QString name, QObject *parent) : Command(parent) {
8
8
 
9
9
  void NullCommand::start() {
10
10
  QString failure = QString("[Capybara WebKit] Unknown command: ") + m_name + "\n";
11
- emit finished(new Response(false, failure));
11
+ emitFinished(false, failure);
12
12
  }
13
13
 
@@ -9,13 +9,14 @@ PageLoadingCommand::PageLoadingCommand(Command *command, WebPageManager *manager
9
9
  m_pageLoadingFromCommand = false;
10
10
  m_pageSuccess = true;
11
11
  m_pendingResponse = NULL;
12
- connect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
13
- connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
12
+ m_command->setParent(this);
14
13
  }
15
14
 
16
15
  void PageLoadingCommand::start() {
17
16
  m_manager->logger() << "Started" << m_command->toString();
18
17
  connect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
18
+ connect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
19
+ connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
19
20
  m_command->start();
20
21
  };
21
22
 
@@ -29,7 +30,7 @@ void PageLoadingCommand::pendingLoadFinished(bool success) {
29
30
  emit finished(m_pendingResponse);
30
31
  } else {
31
32
  QString message = m_manager->currentPage()->failureString();
32
- emit finished(new Response(false, message));
33
+ emitFinished(false, message);
33
34
  }
34
35
  }
35
36
  }
@@ -43,7 +44,7 @@ void PageLoadingCommand::pageLoadingFromCommand() {
43
44
  void PageLoadingCommand::commandFinished(Response *response) {
44
45
  disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
45
46
  m_manager->logger() << "Finished" << m_command->toString() << "with response" << response->toString();
46
- m_command->deleteLater();
47
+
47
48
  if (m_pageLoadingFromCommand)
48
49
  m_pendingResponse = response;
49
50
  else
@@ -15,5 +15,5 @@ void Render::start() {
15
15
 
16
16
  bool result = page()->render( imagePath );
17
17
 
18
- emit finished(new Response(result));
18
+ emitFinished(result);
19
19
  }
@@ -10,6 +10,6 @@ void Reset::start() {
10
10
 
11
11
  manager()->reset();
12
12
 
13
- emit finished(new Response(true));
13
+ emitFinished(true);
14
14
  }
15
15
 
@@ -12,6 +12,6 @@ void ResizeWindow::start() {
12
12
  QSize size(width, height);
13
13
  page()->setViewportSize(size);
14
14
 
15
- emit finished(new Response(true));
15
+ emitFinished(true);
16
16
  }
17
17
 
@@ -1,17 +1,17 @@
1
1
  #include "Response.h"
2
2
  #include <iostream>
3
3
 
4
- Response::Response(bool success, QString message) {
4
+ Response::Response(bool success, QString message, QObject *parent) : QObject(parent) {
5
5
  m_success = success;
6
6
  m_message = message.toUtf8();
7
7
  }
8
8
 
9
- Response::Response(bool success, QByteArray message) {
9
+ Response::Response(bool success, QByteArray message, QObject *parent) : QObject(parent) {
10
10
  m_success = success;
11
11
  m_message = message;
12
12
  }
13
13
 
14
- Response::Response(bool success) {
14
+ Response::Response(bool success, QObject *parent) : QObject(parent) {
15
15
  m_success = success;
16
16
  }
17
17
 
@@ -1,11 +1,17 @@
1
+ #ifndef RESPONSE_H
2
+ #define RESPONSE_H
3
+
4
+ #include <QObject>
1
5
  #include <QString>
2
6
  #include <QByteArray>
3
7
 
4
- class Response {
8
+ class Response : public QObject {
9
+ Q_OBJECT
10
+
5
11
  public:
6
- Response(bool success, QString message);
7
- Response(bool success, QByteArray message);
8
- Response(bool success);
12
+ Response(bool success, QString message, QObject *parent);
13
+ Response(bool success, QByteArray message, QObject *parent);
14
+ Response(bool success, QObject *parent);
9
15
  bool isSuccess() const;
10
16
  QByteArray message() const;
11
17
  QString toString() const;
@@ -14,3 +20,6 @@ class Response {
14
20
  bool m_success;
15
21
  QByteArray m_message;
16
22
  };
23
+
24
+ #endif
25
+
@@ -7,5 +7,5 @@ SetConfirmAction::SetConfirmAction(WebPageManager *manager, QStringList &argumen
7
7
  void SetConfirmAction::start()
8
8
  {
9
9
  page()->setConfirmAction(arguments()[0]);
10
- emit finished(new Response(true));
10
+ emitFinished(true);
11
11
  }
@@ -11,5 +11,5 @@ void SetCookie::start()
11
11
  QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(arguments()[0].toAscii());
12
12
  NetworkCookieJar *jar = manager()->cookieJar();
13
13
  jar->overwriteCookies(cookies);
14
- emit finished(new Response(true));
14
+ emitFinished(true);
15
15
  }
@@ -7,5 +7,5 @@ SetPromptAction::SetPromptAction(WebPageManager *manager, QStringList &arguments
7
7
  void SetPromptAction::start()
8
8
  {
9
9
  page()->setPromptAction(arguments()[0]);
10
- emit finished(new Response(true));
10
+ emitFinished(true);
11
11
  }
@@ -7,5 +7,5 @@ SetPromptText::SetPromptText(WebPageManager *manager, QStringList &arguments, QO
7
7
  void SetPromptText::start()
8
8
  {
9
9
  page()->setPromptText(arguments()[0]);
10
- emit finished(new Response(true));
10
+ emitFinished(true);
11
11
  }
@@ -1,7 +1,7 @@
1
1
  #include "SetProxy.h"
2
2
  #include "WebPage.h"
3
3
  #include "WebPageManager.h"
4
- #include <QNetworkAccessManager>
4
+ #include "NetworkAccessManager.h"
5
5
  #include <QNetworkProxy>
6
6
 
7
7
  SetProxy::SetProxy(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
@@ -19,5 +19,5 @@ void SetProxy::start()
19
19
  arguments()[3]);
20
20
 
21
21
  page()->networkAccessManager()->setProxy(proxy);
22
- emit finished(new Response(true));
22
+ emitFinished(true);
23
23
  }
@@ -8,5 +8,5 @@ SetSkipImageLoading::SetSkipImageLoading(WebPageManager *manager, QStringList &a
8
8
 
9
9
  void SetSkipImageLoading::start() {
10
10
  page()->setSkipImageLoading(arguments().contains("true"));
11
- emit finished(new Response(true));
11
+ emitFinished(true);
12
12
  }
@@ -11,9 +11,9 @@ void SetTimeout::start() {
11
11
 
12
12
  if (ok) {
13
13
  manager()->setTimeout(timeout);
14
- emit finished(new Response(true));
14
+ emitFinished(true);
15
15
  } else {
16
- emit finished(new Response(false, QString("Invalid value for timeout")));
16
+ emitFinished(false, QString("Invalid value for timeout"));
17
17
  }
18
18
  }
19
19
 
@@ -0,0 +1,15 @@
1
+
2
+ #include "SetUrlBlacklist.h"
3
+ #include "WebPageManager.h"
4
+ #include "WebPage.h"
5
+ #include "NetworkAccessManager.h"
6
+
7
+ SetUrlBlacklist::SetUrlBlacklist(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
8
+ }
9
+
10
+ void SetUrlBlacklist::start() {
11
+ NetworkAccessManager* networkAccessManager = page()->networkAccessManager();
12
+ networkAccessManager->setUrlBlacklist(arguments());
13
+ emitFinished(true);
14
+ }
15
+
@@ -0,0 +1,11 @@
1
+
2
+ #include "SocketCommand.h"
3
+
4
+ class SetUrlBlacklist : public SocketCommand {
5
+ Q_OBJECT
6
+
7
+ public:
8
+ SetUrlBlacklist(WebPageManager *manager, QStringList &arguments, QObject *parent = 0);
9
+ virtual void start();
10
+ };
11
+
@@ -8,6 +8,6 @@ Status::Status(WebPageManager *manager, QStringList &arguments, QObject *parent)
8
8
 
9
9
  void Status::start() {
10
10
  int status = page()->getLastStatus();
11
- emit finished(new Response(true, QString::number(status)));
11
+ emitFinished(true, QString::number(status));
12
12
  }
13
13
 
@@ -3,17 +3,20 @@
3
3
  #include "WebPageManager.h"
4
4
  #include "WebPage.h"
5
5
  #include <QTimer>
6
+ #include <QApplication>
6
7
 
7
8
  TimeoutCommand::TimeoutCommand(Command *command, WebPageManager *manager, QObject *parent) : Command(parent) {
8
9
  m_command = command;
9
10
  m_manager = manager;
10
11
  m_timer = new QTimer(this);
11
12
  m_timer->setSingleShot(true);
13
+ m_command->setParent(this);
12
14
  connect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
13
15
  connect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
14
16
  }
15
17
 
16
18
  void TimeoutCommand::start() {
19
+ QApplication::processEvents();
17
20
  if (m_manager->isLoading()) {
18
21
  m_manager->logger() << this->toString() << "waiting for load to finish";
19
22
  connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
@@ -36,13 +39,13 @@ void TimeoutCommand::startTimeout() {
36
39
  }
37
40
 
38
41
  void TimeoutCommand::pendingLoadFinished(bool success) {
42
+ disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
39
43
  if (success) {
40
44
  startCommand();
41
45
  } else {
42
46
  disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
43
47
  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()));
48
+ emitFinished(false, m_manager->currentPage()->failureString());
46
49
  }
47
50
  }
48
51
 
@@ -55,15 +58,12 @@ void TimeoutCommand::commandTimeout() {
55
58
  disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
56
59
  disconnect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
57
60
  m_manager->currentPage()->triggerAction(QWebPage::Stop);
58
- m_command->deleteLater();
59
- emit finished(new Response(false, QString("timeout")));
61
+ emit finished(new Response(false, QString("timeout"), this));
60
62
  }
61
63
 
62
64
  void TimeoutCommand::commandFinished(Response *response) {
63
65
  disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
64
66
  disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
65
- disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
66
- m_command->deleteLater();
67
67
  emit finished(response);
68
68
  }
69
69
 
@@ -26,9 +26,6 @@ class TimeoutCommand : public Command {
26
26
  void pageLoadingFromCommand();
27
27
  void pendingLoadFinished(bool);
28
28
 
29
- signals:
30
- void finished(Response *response);
31
-
32
29
  protected:
33
30
  void startCommand();
34
31
  void startTimeout();
@@ -10,17 +10,14 @@ UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkRepl
10
10
  void UnsupportedContentHandler::renderNonHtmlContent() {
11
11
  QByteArray text = m_reply->readAll();
12
12
  m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
13
- m_page->networkAccessManagerFinishedReply(m_reply);
14
- m_page->loadFinished(true);
13
+ m_page->unsupportedContentFinishedReply(m_reply);
15
14
  this->deleteLater();
16
15
  }
17
16
 
18
17
  void UnsupportedContentHandler::waitForReplyToFinish() {
19
18
  connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
20
- disconnect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
21
19
  }
22
20
 
23
21
  void UnsupportedContentHandler::replyFinished() {
24
22
  renderNonHtmlContent();
25
- connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
26
23
  }
@@ -9,5 +9,5 @@ Visit::Visit(WebPageManager *manager, QStringList &arguments, QObject *parent) :
9
9
  void Visit::start() {
10
10
  QUrl requestedUrl = QUrl::fromEncoded(arguments()[0].toUtf8(), QUrl::StrictMode);
11
11
  page()->currentFrame()->load(QUrl(requestedUrl));
12
- emit finished(new Response(true));
12
+ emitFinished(true);
13
13
  }
@@ -14,6 +14,7 @@ WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
14
14
  m_failed = false;
15
15
  m_manager = manager;
16
16
  m_uuid = QUuid::createUuid().toString();
17
+ m_unsupportedContentLoaded = false;
17
18
 
18
19
  setForwardUnsupportedContent(true);
19
20
  loadJavascript();
@@ -33,7 +34,6 @@ WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
33
34
  resetWindowSize();
34
35
 
35
36
  settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
36
- currentFrame()->setUrl(QUrl("about:blank"));
37
37
  }
38
38
 
39
39
  void WebPage::resetWindowSize() {
@@ -45,18 +45,15 @@ void WebPage::setCustomNetworkAccessManager() {
45
45
  NetworkAccessManager *manager = new NetworkAccessManager(this);
46
46
  manager->setCookieJar(m_manager->cookieJar());
47
47
  this->setNetworkAccessManager(manager);
48
- connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(networkAccessManagerFinishedReply(QNetworkReply *)));
49
48
  connect(manager, SIGNAL(sslErrors(QNetworkReply *, QList<QSslError>)),
50
49
  this, SLOT(handleSslErrorsForReply(QNetworkReply *, QList<QSslError>)));
51
- connect(manager, SIGNAL(requestCreated(QByteArray &, QNetworkReply *)), this, SLOT(networkAccessManagerCreatedRequest(QByteArray &, QNetworkReply *)));
50
+ connect(manager, SIGNAL(requestCreated(QByteArray &, QNetworkReply *)),
51
+ SIGNAL(requestCreated(QByteArray &, QNetworkReply *)));
52
52
  }
53
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);
54
+ void WebPage::unsupportedContentFinishedReply(QNetworkReply *reply) {
55
+ m_unsupportedContentLoaded = true;
56
+ m_manager->replyFinished(reply);
60
57
  }
61
58
 
62
59
  void WebPage::loadJavascript() {
@@ -73,7 +70,7 @@ void WebPage::loadJavascript() {
73
70
  }
74
71
 
75
72
  void WebPage::setUserStylesheet() {
76
- QString data = QString("* { font-family: 'Arial' ! important; }").toUtf8().toBase64();
73
+ QString data = QString("*, :first-line, :first-letter, :before, :after { font-family: 'Arial' ! important; }").toUtf8().toBase64();
77
74
  QUrl url = QUrl(QString("data:text/css;charset=utf-8;base64,") + data);
78
75
  settings()->setUserStyleSheetUrl(url);
79
76
  }
@@ -86,20 +83,20 @@ QString WebPage::userAgentForUrl(const QUrl &url ) const {
86
83
  }
87
84
  }
88
85
 
89
- QString WebPage::consoleMessages() {
90
- return m_consoleMessages.join("\n");
86
+ QVariantList WebPage::consoleMessages() {
87
+ return m_consoleMessages;
91
88
  }
92
89
 
93
- QString WebPage::alertMessages() {
94
- return m_alertMessages.join("\n");
90
+ QVariantList WebPage::alertMessages() {
91
+ return m_alertMessages;
95
92
  }
96
93
 
97
- QString WebPage::confirmMessages() {
98
- return m_confirmMessages.join("\n");
94
+ QVariantList WebPage::confirmMessages() {
95
+ return m_confirmMessages;
99
96
  }
100
97
 
101
- QString WebPage::promptMessages() {
102
- return m_promptMessages.join("\n");
98
+ QVariantList WebPage::promptMessages() {
99
+ return m_promptMessages;
103
100
  }
104
101
 
105
102
  void WebPage::setUserAgent(QString userAgent) {
@@ -134,17 +131,22 @@ QVariant WebPage::invokeCapybaraFunction(QString &name, const QStringList &argum
134
131
  }
135
132
 
136
133
  void WebPage::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) {
137
- QString fullMessage = QString::number(lineNumber) + "|" + message;
138
- if (!sourceID.isEmpty())
139
- fullMessage = sourceID + "|" + fullMessage;
140
- m_consoleMessages.append(fullMessage);
141
- std::cout << qPrintable(fullMessage) << std::endl;
134
+ QVariantMap m;
135
+ m["message"] = message;
136
+ QString fullMessage = QString(message);
137
+ if (!sourceID.isEmpty()) {
138
+ fullMessage = sourceID + "|" + QString::number(lineNumber) + "|" + fullMessage;
139
+ m["source"] = sourceID;
140
+ m["line_number"] = lineNumber;
141
+ }
142
+ m_consoleMessages.append(m);
143
+ m_manager->logger() << qPrintable(fullMessage);
142
144
  }
143
145
 
144
146
  void WebPage::javaScriptAlert(QWebFrame *frame, const QString &message) {
145
147
  Q_UNUSED(frame);
146
148
  m_alertMessages.append(message);
147
- std::cout << "ALERT: " << qPrintable(message) << std::endl;
149
+ m_manager->logger() << "ALERT:" << qPrintable(message);
148
150
  }
149
151
 
150
152
  bool WebPage::javaScriptConfirm(QWebFrame *frame, const QString &message) {
@@ -169,6 +171,7 @@ bool WebPage::javaScriptPrompt(QWebFrame *frame, const QString &message, const Q
169
171
  void WebPage::loadStarted() {
170
172
  m_loading = true;
171
173
  m_errorPageMessage = QString();
174
+ m_unsupportedContentLoaded = false;
172
175
  }
173
176
 
174
177
  void WebPage::loadFinished(bool success) {
@@ -221,13 +224,12 @@ QString WebPage::chooseFile(QWebFrame *parentFrame, const QString &suggestedFile
221
224
  Q_UNUSED(parentFrame);
222
225
  Q_UNUSED(suggestedFile);
223
226
 
224
- return getLastAttachedFileName();
227
+ return getAttachedFileNames().first();
225
228
  }
226
229
 
227
230
  bool WebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) {
228
231
  if (extension == ChooseMultipleFilesExtension) {
229
- QStringList names = QStringList() << getLastAttachedFileName();
230
- static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = names;
232
+ static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = getAttachedFileNames();
231
233
  return true;
232
234
  }
233
235
  else if (extension == QWebPage::ErrorPageExtension) {
@@ -239,8 +241,8 @@ bool WebPage::extension(Extension extension, const ExtensionOption *option, Exte
239
241
  return false;
240
242
  }
241
243
 
242
- QString WebPage::getLastAttachedFileName() {
243
- return currentFrame()->evaluateJavaScript(QString("Capybara.lastAttachedFile")).toString();
244
+ QStringList WebPage::getAttachedFileNames() {
245
+ return currentFrame()->evaluateJavaScript(QString("Capybara.attachedFiles")).toStringList();
244
246
  }
245
247
 
246
248
  void WebPage::handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &errors) {
@@ -253,11 +255,15 @@ void WebPage::setSkipImageLoading(bool skip) {
253
255
  }
254
256
 
255
257
  int WebPage::getLastStatus() {
256
- return qobject_cast<NetworkAccessManager *>(networkAccessManager())->statusFor(currentFrame()->url());
258
+ return networkAccessManager()->statusFor(currentFrame()->requestedUrl());
257
259
  }
258
260
 
259
261
  const QList<QNetworkReply::RawHeaderPair> &WebPage::pageHeaders() {
260
- return qobject_cast<NetworkAccessManager *>(networkAccessManager())->headersFor(currentFrame()->url());
262
+ return networkAccessManager()->headersFor(currentFrame()->requestedUrl());
263
+ }
264
+
265
+ NetworkAccessManager *WebPage::networkAccessManager() {
266
+ return qobject_cast<NetworkAccessManager *>(QWebPage::networkAccessManager());
261
267
  }
262
268
 
263
269
  void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
@@ -272,6 +278,10 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
272
278
  }
273
279
  }
274
280
 
281
+ bool WebPage::unsupportedContentLoaded() {
282
+ return m_unsupportedContentLoaded;
283
+ }
284
+
275
285
  bool WebPage::supportsExtension(Extension extension) const {
276
286
  if (extension == ErrorPageExtension)
277
287
  return true;