Skip to content

customRequestHeaders tests added to test suite #1

Closed
wants to merge 7 commits into from
View
51 test/webpage-spec.js
@@ -75,6 +75,11 @@ describe("WebPage object", function() {
expect(page.settings).toNotEqual(null);
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});
@@ -207,7 +212,7 @@ describe("WebPage object", function() {
expect(fileName).toEqual('README.md');
});
});
-
+
it("should support console.log with multiple arguments", function() {
var message;
runs(function() {
@@ -275,6 +280,50 @@ 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 () {
Something went wrong with that request. Please try again.