layout/generic/test/file_bug514732_helper.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:7c05c33363ce
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=514732
5 -->
6 <head>
7 <title>Test for Bug 514732</title>
8 </head>
9 <body>
10 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug?id=514732">Mozilla Bug 514732</a>
11
12 <div id="imgs" style="whitespace: nowrap; overflow: visible; height: 10px;"></div>
13
14 <iframe id="testframe" src="./file_bug514732_1.html"></iframe>
15
16 <br/><br/>
17 <div id="log">log:<br/></div>
18 <br/><br/>
19
20 <script class="testbody" style="width: 300; height: 150;" type="text/javascript;version=1.8">
21 // Import test API
22 var is = window.opener.is;
23 var ok = window.opener.ok;
24 var todo = window.opener.todo;
25 var finish = window.opener.SimpleTest.finish;
26
27 function log(msg) {
28 document.getElementById("log").innerHTML += msg;
29 }
30
31 function logln(msg) {
32 if (arguments.length == 0) msg = "";
33 document.getElementById("log").innerHTML += msg + "<br/>";
34 }
35
36 function logev(ev) {
37 logln([ev.x, ev.y, ev.width, ev.height].join(' '));
38 }
39
40 /* Absolutely position a 500x500 div at x, y on doc */
41 function phoom(doc, x, y) {
42 var d = doc.createElement('div');
43 d.id = "phoomer";
44 d.style.position = "absolute";
45 d.style.left = x + 'px';
46 d.style.top = y + 'px';
47 d.style.backgroundColor = "#00FFF0";
48 d.style.width = 500 + 'px';
49 d.style.height = 500 + 'px';
50 doc.getElementById('imgs').appendChild(d);
51 }
52
53 function unphoom(doc) {
54 var phoomer = doc.getElementById('phoomer');
55 if (phoomer)
56 doc.getElementById('imgs').removeChild(phoomer);
57 }
58
59 function getDocBodyDimensions(doc) {
60 return [doc.documentElement.scrollWidth, doc.documentElement.scrollHeight];
61 }
62
63 function makeResult() {
64 return {
65 success: false,
66 event: null
67 };
68 }
69
70 function makeListener(result, eventGen) {
71 return function(ev) {
72 result.success = true;
73 result.event = ev;
74 setTimeout(function() { eventGen.next(); }, 0);
75 };
76 }
77
78 function waitInterrupt(result, gen) {
79 result.event = null;
80 result.success = false;
81 setTimeout(function() { if (!result.success) gen.next(); }, 3500);
82 }
83
84 function testPhoom(isCapturing, x, y, expectEvent) {
85
86 var eventGen = (function() {
87 var innerdoc = document.getElementById('testframe').contentDocument;
88
89 for (var doc of [document, innerdoc]) {
90 var inner = (doc == innerdoc);
91 var w, h, result, listener;
92
93 /* --- EXPANSION --- */
94
95 result = makeResult();
96 listener = makeListener(result, eventGen);
97
98 doc.addEventListener("MozScrolledAreaChanged", listener, isCapturing);
99
100 if (!expectEvent) waitInterrupt(result, eventGen);
101 phoom(doc, x, y);
102 yield;
103
104 doc.removeEventListener("MozScrolledAreaChanged", listener, isCapturing);
105
106 /* If we're expecting an event, better check that we got one. If we are not expecting one,
107 one can still arrive, but we don't complain if it did not. In either case, any event
108 that arrives will have its data checked below. */
109 if (expectEvent) {
110 ok(result.success, "Received expected " + (inner ? "inner" : "") + " expansion event");
111 }
112
113 if (result.success) {
114 is(result.event.x, 0, "Expansion event x is 0");
115 is(result.event.y, 0, "Expansion event y is 0");
116 if (inner) {
117 /* In iframe-land, the values of |myiframe.contentDocument.documentElement.scrollWidth| and
118 |.scrollHeight| appear to be not as expected (they stay very small). This is fine, since
119 we know exactly where we're positioning our fixed-dimensions div, and we know our iframe's
120 dimensions, so we can do our own math. NB: The inner iframe is styled at 300x500. */
121 is(Math.round(result.event.width),
122 Math.max(x + 500, 300),
123 "Inner expansion event width matches body width");
124 is(Math.round(result.event.height),
125 Math.max(y + 500, 150),
126 "Inner expansion event height matches body height");
127 } else {
128 [w, h] = getDocBodyDimensions(doc);
129 is(Math.round(result.event.width), w, "Expansion event width matches body width");
130 is(Math.round(result.event.height), h, "Expansion event height matches body height");
131 }
132 }
133
134 /* --- CONTRACTION --- */
135
136 result = makeResult();
137 listener = makeListener(result, eventGen);
138
139 doc.addEventListener("MozScrolledAreaChanged", listener, isCapturing);
140
141 if (!expectEvent) waitInterrupt(result, eventGen);
142 unphoom(doc);
143 yield;
144
145 doc.removeEventListener("MozScrolledAreaChanged", listener, isCapturing);
146
147 if (expectEvent) {
148 ok(result.success, "Received expected " + (inner ? "inner" : "") + " contraction event");
149 }
150
151 if (result.success) {
152 is(result.event.x, 0, "Contraction event x is 0");
153 is(result.event.y, 0, "Contraction event y is 0");
154 if (inner) {
155 is(Math.round(result.event.width), 300, "Inner contraction event width matches body width");
156 is(Math.round(result.event.height), 150, "Inner contraction event height matches body height");
157 } else {
158 [w, h] = getDocBodyDimensions(doc);
159 is(Math.round(result.event.width), w, "Contraction event width matches body width");
160 is(Math.round(result.event.height), h, "Contraction event height matches body height");
161 }
162 }
163 }
164
165 setTimeout(nextTest, 0);
166
167 yield;
168 })();
169
170 setTimeout(function() { eventGen.next(); }, 0);
171 }
172
173 function testPreliminaries() {
174 /* Do any setup here */
175 nextTest();
176 }
177
178 function testEventCapturingHorz() {
179 testPhoom(true, 10000, 0, true); // calls nextTest() when finished
180 }
181
182 function testEventCapturingVert() {
183 testPhoom(true, 0, 10000, true); // calls nextTest() when finished
184 }
185
186 function testEventCapturingBoth() {
187 testPhoom(true, 10000, 10000, true); // calls nextTest() when finished
188 }
189
190 function testEventCapturingNegv() {
191 testPhoom(true, -10000, -10000, false); // calls nextTest() when finished
192 }
193
194 function testEventBubblingHorz() {
195 testPhoom(false, 10000, 0, true); // calls nextTest() when finished
196 }
197
198 function testEventBubblingVert() {
199 testPhoom(false, 0, 10000, true); // calls nextTest() when finished
200 }
201
202 function testEventBubblingBoth() {
203 testPhoom(false, 10000, 10000, true); // calls nextTest() when finished
204 }
205
206 function testEventBubblingNegv() {
207 testPhoom(false, -10000, -10000, false); // calls nextTest() when finished
208 }
209
210 function testCustomCreationHelper(creatingDoc, listeningDoc, x, y, w, h, expectEvent) {
211 var result = makeResult();
212
213 var listener = function(evt) {
214 result.success = true;
215 result.event = evt;
216 };
217
218 var ev = creatingDoc.createEvent("ScrollAreaEvent");
219 ev.initScrollAreaEvent("MozScrolledAreaChanged",
220 true, true, window, 0,
221 x, y, w, h);
222
223 listeningDoc.addEventListener("MozScrolledAreaChanged", listener, true);
224
225 result.success = false;
226 creatingDoc.dispatchEvent(ev);
227
228 listeningDoc.removeEventListener("MozScrolledAreaChanged", listener, true);
229
230 is(result.success, expectEvent, "Received custom event iff expected");
231 if (result.success) {
232 is(result.event.x, x, "Custom event data matches for x");
233 is(result.event.y, y, "Custom event data matches for y");
234 is(result.event.width, w, "Custom event data matches for width");
235 is(result.event.height, h, "Custom event data matches for height");
236 }
237 }
238
239 function testCustomCreation() {
240 var innerdoc = document.getElementById('testframe').contentDocument;
241 testCustomCreationHelper(document, document, 2, 7, 1, 8, true); // e = 2.718 ...
242 testCustomCreationHelper(innerdoc, innerdoc, 2, 8, 1, 8, true); // ... 2818 ...
243 testCustomCreationHelper(innerdoc, document, 2, 8, 4, 5, false); // ... 2845 ...
244 nextTest();
245 }
246
247 var TESTS = [testPreliminaries,
248 testEventCapturingHorz,
249 testEventCapturingVert,
250 testEventCapturingBoth,
251 testEventCapturingNegv,
252 testEventBubblingHorz,
253 testEventBubblingVert,
254 testEventBubblingBoth,
255 testEventBubblingNegv,
256 testCustomCreation,
257 __end];
258
259 var PC = 0;
260
261 function nextTest() {
262 TESTS[PC++]();
263 }
264
265 function __end() {
266 log("done!");
267 finish();
268 window.close();
269 }
270
271 /*
272 * We need both the parent document and all iframe documents to load
273 * before starting anything
274 */
275 var loaded = 0;
276
277 window
278 .addEventListener('load', function(ev) {
279 logln(++loaded);
280 if (loaded >= 2) {
281 logln("go...");
282 nextTest();
283 }
284 }, false);
285
286 document.getElementById("testframe").contentWindow
287 .addEventListener('load', function(ev) {
288 logln(++loaded);
289 if (loaded >= 2) {
290 logln("go...");
291 nextTest();
292 }
293 }, false);
294
295 // window.opener says: SimpleTest.waitForExplicitFinish();
296
297 </script>
298
299 </body>
300 </html>

mercurial