david 2012-03-26 16:25:08 +02:00 committed by Ariya Hidayat
parent 6d343f4d0f
commit 55fa808689
1 changed files with 48 additions and 0 deletions

View File

@ -76,6 +76,11 @@ describe("WebPage object", function() {
expect(page.settings).toNotEqual({});
});
expectHasProperty(page, 'customHeaders');
it("should have customHeaders as an empty object", function() {
expect(page.customHeaders).toEqual({});
});
checkViewportSize(page, {height:300,width:400});
expectHasFunction(page, 'deleteLater');
@ -275,6 +280,49 @@ describe("WebPage object", function() {
expect(page.evaluate(function() { return caughtError })).toEqual(true);
});
})
it("should set custom headers properly", function() {
var server = require('webserver').create();
server.listen(12345, function(request, response) {
// echo received request headers in response body
response.write(JSON.stringify(request.headers));
response.close();
});
var url = "http://localhost:12345/foo/headers.txt?ab=cd";
var customHeaders = {
"Custom-Key" : "Custom-Value",
"User-Agent" : "Overriden-UA",
"Referer" : "Overriden-Referer",
};
page.customHeaders = customHeaders;
var handled = false;
runs(function() {
expect(handled).toEqual(false);
page.open(url, function (status) {
expect(status == 'success').toEqual(true);
handled = true;
var echoedHeaders = JSON.parse(page.plainText);
// console.log(JSON.stringify(echoedHeaders, null, 4));
// console.log(JSON.stringify(customHeaders, null, 4));
expect(echoedHeaders["Custom-Key"]).toEqual(customHeaders["Custom-Key"]);
expect(echoedHeaders["User-Agent"]).toEqual(customHeaders["User-Agent"]);
expect(echoedHeaders["Referer"]).toEqual(customHeaders["Referer"]);
});
});
waits(50);
runs(function() {
expect(handled).toEqual(true);
server.close();
});
});
});
describe("WebPage construction with options", function () {