mirror of https://github.com/vitalif/phantomjs
parent
f95ef19fcb
commit
d52df7a1cf
|
@ -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);
|
||||
});
|
|
@ -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',
|
||||
|
|
|
@ -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/';
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Show logo</title>
|
||||
</head>
|
||||
<body>
|
||||
<img src="logo.png"/>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Loading…
Reference in New Issue