capybara-webkit 0.14.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +21 -0
  3. data/Appraisals +4 -4
  4. data/CONTRIBUTING.md +14 -3
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +27 -19
  7. data/NEWS.md +15 -0
  8. data/README.md +126 -76
  9. data/Vagrantfile +7 -0
  10. data/capybara-webkit.gemspec +3 -0
  11. data/gemfiles/2.0.gemfile +7 -0
  12. data/gemfiles/2.0.gemfile.lock +72 -0
  13. data/gemfiles/2.1.gemfile +7 -0
  14. data/gemfiles/2.1.gemfile.lock +71 -0
  15. data/lib/capybara/webkit/browser.rb +22 -22
  16. data/lib/capybara/webkit/connection.rb +9 -6
  17. data/lib/capybara/webkit/driver.rb +22 -6
  18. data/lib/capybara/webkit/errors.rb +25 -0
  19. data/lib/capybara/webkit/node.rb +36 -10
  20. data/lib/capybara/webkit/version.rb +1 -1
  21. data/spec/browser_spec.rb +16 -1
  22. data/spec/capybara_webkit_builder_spec.rb +9 -3
  23. data/spec/connection_spec.rb +19 -3
  24. data/spec/driver_spec.rb +324 -144
  25. data/spec/errors_spec.rb +11 -0
  26. data/spec/integration/session_spec.rb +244 -0
  27. data/spec/selenium_compatibility_spec.rb +3 -1
  28. data/spec/spec_helper.rb +1 -9
  29. data/src/Authenticate.cpp +3 -2
  30. data/src/ClearCookies.cpp +1 -1
  31. data/src/ClearPromptText.cpp +1 -1
  32. data/src/Command.cpp +8 -4
  33. data/src/Command.h +7 -4
  34. data/src/CommandFactory.cpp +4 -2
  35. data/src/CommandParser.cpp +1 -1
  36. data/src/Connection.cpp +4 -4
  37. data/src/ConsoleMessages.cpp +1 -1
  38. data/src/CurrentUrl.cpp +2 -2
  39. data/src/EnableLogging.cpp +1 -1
  40. data/src/ErrorMessage.cpp +26 -0
  41. data/src/ErrorMessage.h +21 -0
  42. data/src/Evaluate.cpp +1 -1
  43. data/src/Execute.cpp +3 -2
  44. data/src/FindCss.cpp +13 -0
  45. data/src/FindCss.h +11 -0
  46. data/src/FindXpath.cpp +13 -0
  47. data/src/FindXpath.h +11 -0
  48. data/src/FrameFocus.cpp +4 -3
  49. data/src/GetCookies.cpp +1 -1
  50. data/src/GetTimeout.cpp +1 -1
  51. data/src/GetWindowHandle.cpp +1 -1
  52. data/src/GetWindowHandles.cpp +1 -1
  53. data/src/Header.cpp +2 -2
  54. data/src/Headers.cpp +1 -6
  55. data/src/IgnoreSslErrors.cpp +1 -1
  56. data/src/InvocationResult.cpp +29 -0
  57. data/src/InvocationResult.h +16 -0
  58. data/src/JavascriptAlertMessages.cpp +1 -1
  59. data/src/JavascriptCommand.cpp +15 -0
  60. data/src/JavascriptCommand.h +20 -0
  61. data/src/JavascriptConfirmMessages.cpp +1 -1
  62. data/src/JavascriptInvocation.cpp +128 -1
  63. data/src/JavascriptInvocation.h +22 -1
  64. data/src/JavascriptPromptMessages.cpp +1 -1
  65. data/src/NetworkAccessManager.cpp +8 -16
  66. data/src/NetworkAccessManager.h +5 -11
  67. data/src/NetworkReplyProxy.cpp +91 -0
  68. data/src/NetworkReplyProxy.h +65 -0
  69. data/src/Node.cpp +4 -4
  70. data/src/Node.h +2 -2
  71. data/src/NullCommand.cpp +2 -1
  72. data/src/PageLoadingCommand.cpp +2 -1
  73. data/src/Render.cpp +1 -1
  74. data/src/Reset.cpp +1 -1
  75. data/src/ResizeWindow.cpp +1 -1
  76. data/src/Response.cpp +7 -0
  77. data/src/Response.h +8 -3
  78. data/src/SetConfirmAction.cpp +1 -1
  79. data/src/SetCookie.cpp +2 -2
  80. data/src/SetPromptAction.cpp +1 -1
  81. data/src/SetPromptText.cpp +1 -1
  82. data/src/SetProxy.cpp +2 -2
  83. data/src/SetSkipImageLoading.cpp +1 -1
  84. data/src/SetTimeout.cpp +3 -2
  85. data/src/SetUrlBlacklist.cpp +2 -2
  86. data/src/Status.cpp +1 -1
  87. data/src/TimeoutCommand.cpp +4 -2
  88. data/src/Title.cpp +11 -0
  89. data/src/Title.h +9 -0
  90. data/src/Version.cpp +13 -0
  91. data/src/Version.h +10 -0
  92. data/src/Visit.cpp +1 -1
  93. data/src/WebPage.cpp +49 -27
  94. data/src/WebPage.h +14 -7
  95. data/src/WebPageManager.cpp +10 -1
  96. data/src/WebPageManager.h +4 -1
  97. data/src/WindowFocus.cpp +3 -2
  98. data/src/body.cpp +3 -6
  99. data/src/capybara.js +103 -101
  100. data/src/find_command.h +4 -2
  101. data/src/main.cpp +1 -1
  102. data/src/stable.h +39 -0
  103. data/src/webkit_server.pro +26 -6
  104. data/vagrant_setup.sh +58 -0
  105. metadata +51 -78
  106. data/gemfiles/1.0.gemfile +0 -7
  107. data/gemfiles/1.0.gemfile.lock +0 -70
  108. data/gemfiles/1.1.gemfile +0 -7
  109. data/gemfiles/1.1.gemfile.lock +0 -70
  110. data/src/Find.cpp +0 -20
  111. data/src/Find.h +0 -11
