Skip to content
This repository
Newer
Older
100644 72 lines (62 sloc) 2.506 kb
cbb58d05 »
2012-10-24 Revert "Revert "Add configurable timeouts to commands.""
1 #include "TimeoutCommand.h"
2 #include "Command.h"
3 #include "WebPageManager.h"
4 #include "WebPage.h"
6c72a991 »
2013-02-02 Serialize errors as JSON
5 #include "ErrorMessage.h"
cbb58d05 »
2012-10-24 Revert "Revert "Add configurable timeouts to commands.""
6 #include <QTimer>
56fcecdd »
2012-11-24 Process all pending events before checking if page is loading
7 #include <QApplication>
cbb58d05 »
2012-10-24 Revert "Revert "Add configurable timeouts to commands.""
8
9 TimeoutCommand::TimeoutCommand(Command *command, WebPageManager *manager, QObject *parent) : Command(parent) {
10 m_command = command;
11 m_manager = manager;
12 m_timer = new QTimer(this);
13 m_timer->setSingleShot(true);
77811ca9 »
2012-12-12 Fix memory leak of response.
14 m_command->setParent(this);
cbb58d05 »
2012-10-24 Revert "Revert "Add configurable timeouts to commands.""
15 connect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
16 connect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
17 }
18
19 void TimeoutCommand::start() {
56fcecdd »
2012-11-24 Process all pending events before checking if page is loading
20 QApplication::processEvents();
cbb58d05 »
2012-10-24 Revert "Revert "Add configurable timeouts to commands.""
21 if (m_manager->isLoading()) {
67b8a339 »
2012-10-24 Remove m_commandWaiting and add logging to TimeoutCommand
22 m_manager->logger() << this->toString() << "waiting for load to finish";
cbb58d05 »
2012-10-24 Revert "Revert "Add configurable timeouts to commands.""
23 connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
24 startTimeout();
25 } else {
26 startCommand();
27 }
28 }
29
30 void TimeoutCommand::startCommand() {
31 connect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
32 m_command->start();
33 }
34
35 void TimeoutCommand::startTimeout() {
36 int timeout = m_manager->getTimeout();
37 if (timeout > 0) {
38 m_timer->start(timeout * 1000);
39 }
40 }
41
42 void TimeoutCommand::pendingLoadFinished(bool success) {
bca84f9a »
2012-12-18 Don't start queued commands more than once
43 disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
cbb58d05 »
2012-10-24 Revert "Revert "Add configurable timeouts to commands.""
44 if (success) {
45 startCommand();
46 } else {
7289a8e7 »
2012-10-25 Disconnect signals from TimeoutCommand after fired
47 disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
48 disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
c74949bd »
2013-02-11 Rename Command::emitFinished to finish
49 finish(false, new ErrorMessage(m_manager->currentPage()->failureString()));
cbb58d05 »
2012-10-24 Revert "Revert "Add configurable timeouts to commands.""
50 }
51 }
52
53 void TimeoutCommand::pageLoadingFromCommand() {
54 startTimeout();
55 }
56
57 void TimeoutCommand::commandTimeout() {
7289a8e7 »
2012-10-25 Disconnect signals from TimeoutCommand after fired
58 disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
59 disconnect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
60 disconnect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
cbb58d05 »
2012-10-24 Revert "Revert "Add configurable timeouts to commands.""
61 m_manager->currentPage()->triggerAction(QWebPage::Stop);
6c72a991 »
2013-02-02 Serialize errors as JSON
62 QString message = QString("Request timed out after %1 second(s)").arg(m_manager->getTimeout());
c74949bd »
2013-02-11 Rename Command::emitFinished to finish
63 finish(false, new ErrorMessage("Capybara::Webkit::TimeoutError", message));
cbb58d05 »
2012-10-24 Revert "Revert "Add configurable timeouts to commands.""
64 }
65
66 void TimeoutCommand::commandFinished(Response *response) {
7289a8e7 »
2012-10-25 Disconnect signals from TimeoutCommand after fired
67 disconnect(m_timer, SIGNAL(timeout()), this, SLOT(commandTimeout()));
68 disconnect(m_manager, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
cbb58d05 »
2012-10-24 Revert "Revert "Add configurable timeouts to commands.""
69 emit finished(response);
70 }
71
Something went wrong with that request. Please try again.