|
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 type="application/javascript" 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 function get_pref() |
|
20 { |
|
21 return SpecialPowers.getBoolPref("dom.send_after_paint_to_content"); |
|
22 } |
|
23 |
|
24 function set_pref(val) |
|
25 { |
|
26 SpecialPowers.setBoolPref("dom.send_after_paint_to_content", val); |
|
27 } |
|
28 |
|
29 SimpleTest.waitForExplicitFinish(); |
|
30 |
|
31 window.addEventListener("load", step0, false); |
|
32 |
|
33 is(get_pref(), true, "pref defaults to true in mochitest harness"); |
|
34 |
|
35 function print_rect(rect) { |
|
36 return "(top=" + rect.top + ",left=" + rect.left + ",width=" + rect.width + ",height=" + rect.height + ")"; |
|
37 } |
|
38 |
|
39 function print_event(event) { |
|
40 var res = "boundingClientRect=" + print_rect(event.boundingClientRect); |
|
41 var rects = event.clientRects; |
|
42 for (var i = 0; i < rects.length; ++i) { |
|
43 res += " clientRects[" + i + "]=" + print_rect(rects[i]); |
|
44 } |
|
45 return res; |
|
46 } |
|
47 |
|
48 function step0(event) { |
|
49 // Wait until we get the MozAfterPaint following the load event |
|
50 // before starting. |
|
51 ok(true, "loaded"); |
|
52 window.addEventListener("MozAfterPaint", step1, false); |
|
53 |
|
54 // Ensure a MozAfterPaint event is fired |
|
55 div.style.backgroundColor = "yellow"; |
|
56 } |
|
57 |
|
58 var start; |
|
59 var div = document.getElementById("display"); |
|
60 |
|
61 function step1(event) |
|
62 { |
|
63 ok(true, "step1 reached: " + print_event(event)); |
|
64 window.removeEventListener("MozAfterPaint", step1, false); |
|
65 |
|
66 start = Date.now(); |
|
67 |
|
68 window.addEventListener("MozAfterPaint", step2, false); |
|
69 |
|
70 div.style.backgroundColor = "blue"; |
|
71 } |
|
72 |
|
73 function step2(event) |
|
74 { |
|
75 ok(true, "step2 reached: " + print_event(event)); |
|
76 window.removeEventListener("MozAfterPaint", step2, false); |
|
77 |
|
78 var end = Date.now(); |
|
79 var timeout = 3 * Math.max(end - start, 300); |
|
80 |
|
81 ok(true, "got MozAfterPaint (timeout for next step is " + timeout + "ms)"); |
|
82 |
|
83 // Set the pref for our second test |
|
84 set_pref(false); |
|
85 |
|
86 // When there was previously another page in our window, we seem to |
|
87 // get duplicate events, simultaneously, so we need to register our |
|
88 // next listener after a zero timeout. |
|
89 setTimeout(step3, 0, timeout); |
|
90 } |
|
91 function step3(timeout) |
|
92 { |
|
93 ok(true, "step3 reached"); |
|
94 window.addEventListener("MozAfterPaint", failstep, false); |
|
95 |
|
96 div.style.backgroundColor = "fuchsia"; |
|
97 |
|
98 setTimeout(step4, timeout); |
|
99 } |
|
100 |
|
101 function failstep(event) |
|
102 { |
|
103 ok(true, "failstep reached: " + print_event(event)); |
|
104 ok(false, "got MozAfterPaint when we should not have"); |
|
105 } |
|
106 |
|
107 function step4() |
|
108 { |
|
109 ok(true, "step4 reached"); // If we didn't get the failure in failstep, |
|
110 // then we passed. |
|
111 |
|
112 window.removeEventListener("MozAfterPaint", failstep, false); |
|
113 |
|
114 // Set the pref back in its initial state. |
|
115 set_pref(true); |
|
116 |
|
117 SimpleTest.finish(); |
|
118 } |
|
119 |
|
120 </script> |
|
121 </pre> |
|
122 </body> |
|
123 </html> |