Make FindModal synchronous

* There's no need to poll for the modal when we have an event loop.
This commit is contained in:
Matthew Horan 2014-07-15 22:55:24 -04:00
parent 64762b6fad
commit 8dbf3b8e31
6 changed files with 22 additions and 14 deletions

View File

@ -282,12 +282,7 @@ module Capybara::Webkit
def find_modal(type, id, options)
Timeout::timeout(options[:wait] || Capybara.default_wait_time) do
begin
browser.find_modal(id)
rescue ModalIndexError
sleep 0.05
retry
end
browser.find_modal(id)
end
rescue ModalNotFound
raise Capybara::ModalNotFound,

View File

@ -20,9 +20,6 @@ module Capybara::Webkit
class ConnectionError < StandardError
end
class ModalIndexError < StandardError
end
class ModalNotFound < StandardError
end

View File

@ -5,17 +5,25 @@
#include "ErrorMessage.h"
FindModal::FindModal(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
m_modalId = 0;
}
void FindModal::start() {
int modalId = arguments()[0].toInt();
if (page()->modalCount() < modalId) {
finish(false, new ErrorMessage("ModalIndexError", ""));
m_modalId = arguments()[0].toInt();
if (page()->modalCount() < m_modalId) {
connect(page(), SIGNAL(modalReady(int)), SLOT(handleModalReady(int)));
} else {
if (page()->modalMessage(modalId).isNull()) {
handleModalReady(m_modalId);
}
}
void FindModal::handleModalReady(int modalId) {
if (modalId == m_modalId) {
sender()->disconnect(SIGNAL(modalReady(int)), this, SLOT(handleModalReady(int)));
if (page()->modalMessage(m_modalId).isNull()) {
finish(false, new ErrorMessage("ModalNotFound", ""));
} else {
finish(true, page()->modalMessage(modalId));
finish(true, page()->modalMessage(m_modalId));
}
}
}

View File

@ -6,5 +6,11 @@ class FindModal : public SocketCommand {
public:
FindModal(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
public slots:
void handleModalReady(int);
private:
int m_modalId;
};

View File

@ -476,4 +476,5 @@ void WebPage::addModalMessage(bool expectedType, const QString &message, const Q
m_modalMessages << message;
else
m_modalMessages << QString();
emit modalReady(m_modalMessages.length());
}

View File

@ -71,6 +71,7 @@ class WebPage : public QWebPage {
void pageFinished(bool);
void requestCreated(QByteArray &url, QNetworkReply *reply);
void replyFinished(QNetworkReply *reply);
void modalReady(int);
protected:
virtual void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID);