Commit 5b767815 5b76781501249d57da7c2be254444ea449ed9c68 by Nicolas Perriault

fixes #119 - file:// resource won't set HTTP status

Casper.currentHTTPStatus defaults to `null` when resource are loaded
using the `file://` protocol.
1 parent 98edb663
...@@ -113,7 +113,7 @@ var Casper = function Casper(options) { ...@@ -113,7 +113,7 @@ var Casper = function Casper(options) {
113 this.colorizer = this.getColorizer(); 113 this.colorizer = this.getColorizer();
114 this.currentResponse = undefined; 114 this.currentResponse = undefined;
115 this.currentUrl = 'about:blank'; 115 this.currentUrl = 'about:blank';
116 this.currentHTTPStatus = 0; 116 this.currentHTTPStatus = null;
117 this.defaultWaitTimeout = 5000; 117 this.defaultWaitTimeout = 5000;
118 this.history = []; 118 this.history = [];
119 this.loadInProgress = false; 119 this.loadInProgress = false;
...@@ -1690,7 +1690,7 @@ function createPage(casper) { ...@@ -1690,7 +1690,7 @@ function createPage(casper) {
1690 } 1690 }
1691 if (resource.url === casper.requestUrl && resource.stage === "end") { 1691 if (resource.url === casper.requestUrl && resource.stage === "end") {
1692 casper.currentResponse = resource; 1692 casper.currentResponse = resource;
1693 casper.currentHTTPStatus = resource.status; 1693 casper.currentHTTPStatus = /^http/i.test(resource.url) ? resource.status : null;
1694 casper.emit('http.status.' + resource.status, resource); 1694 casper.emit('http.status.' + resource.status, resource);
1695 if (utils.isObject(casper.options.httpStatusHandlers) && 1695 if (utils.isObject(casper.options.httpStatusHandlers) &&
1696 resource.status in casper.options.httpStatusHandlers && 1696 resource.status in casper.options.httpStatusHandlers &&
......
...@@ -9,19 +9,29 @@ var service = server.listen(8090, function (request, response) { ...@@ -9,19 +9,29 @@ var service = server.listen(8090, function (request, response) {
9 response.write(""); 9 response.write("");
10 response.close(); 10 response.close();
11 }); 11 });
12 var fs = require("fs");
12 13
14 casper.start();
15
16 // file protocol
17 casper.thenOpen('file://' + phantom.casperPath + '/tests/site/index.html', function() {
18 this.test.assertHttpStatus(null, 'file:// protocol does not set a HTTP status');
19 });
20
21 // http protocol
13 codes = [100, 101, 102, 118, 200, 201, 202, 203, 204, 205, 206, 207, 210, 22 codes = [100, 101, 102, 118, 200, 201, 202, 203, 204, 205, 206, 207, 210,
14 300, 301, 302, 303, 304, 305, 307, 310, 23 300, 301, 302, 303, 304, 305, 307, 310,
15 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 24 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413,
16 414, 415, 416, 417, 418, 422, 423, 424, 425, 426, 449, 450, 25 414, 415, 416, 417, 418, 422, 423, 424, 425, 426, 449, 450,
17 500, 501, 502, 503, 504, 505, 507, 509]; 26 500, 501, 502, 503, 504, 505, 507, 509];
18 27
19 casper.start('http://google.com').each(codes, function(self, code) { 28 casper.thenOpen('http://google.com').each(codes, function(self, code) {
20 if (code === 100) { 29 if (code === 100) {
21 // HTTP 100 is CONTINUE, so don't expect a terminated response 30 // HTTP 100 is CONTINUE, so don't expect a terminated response
22 return; 31 return;
23 } 32 }
24 this.thenOpen('http://localhost:8090/' + code, function() { 33 this.thenOpen('http://localhost:8090/' + code, function() {
34 this.test.assertEquals(this.currentHTTPStatus, code);
25 this.test.assertHttpStatus(code); 35 this.test.assertHttpStatus(code);
26 }); 36 });
27 }); 37 });
......