Files
Ariya Hidayat f20835735c Port custom headers testing of web page.
The HTTP server launched by the test runner has a new endpoint called
/echo. This simply echoes back some information (current on the made
request, in the future it will be expanded to further information)
formatted as JSON. This echo system facilitates easy testing for request
header manipulation feature.

https://github.com/ariya/phantomjs/issues/12439
2014-09-07 21:13:59 -07:00

26 lines
864 B
JavaScript

var assert = require('../../assert');
var webpage = require('webpage');
// NOTE: HTTP header names are case-insensitive. Our test server
// returns the name in lowercase.
var page = webpage.create();
assert.typeOf(page.customHeaders, 'object');
assert.strictEqual(JSON.stringify(page.customHeaders), '{}');
page.customHeaders = { 'CustomHeader': 'ModifiedCustomValue' };
page.onResourceRequested = function(requestData, request) {
assert.typeOf(request.setHeader, 'function');
request.setHeader('CustomHeader', 'ModifiedCustomValue');
};
page.open('http://localhost:9180/echo', function (status) {
var json, headers;
assert.equal(status, 'success');
json = JSON.parse(page.plainText);
headers = json.headers;
assert.isTrue(headers.hasOwnProperty('customheader'));
assert.equal(headers.customheader, 'ModifiedCustomValue');
});