michael@0: michael@0: function oneShot(testNum, str) michael@0: { michael@0: dump("Test #" + testNum + " successful:" + str + "\n"); michael@0: } michael@0: michael@0: setTimeout(oneShot, 1000, 1, "one shot timer with function argument"); michael@0: setTimeout("oneShot(2, 'one shot timer with string argument');", 2000); michael@0: michael@0: function reschedule(testNum, numTimes) michael@0: { michael@0: if (numTimes == 4) { michael@0: dump("Test #" + testNum + " successful: Creating a timeout in a timeout\n"); michael@0: kickoff4(); michael@0: } michael@0: else { michael@0: dump("Test #" + testNum + " in progress: " + numTimes + "\n"); michael@0: setTimeout(reschedule, 500, 3, numTimes+1); michael@0: } michael@0: } michael@0: michael@0: setTimeout(reschedule, 3000, 3, 0); michael@0: michael@0: var count = 0; michael@0: var repeat_timer = null; michael@0: function repeat(testNum, numTimes, str, func, delay) michael@0: { michael@0: dump("Test #" + testNum + " in progress: interval delayed by " + delay + " milliseconds\n"); michael@0: if (count++ > numTimes) { michael@0: clearInterval(repeat_timer); michael@0: dump("Test #" + testNum + " successful: " + str + "\n"); michael@0: if (func != null) { michael@0: func(); michael@0: } michael@0: } michael@0: } michael@0: michael@0: function kickoff4() michael@0: { michael@0: repeat_timer = setInterval(repeat, 500, 4, 5, "interval test", kickoff5); michael@0: } michael@0: michael@0: //setTimeout(kickoff4, 5000); michael@0: michael@0: function oneShot2(testNum) michael@0: { michael@0: dump("Test #" + testNum + " in progress: one shot timer\n"); michael@0: if (count++ == 4) { michael@0: dump("Test #" + testNum + " in progress: end of one shots\n"); michael@0: } michael@0: else { michael@0: setTimeout(oneShot2, 500, 5); michael@0: } michael@0: } michael@0: michael@0: function kickoff5() michael@0: { michael@0: count = 0; michael@0: setTimeout(oneShot2, 500, 5); michael@0: repeat_timer = setInterval("repeat(5, 8, 'multiple timer test', kickoff6)", 600); michael@0: } michael@0: michael@0: //setTimeout(kickoff5, 12000); michael@0: michael@0: function kickoff6() michael@0: { michael@0: dump("Test #6: Interval timeout should end when you go to a new page\n"); michael@0: setInterval(repeat, 1000, 6, 1000, "endless timer test", null); michael@0: } michael@0: michael@0: //setTimeout(kickoff6, 18000);