summaryrefslogtreecommitdiffstats
path: root/dom/tests/js/timer.js
blob: ac1ed1ef34f2e8916e88786771540ea4c60bf6ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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);