test_sanity_waitForCondition.html (1383B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>SimpleTest.waitForCondition test</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> 8 </head> 9 <body> 10 <script> 11 12 var captureFailure = false; 13 var capturedFailures = []; 14 window.ok = function (cond, name) { 15 if (!captureFailure) { 16 SimpleTest.ok(cond, name); 17 } else if (cond) { 18 SimpleTest.ok(false, `Expect a failure with "${name}"`); 19 } else { 20 capturedFailures.push(name); 21 } 22 }; 23 24 SimpleTest.waitForExplicitFinish(); 25 SimpleTest.requestFlakyTimeout("test behavior SimpleTest.waitForCondition"); 26 27 addLoadEvent(testNormal); 28 29 function testNormal() { 30 var condition = false; 31 SimpleTest.waitForCondition(() => condition, () => { 32 ok(condition, "Should only be called when condition is true"); 33 SimpleTest.executeSoon(testTimeout); 34 }, "Shouldn't timeout"); 35 setTimeout(() => { condition = true; }, 1000); 36 } 37 38 function testTimeout() { 39 captureFailure = true; 40 SimpleTest.waitForCondition(() => false, () => { 41 captureFailure = false; 42 is(capturedFailures.length, 1, "Should captured one failure"); 43 is(capturedFailures[0], "Should timeout", 44 "Should capture the failure passed in"); 45 SimpleTest.executeSoon(() => SimpleTest.finish()); 46 }, "Should timeout"); 47 } 48 49 </script> 50 </body> 51 </html>