From f29b76bb7fc1163a5d9465f0be0eaee020dd8e06 Mon Sep 17 00:00:00 2001 From: Ariya Hidayat Date: Tue, 9 Sep 2014 23:01:41 -0700 Subject: [PATCH] Port the test for resource request error handling. https://github.com/ariya/phantomjs/issues/12439 --- test/module/webpage/resource-request-error.js | 17 ++++++++ test/run-tests.py | 1 + test/webpage-spec.js | 43 ------------------- test/www/missing-img.html | 8 ++++ 4 files changed, 26 insertions(+), 43 deletions(-) create mode 100644 test/module/webpage/resource-request-error.js create mode 100644 test/www/missing-img.html diff --git a/test/module/webpage/resource-request-error.js b/test/module/webpage/resource-request-error.js new file mode 100644 index 00000000..899b43b0 --- /dev/null +++ b/test/module/webpage/resource-request-error.js @@ -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'); +}); diff --git a/test/run-tests.py b/test/run-tests.py index 7feb751e..e7ccf550 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -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', diff --git a/test/webpage-spec.js b/test/webpage-spec.js index 65eb4c92..7dc4132e 100644 --- a/test/webpage-spec.js +++ b/test/webpage-spec.js @@ -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(''); - 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(); diff --git a/test/www/missing-img.html b/test/www/missing-img.html new file mode 100644 index 00000000..cc142eca --- /dev/null +++ b/test/www/missing-img.html @@ -0,0 +1,8 @@ + + + Missing image + + + + +