dom/tests/js/timer.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     2 function oneShot(testNum, str)
     3 {
     4   dump("Test #" + testNum + " successful:" + str + "\n");
     5 }
     7 setTimeout(oneShot, 1000, 1, "one shot timer with function argument");
     8 setTimeout("oneShot(2, 'one shot timer with string argument');", 2000);
    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 }
    22 setTimeout(reschedule, 3000, 3, 0); 
    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 }
    38 function kickoff4()
    39 {
    40   repeat_timer = setInterval(repeat, 500, 4, 5, "interval test", kickoff5);
    41 }
    43 //setTimeout(kickoff4, 5000);
    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 }
    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 }
    63 //setTimeout(kickoff5, 12000);
    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 }
    71 //setTimeout(kickoff6, 18000);

mercurial