Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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>
12 <div id="imgs" style="whitespace: nowrap; overflow: visible; height: 10px;"></div>
14 <iframe id="testframe" src="./file_bug514732_1.html"></iframe>
16 <br/><br/>
17 <div id="log">log:<br/></div>
18 <br/><br/>
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;
27 function log(msg) {
28 document.getElementById("log").innerHTML += msg;
29 }
31 function logln(msg) {
32 if (arguments.length == 0) msg = "";
33 document.getElementById("log").innerHTML += msg + "<br/>";
34 }
36 function logev(ev) {
37 logln([ev.x, ev.y, ev.width, ev.height].join(' '));
38 }
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 }
53 function unphoom(doc) {
54 var phoomer = doc.getElementById('phoomer');
55 if (phoomer)
56 doc.getElementById('imgs').removeChild(phoomer);
57 }
59 function getDocBodyDimensions(doc) {
60 return [doc.documentElement.scrollWidth, doc.documentElement.scrollHeight];
61 }
63 function makeResult() {
64 return {
65 success: false,
66 event: null
67 };
68 }
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 }
78 function waitInterrupt(result, gen) {
79 result.event = null;
80 result.success = false;
81 setTimeout(function() { if (!result.success) gen.next(); }, 3500);
82 }
84 function testPhoom(isCapturing, x, y, expectEvent) {
86 var eventGen = (function() {
87 var innerdoc = document.getElementById('testframe').contentDocument;
89 for (var doc of [document, innerdoc]) {
90 var inner = (doc == innerdoc);
91 var w, h, result, listener;
93 /* --- EXPANSION --- */
95 result = makeResult();
96 listener = makeListener(result, eventGen);
98 doc.addEventListener("MozScrolledAreaChanged", listener, isCapturing);
100 if (!expectEvent) waitInterrupt(result, eventGen);
101 phoom(doc, x, y);
102 yield;
104 doc.removeEventListener("MozScrolledAreaChanged", listener, isCapturing);
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 }
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 }
134 /* --- CONTRACTION --- */
136 result = makeResult();
137 listener = makeListener(result, eventGen);
139 doc.addEventListener("MozScrolledAreaChanged", listener, isCapturing);
141 if (!expectEvent) waitInterrupt(result, eventGen);
142 unphoom(doc);
143 yield;
145 doc.removeEventListener("MozScrolledAreaChanged", listener, isCapturing);
147 if (expectEvent) {
148 ok(result.success, "Received expected " + (inner ? "inner" : "") + " contraction event");
149 }
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 }
165 setTimeout(nextTest, 0);
167 yield;
168 })();
170 setTimeout(function() { eventGen.next(); }, 0);
171 }
173 function testPreliminaries() {
174 /* Do any setup here */
175 nextTest();
176 }
178 function testEventCapturingHorz() {
179 testPhoom(true, 10000, 0, true); // calls nextTest() when finished
180 }
182 function testEventCapturingVert() {
183 testPhoom(true, 0, 10000, true); // calls nextTest() when finished
184 }
186 function testEventCapturingBoth() {
187 testPhoom(true, 10000, 10000, true); // calls nextTest() when finished
188 }
190 function testEventCapturingNegv() {
191 testPhoom(true, -10000, -10000, false); // calls nextTest() when finished
192 }
194 function testEventBubblingHorz() {
195 testPhoom(false, 10000, 0, true); // calls nextTest() when finished
196 }
198 function testEventBubblingVert() {
199 testPhoom(false, 0, 10000, true); // calls nextTest() when finished
200 }
202 function testEventBubblingBoth() {
203 testPhoom(false, 10000, 10000, true); // calls nextTest() when finished
204 }
206 function testEventBubblingNegv() {
207 testPhoom(false, -10000, -10000, false); // calls nextTest() when finished
208 }
210 function testCustomCreationHelper(creatingDoc, listeningDoc, x, y, w, h, expectEvent) {
211 var result = makeResult();
213 var listener = function(evt) {
214 result.success = true;
215 result.event = evt;
216 };
218 var ev = creatingDoc.createEvent("ScrollAreaEvent");
219 ev.initScrollAreaEvent("MozScrolledAreaChanged",
220 true, true, window, 0,
221 x, y, w, h);
223 listeningDoc.addEventListener("MozScrolledAreaChanged", listener, true);
225 result.success = false;
226 creatingDoc.dispatchEvent(ev);
228 listeningDoc.removeEventListener("MozScrolledAreaChanged", listener, true);
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 }
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 }
247 var TESTS = [testPreliminaries,
248 testEventCapturingHorz,
249 testEventCapturingVert,
250 testEventCapturingBoth,
251 testEventCapturingNegv,
252 testEventBubblingHorz,
253 testEventBubblingVert,
254 testEventBubblingBoth,
255 testEventBubblingNegv,
256 testCustomCreation,
257 __end];
259 var PC = 0;
261 function nextTest() {
262 TESTS[PC++]();
263 }
265 function __end() {
266 log("done!");
267 finish();
268 window.close();
269 }
271 /*
272 * We need both the parent document and all iframe documents to load
273 * before starting anything
274 */
275 var loaded = 0;
277 window
278 .addEventListener('load', function(ev) {
279 logln(++loaded);
280 if (loaded >= 2) {
281 logln("go...");
282 nextTest();
283 }
284 }, false);
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);
295 // window.opener says: SimpleTest.waitForExplicitFinish();
297 </script>
299 </body>
300 </html>