Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | |
michael@0 | 2 | function oneShot(testNum, str) |
michael@0 | 3 | { |
michael@0 | 4 | dump("Test #" + testNum + " successful:" + str + "\n"); |
michael@0 | 5 | } |
michael@0 | 6 | |
michael@0 | 7 | setTimeout(oneShot, 1000, 1, "one shot timer with function argument"); |
michael@0 | 8 | setTimeout("oneShot(2, 'one shot timer with string argument');", 2000); |
michael@0 | 9 | |
michael@0 | 10 | function reschedule(testNum, numTimes) |
michael@0 | 11 | { |
michael@0 | 12 | if (numTimes == 4) { |
michael@0 | 13 | dump("Test #" + testNum + " successful: Creating a timeout in a timeout\n"); |
michael@0 | 14 | kickoff4(); |
michael@0 | 15 | } |
michael@0 | 16 | else { |
michael@0 | 17 | dump("Test #" + testNum + " in progress: " + numTimes + "\n"); |
michael@0 | 18 | setTimeout(reschedule, 500, 3, numTimes+1); |
michael@0 | 19 | } |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | setTimeout(reschedule, 3000, 3, 0); |
michael@0 | 23 | |
michael@0 | 24 | var count = 0; |
michael@0 | 25 | var repeat_timer = null; |
michael@0 | 26 | function repeat(testNum, numTimes, str, func, delay) |
michael@0 | 27 | { |
michael@0 | 28 | dump("Test #" + testNum + " in progress: interval delayed by " + delay + " milliseconds\n"); |
michael@0 | 29 | if (count++ > numTimes) { |
michael@0 | 30 | clearInterval(repeat_timer); |
michael@0 | 31 | dump("Test #" + testNum + " successful: " + str + "\n"); |
michael@0 | 32 | if (func != null) { |
michael@0 | 33 | func(); |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function kickoff4() |
michael@0 | 39 | { |
michael@0 | 40 | repeat_timer = setInterval(repeat, 500, 4, 5, "interval test", kickoff5); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | //setTimeout(kickoff4, 5000); |
michael@0 | 44 | |
michael@0 | 45 | function oneShot2(testNum) |
michael@0 | 46 | { |
michael@0 | 47 | dump("Test #" + testNum + " in progress: one shot timer\n"); |
michael@0 | 48 | if (count++ == 4) { |
michael@0 | 49 | dump("Test #" + testNum + " in progress: end of one shots\n"); |
michael@0 | 50 | } |
michael@0 | 51 | else { |
michael@0 | 52 | setTimeout(oneShot2, 500, 5); |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function kickoff5() |
michael@0 | 57 | { |
michael@0 | 58 | count = 0; |
michael@0 | 59 | setTimeout(oneShot2, 500, 5); |
michael@0 | 60 | repeat_timer = setInterval("repeat(5, 8, 'multiple timer test', kickoff6)", 600); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | //setTimeout(kickoff5, 12000); |
michael@0 | 64 | |
michael@0 | 65 | function kickoff6() |
michael@0 | 66 | { |
michael@0 | 67 | dump("Test #6: Interval timeout should end when you go to a new page\n"); |
michael@0 | 68 | setInterval(repeat, 1000, 6, 1000, "endless timer test", null); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | //setTimeout(kickoff6, 18000); |