1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/test/file_bug514732_helper.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,300 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=514732 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 514732</title> 1.11 +</head> 1.12 +<body> 1.13 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug?id=514732">Mozilla Bug 514732</a> 1.14 + 1.15 +<div id="imgs" style="whitespace: nowrap; overflow: visible; height: 10px;"></div> 1.16 + 1.17 +<iframe id="testframe" src="./file_bug514732_1.html"></iframe> 1.18 + 1.19 +<br/><br/> 1.20 +<div id="log">log:<br/></div> 1.21 +<br/><br/> 1.22 + 1.23 +<script class="testbody" style="width: 300; height: 150;" type="text/javascript;version=1.8"> 1.24 +// Import test API 1.25 +var is = window.opener.is; 1.26 +var ok = window.opener.ok; 1.27 +var todo = window.opener.todo; 1.28 +var finish = window.opener.SimpleTest.finish; 1.29 + 1.30 +function log(msg) { 1.31 + document.getElementById("log").innerHTML += msg; 1.32 +} 1.33 + 1.34 +function logln(msg) { 1.35 + if (arguments.length == 0) msg = ""; 1.36 + document.getElementById("log").innerHTML += msg + "<br/>"; 1.37 +} 1.38 + 1.39 +function logev(ev) { 1.40 + logln([ev.x, ev.y, ev.width, ev.height].join(' ')); 1.41 +} 1.42 + 1.43 +/* Absolutely position a 500x500 div at x, y on doc */ 1.44 +function phoom(doc, x, y) { 1.45 + var d = doc.createElement('div'); 1.46 + d.id = "phoomer"; 1.47 + d.style.position = "absolute"; 1.48 + d.style.left = x + 'px'; 1.49 + d.style.top = y + 'px'; 1.50 + d.style.backgroundColor = "#00FFF0"; 1.51 + d.style.width = 500 + 'px'; 1.52 + d.style.height = 500 + 'px'; 1.53 + doc.getElementById('imgs').appendChild(d); 1.54 +} 1.55 + 1.56 +function unphoom(doc) { 1.57 + var phoomer = doc.getElementById('phoomer'); 1.58 + if (phoomer) 1.59 + doc.getElementById('imgs').removeChild(phoomer); 1.60 +} 1.61 + 1.62 +function getDocBodyDimensions(doc) { 1.63 + return [doc.documentElement.scrollWidth, doc.documentElement.scrollHeight]; 1.64 +} 1.65 + 1.66 +function makeResult() { 1.67 + return { 1.68 + success: false, 1.69 + event: null 1.70 + }; 1.71 +} 1.72 + 1.73 +function makeListener(result, eventGen) { 1.74 + return function(ev) { 1.75 + result.success = true; 1.76 + result.event = ev; 1.77 + setTimeout(function() { eventGen.next(); }, 0); 1.78 + }; 1.79 +} 1.80 + 1.81 +function waitInterrupt(result, gen) { 1.82 + result.event = null; 1.83 + result.success = false; 1.84 + setTimeout(function() { if (!result.success) gen.next(); }, 3500); 1.85 +} 1.86 + 1.87 +function testPhoom(isCapturing, x, y, expectEvent) { 1.88 + 1.89 + var eventGen = (function() { 1.90 + var innerdoc = document.getElementById('testframe').contentDocument; 1.91 + 1.92 + for (var doc of [document, innerdoc]) { 1.93 + var inner = (doc == innerdoc); 1.94 + var w, h, result, listener; 1.95 + 1.96 + /* --- EXPANSION --- */ 1.97 + 1.98 + result = makeResult(); 1.99 + listener = makeListener(result, eventGen); 1.100 + 1.101 + doc.addEventListener("MozScrolledAreaChanged", listener, isCapturing); 1.102 + 1.103 + if (!expectEvent) waitInterrupt(result, eventGen); 1.104 + phoom(doc, x, y); 1.105 + yield; 1.106 + 1.107 + doc.removeEventListener("MozScrolledAreaChanged", listener, isCapturing); 1.108 + 1.109 + /* If we're expecting an event, better check that we got one. If we are not expecting one, 1.110 + one can still arrive, but we don't complain if it did not. In either case, any event 1.111 + that arrives will have its data checked below. */ 1.112 + if (expectEvent) { 1.113 + ok(result.success, "Received expected " + (inner ? "inner" : "") + " expansion event"); 1.114 + } 1.115 + 1.116 + if (result.success) { 1.117 + is(result.event.x, 0, "Expansion event x is 0"); 1.118 + is(result.event.y, 0, "Expansion event y is 0"); 1.119 + if (inner) { 1.120 + /* In iframe-land, the values of |myiframe.contentDocument.documentElement.scrollWidth| and 1.121 + |.scrollHeight| appear to be not as expected (they stay very small). This is fine, since 1.122 + we know exactly where we're positioning our fixed-dimensions div, and we know our iframe's 1.123 + dimensions, so we can do our own math. NB: The inner iframe is styled at 300x500. */ 1.124 + is(Math.round(result.event.width), 1.125 + Math.max(x + 500, 300), 1.126 + "Inner expansion event width matches body width"); 1.127 + is(Math.round(result.event.height), 1.128 + Math.max(y + 500, 150), 1.129 + "Inner expansion event height matches body height"); 1.130 + } else { 1.131 + [w, h] = getDocBodyDimensions(doc); 1.132 + is(Math.round(result.event.width), w, "Expansion event width matches body width"); 1.133 + is(Math.round(result.event.height), h, "Expansion event height matches body height"); 1.134 + } 1.135 + } 1.136 + 1.137 + /* --- CONTRACTION --- */ 1.138 + 1.139 + result = makeResult(); 1.140 + listener = makeListener(result, eventGen); 1.141 + 1.142 + doc.addEventListener("MozScrolledAreaChanged", listener, isCapturing); 1.143 + 1.144 + if (!expectEvent) waitInterrupt(result, eventGen); 1.145 + unphoom(doc); 1.146 + yield; 1.147 + 1.148 + doc.removeEventListener("MozScrolledAreaChanged", listener, isCapturing); 1.149 + 1.150 + if (expectEvent) { 1.151 + ok(result.success, "Received expected " + (inner ? "inner" : "") + " contraction event"); 1.152 + } 1.153 + 1.154 + if (result.success) { 1.155 + is(result.event.x, 0, "Contraction event x is 0"); 1.156 + is(result.event.y, 0, "Contraction event y is 0"); 1.157 + if (inner) { 1.158 + is(Math.round(result.event.width), 300, "Inner contraction event width matches body width"); 1.159 + is(Math.round(result.event.height), 150, "Inner contraction event height matches body height"); 1.160 + } else { 1.161 + [w, h] = getDocBodyDimensions(doc); 1.162 + is(Math.round(result.event.width), w, "Contraction event width matches body width"); 1.163 + is(Math.round(result.event.height), h, "Contraction event height matches body height"); 1.164 + } 1.165 + } 1.166 + } 1.167 + 1.168 + setTimeout(nextTest, 0); 1.169 + 1.170 + yield; 1.171 + })(); 1.172 + 1.173 + setTimeout(function() { eventGen.next(); }, 0); 1.174 +} 1.175 + 1.176 +function testPreliminaries() { 1.177 + /* Do any setup here */ 1.178 + nextTest(); 1.179 +} 1.180 + 1.181 +function testEventCapturingHorz() { 1.182 + testPhoom(true, 10000, 0, true); // calls nextTest() when finished 1.183 +} 1.184 + 1.185 +function testEventCapturingVert() { 1.186 + testPhoom(true, 0, 10000, true); // calls nextTest() when finished 1.187 +} 1.188 + 1.189 +function testEventCapturingBoth() { 1.190 + testPhoom(true, 10000, 10000, true); // calls nextTest() when finished 1.191 +} 1.192 + 1.193 +function testEventCapturingNegv() { 1.194 + testPhoom(true, -10000, -10000, false); // calls nextTest() when finished 1.195 +} 1.196 + 1.197 +function testEventBubblingHorz() { 1.198 + testPhoom(false, 10000, 0, true); // calls nextTest() when finished 1.199 +} 1.200 + 1.201 +function testEventBubblingVert() { 1.202 + testPhoom(false, 0, 10000, true); // calls nextTest() when finished 1.203 +} 1.204 + 1.205 +function testEventBubblingBoth() { 1.206 + testPhoom(false, 10000, 10000, true); // calls nextTest() when finished 1.207 +} 1.208 + 1.209 +function testEventBubblingNegv() { 1.210 + testPhoom(false, -10000, -10000, false); // calls nextTest() when finished 1.211 +} 1.212 + 1.213 +function testCustomCreationHelper(creatingDoc, listeningDoc, x, y, w, h, expectEvent) { 1.214 + var result = makeResult(); 1.215 + 1.216 + var listener = function(evt) { 1.217 + result.success = true; 1.218 + result.event = evt; 1.219 + }; 1.220 + 1.221 + var ev = creatingDoc.createEvent("ScrollAreaEvent"); 1.222 + ev.initScrollAreaEvent("MozScrolledAreaChanged", 1.223 + true, true, window, 0, 1.224 + x, y, w, h); 1.225 + 1.226 + listeningDoc.addEventListener("MozScrolledAreaChanged", listener, true); 1.227 + 1.228 + result.success = false; 1.229 + creatingDoc.dispatchEvent(ev); 1.230 + 1.231 + listeningDoc.removeEventListener("MozScrolledAreaChanged", listener, true); 1.232 + 1.233 + is(result.success, expectEvent, "Received custom event iff expected"); 1.234 + if (result.success) { 1.235 + is(result.event.x, x, "Custom event data matches for x"); 1.236 + is(result.event.y, y, "Custom event data matches for y"); 1.237 + is(result.event.width, w, "Custom event data matches for width"); 1.238 + is(result.event.height, h, "Custom event data matches for height"); 1.239 + } 1.240 +} 1.241 + 1.242 +function testCustomCreation() { 1.243 + var innerdoc = document.getElementById('testframe').contentDocument; 1.244 + testCustomCreationHelper(document, document, 2, 7, 1, 8, true); // e = 2.718 ... 1.245 + testCustomCreationHelper(innerdoc, innerdoc, 2, 8, 1, 8, true); // ... 2818 ... 1.246 + testCustomCreationHelper(innerdoc, document, 2, 8, 4, 5, false); // ... 2845 ... 1.247 + nextTest(); 1.248 +} 1.249 + 1.250 +var TESTS = [testPreliminaries, 1.251 + testEventCapturingHorz, 1.252 + testEventCapturingVert, 1.253 + testEventCapturingBoth, 1.254 + testEventCapturingNegv, 1.255 + testEventBubblingHorz, 1.256 + testEventBubblingVert, 1.257 + testEventBubblingBoth, 1.258 + testEventBubblingNegv, 1.259 + testCustomCreation, 1.260 + __end]; 1.261 + 1.262 +var PC = 0; 1.263 + 1.264 +function nextTest() { 1.265 + TESTS[PC++](); 1.266 +} 1.267 + 1.268 +function __end() { 1.269 + log("done!"); 1.270 + finish(); 1.271 + window.close(); 1.272 +} 1.273 + 1.274 +/* 1.275 + * We need both the parent document and all iframe documents to load 1.276 + * before starting anything 1.277 + */ 1.278 +var loaded = 0; 1.279 + 1.280 +window 1.281 +.addEventListener('load', function(ev) { 1.282 + logln(++loaded); 1.283 + if (loaded >= 2) { 1.284 + logln("go..."); 1.285 + nextTest(); 1.286 + } 1.287 +}, false); 1.288 + 1.289 +document.getElementById("testframe").contentWindow 1.290 +.addEventListener('load', function(ev) { 1.291 + logln(++loaded); 1.292 + if (loaded >= 2) { 1.293 + logln("go..."); 1.294 + nextTest(); 1.295 + } 1.296 +}, false); 1.297 + 1.298 +// window.opener says: SimpleTest.waitForExplicitFinish(); 1.299 + 1.300 +</script> 1.301 + 1.302 +</body> 1.303 +</html>