@@ -1,19 +1,40 @@
1
1
  #include <QObject>
2
2
  #include <QString>
3
3
  #include <QStringList>
4
+ #include <QEvent>
5
+ #include <QWebElement>
6
+
7
+ class WebPage;
8
+ class InvocationResult;
4
9
 
5
10
  class JavascriptInvocation : public QObject {
6
11
  Q_OBJECT
7
12
  Q_PROPERTY(QString functionName READ functionName)
8
13
  Q_PROPERTY(QStringList arguments READ arguments)
14
+ Q_PROPERTY(QVariant error READ getError WRITE setError)
9
15
 
10
16
  public:
11
- JavascriptInvocation(const QString &functionName, const QStringList &arguments, QObject *parent = 0);
17
+ JavascriptInvocation(const QString &functionName, const QStringList &arguments, WebPage *page, QObject *parent = 0);
12
18
  QString &functionName();
13
19
  QStringList &arguments();
20
+ Q_INVOKABLE void leftClick(int x, int y);
21
+ Q_INVOKABLE void rightClick(int x, int y);
22
+ Q_INVOKABLE void doubleClick(int x, int y);
23
+ Q_INVOKABLE bool clickTest(QWebElement element, int absoluteX, int absoluteY);
24
+ Q_INVOKABLE QVariantMap clickPosition(QWebElement element, int left, int top, int width, int height);
25
+ Q_INVOKABLE void hover(int absoluteX, int absoluteY);
26
+ Q_INVOKABLE void keypress(QChar);
27
+ QVariant getError();
28
+ void setError(QVariant error);
29
+ InvocationResult invoke(QWebFrame *);
14
30
 
15
31
  private:
16
32
  QString m_functionName;
17
33
  QStringList m_arguments;
34
+ WebPage *m_page;
35
+ QVariant m_error;
36
+ void mouseEvent(QEvent::Type type, const QPoint & position, Qt::MouseButton button);
37
+ void hover(const QPoint &);
38
+ int keyCodeFor(const QChar &);
18
39
  };
19
40
 
@@ -9,5 +9,5 @@ void JavascriptPromptMessages::start()
9
9
  {
10
10
  JsonSerializer serializer;
11
11
  QByteArray json = serializer.serialize(page()->promptMessages());
12
- emitFinished(true, json);
12
+ finish(true, json);
13
13
  }
@@ -3,6 +3,7 @@
3
3
  #include <iostream>
4
4
  #include <fstream>
5
5
  #include "NoOpReply.h"
6
+ #include "NetworkReplyProxy.h"
6
7
 
