tor-browser

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

callback-multiple-calls.html (1403B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>multiple calls to requestIdleCallback</title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <div id="log"></div>
      7 <script>
      8  let option = {timeout: 50};
      9 
     10  async_test(function (t) {
     11    assert_false(document.hidden, "document.hidden must exist and be false to run this test properly");
     12    var counter = 0;
     13    function f(c) {
     14      assert_equals(counter, c);
     15      if (counter === 49) {
     16        t.done();
     17      }
     18 
     19      ++counter;
     20    }
     21    for (var i = 0; i < 100; ++i) {
     22      let j = i;
     23      window.requestIdleCallback(t.step_func(function () { f(j) }), option);
     24    }
     25  }, "requestIdleCallback callbacks should be invoked in order (called iteratively)");
     26 
     27  async_test(function (t) {
     28    assert_false(document.hidden, "document.hidden must exist and be false to run this test properly");
     29    var counter = 0;
     30 
     31    function f(c) {
     32      assert_equals(counter, c);
     33      if (counter === 49) {
     34        t.done();
     35      }
     36 
     37      ++counter;
     38      window.requestIdleCallback(t.step_func(function () { f(c + 1) }), option);
     39    }
     40 
     41    window.requestIdleCallback(t.step_func(function () { f(0) }), option);
     42  }, "requestIdleCallback callbacks should be invoked in order (called recursively)");
     43 
     44  let generateIdlePeriods = _ => requestAnimationFrame(generateIdlePeriods);
     45  generateIdlePeriods();
     46 </script>