tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

timer-nesting-not-inherited-in-microtask.html (1597B)


      1 <!DOCTYPE html>
      2 <html>
      3 <link rel="help" href="https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint">
      4 <link rel="help" href="https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timer-initialisation-steps">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script>
      8 // queue a microtask after the timer has reached the spec-defined maximum nesting level. Then we ensure
      9 // the new timer did not inherit the nesting level from the outer timer task by checking that the sub-4ms
     10 // timeout was not clamped to 4ms.
     11 
     12 test(() => {
     13    assert_equals(typeof performance.now, "function");
     14 }, "Test requires performance.now() to measure approximate timing of callbacks.");
     15 
     16 
     17 let t = async_test("Test that a timer scheduled during a microtask checkpoint does not inherit the timer nesting level of the task that just ran.");
     18 
     19 var rescheduleTimeoutCalledCount = 0;
     20 function rescheduleTimeout()
     21 {
     22    if (++rescheduleTimeoutCalledCount > 15)
     23        return t.done();
     24    else if (rescheduleTimeoutCalledCount > 5) {
     25        queueMicrotask(() => {
     26            const checkNotNestedScheduledAt = performance.now();
     27            setTimeout(() => {
     28                const approximateDelay = performance.now() - checkNotNestedScheduledAt;
     29                t.step(() => assert_less_than(approximateDelay, 4, "Timer should not be clamped to 4ms"));
     30            }, 1);
     31        });
     32    }
     33    setTimeout(rescheduleTimeout, 8);
     34 }
     35 
     36 window.addEventListener("load", () => setTimeout(rescheduleTimeout, 8));
     37 </script>
     38 </html>