compat with phantomjs 1.9
Showing
8 changed files
with
66 additions
and
42 deletions
... | @@ -133,7 +133,7 @@ var Casper = function Casper(options) { | ... | @@ -133,7 +133,7 @@ var Casper = function Casper(options) { |
133 | this.popups = pagestack.create(); | 133 | this.popups = pagestack.create(); |
134 | // properties | 134 | // properties |
135 | this.checker = null; | 135 | this.checker = null; |
136 | this.currentResponse = undefined; | 136 | this.currentResponse = {}; |
137 | this.currentUrl = 'about:blank'; | 137 | this.currentUrl = 'about:blank'; |
138 | this.currentHTTPStatus = null; | 138 | this.currentHTTPStatus = null; |
139 | this.history = []; | 139 | this.history = []; |
... | @@ -1049,7 +1049,7 @@ Casper.prototype.handleReceivedResource = function(resource) { | ... | @@ -1049,7 +1049,7 @@ Casper.prototype.handleReceivedResource = function(resource) { |
1049 | return; | 1049 | return; |
1050 | } | 1050 | } |
1051 | this.currentHTTPStatus = null; | 1051 | this.currentHTTPStatus = null; |
1052 | this.currentResponse = undefined; | 1052 | this.currentResponse = {}; |
1053 | if (utils.isHTTPResource(resource)) { | 1053 | if (utils.isHTTPResource(resource)) { |
1054 | this.emit('page.resource.received', resource); | 1054 | this.emit('page.resource.received', resource); |
1055 | this.currentResponse = resource; | 1055 | this.currentResponse = resource; |
... | @@ -1503,6 +1503,7 @@ Casper.prototype.start = function start(location, then) { | ... | @@ -1503,6 +1503,7 @@ Casper.prototype.start = function start(location, then) { |
1503 | this.emit('starting'); | 1503 | this.emit('starting'); |
1504 | this.log('Starting...', "info"); | 1504 | this.log('Starting...', "info"); |
1505 | this.startTime = new Date().getTime(); | 1505 | this.startTime = new Date().getTime(); |
1506 | this.currentResponse = {}; | ||
1506 | this.history = []; | 1507 | this.history = []; |
1507 | this.popups = pagestack.create(); | 1508 | this.popups = pagestack.create(); |
1508 | this.steps = []; | 1509 | this.steps = []; | ... | ... |
... | @@ -59,9 +59,10 @@ responseHeaders.prototype.get = function get(name){ | ... | @@ -59,9 +59,10 @@ responseHeaders.prototype.get = function get(name){ |
59 | }; | 59 | }; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Augment the response with proper prototypes | 62 | * Augments the response with proper prototypes. |
63 | * | 63 | * |
64 | * @param mixed response Phantom response or undefined (generally with local files) | 64 | * @param Mixed response Phantom response or undefined (generally with local files) |
65 | * @return Object Augmented response | ||
65 | */ | 66 | */ |
66 | exports.augmentResponse = function(response) { | 67 | exports.augmentResponse = function(response) { |
67 | "use strict"; | 68 | "use strict"; |
... | @@ -70,4 +71,5 @@ exports.augmentResponse = function(response) { | ... | @@ -70,4 +71,5 @@ exports.augmentResponse = function(response) { |
70 | return; | 71 | return; |
71 | } | 72 | } |
72 | response.headers.__proto__ = responseHeaders.prototype; | 73 | response.headers.__proto__ = responseHeaders.prototype; |
74 | return response; | ||
73 | }; | 75 | }; | ... | ... |
... | @@ -997,6 +997,7 @@ Tester.prototype.done = function done() { | ... | @@ -997,6 +997,7 @@ Tester.prototype.done = function done() { |
997 | this.executed = 0; | 997 | this.executed = 0; |
998 | } | 998 | } |
999 | this.emit('test.done'); | 999 | this.emit('test.done'); |
1000 | this.casper.currentHTTPResponse = {}; | ||
1000 | this.running = this.started = false; | 1001 | this.running = this.started = false; |
1001 | var nextTest = this.queue.shift(); | 1002 | var nextTest = this.queue.shift(); |
1002 | if (nextTest) { | 1003 | if (nextTest) { | ... | ... |
... | @@ -114,7 +114,7 @@ function equals(v1, v2) { | ... | @@ -114,7 +114,7 @@ function equals(v1, v2) { |
114 | return v1.toString() === v2.toString(); | 114 | return v1.toString() === v2.toString(); |
115 | } | 115 | } |
116 | if (v1 instanceof Object) { | 116 | if (v1 instanceof Object) { |
117 | if (Object.keys(v1).length !== Object.keys(v2).length) { | 117 | if (!(v2 instanceof Object) || Object.keys(v1).length !== Object.keys(v2).length) { |
118 | return false; | 118 | return false; |
119 | } | 119 | } |
120 | for (var k in v1) { | 120 | for (var k in v1) { | ... | ... |
... | @@ -14,7 +14,7 @@ var service = server.listen(8090, function(request, response) { | ... | @@ -14,7 +14,7 @@ var service = server.listen(8090, function(request, response) { |
14 | 14 | ||
15 | casper.test.begin('Casper.headers.get() using file protocol', 1, function(test) { | 15 | casper.test.begin('Casper.headers.get() using file protocol', 1, function(test) { |
16 | casper.start('file://' + phantom.casperPath + 'tests/site/index.html', function(response) { | 16 | casper.start('file://' + phantom.casperPath + 'tests/site/index.html', function(response) { |
17 | test.assertEquals(response, undefined, 'No response available on local page'); | 17 | test.assertEquals(response, {data: null}, 'Empty http response on local page'); |
18 | }).run(function() { | 18 | }).run(function() { |
19 | test.done(); | 19 | test.done(); |
20 | }) | 20 | }) | ... | ... |
... | @@ -6,17 +6,17 @@ casper.test.begin('handling navigation history', 4, function(test) { | ... | @@ -6,17 +6,17 @@ casper.test.begin('handling navigation history', 4, function(test) { |
6 | casper.thenOpen('tests/site/page3.html'); | 6 | casper.thenOpen('tests/site/page3.html'); |
7 | casper.back(); | 7 | casper.back(); |
8 | casper.then(function() { | 8 | casper.then(function() { |
9 | test.assertMatch(this.getCurrentUrl(), /tests\/site\/page2\.html$/, | 9 | test.assertMatch(this.getCurrentUrl(), /page2\.html$/, |
10 | 'Casper.back() can go back an history step'); | 10 | 'Casper.back() can go back an history step'); |
11 | }); | 11 | }); |
12 | casper.forward(); | 12 | casper.forward(); |
13 | casper.then(function() { | 13 | casper.then(function() { |
14 | test.assertMatch(this.getCurrentUrl(), /tests\/site\/page3\.html$/, | 14 | test.assertMatch(this.getCurrentUrl(), /page3\.html$/, |
15 | 'Casper.forward() can go forward an history step'); | 15 | 'Casper.forward() can go forward an history step'); |
16 | }); | 16 | }); |
17 | casper.run(function() { | 17 | casper.run(function() { |
18 | test.assert(this.history.length > 0, 'Casper.history contains urls'); | 18 | test.assert(this.history.length > 0, 'Casper.history contains urls'); |
19 | test.assertMatch(this.history[0], /tests\/site\/page1\.html$/, | 19 | test.assertMatch(this.history[0], /page1\.html$/, |
20 | 'Casper.history has the correct first url'); | 20 | 'Casper.history has the correct first url'); |
21 | test.done(); | 21 | test.done(); |
22 | }); | 22 | }); | ... | ... |
... | @@ -40,10 +40,14 @@ casper.test.begin('eachThen() tests', 1, function(test) { | ... | @@ -40,10 +40,14 @@ casper.test.begin('eachThen() tests', 1, function(test) { |
40 | var received = []; | 40 | var received = []; |
41 | 41 | ||
42 | casper.start().eachThen([1, 2, 3], function(response) { | 42 | casper.start().eachThen([1, 2, 3], function(response) { |
43 | if (!response) { | ||
44 | test.fail('No response received'); | ||
45 | } | ||
43 | received.push(response.data); | 46 | received.push(response.data); |
44 | }); | 47 | }); |
45 | 48 | ||
46 | casper.run(function() { | 49 | casper.run(function() { |
50 | console.log('PLOP!!!'); | ||
47 | test.assertEquals(received, [1, 2, 3], | 51 | test.assertEquals(received, [1, 2, 3], |
48 | 'Casper.eachThen() passes item to step data'); | 52 | 'Casper.eachThen() passes item to step data'); |
49 | test.done(); | 53 | test.done(); | ... | ... |
... | @@ -6,43 +6,59 @@ | ... | @@ -6,43 +6,59 @@ |
6 | */ | 6 | */ |
7 | var fs = require('fs'); | 7 | var fs = require('fs'); |
8 | var utils = require('utils'); | 8 | var utils = require('utils'); |
9 | var server = require('webserver').create(); | ||
10 | var service = server.listen(8090, function (request, response) { | ||
11 | var code = parseInt(/^\/(\d+)$/.exec(request.url)[1], 10); | ||
12 | response.statusCode = code; | ||
13 | response.write(""); | ||
14 | response.close(); | ||
15 | }); | ||
16 | 9 | ||
17 | casper.test.begin("HTTP status code handling", 109, function(test) { | 10 | casper.test.begin("HTTP status code handling", 163, { |
18 | casper.start(); | 11 | setUp: function(test) { |
12 | this.server = require('webserver').create(); | ||
13 | this.server.listen(8090, function (request, response) { | ||
14 | response.statusCode = parseInt(/^\/(\d+)$/.exec(request.url)[1], 10); | ||
15 | response.write(""); | ||
16 | response.close(); | ||
17 | }); | ||
18 | this.testCodes = [ | ||
19 | 100, 101, 102, 118, 200, 201, 202, 203, 204, 205, 206, 207, 210, | ||
20 | 300, 301, 302, 303, 304, 305, 307, 310 | ||
21 | ]; | ||
22 | if (utils.ltVersion(phantom.version, '1.9.0')) { | ||
23 | // https://github.com/ariya/phantomjs/issues/11163 | ||
24 | this.testCodes = this.testCodes.concat([ | ||
25 | 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, | ||
26 | 414, 415, 416, 417, 418, 422, 423, 424, 425, 426, 449, 450, | ||
27 | 500, 501, 502, 503, 504, 505, 507, 509 | ||
28 | ]); | ||
29 | } else { | ||
30 | test.skip(102); | ||
31 | } | ||
32 | }, | ||
19 | 33 | ||
20 | // file protocol | 34 | tearDown: function() { |
21 | casper.thenOpen('file://' + phantom.casperPath + '/tests/site/index.html', function() { | 35 | this.server.close(); |
22 | this.test.assertHttpStatus(null, 'file:// protocol does not set a HTTP status'); | 36 | }, |
23 | }); | ||
24 | 37 | ||
25 | // http protocol | 38 | test: function(test) { |
26 | var codes = [100, 101, 102, 118, 200, 201, 202, 203, 204, 205, 206, 207, 210, | 39 | casper.start(); |
27 | 300, 301, 302, 303, 304, 305, 307, 310, | ||
28 | 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, | ||
29 | 414, 415, 416, 417, 418, 422, 423, 424, 425, 426, 449, 450, | ||
30 | 500, 501, 502, 503, 504, 505, 507, 509]; | ||
31 | 40 | ||
32 | casper.each(codes, function(self, code) { | 41 | // file protocol |
33 | if (code === 100) { | 42 | casper.thenOpen('file://' + phantom.casperPath + '/tests/site/index.html', function() { |
34 | // HTTP 100 is CONTINUE, so don't expect a terminated response | 43 | this.test.assertHttpStatus(null, 'file:// protocol does not set a HTTP status'); |
35 | return; | ||
36 | } | ||
37 | this.thenOpen('http://localhost:8090/' + code, function() { | ||
38 | this.test.assertEquals(this.currentHTTPStatus, code, | ||
39 | utils.format('Status is stored in casper.currentHTTPStatus' , code)); | ||
40 | this.test.assertHttpStatus(code, utils.format('HTTP %d handled' , code)); | ||
41 | }); | 44 | }); |
42 | }); | ||
43 | 45 | ||
44 | casper.run(function() { | 46 | casper.each(this.testCodes, function(self, code) { |
45 | server.close(); | 47 | if (code === 100) { |
46 | this.test.done(); | 48 | // HTTP 100 is CONTINUE, so don't expect a terminated response |
47 | }); | 49 | return; |
50 | } | ||
51 | this.thenOpen('http://localhost:8090/' + code, function(resource) { | ||
52 | test.assertEquals(resource.status, code, | ||
53 | 'Status is stored in resource.status'); | ||
54 | test.assertEquals(this.currentHTTPStatus, code, | ||
55 | 'Status is stored in casper.currentHTTPStatus'); | ||
56 | test.assertHttpStatus(code, utils.format('HTTP %d handled' , code)); | ||
57 | }); | ||
58 | }); | ||
59 | |||
60 | casper.run(function() { | ||
61 | this.test.done(); | ||
62 | }); | ||
63 | } | ||
48 | }); | 64 | }); | ... | ... |
-
Please register or sign in to post a comment