Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't wait for finished replies

Synchronous requests will have emitted the finished signal by the time
we connect to it.
  • Loading branch information...
commit 5bef33624cec012a472849eb03ab96414f9911b5 1 parent 6156980
@mhoran mhoran authored
View
37 spec/driver_spec.rb
@@ -2055,6 +2055,43 @@ def log
end
end
+ context "synchronous ajax app" do
+ let(:driver) do
+ driver_for_app do
+ get '/' do
+ <<-HTML
+ <html>
+ <body>
+ <form id="theForm">
+ <input type="submit" value="Submit" />
+ </form>
+ <script>
+ document.getElementById('theForm').onsubmit = function() {
+ xhr = new XMLHttpRequest();
+ xhr.open('POST', '/', false);
+ xhr.setRequestHeader('Content-Type', 'text/plain');
+ xhr.send('hello');
+ console.log(xhr.response);
+ }
+ </script>
+ </body>
+ </html>
+ HTML
+ end
+
+ post '/' do
+ request.body.read
+ end
+ end
+ end
+
+ it 'should not hang the server' do
+ visit('/')
+ driver.find('//input').first.click
+ driver.console_messages.first[:message].should == "hello"
+ end
+ end
+
def driver_url(driver, path)
URI.parse(driver.current_url).merge(path).to_s
end
View
3  src/UnsupportedContentHandler.cpp
@@ -10,8 +10,7 @@ UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkRepl
void UnsupportedContentHandler::renderNonHtmlContent() {
QByteArray text = m_reply->readAll();
m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
- m_page->setUnsupportedContentLoaded();
- m_page->networkAccessManagerFinishedReply(m_reply);
+ m_page->unsupportedContentFinishedReply(m_reply);
m_page->loadFinished(true);
this->deleteLater();
}
View
17 src/WebPage.cpp
@@ -45,18 +45,15 @@ void WebPage::setCustomNetworkAccessManager() {
NetworkAccessManager *manager = new NetworkAccessManager(this);
manager->setCookieJar(m_manager->cookieJar());
this->setNetworkAccessManager(manager);
- 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(QByteArray &, QNetworkReply *)), this, SLOT(networkAccessManagerCreatedRequest(QByteArray &, QNetworkReply *)));
+ connect(manager, SIGNAL(requestCreated(QByteArray &, QNetworkReply *)),
+ SIGNAL(requestCreated(QByteArray &, QNetworkReply *)));
}
-void WebPage::networkAccessManagerCreatedRequest(QByteArray &url, QNetworkReply *reply) {
- emit requestCreated(url, reply);
-}
-
-void WebPage::networkAccessManagerFinishedReply(QNetworkReply *reply) {
- emit replyFinished(reply);
+void WebPage::unsupportedContentFinishedReply(QNetworkReply *reply) {
+ m_unsupportedContentLoaded = true;
+ m_manager->replyFinished(reply);
}
void WebPage::loadJavascript() {
@@ -276,10 +273,6 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
}
}
-void WebPage::setUnsupportedContentLoaded() {
- m_unsupportedContentLoaded = true;
-}
-
bool WebPage::unsupportedContentLoaded() {
return m_unsupportedContentLoaded;
}
View
4 src/WebPage.h
@@ -34,8 +34,8 @@ class WebPage : public QWebPage {
bool matchesWindowSelector(QString);
void setFocus();
NetworkAccessManager *networkAccessManager();
- void setUnsupportedContentLoaded();
bool unsupportedContentLoaded();
+ void unsupportedContentFinishedReply(QNetworkReply *reply);
public slots:
bool shouldInterruptJavaScript();
@@ -47,8 +47,6 @@ class WebPage : public QWebPage {
void frameCreated(QWebFrame *);
void handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &);
void handleUnsupportedContent(QNetworkReply *reply);
- void networkAccessManagerCreatedRequest(QByteArray &url, QNetworkReply *reply);
- void networkAccessManagerFinishedReply(QNetworkReply *reply);
signals:
void pageFinished(bool);
View
15 src/WebPageManager.cpp
@@ -36,8 +36,6 @@ WebPage *WebPageManager::createPage(QObject *parent) {
this, SLOT(setPageStatus(bool)));
connect(page, SIGNAL(requestCreated(QByteArray &, QNetworkReply *)),
this, SLOT(requestCreated(QByteArray &, QNetworkReply *)));
- connect(page, SIGNAL(replyFinished(QNetworkReply *)),
- this, SLOT(replyFinished(QNetworkReply *)));
append(page);
return page;
}
@@ -51,7 +49,18 @@ void WebPageManager::emitLoadStarted() {
void WebPageManager::requestCreated(QByteArray &url, QNetworkReply *reply) {
logger() << "Started request to" << url;
- m_started += reply;
+ if (reply->isFinished())
+ replyFinished(reply);
+ else {
+ connect(reply, SIGNAL(finished()), SLOT(handleReplyFinished()));
+ m_started += reply;
+ }
+}
+
+void WebPageManager::handleReplyFinished() {
+ QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
+ disconnect(reply, SIGNAL(finished()), this, SLOT(handleReplyFinished()));
+ replyFinished(reply);
}
void WebPageManager::replyFinished(QNetworkReply *reply) {
View
3  src/WebPageManager.h
@@ -29,12 +29,13 @@ class WebPageManager : public QObject {
bool isLoading() const;
QDebug logger() const;
void enableLogging();
+ void replyFinished(QNetworkReply *reply);
public slots:
void emitLoadStarted();
void setPageStatus(bool);
void requestCreated(QByteArray &url, QNetworkReply *reply);
- void replyFinished(QNetworkReply *reply);
+ void handleReplyFinished();
signals:
void pageFinished(bool);
Please sign in to comment.
Something went wrong with that request. Please try again.