tor-browser

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

test_refreshDriver_hasPendingTick.html (3081B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1756269
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1756269: the nsIDOMWindowUtils.refreshDriverHasPendingTick API</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <style>
     12    @keyframes growWidth {
     13      from { width: 20px; }
     14      to   { width: 30px; }
     15    }
     16    .animating {
     17      animation: 1s growWidth infinite alternate;
     18    }
     19    #sometimesAnimated {
     20      background: blue;
     21      width: 10px;
     22      height: 10px;
     23    }
     24  </style>
     25 </head>
     26 <body onload="run()">
     27 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1756269">Mozilla Bug 1756269</a>
     28 <div id="display">
     29  <div id="sometimesAnimated"></div>
     30 </div>
     31 <pre id="test">
     32 <script>
     33 "use strict";
     34 SimpleTest.waitForExplicitFinish();
     35 SimpleTest.requestFlakyTimeout("need to allow time to pass so that we can " +
     36                               "detect unwanted extra refresh driver ticks");
     37 const gUtils = SpecialPowers.getDOMWindowUtils(window);
     38 
     39 async function startAnimAndExpectTick() {
     40  // Start an animation:
     41  sometimesAnimated.classList.add("animating");
     42 
     43  // double-rAF to flush pending paints:
     44  await new Promise(r => requestAnimationFrame(r));
     45  await new Promise(r => requestAnimationFrame(r));
     46 
     47  ok(gUtils.refreshDriverHasPendingTick,
     48     "Expecting refresh driver to be ticking when animated content is present");
     49 
     50  // clean up, i.e. remove animation:
     51  sometimesAnimated.classList.remove("animating");
     52 
     53  // double-rAF to flush pending paints:
     54  await new Promise(r => requestAnimationFrame(r));
     55  await new Promise(r => requestAnimationFrame(r));
     56 }
     57 
     58 async function expectTicksToStop() {
     59  let didStopTicking = false;
     60  // Note: The maximum loop count here is an arbitrary large value, just to let
     61  // us gracefully handle edge cases where multiple setTimeouts resolve before
     62  // a pending refresh driver tick.  Really, we just want to be sure the refresh
     63  // driver *eventually* stops ticking, and we can do so gracefully by polling
     64  // with some generous-but-finite number of checks here.
     65  for (var i = 0; i < 100; i++) {
     66    await new Promise(r => setTimeout(r, 8));
     67    if(!gUtils.refreshDriverHasPendingTick) {
     68      didStopTicking = true;
     69      break;
     70    }
     71  }
     72  ok(didStopTicking, "refresh driver should have eventually stopped ticking");
     73 }
     74 
     75 async function run() {
     76  // By default, the refresh driver ticks on its own for some period of time
     77  // after pageload.  Turn that off so we don't have to wait it out:
     78  await SpecialPowers.pushPrefEnv({'set':
     79                                   [['layout.keep_ticking_after_load_ms', 0]]});
     80 
     81  // Start out with a double-rAF, to flush paints from pageload:
     82  await new Promise(r => requestAnimationFrame(r));
     83  await new Promise(r => requestAnimationFrame(r));
     84 
     85  await startAnimAndExpectTick();
     86  await expectTicksToStop();
     87  await startAnimAndExpectTick();
     88  await expectTicksToStop();
     89 
     90  SimpleTest.finish();
     91 }
     92 </script>
     93 </pre>
     94 </body>
     95 </html>