tor-browser

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

test_bug629838.html (2739B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Tests for MozAfterPaint</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 <p id="display">
     10 <div width="100" height="100" id="p" style="background-color: rgb(0,0,0)"/>
     11 </p>
     12 <div id="content" style="display: none">
     13  
     14 </div>
     15 <pre id="test">
     16 <script class="testbody" type="text/javascript">
     17 
     18 SimpleTest.waitForExplicitFinish();
     19 SimpleTest.requestFlakyTimeout("untriaged");
     20 
     21 var initialPaintCount, afterPaintCount;
     22 var color = 0;
     23 
     24 function onAfterPaint () {
     25  afterPaintCount += 1;
     26 }
     27 
     28 function startTest() {
     29  setTimeout(function () {
     30    afterPaintCount = 0;
     31    initialPaintCount = SpecialPowers.DOMWindowUtils.paintCount;
     32    window.addEventListener("MozAfterPaint", onAfterPaint, true);
     33    doBackgroundFlicker();
     34  }, 500);
     35 }
     36 
     37 document.addEventListener("DOMContentLoaded", startTest, true);
     38 
     39 // Unfortunately we cannot reliably assert that mozPaintCount and afterPaintCount increment perfectly
     40 // in sync, because they can diverge in the presence of OS-triggered paints or system load.
     41 // Instead, wait for a minimum number of afterPaint events to at least ensure that they are being fired.
     42 const minimumAfterPaintsToPass = 10;
     43 
     44 function doElementFlicker() {
     45  ok(true, "Element color iteration " + color + 
     46     ", afterpaint count: " + afterPaintCount +
     47     ", mozpaint count: " + SpecialPowers.DOMWindowUtils.paintCount);
     48  if (afterPaintCount >= minimumAfterPaintsToPass) { 
     49    ok(true, "afterPaintCount incremented enough from color changes.");
     50    SimpleTest.finish();
     51    return;
     52  }
     53 
     54  color = (color + 1) % 256;
     55  document.getElementById("p").style.backgroundColor = "rgb(" + color + "," + color + "," + color + ")";
     56  setTimeout(doElementFlicker, 0);
     57 }
     58 
     59 function doBackgroundFlicker() {
     60  ok(true, "Background color iteration " + color + 
     61     ", afterpaint count: " + afterPaintCount +
     62     ", mozpaint count: " + SpecialPowers.DOMWindowUtils.paintCount);
     63  if (afterPaintCount >= minimumAfterPaintsToPass) {
     64    ok(true, "afterPaintCount incremented enough from background color changes.");
     65    afterPaintCount = 0;
     66    initialPaintCount = SpecialPowers.DOMWindowUtils.paintCount;
     67    doElementFlicker();
     68    return;
     69  }
     70 
     71  color = (color + 1) % 256;
     72  document.body.style.backgroundColor = "rgb(" + color + "," + color + "," + color + ")";
     73  setTimeout(doBackgroundFlicker, 0);
     74 }
     75 
     76 </script>
     77 </pre>
     78 
     79 <div style="height:4000px"></div>
     80 <a id="first"  href="http://www.mozilla.org/">first<br>link</a>
     81 <a id="second" href="http://www.mozilla.org/">second link</a>
     82 <a id="third"  href="http://www.mozilla.org/">third<br>link</a>
     83 <div style="height:4000px"></div>
     84 
     85 </body>
     86 </html>