7
8
  NetworkAccessManager::NetworkAccessManager(QObject *parent):QNetworkAccessManager(parent) {
8
9
  connect(this, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), SLOT(provideAuthentication(QNetworkReply*,QAuthenticator*)));
@@ -13,7 +14,7 @@ QNetworkReply* NetworkAccessManager::createRequest(QNetworkAccessManager::Operat
13
14
  QNetworkRequest new_request(request);
14
15
  QByteArray url = new_request.url().toEncoded();
15
16
  if (this->isBlacklisted(new_request.url())) {
16
- return new NoOpReply(new_request, this);
17
+ return new NetworkReplyProxy(new NoOpReply(new_request), this);
17
18
  } else {
18
19
  if (operation != QNetworkAccessManager::PostOperation && operation != QNetworkAccessManager::PutOperation) {
19
20
  new_request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant());
@@ -21,9 +22,9 @@ QNetworkReply* NetworkAccessManager::createRequest(QNetworkAccessManager::Operat
21
22
  QHashIterator<QString, QString> item(m_headers);
22
23
  while (item.hasNext()) {
23
24
  item.next();
24
- new_request.setRawHeader(item.key().toAscii(), item.value().toAscii());
25
+ new_request.setRawHeader(item.key().toLatin1(), item.value().toLatin1());
25
26
  }
26
- QNetworkReply *reply = QNetworkAccessManager::createRequest(operation, new_request, outgoingData);
27
+ QNetworkReply *reply = new NetworkReplyProxy(QNetworkAccessManager::createRequest(operation, new_request, outgoingData), this);
27
28
  emit requestCreated(url, reply);
28
29
  return reply;
29
30
  }
@@ -37,10 +38,7 @@ void NetworkAccessManager::finished(QNetworkReply *reply) {
37
38
  QUrl requestedUrl = reply->url();
38
39
  while (m_redirectMappings.contains(requestedUrl))
39
40
  requestedUrl = m_redirectMappings.take(requestedUrl);
40
- NetworkResponse response;
41
- response.statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
42
- response.headers = reply->rawHeaderPairs();
43
- m_responses[requestedUrl] = response;
41
+ emit finished(requestedUrl, reply);
44
42
  }
45
43
  }
46
44
 
@@ -48,8 +46,10 @@ void NetworkAccessManager::addHeader(QString key, QString value) {
48
46
  m_headers.insert(key, value);
49
47
  }
50
48
 
51
- void NetworkAccessManager::resetHeaders() {
49
+ void NetworkAccessManager::reset() {
52
50
  m_headers.clear();
51
+ m_userName = QString();
52
+ m_password = QString();
53
53
  }
54
54
 
55
55
  void NetworkAccessManager::setUserName(const QString &userName) {
@@ -68,14 +68,6 @@ void NetworkAccessManager::provideAuthentication(QNetworkReply *reply, QAuthenti
68
68
  authenticator->setPassword(m_password);
69
69
  }
70
70
 
71
- int NetworkAccessManager::statusFor(QUrl url) {
72
- return m_responses[url].statusCode;
73
- }
74
-
75
- const QList<QNetworkReply::RawHeaderPair> &NetworkAccessManager::headersFor(QUrl url) {
76
- return m_responses[url].headers;
77
- }
78
-
79
71
  void NetworkAccessManager::setUrlBlacklist(QStringList urlBlacklist) {
80
72
  m_urlBlacklist.clear();
81
73
 
@@ -1,3 +1,5 @@
1
+ #ifndef __NETWORKACCESSMANAGER_H
2
+ #define __NETWORKACCESSMANAGER_H
1
3
  #include <QtNetwork/QNetworkAccessManager>
2
4
  #include <QtNetwork/QNetworkRequest>
3
5
  #include <QtNetwork/QNetworkReply>
@@ -7,20 +9,12 @@ class NetworkAccessManager : public QNetworkAccessManager {
7
9
 
8
10
  Q_OBJECT
9
11
 
10
- struct NetworkResponse {
11
- int statusCode;
12
- QList<QNetworkReply::RawHeaderPair> headers;
13
- NetworkResponse() : statusCode(0) { }
14
- };
15
-
16
12
  public:
17
13
  NetworkAccessManager(QObject *parent = 0);
18
14
  void addHeader(QString key, QString value);
19
- void resetHeaders();
15
+ void reset();
20
16
  void setUserName(const QString &userName);
21
17
  void setPassword(const QString &password);
22
- int statusFor(QUrl url);
23
- const QList<QNetworkReply::RawHeaderPair> &headersFor(QUrl url);
24
18
  void setUrlBlacklist(QStringList urlBlacklist);
25
19
 
26
20
  protected:
@@ -29,10 +23,8 @@ class NetworkAccessManager : public QNetworkAccessManager {
29
23
  QString m_password;
30
24
  QList<QUrl> m_urlBlacklist;
31
25
 
32
-
33
26
  private:
34
27
  QHash<QString, QString> m_headers;
35
- QHash<QUrl, NetworkResponse> m_responses;
36
28
  bool isBlacklisted(QUrl url);
37
29
  QHash<QUrl, QUrl> m_redirectMappings;
38
30
 
@@ -42,4 +34,6 @@ class NetworkAccessManager : public QNetworkAccessManager {
42
34
 
43
35
  signals:
44
36
  void requestCreated(QByteArray &url, QNetworkReply *reply);
37
+ void finished(QUrl &, QNetworkReply *);
45
38
  };
39
+ #endif
@@ -0,0 +1,91 @@
1
+ #include "NetworkReplyProxy.h"
2
+
3
+ NetworkReplyProxy::NetworkReplyProxy(QNetworkReply* reply, QObject* parent)
4
+ : QNetworkReply(parent)
5
+ , m_reply(reply)
6
+ {
7
+ m_reply->setParent(this);
8
+
9
+ setOperation(m_reply->operation());
10
+ setRequest(m_reply->request());
11
+ setUrl(m_reply->url());
12
+
13
+ if (m_reply->isFinished()) {
14
+ readInternal();
15
+ setFinished(true);
16
+ }
17
+
18
+ applyMetaData();
19
+
20
+ connect(m_reply, SIGNAL(metaDataChanged()), SLOT(applyMetaData()));
21
+ connect(m_reply, SIGNAL(readyRead()), SLOT(handleReadyRead()));
22
+ connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(errorInternal(QNetworkReply::NetworkError)));
23
+ connect(m_reply, SIGNAL(finished()), SLOT(handleFinished()));
24
+
25
+ connect(m_reply, SIGNAL(uploadProgress(qint64,qint64)), SIGNAL(uploadProgress(qint64,qint64)));
26
+ connect(m_reply, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(downloadProgress(qint64,qint64)));
27
+ connect(m_reply, SIGNAL(sslErrors(const QList<QSslError> &)), SIGNAL(sslErrors(const QList<QSslError> &)));
28
+
29
+ setOpenMode(ReadOnly);
30
+ }
31
+
32
+ void NetworkReplyProxy::abort() { m_reply->abort(); }
33
+ void NetworkReplyProxy::close() { m_reply->close(); }
34
+ bool NetworkReplyProxy::isSequential() const { return m_reply->isSequential(); }
35
+
36
+ void NetworkReplyProxy::handleFinished() {
37
+ setFinished(true);
38
+ emit finished();
39
+ }
40
+
41
+ qint64 NetworkReplyProxy::bytesAvailable() const
42
+ {
43
+ return m_buffer.size() + QIODevice::bytesAvailable();
44
+ }
45
+
46
+ qint64 NetworkReplyProxy::readData(char* data, qint64 maxlen)
47
+ {
48
+ qint64 size = qMin(maxlen, qint64(m_buffer.size()));
49
+ memcpy(data, m_buffer.constData(), size);
50
+ m_buffer.remove(0, size);
51
+ return size;
52
+ }
53
+
54
+ void NetworkReplyProxy::ignoreSslErrors() { m_reply->ignoreSslErrors(); }
55
+ void NetworkReplyProxy::applyMetaData() {
56
+ foreach(QNetworkReply::RawHeaderPair header, m_reply->rawHeaderPairs())
57
+ setRawHeader(header.first, header.second);
58
+
59
+ setAttribute(QNetworkRequest::HttpStatusCodeAttribute, m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute));
60
+ setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, m_reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute));
61
+ setAttribute(QNetworkRequest::RedirectionTargetAttribute, m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute));
62
+ setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, m_reply->attribute(QNetworkRequest::ConnectionEncryptedAttribute));
63
+ setAttribute(QNetworkRequest::CacheLoadControlAttribute, m_reply->attribute(QNetworkRequest::CacheLoadControlAttribute));
64
+ setAttribute(QNetworkRequest::CacheSaveControlAttribute, m_reply->attribute(QNetworkRequest::CacheSaveControlAttribute));
65
+ setAttribute(QNetworkRequest::SourceIsFromCacheAttribute, m_reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute));
66
+ setAttribute(QNetworkRequest::DoNotBufferUploadDataAttribute, m_reply->attribute(QNetworkRequest::DoNotBufferUploadDataAttribute));
67
+ emit metaDataChanged();
68
+ }
69
+
70
+ void NetworkReplyProxy::errorInternal(QNetworkReply::NetworkError _error)
71
+ {
72
+ setError(_error, errorString());
73
+ emit error(_error);
74
+ }
75
+
76
+ void NetworkReplyProxy::readInternal() {
77
+ QByteArray data = m_reply->readAll();
78
+ m_data += data;
79
+ m_buffer += data;
80
+ }
81
+
82
+ void NetworkReplyProxy::handleReadyRead()
83
+ {
84
+ readInternal();
85
+ emit readyRead();
86
+ }
87
+
88
+ QByteArray NetworkReplyProxy::data() {
89
+ return m_data;
90
+ }
91
+
@@ -0,0 +1,65 @@
1
+ #ifndef _NETWORKREPLYPROXY_H
2
+ #define _NETWORKREPLYPROXY_H
3
+ /*
4
+ * Copyright (C) 2009, 2010 Nokia Corporation and/or its subsidiary(-ies)
5
+ * Copyright (C) 2009, 2010 Holger Hans Peter Freyther
6
+ *
7
+ * All rights reserved.
8
+ *
9
+ * Redistribution and use in source and binary forms, with or without
10
+ * modification, are permitted provided that the following conditions
11
+ * are met:
12
+ * 1. Redistributions of source code must retain the above copyright
13
+ * notice, this list of conditions and the following disclaimer.
14
+ * 2. Redistributions in binary form must reproduce the above copyright
15
+ * notice, this list of conditions and the following disclaimer in the
16
+ * documentation and/or other materials provided with the distribution.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
19
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ */
30
+
31
+ #include <QObject>
32
+ #include <QtNetwork/QNetworkReply>
33
+
34
+ class NetworkReplyProxy : public QNetworkReply {
35
+ Q_OBJECT
36
+
37
+ public:
38
+ NetworkReplyProxy(QNetworkReply* reply, QObject* parent);
39
+
40
+ virtual void abort();
41
+ virtual void close();
42
+ virtual bool isSequential() const;
43
+
44
+ virtual qint64 bytesAvailable() const;
45
+
46
+ virtual qint64 readData(char* data, qint64 maxlen);
47
+
48
+ QByteArray data();
49
+
50
+ public slots:
51
+ void ignoreSslErrors();
52
+ void applyMetaData();
53
+ void errorInternal(QNetworkReply::NetworkError _error);
54
+ void handleReadyRead();
55
+ void handleFinished();
56
+
57
+ private:
58
+ void readInternal();
59
+
60
+ QNetworkReply* m_reply;
61
+ QByteArray m_data;
62
+ QByteArray m_buffer;
63
+ };
64
+
65
+ #endif
data/src/Node.cpp CHANGED
@@ -1,16 +1,16 @@
1
1
  #include "Node.h"
