Port the test for resource request error handling.

https://github.com/ariya/phantomjs/issues/12439
2.0
Ariya Hidayat 2014-09-09 23:01:41 -07:00
parent 804f61bcf5
commit f29b76bb7f
4 changed files with 26 additions and 43 deletions

View File

@ -0,0 +1,17 @@
var assert = require('../../assert');
var webpage = require('webpage');
var page = webpage.create();
page.onResourceError = function(err) {
assert.equal(err.status, 404);
assert.equal(err.statusText, 'File not found');
assert.equal(err.url, 'http://localhost:9180/notExist.png');
assert.equal(err.errorCode, 203);
assert.isTrue(err.errorString.match('Error downloading http://localhost:9180/notExist.png'));
assert.isTrue(err.errorString.match('server replied: File not found'));
};
page.open('http://localhost:9180/missing-img.html', function (status) {
assert.equal(status, 'success');
});

View File

@ -32,6 +32,7 @@ TESTS = [
'module/webpage/add-header.js',
'module/webpage/remove-header.js',
'module/webpage/modify-header.js',
'module/webpage/resource-request-error.js',
'module/system/system.js',
'module/system/args.js',
'module/system/os.js',

View File

@ -1150,49 +1150,6 @@ describe("WebPage object", function() {
});
});
it('should handle resource request errors', function() {
var server = require('webserver').create();
var page = require('webpage').create();
server.listen(12345, function(request, response) {
if (request.url == '/notExistResource.png') {
response.statusCode = 404;
response.write('Not found!');
response.close();
} else {
response.statusCode = 200;
response.write('<html><body><img src="notExistResource.png"/></body></html>');
response.close();
}
});
var handled = false;
runs(function() {
page.onResourceError = function(errorData) {
expect(errorData['url']).toEqual('http://localhost:12345/notExistResource.png');
expect(errorData['errorCode']).toEqual(203);
expect(errorData['errorString']).toContain('notExistResource.png - server replied: Not Found');
expect(errorData['status']).toEqual(404);
expect(errorData['statusText']).toContain("Not Found");
handled = true;
};
page.open('http://localhost:12345', function(status) {
expect(status).toEqual('success');
});
});
waits(5000);
runs(function() {
expect(handled).toEqual(true);
page.close();
server.close();
});
});
it("should change a url request with an encoded query string", function() {
var page = new require('webpage').create();

View File

@ -0,0 +1,8 @@
<html>
<head>
<title>Missing image</title>
</head>
<body>
<img src="notExist.png"/>
</body>
</html>