tor-browser

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

test_after_paint_pref.html (3511B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=608030
      5 -->
      6 <head>
      7  <title>Test for MozAfterPaint pref Bug 608030</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=608030">Mozilla Bug 608030</a>
     13 <div id="display" style="width: 10em; height: 5em; background-color: red"></div>
     14 <pre id="test">
     15 <script type="application/javascript">
     16 
     17 /** Test for Bug 608030 */
     18 
     19 SimpleTest.waitForExplicitFinish();
     20 SimpleTest.requestFlakyTimeout("untriaged");
     21 
     22 window.addEventListener("load", step0);
     23 
     24 is(SpecialPowers.getBoolPref("dom.send_after_paint_to_content"), true, "pref defaults to true in mochitest harness");
     25 
     26 function print_rect(rect) {
     27  if (!rect) {
     28    rect = { top: 0, left: 0, width: 0, right: 0 };
     29  }
     30  return "(top=" + rect.top + ",left=" + rect.left + ",width=" + rect.width + ",height=" + rect.height + ")";
     31 }
     32 
     33 function print_event(event) {
     34  var res = "boundingClientRect=" + print_rect(event.boundingClientRect);
     35  var rects = event.clientRects;
     36  if (rects) {
     37    for (var i = 0; i < rects.length; ++i) {
     38      res += " clientRects[" + i + "]=" + print_rect(rects[i]);
     39    }
     40  }
     41  return res;
     42 }
     43 
     44 function step0(event) {
     45  // Wait until we get the MozAfterPaint following the load event
     46  // before starting.
     47  ok(true, "loaded");
     48  window.addEventListener("MozAfterPaint", step1);
     49 
     50  // Ensure a MozAfterPaint event is fired
     51  div.style.backgroundColor = "yellow";
     52 }
     53 
     54 var start;
     55 var div = document.getElementById("display");
     56 
     57 function step1(event)
     58 {
     59  ok(true, "step1 reached: " + print_event(event));
     60  window.removeEventListener("MozAfterPaint", step1);
     61 
     62  start = Date.now();
     63 
     64  window.addEventListener("MozAfterPaint", step2);
     65 
     66  div.style.backgroundColor = "blue";
     67 }
     68 
     69 async function step2(event)
     70 {
     71  ok(true, "step2 reached: " + print_event(event));
     72  window.removeEventListener("MozAfterPaint", step2);
     73 
     74  var end = Date.now();
     75  var timeout = 3 * Math.max(end - start, 300);
     76 
     77  ok(true, "got MozAfterPaint (timeout for next step is " + timeout + "ms)");
     78 
     79  // Set the pref for our second test
     80 
     81  // When there was previously another page in our window, we seem to
     82  // get duplicate events, simultaneously, so we need to register our
     83  // next listener after a zero timeout.
     84  await SpecialPowers.pushPrefEnv({'set': [['dom.send_after_paint_to_content', false]]});
     85 
     86  // Wait for a double-rAF, to ensure we get a refresh driver tick (which, for
     87  // this pref, is what actually makes the pref-adjustment take effect).
     88  await new Promise(resolve  => requestAnimationFrame(resolve));
     89  await new Promise(resolve  => requestAnimationFrame(resolve));
     90 
     91  setTimeout(step3, 0, timeout);
     92 }
     93 function step3(timeout)
     94 {
     95  ok(true, "step3 reached");
     96  window.addEventListener("MozAfterPaint", failstep);
     97 
     98  div.style.backgroundColor = "fuchsia";
     99 
    100  setTimeout(step4, timeout);
    101 }
    102 
    103 function failstep(event)
    104 {
    105  ok(true, "failstep reached: " + print_event(event));
    106  ok(false, "got MozAfterPaint when we should not have");
    107 }
    108 
    109 function step4()
    110 {
    111  ok(true, "step4 reached"); // If we didn't get the failure in failstep,
    112                             // then we passed.
    113 
    114  window.removeEventListener("MozAfterPaint", failstep);
    115 
    116  // Set the pref back in its initial state.
    117  SpecialPowers.pushPrefEnv({'set': [['dom.send_after_paint_to_content', true]]}, SimpleTest.finish);
    118 }
    119 
    120 </script>
    121 </pre>
    122 </body>
    123 </html>