blob: 8e40ad21c280a381679e7d84e078ee421daee03d [file] [log] [blame]
<html>
<head>
<script type="text/javascript" src="../../resources/js-test-pre.js"></script>
<script>
window.jsTestIsAsync = true;
description("Runs 3 separate 1 second &lt;script&gt; blocks with a setTimeout schedule before each. The execution time of the setTimeout is when the HTML yielded to the event loop. The yields also represent painting opportunities. We want the parser to yield every 0.5 seconds once it has seen a script.");
var startTime = new Date().getTime();
var tolerance = 400; // 400 ms
function expectElapsedTime(expectedTime) {
shouldBeCloseTo("new Date().getTime() - startTime", expectedTime, tolerance);
}
function sleep(ms) {
var endTime = (new Date().getTime()) + ms;
while ((new Date().getTime()) < endTime);
}
</script>
</head>
<body>
<p></p>
<script>
setTimeout(function() { expectElapsedTime(1000) }, 0);
</script>
<script>
sleep(1000);
</script>
<script>
setTimeout(function() { expectElapsedTime(2000) }, 0);
</script>
<script>
sleep(1000);
</script>
<script>
setTimeout(function() {
expectElapsedTime(3000);
finishJSTest();
}, 0);
</script>
<script>
sleep(1000);
</script>
<script type="text/javascript" src="../../resources/js-test-post.js"></script>
</body>
</html>