1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Delete pending commands on reset

* If an exception is raised in the Ruby process, it's possible for Reset
  to be sent to the server while the previous command is still running.
  This ensures that pending commands are stopped when handling Reset.
This commit is contained in:
Matthew Horan 2014-07-15 22:53:18 -04:00
parent d7f724d315
commit 64762b6fad
2 changed files with 9 additions and 3 deletions

View file

@ -17,6 +17,7 @@ Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *par
m_commandFactory = new CommandFactory(m_manager, this);
m_commandParser = new CommandParser(socket, m_commandFactory, this);
m_pageSuccess = true;
m_pendingCommand = NULL;
connect(m_socket, SIGNAL(readyRead()), m_commandParser, SLOT(checkNext()));
connect(m_commandParser, SIGNAL(commandReady(Command *)), this, SLOT(commandReady(Command *)));
connect(m_manager, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
@ -28,10 +29,13 @@ void Connection::commandReady(Command *command) {
}
void Connection::startCommand(Command *command) {
if (m_pendingCommand) {
m_pendingCommand->deleteLater();
}
if (m_pageSuccess) {
command = new TimeoutCommand(new PageLoadingCommand(command, m_manager, this), m_manager, this);
connect(command, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
command->start();
m_pendingCommand = new TimeoutCommand(new PageLoadingCommand(command, m_manager, this), m_manager, this);
connect(m_pendingCommand, SIGNAL(finished(Response *)), this, SLOT(finishCommand(Response *)));
m_pendingCommand->start();
} else {
writePageLoadFailure();
}
@ -52,6 +56,7 @@ void Connection::finishCommand(Response *response) {
m_pageSuccess = true;
writeResponse(response);
sender()->deleteLater();
m_pendingCommand = NULL;
}
void Connection::writeResponse(Response *response) {

View file

@ -32,5 +32,6 @@ class Connection : public QObject {
CommandFactory *m_commandFactory;
bool m_pageSuccess;
WebPage *currentPage();
Command *m_pendingCommand;
};