mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-07-30 09:16:07 -04:00
test: add max-timers test
This commit is contained in:
40
src/browser/tests/window/timer_limits.html
Normal file
40
src/browser/tests/window/timer_limits.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<script id=one-shot-limit>
|
||||
// One-shot timers pile up legitimately: a fan-out of async tasks that each
|
||||
// yield through `new Promise((r) => setTimeout(r))` queues one per task, and
|
||||
// none of them can run until the microtask queue drains.
|
||||
const timeouts = [];
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
timeouts.push(window.setTimeout(() => {}, 100000));
|
||||
}
|
||||
testing.expectEqual(1000, timeouts.length);
|
||||
|
||||
for (const id of timeouts) {
|
||||
window.clearTimeout(id);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id=interval-limit>
|
||||
const intervals = [];
|
||||
let threw = false;
|
||||
try {
|
||||
for (let i = 0; i < 600; i++) {
|
||||
intervals.push(window.setInterval(() => {}, 100000));
|
||||
}
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
}
|
||||
testing.expectEqual(true, threw);
|
||||
testing.expectEqual(512, intervals.length);
|
||||
|
||||
window.clearInterval(intervals.pop());
|
||||
intervals.push(window.setInterval(() => {}, 100000));
|
||||
testing.expectEqual(512, intervals.length);
|
||||
|
||||
for (const id of intervals) {
|
||||
window.clearInterval(id);
|
||||
}
|
||||
</script>
|
||||
:
|
||||
Reference in New Issue
Block a user