1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/base/tests/test_event_target_iframe_oop.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,178 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html id="html" style="height:100%"> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=921928 1.8 +--> 1.9 +<head> 1.10 + <title>Test for bug 921928</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 + <style> 1.15 + #dialer { 1.16 + position: absolute; 1.17 + left: 0; 1.18 + top: 0; 1.19 + width: 100%; 1.20 + height: 50px; 1.21 + background: green; 1.22 + } 1.23 + 1.24 + #apps { 1.25 + position: absolute; 1.26 + left: 0; 1.27 + top: 51px; 1.28 + width: 100%; 1.29 + height: 100px; 1.30 + background: blue; 1.31 + } 1.32 + 1.33 + .hit { 1.34 + position: absolute; 1.35 + width: 3px; 1.36 + height: 3px; 1.37 + z-index: 20; 1.38 + background: red; 1.39 + border: 1px solid red; 1.40 + } 1.41 + </style> 1.42 +</head> 1.43 +<body id="body" style="margin:0; width:100%; height:100%"> 1.44 +<script type="application/javascript"> 1.45 +SimpleTest.waitForExplicitFinish(); 1.46 + 1.47 +var prefs = [ 1.48 + ["ui.mouse.radius.enabled", true], 1.49 + ["ui.mouse.radius.inputSource.touchOnly", false], 1.50 + ["ui.mouse.radius.leftmm", 12], 1.51 + ["ui.mouse.radius.topmm", 8], 1.52 + ["ui.mouse.radius.rightmm", 4], 1.53 + ["ui.mouse.radius.bottommm", 4], 1.54 + ["ui.mouse.radius.visitedweight", 50], 1.55 + ["dom.mozBrowserFramesEnabled", true] 1.56 +]; 1.57 + 1.58 +var eventTarget; 1.59 +var debugHit = []; 1.60 + 1.61 +function endTest() { 1.62 + SimpleTest.finish(); 1.63 + SpecialPowers.removePermission("browser", location.href); 1.64 + for (var pref in prefs) { 1.65 + SpecialPowers.pushPrefEnv({"clear": pref[0]}, function() {}); 1.66 + } 1.67 +} 1.68 + 1.69 +function testMouseClick(idPosition, dx, dy, idTarget, msg, options) { 1.70 + eventTarget = null; 1.71 + synthesizeMouse(document.getElementById(idPosition), dx, dy, options || {}); 1.72 + try { 1.73 + is(eventTarget.id, idTarget, 1.74 + "checking '" + idPosition + "' offset " + dx + "," + dy + " [" + msg + "]"); 1.75 + } catch (ex) { 1.76 + ok(false, "checking '" + idPosition + "' offset " + dx + "," + dy + " [" + msg + "]; got " + eventTarget); 1.77 + } 1.78 +} 1.79 + 1.80 +function showDebug() { 1.81 + for (var i = 0; i < debugHit.length; i++) { 1.82 + document.body.appendChild(debugHit[i]); 1.83 + } 1.84 + 1.85 + var screenshot = SpecialPowers.snapshotWindow(window, true); 1.86 + dump('IMAGE:' + screenshot.toDataURL() + '\n'); 1.87 +} 1.88 + 1.89 +/* 1.90 + Setup the test environment: enabling event fluffing (all ui.* preferences), 1.91 + and enabling remote process. 1.92 +*/ 1.93 +function setupTest(cont) { 1.94 + SpecialPowers.addPermission("browser", true, document); 1.95 + SpecialPowers.pushPrefEnv({"set": prefs}, cont); 1.96 +} 1.97 + 1.98 +function execTest() { 1.99 + /* 1.100 + Creating two iframes that mimics the attention screen behavior on the 1.101 + device: 1.102 + - the 'dialer' iframe is the attention screen you have when a call is 1.103 + in place. it is a green bar, so we copy it as green here too 1.104 + - the 'apps' iframe mimics another application that is being run, be it 1.105 + dialer, sms, ..., anything that the user might want to trigger during 1.106 + a call 1.107 + 1.108 + The bug we intent to reproduce here is that in this case, if the user taps 1.109 + onto the top of the 'apps', the event fluffing code will in fact redirect 1.110 + the event to the 'dialer' iframe. In practice, this is bug 921928 where 1.111 + during a call the user wants to place a second call, and while typing the 1.112 + phone number, wants to tap onto the 'delete' key to erase a digit, but ends 1.113 + tapping and activating the dialer. 1.114 + */ 1.115 + var dialer = document.createElement('iframe'); 1.116 + dialer.id = 'dialer'; 1.117 + dialer.src = ''; 1.118 + // Force OOP 1.119 + dialer.setAttribute('mozbrowser', 'true'); 1.120 + dialer.setAttribute('remote', 'true'); 1.121 + document.body.appendChild(dialer); 1.122 + 1.123 + var apps = document.createElement('iframe'); 1.124 + apps.id = 'apps'; 1.125 + apps.src = 'bug921928_event_target_iframe_apps_oop.html'; 1.126 + // Force OOP 1.127 + apps.setAttribute('mozbrowser', 'true'); 1.128 + apps.setAttribute('remote', 'true'); 1.129 + document.body.appendChild(apps); 1.130 + 1.131 + var handleEvent = function(event) { 1.132 + eventTarget = event.target; 1.133 + 1.134 + // We draw a small red div to show where the event has tapped 1.135 + var hit = document.createElement('div'); 1.136 + hit.style.left = (event.clientX - 1.5) + 'px'; 1.137 + hit.style.top = (event.clientY - 1.5) + 'px'; 1.138 + hit.classList.add('hit'); 1.139 + debugHit.push(hit); 1.140 + }; 1.141 + 1.142 + // In real life, the 'dialer' has a 'mousedown', so we mimic one too, 1.143 + // to reproduce the same behavior 1.144 + dialer.addEventListener('mousedown', function(e) {}); 1.145 + 1.146 + // This event listener is just here to record what iframe has been hit, 1.147 + // and sets the 'eventTarget' to the iframe's id value so that the 1.148 + // testMouseClick() code can correctly check. We cannot add it on the 1.149 + // 'apps' otherwise it will alter the behavior of the test. 1.150 + document.addEventListener('mousedown', handleEvent); 1.151 + 1.152 + // In the following, the coordinates are relative to the iframe 1.153 + 1.154 + // First, we check that tapping onto the 'dialer' correctly triggers the 1.155 + // dialer. 1.156 + testMouseClick("dialer", 20, 1, "dialer", "correct hit on dialer with mouse input"); 1.157 + testMouseClick("dialer", 20, 1, "dialer", "correct hit on dialer with touch input", { 1.158 + inputSource: SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH 1.159 + }); 1.160 + 1.161 + // Now this is it: we tap inside 'apps', but very close to the border between 1.162 + // 'apps' and 'dialer'. Without the fix from this bug, this test will fail. 1.163 + testMouseClick("apps", 20, 1, "apps", "apps <iframe mozbrowser remote> hit for mouse input"); 1.164 + testMouseClick("apps", 20, 1, "apps", "apps <iframe mozbrowser remote> hit for touch input", { 1.165 + inputSource: SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH 1.166 + }); 1.167 + 1.168 + // Show small red spots of where the click happened 1.169 + // showDebug(); 1.170 + 1.171 + endTest(); 1.172 +} 1.173 + 1.174 +function runTest() { 1.175 + setupTest(execTest); 1.176 +} 1.177 + 1.178 +addEventListener('load', function() { SimpleTest.executeSoon(runTest); }); 1.179 +</script> 1.180 +</body> 1.181 +</html>