2
2
  #include "WebPage.h"
3
3
  #include "WebPageManager.h"
4
+ #include "InvocationResult.h"
4
5
 
5
- Node::Node(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
6
+ Node::Node(WebPageManager *manager, QStringList &arguments, QObject *parent) : JavascriptCommand(manager, arguments, parent) {
6
7
  }
7
8
 
8
9
  void Node::start() {
9
10
  QStringList functionArguments(arguments());
10
11
  QString functionName = functionArguments.takeFirst();
11
- QVariant result = page()->invokeCapybaraFunction(functionName, functionArguments);
12
- QString attributeValue = result.toString();
13
- emitFinished(true, attributeValue);
12
+ InvocationResult result = page()->invokeCapybaraFunction(functionName, functionArguments);
13
+ finish(&result);
14
14
  }
15
15
 
16
16
  QString Node::toString() const {
data/src/Node.h CHANGED
@@ -1,7 +1,7 @@
1
- #include "SocketCommand.h"
1
+ #include "JavascriptCommand.h"
2
2
  #include <QStringList>
3
3
 
4
- class Node : public SocketCommand {
4
+ class Node : public JavascriptCommand {
5
5
  Q_OBJECT
6
6
 
7
7
  public:
data/src/NullCommand.cpp CHANGED
@@ -1,6 +1,7 @@
1
1
  #include "NullCommand.h"
2
2
  #include "WebPage.h"
3
3
  #include "WebPageManager.h"
4
+ #include "ErrorMessage.h"
4
5
 
5
6
  NullCommand::NullCommand(QString name, QObject *parent) : Command(parent) {
6
7
  m_name = name;
@@ -8,6 +9,6 @@ NullCommand::NullCommand(QString name, QObject *parent) : Command(parent) {
8
9
 
9
10
  void NullCommand::start() {
10
11
  QString failure = QString("[Capybara WebKit] Unknown command: ") + m_name + "\n";
11
- emitFinished(false, failure);
12
+ finish(false, new ErrorMessage(failure));
12
13
  }
13
14
 
@@ -2,6 +2,7 @@
2
2
  #include "SocketCommand.h"
3
3
  #include "WebPage.h"
4
4
  #include "WebPageManager.h"
5
+ #include "ErrorMessage.h"
5
6
 
6
7
  PageLoadingCommand::PageLoadingCommand(Command *command, WebPageManager *manager, QObject *parent) : Command(parent) {
7
8
  m_manager = manager;
@@ -30,7 +31,7 @@ void PageLoadingCommand::pendingLoadFinished(bool success) {
30
31
  emit finished(m_pendingResponse);
31
32
  } else {
32
33
  QString message = m_manager->currentPage()->failureString();
33
- emitFinished(false, message);
34
+ finish(false, new ErrorMessage(message));
34
35
  }
35
36
  }
36
37
  }
data/src/Render.cpp CHANGED
@@ -14,5 +14,5 @@ void Render::start() {
14
14
 
15
15
  bool result = page()->render( imagePath, size );
16
16
 
17
- emitFinished(result);
17
+ finish(result);
18
18
  }
data/src/Reset.cpp CHANGED
@@ -10,6 +10,6 @@ void Reset::start() {
10
10
 
11
11
  manager()->reset();
12
12
 
13
- emitFinished(true);
13
+ finish(true);
14
14
  }
15
15
 
data/src/ResizeWindow.cpp CHANGED
@@ -12,6 +12,6 @@ void ResizeWindow::start() {
12
12
  QSize size(width, height);
13
13
  page()->setViewportSize(size);
14
14
 
15
- emitFinished(true);
15
+ finish(true);
16
16
  }
17
17
 
data/src/Response.cpp CHANGED
@@ -1,4 +1,5 @@
1
1
  #include "Response.h"
2
+ #include "ErrorMessage.h"
2
3
  #include <iostream>
3
4
 
4
5
  Response::Response(bool success, QString message, QObject *parent) : QObject(parent) {
@@ -11,6 +12,12 @@ Response::Response(bool success, QByteArray message, QObject *parent) : QObject(
11
12
  m_message = message;
12
13
  }
13
14
 
15
+ Response::Response(bool success, ErrorMessage *message, QObject *parent) : QObject(parent) {
16
+ m_success = success;
17
+ m_message = message->toString();
18
+ message->deleteLater();
19
+ }
20
+
14
21
  Response::Response(bool success, QObject *parent) : QObject(parent) {
15
22
  m_success = success;
16
23
  }
data/src/Response.h CHANGED
@@ -5,20 +5,25 @@
5
5
  #include <QString>
6
6
  #include <QByteArray>
7
7
 
8
+ class ErrorMessage;
9
+
8
10
  class Response : public QObject {
9
11
  Q_OBJECT
10
12
 
11
13
  public:
12
- Response(bool success, QString message, QObject *parent);
13
- Response(bool success, QByteArray message, QObject *parent);
14
+ Response(bool success, QString message, QObject *parent = 0);
15
+ Response(bool success, QByteArray message, QObject *parent = 0);
16
+ Response(bool success, ErrorMessage *message, QObject *parent = 0);
14
17
  Response(bool success, QObject *parent);
15
18
  bool isSuccess() const;
16
19
  QByteArray message() const;
17
20
  QString toString() const;
18
21
 
22
+ protected:
23
+ QByteArray m_message;
24
+
19
25
  private:
20
26
  bool m_success;
21
- QByteArray m_message;
22
27
  };
23
28
 
24
29
  #endif