<html>
<head>
<script>
function log(msg) {
    var element = document.createElement("div");
    element.textContent = msg;
    document.body.appendChild(element);
    document.body.appendChild(document.createElement("br"));
}

var count = 0;
function fastTimeoutHandler() {
    ++count;
    setTimeout(fastTimeoutHandler, 1);
}

function slowTimeoutHandler() {
    // Note: the count threshold is tied somewhat to the
    // maxTimerNestingLevel in DOMTimer.cpp.
    // Up to 10, we use 1ms, and after that, it becomes 500ms. So, it should be 12.
    if (count < 12)
        log("PASS");
    else
        log("FAIL -- timeout ran " + count + " times");
    testRunner.notifyDone();
}

function runTest() {
    if (!window.testRunner) {
        log("This test requires the LayoutTestController");
        return;
    }

    testRunner.dumpAsText();
    testRunner.waitUntilDone();

    // Make timers run no more often than twice a second.
    internals.settings.setMinimumTimerInterval(0.5);

    setTimeout(slowTimeoutHandler, 1000);
    setTimeout(fastTimeoutHandler, 1);
}
</script>
</head>
<body onload="runTest()">
</body>
</html>
