dom/tests/js/timer.js

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

mercurial