Permalink
Browse files

Setup multi-window sync.

  • Loading branch information...
1 parent 58e6a25 commit 784b9b7f63cc94da8ee6b30077d05faf70190e71 @halogenandtoast halogenandtoast committed with jferris Jun 29, 2012
View
@@ -1640,7 +1640,7 @@ def which_for(character)
end
it "supports finding a window by title" do
- subject.visit("/new_window")
+ subject.visit("/new_window?sleep=5")
subject.within_window('My New Window') do
subject.find("//p").first.text.should == "finished"
end
View
@@ -23,7 +23,7 @@ Connection::Connection(QTcpSocket *socket, WebPageManager *manager, QObject *par
void Connection::commandReady(Command *command) {
m_queuedCommand = command;
- if (currentPage()->isLoading())
+ if (m_manager->isLoading())
m_commandWaiting = true;
else
startCommand();
@@ -18,7 +18,9 @@ QNetworkReply* NetworkAccessManager::createRequest(QNetworkAccessManager::Operat
item.next();
new_request.setRawHeader(item.key().toAscii(), item.value().toAscii());
}
- return QNetworkAccessManager::createRequest(operation, new_request, outgoingData);
+ QNetworkReply *reply = QNetworkAccessManager::createRequest(operation, new_request, outgoingData);
+ emit requestCreated(reply);
+ return reply;
};
void NetworkAccessManager::addHeader(QString key, QString value) {
@@ -23,4 +23,7 @@ class NetworkAccessManager : public QNetworkAccessManager {
private slots:
void provideAuthentication(QNetworkReply *reply, QAuthenticator *authenticator);
+
+ signals:
+ void requestCreated(QNetworkReply *reply);
};
@@ -27,6 +27,6 @@ void UnsupportedContentHandler::loadUnsupportedContent() {
void UnsupportedContentHandler::finish(bool success) {
connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
- m_page->replyFinished(m_reply);
+ m_page->networkAccessManagerFinishedReply(m_reply);
m_page->loadFinished(success);
}
View
@@ -27,10 +27,6 @@ WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
this, SLOT(frameCreated(QWebFrame *)));
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)),
this, SLOT(handleUnsupportedContent(QNetworkReply*)));
- connect(this, SIGNAL(pageFinished(bool)),
- m_manager, SLOT(emitPageFinished(bool)));
- connect(this, SIGNAL(loadStarted()),
- m_manager, SLOT(emitLoadStarted()));
resetWindowSize();
settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
@@ -45,9 +41,30 @@ void WebPage::setCustomNetworkAccessManager() {
NetworkAccessManager *manager = new NetworkAccessManager(this);
manager->setCookieJar(m_manager->cookieJar());
this->setNetworkAccessManager(manager);
- connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
+ connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(networkAccessManagerFinishedReply(QNetworkReply *)));
connect(manager, SIGNAL(sslErrors(QNetworkReply *, QList<QSslError>)),
this, SLOT(handleSslErrorsForReply(QNetworkReply *, QList<QSslError>)));
+ connect(manager, SIGNAL(requestCreated(QNetworkReply *)), this, SLOT(networkAccessManagerCreatedRequest(QNetworkReply *)));
+}
+
+void WebPage::networkAccessManagerCreatedRequest(QNetworkReply *reply) {
+ emit requestCreated(reply);
+}
+
+void WebPage::networkAccessManagerFinishedReply(QNetworkReply *reply) {
+ if (reply->url() == this->currentFrame()->url()) {
+ QStringList headers;
+ m_lastStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ QList<QByteArray> list = reply->rawHeaderList();
+
+ int length = list.size();
+ for(int i = 0; i < length; i++) {
+ headers << list.at(i)+": "+reply->rawHeader(list.at(i));
+ }
+
+ m_pageHeaders = headers.join("\n");
+ }
+ emit replyFinished(reply);
}
void WebPage::loadJavascript() {
@@ -213,21 +230,6 @@ QString WebPage::getLastAttachedFileName() {
return currentFrame()->evaluateJavaScript(QString("Capybara.lastAttachedFile")).toString();
}
-void WebPage::replyFinished(QNetworkReply *reply) {
- if (reply->url() == this->currentFrame()->url()) {
- QStringList headers;
- m_lastStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
- QList<QByteArray> list = reply->rawHeaderList();
-
- int length = list.size();
- for(int i = 0; i < length; i++) {
- headers << list.at(i)+": "+reply->rawHeader(list.at(i));
- }
-
- m_pageHeaders = headers.join("\n");
- }
-}
-
void WebPage::handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &errors) {
if (m_manager->ignoreSslErrors())
reply->ignoreSslErrors(errors);
View
@@ -35,12 +35,15 @@ class WebPage : public QWebPage {
bool isLoading() const;
QString pageHeaders();
void frameCreated(QWebFrame *);
- void replyFinished(QNetworkReply *reply);
void handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &);
void handleUnsupportedContent(QNetworkReply *reply);
+ void networkAccessManagerCreatedRequest(QNetworkReply *reply);
+ void networkAccessManagerFinishedReply(QNetworkReply *reply);
signals:
void pageFinished(bool);
+ void requestCreated(QNetworkReply *reply);
+ void replyFinished(QNetworkReply *reply);
protected:
virtual void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID);
View
@@ -6,14 +6,15 @@
WebPageManager::WebPageManager(QObject *parent) : QObject(parent) {
m_ignoreSslErrors = false;
m_cookieJar = new NetworkCookieJar(this);
+ m_success = true;
createPage(this)->setFocus();
}
void WebPageManager::append(WebPage *value) {
m_pages.append(value);
}
-QList<WebPage *> WebPageManager::pages() {
+QList<WebPage *> WebPageManager::pages() const {
return m_pages;
}
@@ -27,18 +28,38 @@ WebPage *WebPageManager::currentPage() {
WebPage *WebPageManager::createPage(QObject *parent) {
WebPage *page = new WebPage(this, parent);
+ connect(page, SIGNAL(loadStarted()),
+ this, SLOT(emitLoadStarted()));
+ connect(page, SIGNAL(pageFinished(bool)),
+ this, SLOT(emitPageFinished(bool)));
+ connect(page, SIGNAL(requestCreated(QNetworkReply *)),
+ this, SLOT(requestCreated(QNetworkReply *)));
+ connect(page, SIGNAL(replyFinished(QNetworkReply *)),
+ this, SLOT(replyFinished(QNetworkReply *)));
append(page);
return page;
}
-void WebPageManager::emitPageFinished(bool success) {
- if (currentPage() == sender())
- emit pageFinished(success);
-}
-
void WebPageManager::emitLoadStarted() {
- if (currentPage() == sender())
+ if (m_started.empty()) {
emit loadStarted();
+ }
+}
+
+void WebPageManager::requestCreated(QNetworkReply *reply) {
+ m_started += reply;
+}
+
+void WebPageManager::replyFinished(QNetworkReply *reply) {
+ m_started.remove(reply);
+}
+
+void WebPageManager::emitPageFinished(bool success) {
+ m_success = success && m_success;
+ if (m_started.empty()) {
+ emit pageFinished(m_success);
+ m_success = true;
+ }
}
void WebPageManager::setIgnoreSslErrors(bool value) {
@@ -59,3 +80,12 @@ void WebPageManager::reset() {
NetworkCookieJar *WebPageManager::cookieJar() {
return m_cookieJar;
}
+
+bool WebPageManager::isLoading() const {
+ foreach(WebPage *page, pages()) {
+ if (page->isLoading()) {
+ return true;
+ }
+ }
+ return false;
+}
View
@@ -1,7 +1,9 @@
#ifndef _WEBPAGEMANAGER_H
#define _WEBPAGEMANAGER_H
#include <QList>
+#include <QSet>
#include <QObject>
+#include <QNetworkReply>
class WebPage;
class NetworkCookieJar;
@@ -12,18 +14,21 @@ class WebPageManager : public QObject {
public:
WebPageManager(QObject *parent = 0);
void append(WebPage *value);
- QList<WebPage *> pages();
+ QList<WebPage *> pages() const;
void setCurrentPage(WebPage *);
WebPage *currentPage();
WebPage *createPage(QObject *parent);
void setIgnoreSslErrors(bool);
bool ignoreSslErrors();
void reset();
NetworkCookieJar *cookieJar();
+ bool isLoading() const;
public slots:
- void emitPageFinished(bool);
void emitLoadStarted();
+ void emitPageFinished(bool);
+ void requestCreated(QNetworkReply *reply);
+ void replyFinished(QNetworkReply *reply);
signals:
void pageFinished(bool);
@@ -34,6 +39,8 @@ class WebPageManager : public QObject {
WebPage *m_currentPage;
bool m_ignoreSslErrors;
NetworkCookieJar *m_cookieJar;
+ QSet<QNetworkReply*> m_started;
+ bool m_success;
};
#endif // _WEBPAGEMANAGER_H

0 comments on commit 784b9b7

Please sign in to comment.