Commit 30e703d6 30e703d66462d543e4438b8ab2be0cf4177c6f13 by Nicolas Perriault

fixed test for Casper.waitForResource() where a resource is not requested two times consecutively

1 parent 4dc8e4ca
...@@ -597,14 +597,14 @@ ...@@ -597,14 +597,14 @@
597 /** 597 /**
598 * Checks if a given resource was loaded by the remote page. 598 * Checks if a given resource was loaded by the remote page.
599 * 599 *
600 * @param Function/String test A test function or string. In case a string is passed, 600 * @param Function/String test A test function or string. In case a string is passed, url matching will be tested.
601 * @return Boolean 601 * @return Boolean
602 */ 602 */
603 resourceExists: function(test) { 603 resourceExists: function(test) {
604 var testFn; 604 var testFn;
605 if (isType(test, "string")) { 605 if (isType(test, "string")) {
606 testFn = function (res) { 606 testFn = function (res) {
607 return res.url.match(test); 607 return res.url.search(test) !== -1;
608 }; 608 };
609 } else { 609 } else {
610 testFn = test; 610 testFn = test;
...@@ -670,7 +670,6 @@ ...@@ -670,7 +670,6 @@
670 if (!skipLog) { 670 if (!skipLog) {
671 this.log(stepInfo + ": done in " + (new Date().getTime() - this.startTime) + "ms.", "info"); 671 this.log(stepInfo + ": done in " + (new Date().getTime() - this.startTime) + "ms.", "info");
672 } 672 }
673 this.step++;
674 }, 673 },
675 674
676 /** 675 /**
...@@ -749,7 +748,11 @@ ...@@ -749,7 +748,11 @@
749 this.steps.push(step); 748 this.steps.push(step);
750 } else { 749 } else {
751 // insert substep a level deeper 750 // insert substep a level deeper
751 try {
752 step.level = this.steps[this.step - 1].level + 1; 752 step.level = this.steps[this.step - 1].level + 1;
753 } catch (e) {
754 step.level = 0;
755 }
753 var insertIndex = this.step; 756 var insertIndex = this.step;
754 while (this.steps[insertIndex] && step.level === this.steps[insertIndex].level) { 757 while (this.steps[insertIndex] && step.level === this.steps[insertIndex].level) {
755 insertIndex++; 758 insertIndex++;
...@@ -899,7 +902,7 @@ ...@@ -899,7 +902,7 @@
899 self.waitStart(); 902 self.waitStart();
900 var start = new Date().getTime(); 903 var start = new Date().getTime();
901 var condition = false; 904 var condition = false;
902 var interval = setInterval(function(self, testFx, onTimeout) { 905 var interval = setInterval(function(self, testFx, timeout, onTimeout) {
903 if ((new Date().getTime() - start < timeout) && !condition) { 906 if ((new Date().getTime() - start < timeout) && !condition) {
904 condition = testFx(self); 907 condition = testFx(self);
905 } else { 908 } else {
...@@ -909,7 +912,7 @@ ...@@ -909,7 +912,7 @@
909 if (isType(onTimeout, "function")) { 912 if (isType(onTimeout, "function")) {
910 onTimeout.call(self, self); 913 onTimeout.call(self, self);
911 } else { 914 } else {
912 self.die("Expired timeout, exiting.", "error"); 915 self.die("Timeout of " + timeout + "ms expired, exiting.", "error");
913 } 916 }
914 clearInterval(interval); 917 clearInterval(interval);
915 } else { 918 } else {
...@@ -920,7 +923,7 @@ ...@@ -920,7 +923,7 @@
920 clearInterval(interval); 923 clearInterval(interval);
921 } 924 }
922 } 925 }
923 }, 100, self, testFx, onTimeout); 926 }, 100, self, testFx, timeout, onTimeout);
924 }); 927 });
925 }, 928 },
926 929
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
5 <title>CasperJS test resource</title> 5 <title>CasperJS test resource</title>
6 <script> 6 <script>
7 setTimeout(function () { 7 setTimeout(function () {
8 document.querySelector("img").setAttribute("src","images/phantom.png"); 8 var path = "images/phantom.png?" + new Date();
9 document.querySelector("img").setAttribute("src", path);
9 }, 1000); 10 }, 1000);
10 </script> 11 </script>
11 </head> 12 </head>
......
1 do(casper) -> 1 do(casper) ->
2 casper.onError = ->
3 console.log 'err'
4 casper.start "tests/site/resources.html", -> 2 casper.start "tests/site/resources.html", ->
5 console.log 'loaded'
6 @test.assertEquals @resources.length, 1, "only one resource found" 3 @test.assertEquals @resources.length, 1, "only one resource found"
7 @waitForResource "phantom.png", -> 4 onTime = ->
8 @test.assertEquals( 5 @test.assertEquals(
9 @resources.length 6 @resources.length
10 2 7 2
...@@ -18,5 +15,7 @@ do(casper) -> ...@@ -18,5 +15,7 @@ do(casper) ->
18 "phantom.png" 15 "phantom.png"
19 "phantom image found via test string" 16 "phantom image found via test string"
20 ) 17 )
18 onTimeout = -> @test.fail "waitForResource timeout occured"
19 @waitForResource "phantom.png", onTime, onTimeout
21 20
22 casper.run(-> @test.done()) 21 casper.run(-> @test.done())
......