Fire `onResourceReceived` callback when the resource error occured.

Issue #11163: https://github.com/ariya/phantomjs/issues/11163
1.x
Vitaliy Slobodin 2013-03-30 20:12:49 +04:00 committed by Ariya Hidayat
parent 9ca45ed62e
commit 47dc82681d
2 changed files with 40 additions and 8 deletions

View File

@ -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 File

@ -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 () {