Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fire `onResourceReceived` callback when the resource error occured. #11191

Closed
wants to merge 1 commit into from

3 participants

@Vitallium
Collaborator

I also added id property to the requestData object.

Issue:
#11163

test/webpage-spec.js
@@ -1148,6 +1148,13 @@ describe("WebPage object", function() {
expect(status).toEqual('success');
});
});
+
+ waits(5000);
+
+ runs(function() {
+ page.close();
+ expect(handled).toBeTruly();
@n1k0
n1k0 added a note

toBeTruly()? I think it's toBeTruthy() (now I wonder how the test pass)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Vitallium
Collaborator

Fixed. Thanks. I think it just throws undefined and continue the execution.

@ariya
Owner

Landed. Thanks!

@ariya ariya closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 8 deletions.
  1. +3 −7 src/networkaccessmanager.cpp
  2. +37 −1 test/webpage-spec.js
View
10 src/networkaccessmanager.cpp
@@ -366,6 +366,8 @@ void NetworkAccessManager::handleFinished(QNetworkReply *reply, const QVariant &
m_started.remove(reply);
emit resourceReceived(data);
+
+ reply->deleteLater();
}
void NetworkAccessManager::handleSslErrors(const QList<QSslError> &errors)
@@ -387,17 +389,11 @@ void NetworkAccessManager::handleNetworkError()
<< "(" << reply->errorString() << ")"
<< "URL:" << reply->url().toString();
- m_ids.remove(reply);
-
- if (m_started.contains(reply))
- m_started.remove(reply);
-
QVariantMap data;
+ data["id"] = m_ids.value(reply);
data["url"] = reply->url().toString();
data["errorCode"] = reply->error();
data["errorString"] = reply->errorString();
emit resourceError(data);
-
- reply->deleteLater();
}
View
38 test/webpage-spec.js
@@ -1122,11 +1122,11 @@ describe("WebPage object", function() {
runs(function() {
expect(handled).toEqual(true);
+ page.close();
server.close();
});
});
-
it('should able to abort a network request', function() {
var page = require('webpage').create();
var url = 'http://phantomjs.org';
@@ -1148,6 +1148,13 @@ describe("WebPage object", function() {
expect(status).toEqual('success');
});
});
+
+ waits(5000);
+
+ runs(function() {
+ page.close();
+ expect(handled).toBeTruthy();
+ });
});
it('should fail on secure connection to url with bad cert', function() {
@@ -1207,6 +1214,35 @@ describe("WebPage object", function() {
expect(handled).toBe(true);
});
});
+
+ it('should fire `onResourceReceived` callback when the resource error occured', function() {
+ var page = require('webpage').create();
+ var server = require('webserver').create();
+ var service = server.listen(12345, function (request, response) {
+ var code = parseInt(/^\/(\d+)$/.exec(request.url)[1], 10);
+ response.statusCode = code;
+ response.write("how");
+ response.close();
+ });
+ var handled = 0;
+
+ runs(function() {
+ page.onResourceReceived = function(res) {
+ handled++;
+ };
+
+ page.open('http://localhost:12345/400', function() {
+ server.close();
+ });
+ });
+
+ waits(5000);
+
+ runs(function() {
+ expect(handled).toEqual(2);
+ page.close();
+ });
+ });
});
describe("WebPage construction with options", function () {
Something went wrong with that request. Please try again.