Commit d49e786c d49e786cc0b869525ddb503da3ac5bb3039d11a1 by Nicolas Perriault

Casper.resourceExists() now checks for non 404 HTTP status

1 parent d3a6d79d
...@@ -6,14 +6,15 @@ XXXX-XX-XX, v1.0.0 ...@@ -6,14 +6,15 @@ XXXX-XX-XX, v1.0.0
6 6
7 This version is yet to be released. 7 This version is yet to be released.
8 8
9 - [Casper.resourceExists()](http://casperjs.org/api.html#casper.resourceExists) and related functions now checks for non HTTP-404 received responses.
9 - closes [#230](https://github.com/n1k0/casperjs/issues/230) - added [`ClientUtils.getElementsBound()`](http://casperjs.org/api.html#clientutils.getElementsBounds) and [`Casper.getElementsBound()`](http://casperjs.org/api.html#casper.getElementsBounds) 10 - closes [#230](https://github.com/n1k0/casperjs/issues/230) - added [`ClientUtils.getElementsBound()`](http://casperjs.org/api.html#clientutils.getElementsBounds) and [`Casper.getElementsBound()`](http://casperjs.org/api.html#casper.getElementsBounds)
11 - fixes [#254](https://github.com/n1k0/casperjs/issues/254) - fix up one use of qsa, hit when filling forms with missing elements
10 12
11 2012-10-01, v1.0.0-RC2 13 2012-10-01, v1.0.0-RC2
12 ---------------------- 14 ----------------------
13 15
14 ### Important Changes & Caveats 16 ### Important Changes & Caveats
15 17
16 - fixes [#254](https://github.com/n1k0/casperjs/issues/254) - fix up one use of qsa, hit when filling forms with missing elements
17 - **PhantomJS 1.6 is now the minimal requirement**, PhantomJS 1.7 is supported. 18 - **PhantomJS 1.6 is now the minimal requirement**, PhantomJS 1.7 is supported.
18 - CasperJS continues to ship with its own implementation of CommonJS' module pattern, due to the way it has to work to offer its own executable. While the implementations are nearly the same, **100% compatibility is not guaranteed**. 19 - CasperJS continues to ship with its own implementation of CommonJS' module pattern, due to the way it has to work to offer its own executable. While the implementations are nearly the same, **100% compatibility is not guaranteed**.
19 20
......
...@@ -1054,12 +1054,12 @@ Casper.prototype.resourceExists = function resourceExists(test) { ...@@ -1054,12 +1054,12 @@ Casper.prototype.resourceExists = function resourceExists(test) {
1054 switch (utils.betterTypeOf(test)) { 1054 switch (utils.betterTypeOf(test)) {
1055 case "string": 1055 case "string":
1056 testFn = function _testResourceExists_String(res) { 1056 testFn = function _testResourceExists_String(res) {
1057 return res.url.search(test) !== -1; 1057 return res.url.search(test) !== -1 && res.status !== 404;
1058 }; 1058 };
1059 break; 1059 break;
1060 case "regexp": 1060 case "regexp":
1061 testFn = function _testResourceExists_Regexp(res) { 1061 testFn = function _testResourceExists_Regexp(res) {
1062 return test.test(res.url); 1062 return test.test(res.url) && res.status !== 404;
1063 }; 1063 };
1064 break; 1064 break;
1065 case "function": 1065 case "function":
......
...@@ -3,14 +3,13 @@ ...@@ -3,14 +3,13 @@
3 <head> 3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>CasperJS test resource</title> 5 <title>CasperJS test resource</title>
6 <script>
7 setTimeout(function () {
8 var path = "images/phantom.png?" + new Date();
9 document.querySelector("img").setAttribute("src", path);
10 }, 1000);
11 </script>
12 </head> 6 </head>
13 <body> 7 <body>
14 <img width="55" height="55" border="1"> 8 <script id="loader"></script>
9 <script>
10 setTimeout(function () {
11 document.querySelector("#loader").setAttribute("src", "dummy.js");
12 }, 1000);
13 </script>
15 </body> 14 </body>
16 </html>
...\ No newline at end of file ...\ No newline at end of file
15 </html>
......
...@@ -7,18 +7,18 @@ casper.start "tests/site/resources.html", -> ...@@ -7,18 +7,18 @@ casper.start "tests/site/resources.html", ->
7 "two resources found" 7 "two resources found"
8 ) 8 )
9 @test.assertResourceExists( 9 @test.assertResourceExists(
10 /phantom\.png/i 10 /dummy\.js/i
11 "phantom image found via test RegExp" 11 "phantom image found via test RegExp"
12 ) 12 )
13 @test.assertResourceExists( 13 @test.assertResourceExists(
14 (res) -> res.url.match "phantom.png" 14 (res) -> res.url.match "dummy.js"
15 "phantom image found via test Function" 15 "phantom image found via test Function"
16 ) 16 )
17 @test.assertResourceExists( 17 @test.assertResourceExists(
18 "phantom.png" 18 "dummy.js"
19 "phantom image found via test String" 19 "phantom image found via test String"
20 ) 20 )
21 onTimeout = -> @test.fail "waitForResource timeout occured" 21 onTimeout = -> @test.fail "waitForResource timeout occured"
22 @waitForResource "phantom.png", onTime, onTimeout 22 @waitForResource "dummy.js", onTime, onTimeout
23 23
24 casper.run(-> @test.done()) 24 casper.run(-> @test.done())
......