Commit 94e51f43 94e51f4359c28ce258058e5219822e1180bc10c0 by Nicolas Perriault

migrated http_status tests to new testing format

1 parent 53863ca3
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
4 * Special test server to test for HTTP status codes 4 * Special test server to test for HTTP status codes
5 * 5 *
6 */ 6 */
7 var fs = require('fs');
8 var utils = require('utils');
7 var server = require('webserver').create(); 9 var server = require('webserver').create();
8 var service = server.listen(8090, function (request, response) { 10 var service = server.listen(8090, function (request, response) {
9 var code = parseInt(/^\/(\d+)$/.exec(request.url)[1], 10); 11 var code = parseInt(/^\/(\d+)$/.exec(request.url)[1], 10);
...@@ -11,34 +13,36 @@ var service = server.listen(8090, function (request, response) { ...@@ -11,34 +13,36 @@ var service = server.listen(8090, function (request, response) {
11 response.write(""); 13 response.write("");
12 response.close(); 14 response.close();
13 }); 15 });
14 var fs = require("fs");
15 16
16 casper.start(); 17 casper.test.begin("HTTP status code handling", 109, function(test) {
18 casper.start();
17 19
18 // file protocol 20 // file protocol
19 casper.thenOpen('file://' + phantom.casperPath + '/tests/site/index.html', function() { 21 casper.thenOpen('file://' + phantom.casperPath + '/tests/site/index.html', function() {
20 this.test.assertHttpStatus(null, 'file:// protocol does not set a HTTP status'); 22 this.test.assertHttpStatus(null, 'file:// protocol does not set a HTTP status');
21 }); 23 });
22 24
23 // http protocol 25 // http protocol
24 var codes = [100, 101, 102, 118, 200, 201, 202, 203, 204, 205, 206, 207, 210, 26 var codes = [100, 101, 102, 118, 200, 201, 202, 203, 204, 205, 206, 207, 210,
25 300, 301, 302, 303, 304, 305, 307, 310, 27 300, 301, 302, 303, 304, 305, 307, 310,
26 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 28 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413,
27 414, 415, 416, 417, 418, 422, 423, 424, 425, 426, 449, 450, 29 414, 415, 416, 417, 418, 422, 423, 424, 425, 426, 449, 450,
28 500, 501, 502, 503, 504, 505, 507, 509]; 30 500, 501, 502, 503, 504, 505, 507, 509];
29 31
30 casper.each(codes, function(self, code) { 32 casper.each(codes, function(self, code) {
31 if (code === 100) { 33 if (code === 100) {
32 // HTTP 100 is CONTINUE, so don't expect a terminated response 34 // HTTP 100 is CONTINUE, so don't expect a terminated response
33 return; 35 return;
34 } 36 }
35 this.thenOpen('http://localhost:8090/' + code, function() { 37 this.thenOpen('http://localhost:8090/' + code, function() {
36 this.test.assertEquals(this.currentHTTPStatus, code); 38 this.test.assertEquals(this.currentHTTPStatus, code,
37 this.test.assertHttpStatus(code); 39 utils.format('Status is stored in casper.currentHTTPStatus' , code));
40 this.test.assertHttpStatus(code, utils.format('HTTP %d handled' , code));
41 });
38 }); 42 });
39 });
40 43
41 casper.run(function() { 44 casper.run(function() {
42 server.close(); 45 server.close();
43 this.test.done(109); 46 this.test.done();
47 });
44 }); 48 });
......