1 postMessage("Test started.");
3 // After all the expected timeouts fire, signal the main page the test is complete.
4 var expectedFiringCount = 5;
5 function checkCompletion()
7 if (--expectedFiringCount == 0)
11 // Execute script in a string.
12 setTimeout('postMessage("PASS: timeout 1"); checkCompletion()', 20);
14 // Execute a function.
15 // Note it has the same timeout value as previous timeout, but should be fired reliably
16 // after it because the timer heap maintains the queueing order as well as firing time.
17 setTimeout(function () {
18 postMessage("PASS: timeout 2");
22 // Clear a timeout before it fires.
23 var singleShot = setTimeout('postMessage("FAIL: this timer should be removed before firing")', 0);
24 clearTimeout(singleShot);
26 // Clear interval after it fires.
27 var intervalTimer = setInterval('postMessage("PASS: interval 3"); clearInterval(intervalTimer); checkCompletion();', 20);
29 // Set repeated interval. It will terminate the test after 2 iterations.
30 setInterval('postMessage("PASS: repeated interval"); checkCompletion();', 30);