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