tor-browser

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

callback-idle-periods.html (1805B)


      1 <!DOCTYPE html>
      2 <title>window.requestIdleCallback callback behavior during idle periods.</title>
      3 <meta name="timeout" content="long">
      4 <link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" />
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script>
      8 
      9 async_test(function() {
     10  // Check that if an idle callback calls requestIdleCallback, the new callback
     11  // doesn't get the same deadline (i.e., runs in a new idle period).
     12  var previous_deadline = undefined;
     13  var idle_callbacks_remaining = 10;
     14  var rIC = this.step_func(function(deadline) {
     15    var now = performance.now();
     16    var remaining = deadline.timeRemaining();
     17    var new_deadline = now + remaining;
     18    if (previous_deadline != undefined) {
     19      assert_true(new_deadline >= previous_deadline, "A requestIdleCallback scheduled during an idle period should be called back with a deadline greater than or equal to that in the current idle period.");
     20    }
     21 
     22    // Schedule a new requestIdleCallback.
     23    if (--idle_callbacks_remaining > 0) {
     24      previous_deadline = new_deadline;
     25      requestIdleCallback(rIC);
     26    } else {
     27      this.done();
     28    }
     29  });
     30 
     31  // Spin an empty rAF loop to cause an idle period each frame.
     32  var idle_task_posted = false;
     33  requestAnimationFrame(function rAFLoop() {
     34    if (!idle_task_posted) {
     35      requestIdleCallback(rIC);
     36      idle_task_posted = true;
     37    }
     38    requestAnimationFrame(rAFLoop);
     39  });
     40 }, 'Check that if an idle callback calls requestIdleCallback the new callback doesn\'t run in the current idle period.');
     41 </script>
     42 <h1>Test of requestIdleCallback idle period behavior</h1>
     43 <p>This test validates that window.requestIdleCallback deals with callbacks during idle periods correctly.</p>
     44 <div id="log"></div>