mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 13:55:43 +00:00
Bug 1270301 - Add test for SimpleTest.waitForCondition. r=jmaher
MozReview-Commit-ID: KNLvWJ7VQID --HG-- extra : transplant_source : t%F9d%E2ih%F3%BF%B3%29%DA%87s%84%B8%28I%11%E2%AB
This commit is contained in:
parent
48b93f48cd
commit
54b9c867d3
@ -49,3 +49,4 @@ fail-if = true
|
||||
skip-if = toolkit == 'android' # we use the old manifest style on android
|
||||
fail-if = true
|
||||
[test_spawn_task.html]
|
||||
[test_sanity_waitForCondition.html]
|
||||
|
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>SimpleTest.waitForCondition test</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
|
||||
var captureFailure = false;
|
||||
var capturedFailures = [];
|
||||
window.ok = function (cond, name, diag) {
|
||||
if (!captureFailure) {
|
||||
SimpleTest.ok(cond, name, diag);
|
||||
} else {
|
||||
if (cond) {
|
||||
SimpleTest.ok(false, `Expect a failure with "${name}"`);
|
||||
} else {
|
||||
capturedFailures.push(name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.requestFlakyTimeout("test behavior SimpleTest.waitForCondition");
|
||||
|
||||
addLoadEvent(testNormal);
|
||||
|
||||
function testNormal() {
|
||||
var condition = false;
|
||||
SimpleTest.waitForCondition(() => condition, () => {
|
||||
ok(condition, "Should only be called when condition is true");
|
||||
SimpleTest.executeSoon(testTimeout);
|
||||
}, "Shouldn't timeout");
|
||||
setTimeout(() => { condition = true; }, 1000);
|
||||
}
|
||||
|
||||
function testTimeout() {
|
||||
captureFailure = true;
|
||||
SimpleTest.waitForCondition(() => false, () => {
|
||||
captureFailure = false;
|
||||
is(capturedFailures.length, 1, "Should captured one failure");
|
||||
is(capturedFailures[0], "Should timeout",
|
||||
"Should capture the failure passed in");
|
||||
SimpleTest.executeSoon(() => SimpleTest.finish());
|
||||
}, "Should timeout");
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user