layout/generic/test/file_bug514732_helper.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial