diff --git a/test/module/webpage/abort-network-request.js b/test/module/webpage/abort-network-request.js new file mode 100644 index 00000000..2f36b077 --- /dev/null +++ b/test/module/webpage/abort-network-request.js @@ -0,0 +1,21 @@ +var assert = require('../../assert'); +var webpage = require('webpage'); + +var page = webpage.create(); + +var urlToBlockRexExp = /logo\.png$/i; +var abortCount = 0; + +page.onResourceRequested = function(requestData, request) { + if (urlToBlockRexExp.test(requestData.url)) { + assert.typeOf(request, 'object'); + assert.typeOf(request.abort, 'function'); + request.abort(); + ++abortCount; + } +}; + +page.open('http://localhost:9180/logo.html', function (status) { + assert.equal(status, 'success'); + assert.equal(abortCount, 1); +}); diff --git a/test/run-tests.py b/test/run-tests.py index 4cc2a2a8..37f63c20 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/abort-network-request.js', 'module/webpage/resource-request-error.js', 'module/webpage/resource-received-error.js', 'module/system/system.js', diff --git a/test/webpage-spec.js b/test/webpage-spec.js index 20782048..4176941c 100644 --- a/test/webpage-spec.js +++ b/test/webpage-spec.js @@ -1185,37 +1185,6 @@ describe("WebPage object", function() { }); - it('should able to abort a network request', function() { - var page = require('webpage').create(); - var url = 'http://phantomjs.org'; - var urlToBlockRexExp = /phantomjs-logo\.png$/i; - - var handled = false; - - page.onResourceRequested = function(requestData, request) { - - if (urlToBlockRexExp.test(requestData['url'])) { - expect(typeof request).toEqual('object'); - expect(typeof request.abort).toEqual('function'); - request.abort(); - handled = true; - } - }; - - runs(function() { - page.open(url, function(status) { - expect(status).toEqual('success'); - }); - }); - - waits(5000); - - runs(function() { - page.close(); - expect(handled).toBeTruthy(); - }); - }); - xit('should fail on secure connection to url with bad cert', function() { var page = require('webpage').create(); var url = 'https://tv.eurosport.com/'; diff --git a/test/www/logo.html b/test/www/logo.html new file mode 100644 index 00000000..1323ffdf --- /dev/null +++ b/test/www/logo.html @@ -0,0 +1,8 @@ + + + Show logo + + + + + diff --git a/test/www/logo.png b/test/www/logo.png new file mode 100644 index 00000000..7b44e541 Binary files /dev/null and b/test/www/logo.png differ