Port the test to abort network request.

https://github.com/ariya/phantomjs/issues/12439
2.0
Ariya Hidayat 2014-09-11 09:50:14 -07:00
parent f95ef19fcb
commit d52df7a1cf
5 changed files with 30 additions and 31 deletions

View File

@ -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);
});

View File

@ -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',

View File

@ -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/';

8
test/www/logo.html Normal file
View File

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

BIN
test/www/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB