mirror of https://github.com/vitalif/phantomjs
Port the test to change the URL of network request.
https://github.com/ariya/phantomjs/issues/124392.0
parent
dca6f77a36
commit
3b972fbfbb
|
@ -0,0 +1,33 @@
|
||||||
|
var assert = require('../../assert');
|
||||||
|
var webpage = require('webpage');
|
||||||
|
|
||||||
|
var page = webpage.create();
|
||||||
|
|
||||||
|
var urlToChange = 'http://localhost:9180/logo.png';
|
||||||
|
var alternativeUrl = 'http://localhost:9180/phantomjs-logo.gif';
|
||||||
|
var startStage = 0;
|
||||||
|
var endStage = 0;
|
||||||
|
|
||||||
|
page.onResourceRequested = function(requestData, request) {
|
||||||
|
if (requestData.url === urlToChange) {
|
||||||
|
assert.typeOf(request, 'object');
|
||||||
|
assert.typeOf(request.changeUrl, 'function');
|
||||||
|
request.changeUrl(alternativeUrl);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
page.onResourceReceived = function(data) {
|
||||||
|
if (data.url === alternativeUrl && data.stage === 'start') {
|
||||||
|
++startStage;
|
||||||
|
}
|
||||||
|
if (data.url === alternativeUrl && data.stage === 'end') {
|
||||||
|
++endStage;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
page.open('http://localhost:9180/logo.html', function (status) {
|
||||||
|
assert.equal(status, 'success');
|
||||||
|
assert.equal(startStage, 1);
|
||||||
|
assert.equal(endStage, 1);
|
||||||
|
assert.equal(page.content.match('logo.png'), 'logo.png');
|
||||||
|
});
|
|
@ -33,6 +33,7 @@ TESTS = [
|
||||||
'module/webpage/remove-header.js',
|
'module/webpage/remove-header.js',
|
||||||
'module/webpage/modify-header.js',
|
'module/webpage/modify-header.js',
|
||||||
'module/webpage/repaint-requested.js',
|
'module/webpage/repaint-requested.js',
|
||||||
|
'module/webpage/change-request-url.js',
|
||||||
'module/webpage/abort-network-request.js',
|
'module/webpage/abort-network-request.js',
|
||||||
'module/webpage/resource-request-error.js',
|
'module/webpage/resource-request-error.js',
|
||||||
'module/webpage/resource-received-error.js',
|
'module/webpage/resource-received-error.js',
|
||||||
|
|
|
@ -1208,41 +1208,6 @@ describe("WebPage object", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should change the url of the request', function() {
|
|
||||||
var page = require('webpage').create();
|
|
||||||
var url = 'http://phantomjs.org';
|
|
||||||
var urlToChange = 'http://phantomjs.org/img/phantomjs-logo.png';
|
|
||||||
var alternativeUrl = 'http://phantomjs.org/img/icon-release.png';
|
|
||||||
|
|
||||||
var handled = false;
|
|
||||||
|
|
||||||
runs(function() {
|
|
||||||
page.onResourceRequested = function(requestData, request) {
|
|
||||||
if (requestData['url'] == urlToChange) {
|
|
||||||
expect(typeof request).toEqual('object');
|
|
||||||
expect(typeof request.changeUrl).toEqual('function');
|
|
||||||
request.changeUrl(alternativeUrl);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
page.onResourceReceived = function(data) {
|
|
||||||
if (data['stage'] === 'end' && data['url'] == alternativeUrl) {
|
|
||||||
handled = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
page.open(url, function(status) {
|
|
||||||
expect(status).toEqual('success');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
waits(3000);
|
|
||||||
|
|
||||||
runs(function() {
|
|
||||||
expect(handled).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
xit("should interrupt a long-running JavaScript code", function() {
|
xit("should interrupt a long-running JavaScript code", function() {
|
||||||
var page = new WebPage();
|
var page = new WebPage();
|
||||||
var longRunningScriptCalled = false;
|
var longRunningScriptCalled = false;
|
||||||
|
|
Loading…
Reference in New Issue