blob: c491375dd6f21a72dd78a6e3095efe89db169c81 [file] [log] [blame]
<html>
<body>
<script src="../../resources/js-test.js"></script>
<script>
description('Tests that DOM timers gets throttled on hidden pages once they reach the max nesting level');
jsTestIsAsync = true;
let timerCount = 0;
const timeoutInterval = 10;
const maxNestingLevel = 5;
let timerHandle = 0;
function testTimer()
{
++timerCount;
timerHandle = setTimeout(testTimer, timeoutInterval);
if (timerCount >= maxNestingLevel) {
shouldBeTrue("internals.isTimerThrottled(timerHandle)");
testRunner.resetPageVisibility();
clearTimeout(timerHandle);
finishJSTest();
return;
} else
shouldBeFalse("internals.isTimerThrottled(timerHandle)");
}
function runTest()
{
if (!window.testRunner) {
debug('This test requires testRunner');
return;
}
testRunner.overridePreference("WebKitHiddenPageDOMTimerThrottlingEnabled", 1);
timerHandle = setTimeout(testTimer, timeoutInterval);
shouldBeFalse("internals.isTimerThrottled(timerHandle)");
}
onload = function() {
document.onvisibilitychange = () => {
if (!document.hidden)
return;
document.onvisibilitychange = null;
runTest();
};
testRunner.setPageVisibility("hidden");
};
</script>
</body>
</html>