2009-06-08 15:30:10 +02:00
|
|
|
include("mjsunit.js");
|
2009-04-21 13:52:21 +02:00
|
|
|
|
2009-04-21 16:30:47 +02:00
|
|
|
function onLoad () {
|
2009-04-21 13:52:21 +02:00
|
|
|
assertInstanceof(setTimeout, Function);
|
|
|
|
var starttime = new Date;
|
2009-04-21 16:22:14 +02:00
|
|
|
|
2009-04-21 13:52:21 +02:00
|
|
|
setTimeout(function () {
|
|
|
|
var endtime = new Date;
|
|
|
|
var diff = endtime - starttime;
|
|
|
|
if (diff < 0) diff = -diff;
|
|
|
|
assertTrue(900 < diff || diff < 1100);
|
|
|
|
}, 1000);
|
2009-04-21 16:22:14 +02:00
|
|
|
|
|
|
|
// this timer shouldn't execute
|
|
|
|
var id = setTimeout(function () { assertTrue(false); }, 500);
|
|
|
|
clearTimeout(id);
|
2009-04-29 14:12:24 +02:00
|
|
|
|
|
|
|
var count = 0;
|
|
|
|
setInterval(function () {
|
|
|
|
count += 1;
|
|
|
|
var endtime = new Date;
|
|
|
|
var diff = endtime - starttime;
|
|
|
|
if (diff < 0) diff = -diff;
|
|
|
|
puts(diff);
|
|
|
|
var t = count * 1000;
|
|
|
|
assertTrue(t - 100 < diff || diff < t + 100);
|
|
|
|
assertTrue(count <= 3);
|
|
|
|
if (count == 3)
|
|
|
|
clearInterval(this);
|
|
|
|
}, 1000);
|
2009-04-21 13:52:21 +02:00
|
|
|
}
|