From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- dom/tests/js/timer.js | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 dom/tests/js/timer.js (limited to 'dom/tests/js/timer.js') diff --git a/dom/tests/js/timer.js b/dom/tests/js/timer.js new file mode 100644 index 000000000..ac1ed1ef3 --- /dev/null +++ b/dom/tests/js/timer.js @@ -0,0 +1,71 @@ + +function oneShot(testNum, str) +{ + dump("Test #" + testNum + " successful:" + str + "\n"); +} + +setTimeout(oneShot, 1000, 1, "one shot timer with function argument"); +setTimeout("oneShot(2, 'one shot timer with string argument');", 2000); + +function reschedule(testNum, numTimes) +{ + if (numTimes == 4) { + dump("Test #" + testNum + " successful: Creating a timeout in a timeout\n"); + kickoff4(); + } + else { + dump("Test #" + testNum + " in progress: " + numTimes + "\n"); + setTimeout(reschedule, 500, 3, numTimes+1); + } +} + +setTimeout(reschedule, 3000, 3, 0); + +var count = 0; +var repeat_timer = null; +function repeat(testNum, numTimes, str, func, delay) +{ + dump("Test #" + testNum + " in progress: interval delayed by " + delay + " milliseconds\n"); + if (count++ > numTimes) { + clearInterval(repeat_timer); + dump("Test #" + testNum + " successful: " + str + "\n"); + if (func != null) { + func(); + } + } +} + +function kickoff4() +{ + repeat_timer = setInterval(repeat, 500, 4, 5, "interval test", kickoff5); +} + +//setTimeout(kickoff4, 5000); + +function oneShot2(testNum) +{ + dump("Test #" + testNum + " in progress: one shot timer\n"); + if (count++ == 4) { + dump("Test #" + testNum + " in progress: end of one shots\n"); + } + else { + setTimeout(oneShot2, 500, 5); + } +} + +function kickoff5() +{ + count = 0; + setTimeout(oneShot2, 500, 5); + repeat_timer = setInterval("repeat(5, 8, 'multiple timer test', kickoff6)", 600); +} + +//setTimeout(kickoff5, 12000); + +function kickoff6() +{ + dump("Test #6: Interval timeout should end when you go to a new page\n"); + setInterval(repeat, 1000, 6, 1000, "endless timer test", null); +} + +//setTimeout(kickoff6, 18000); \ No newline at end of file -- cgit v1.2.3