layout/base/tests/test_bug629838.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/base/tests/test_bug629838.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Tests for MozAfterPaint</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="enableTestPlugin.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +</head>
    1.12 +<body>
    1.13 +<p id="display">
    1.14 +<embed type="application/x-test" width="100" height="100" id="p"
    1.15 +       drawmode="solid" color="FF00FF00"></embed>
    1.16 +</p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script class="testbody" type="text/javascript">
    1.22 +
    1.23 +SimpleTest.waitForExplicitFinish();
    1.24 +
    1.25 +var initialPaintCount, afterPaintCount;
    1.26 +var color = 0;
    1.27 +
    1.28 +function onAfterPaint () {
    1.29 +  afterPaintCount += 1;
    1.30 +}
    1.31 +
    1.32 +function startTest() {
    1.33 +  setTimeout(function () {
    1.34 +    afterPaintCount = 0;
    1.35 +    initialPaintCount = window.mozPaintCount;
    1.36 +    window.addEventListener("MozAfterPaint", onAfterPaint, true);
    1.37 +    doBackgroundFlicker();
    1.38 +  }, 500);
    1.39 +}
    1.40 +
    1.41 +document.addEventListener("DOMContentLoaded", startTest, true);
    1.42 +
    1.43 +// Unfortunately we cannot reliably assert that mozPaintCount and afterPaintCount increment perfectly
    1.44 +// in sync, because they can diverge in the presence of OS-triggered paints or system load.
    1.45 +// Instead, wait for a minimum number of afterPaint events to at least ensure that they are being fired.
    1.46 +const minimumAfterPaintsToPass = 10;
    1.47 +
    1.48 +function doPluginFlicker() {
    1.49 +  ok(true, "Plugin color iteration " + color + 
    1.50 +     ", afterpaint count: " + afterPaintCount +
    1.51 +     ", mozpaint count: " + window.mozPaintCount);
    1.52 +  if (afterPaintCount >= minimumAfterPaintsToPass) { 
    1.53 +    ok(true, "afterPaintCount incremented enough from plugin color changes.");
    1.54 +    SimpleTest.finish();
    1.55 +    return;
    1.56 +  }
    1.57 +
    1.58 +  color = (color + 1) % 256;
    1.59 +  var str = color.toString(16);
    1.60 +  if (str.length < 2) {
    1.61 +    str = "0" + str;
    1.62 +  }
    1.63 +  str = "FF" + str + str + str;
    1.64 +  document.getElementById("p").setColor(str);
    1.65 +  setTimeout(doPluginFlicker, 0);
    1.66 +}
    1.67 +
    1.68 +function doBackgroundFlicker() {
    1.69 +  ok(true, "Background color iteration " + color + 
    1.70 +     ", afterpaint count: " + afterPaintCount +
    1.71 +     ", mozpaint count: " + window.mozPaintCount);
    1.72 +  if (afterPaintCount >= minimumAfterPaintsToPass) {
    1.73 +    ok(true, "afterPaintCount incremented enough from background color changes.");
    1.74 +    afterPaintCount = 0;
    1.75 +    initialPaintCount = window.mozPaintCount;
    1.76 +    doPluginFlicker();
    1.77 +    return;
    1.78 +  }
    1.79 +
    1.80 +  color = (color + 1) % 256;
    1.81 +  document.body.style.backgroundColor = "rgb(" + color + "," + color + "," + color + ")";
    1.82 +  setTimeout(doBackgroundFlicker, 0);
    1.83 +}
    1.84 +
    1.85 +</script>
    1.86 +</pre>
    1.87 +
    1.88 +<div style="height:4000px"></div>
    1.89 +<a id="first"  href="http://www.mozilla.org/">first<br>link</a>
    1.90 +<a id="second" href="http://www.mozilla.org/">second link</a>
    1.91 +<a id="third"  href="http://www.mozilla.org/">third<br>link</a>
    1.92 +<div style="height:4000px"></div>
    1.93 +
    1.94 +</body>
    1.95 +</html>
    1.96 +

mercurial