Bug 1270301 - Add test for SimpleTest.waitForCondition. r=jmaher

MozReview-Commit-ID: KNLvWJ7VQID

--HG--
extra : rebase_source : f0f5bdf0a2cf36588c72f7f9c6f44f7d57f4b920
extra : source : 24f4733086dd1d4390b77afe9aeaa4c1ada25ad8
This commit is contained in:
Xidorn Quan 2016-05-10 18:44:55 +10:00
Родитель f355ff0241
Коммит 77024304e3
2 изменённых файлов: 54 добавлений и 0 удалений

Просмотреть файл

@ -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>