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 @@
/**
* Checks if a given resource was loaded by the remote page.
*
* @param Function/String test A test function or string. In case a string is passed,
* @param Function/String test A test function or string. In case a string is passed, url matching will be tested.
* @return Boolean
*/
resourceExists: function(test) {
var testFn;
if (isType(test, "string")) {
testFn = function (res) {
return res.url.match(test);
return res.url.search(test) !== -1;
};
} else {
testFn = test;
......@@ -670,7 +670,6 @@
if (!skipLog) {
this.log(stepInfo + ": done in " + (new Date().getTime() - this.startTime) + "ms.", "info");
}
this.step++;
},
/**
......@@ -744,17 +743,21 @@
}
// check if casper is running
if (this.checker === null) {
// append step to the end of the queue
step.level = 0;
this.steps.push(step);
// append step to the end of the queue
step.level = 0;
this.steps.push(step);
} else {
// insert substep a level deeper
step.level = this.steps[this.step - 1].level + 1;
var insertIndex = this.step;
while (this.steps[insertIndex] && step.level === this.steps[insertIndex].level) {
insertIndex++;
}
this.steps.splice(insertIndex, 0, step);
// insert substep a level deeper
try {
step.level = this.steps[this.step - 1].level + 1;
} catch (e) {
step.level = 0;
}
var insertIndex = this.step;
while (this.steps[insertIndex] && step.level === this.steps[insertIndex].level) {
insertIndex++;
}
this.steps.splice(insertIndex, 0, step);
}
return this;
},
......@@ -899,7 +902,7 @@
self.waitStart();
var start = new Date().getTime();
var condition = false;
var interval = setInterval(function(self, testFx, onTimeout) {
var interval = setInterval(function(self, testFx, timeout, onTimeout) {
if ((new Date().getTime() - start < timeout) && !condition) {
condition = testFx(self);
} else {
......@@ -909,7 +912,7 @@
if (isType(onTimeout, "function")) {
onTimeout.call(self, self);
} else {
self.die("Expired timeout, exiting.", "error");
self.die("Timeout of " + timeout + "ms expired, exiting.", "error");
}
clearInterval(interval);
} else {
......@@ -920,7 +923,7 @@
clearInterval(interval);
}
}
}, 100, self, testFx, onTimeout);
}, 100, self, testFx, timeout, onTimeout);
});
},
......
......@@ -5,7 +5,8 @@
<title>CasperJS test resource</title>
<script>
setTimeout(function () {
document.querySelector("img").setAttribute("src","images/phantom.png");
var path = "images/phantom.png?" + new Date();
document.querySelector("img").setAttribute("src", path);
}, 1000);
</script>
</head>
......
do(casper) ->
casper.onError = ->
console.log 'err'
casper.start "tests/site/resources.html", ->
console.log 'loaded'
@test.assertEquals @resources.length, 1, "only one resource found"
@waitForResource "phantom.png", ->
onTime = ->
@test.assertEquals(
@resources.length
2
......@@ -18,5 +15,7 @@ do(casper) ->
"phantom.png"
"phantom image found via test string"
)
onTimeout = -> @test.fail "waitForResource timeout occured"
@waitForResource "phantom.png", onTime, onTimeout
casper.run(-> @test.done())
......