dom/tests/js/timer.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/js/timer.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +
     1.5 +function oneShot(testNum, str)
     1.6 +{
     1.7 +  dump("Test #" + testNum + " successful:" + str + "\n");
     1.8 +}
     1.9 +
    1.10 +setTimeout(oneShot, 1000, 1, "one shot timer with function argument");
    1.11 +setTimeout("oneShot(2, 'one shot timer with string argument');", 2000);
    1.12 +
    1.13 +function reschedule(testNum, numTimes)
    1.14 +{
    1.15 +  if (numTimes == 4) { 
    1.16 +    dump("Test #" + testNum + " successful: Creating a timeout in a timeout\n");
    1.17 +    kickoff4();
    1.18 +  }
    1.19 +  else {
    1.20 +    dump("Test #" + testNum + " in progress: " + numTimes + "\n");
    1.21 +    setTimeout(reschedule, 500, 3, numTimes+1);
    1.22 +  }
    1.23 +}
    1.24 +
    1.25 +setTimeout(reschedule, 3000, 3, 0); 
    1.26 +
    1.27 +var count = 0;
    1.28 +var repeat_timer = null;
    1.29 +function repeat(testNum, numTimes, str, func, delay)
    1.30 +{
    1.31 +  dump("Test #" + testNum + " in progress: interval delayed by " + delay + " milliseconds\n");
    1.32 +  if (count++ > numTimes) {
    1.33 +    clearInterval(repeat_timer);
    1.34 +    dump("Test #" + testNum + " successful: " + str + "\n");
    1.35 +    if (func != null) {
    1.36 +      func();
    1.37 +    }
    1.38 +  }
    1.39 +}
    1.40 +
    1.41 +function kickoff4()
    1.42 +{
    1.43 +  repeat_timer = setInterval(repeat, 500, 4, 5, "interval test", kickoff5);
    1.44 +}
    1.45 +
    1.46 +//setTimeout(kickoff4, 5000);
    1.47 +
    1.48 +function oneShot2(testNum)
    1.49 +{
    1.50 +  dump("Test #" + testNum + " in progress: one shot timer\n");
    1.51 +  if (count++ == 4) {
    1.52 +    dump("Test #" + testNum + " in progress: end of one shots\n");
    1.53 +  }
    1.54 +  else {
    1.55 +    setTimeout(oneShot2, 500, 5);
    1.56 +  }
    1.57 +}
    1.58 +
    1.59 +function kickoff5()
    1.60 +{
    1.61 +  count = 0;
    1.62 +  setTimeout(oneShot2, 500, 5);
    1.63 +  repeat_timer = setInterval("repeat(5, 8, 'multiple timer test', kickoff6)", 600);
    1.64 +}
    1.65 +
    1.66 +//setTimeout(kickoff5, 12000);
    1.67 +
    1.68 +function kickoff6()
    1.69 +{
    1.70 +  dump("Test #6: Interval timeout should end when you go to a new page\n");
    1.71 +  setInterval(repeat, 1000, 6, 1000, "endless timer test", null);
    1.72 +}
    1.73 +
    1.74 +//setTimeout(kickoff6, 18000);
    1.75 \ No newline at end of file

mercurial