layout/base/tests/test_event_target_iframe_oop.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html id="html" style="height:100%">
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=921928
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for bug 921928</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 <style>
michael@0 12 #dialer {
michael@0 13 position: absolute;
michael@0 14 left: 0;
michael@0 15 top: 0;
michael@0 16 width: 100%;
michael@0 17 height: 50px;
michael@0 18 background: green;
michael@0 19 }
michael@0 20
michael@0 21 #apps {
michael@0 22 position: absolute;
michael@0 23 left: 0;
michael@0 24 top: 51px;
michael@0 25 width: 100%;
michael@0 26 height: 100px;
michael@0 27 background: blue;
michael@0 28 }
michael@0 29
michael@0 30 .hit {
michael@0 31 position: absolute;
michael@0 32 width: 3px;
michael@0 33 height: 3px;
michael@0 34 z-index: 20;
michael@0 35 background: red;
michael@0 36 border: 1px solid red;
michael@0 37 }
michael@0 38 </style>
michael@0 39 </head>
michael@0 40 <body id="body" style="margin:0; width:100%; height:100%">
michael@0 41 <script type="application/javascript">
michael@0 42 SimpleTest.waitForExplicitFinish();
michael@0 43
michael@0 44 var prefs = [
michael@0 45 ["ui.mouse.radius.enabled", true],
michael@0 46 ["ui.mouse.radius.inputSource.touchOnly", false],
michael@0 47 ["ui.mouse.radius.leftmm", 12],
michael@0 48 ["ui.mouse.radius.topmm", 8],
michael@0 49 ["ui.mouse.radius.rightmm", 4],
michael@0 50 ["ui.mouse.radius.bottommm", 4],
michael@0 51 ["ui.mouse.radius.visitedweight", 50],
michael@0 52 ["dom.mozBrowserFramesEnabled", true]
michael@0 53 ];
michael@0 54
michael@0 55 var eventTarget;
michael@0 56 var debugHit = [];
michael@0 57
michael@0 58 function endTest() {
michael@0 59 SimpleTest.finish();
michael@0 60 SpecialPowers.removePermission("browser", location.href);
michael@0 61 for (var pref in prefs) {
michael@0 62 SpecialPowers.pushPrefEnv({"clear": pref[0]}, function() {});
michael@0 63 }
michael@0 64 }
michael@0 65
michael@0 66 function testMouseClick(idPosition, dx, dy, idTarget, msg, options) {
michael@0 67 eventTarget = null;
michael@0 68 synthesizeMouse(document.getElementById(idPosition), dx, dy, options || {});
michael@0 69 try {
michael@0 70 is(eventTarget.id, idTarget,
michael@0 71 "checking '" + idPosition + "' offset " + dx + "," + dy + " [" + msg + "]");
michael@0 72 } catch (ex) {
michael@0 73 ok(false, "checking '" + idPosition + "' offset " + dx + "," + dy + " [" + msg + "]; got " + eventTarget);
michael@0 74 }
michael@0 75 }
michael@0 76
michael@0 77 function showDebug() {
michael@0 78 for (var i = 0; i < debugHit.length; i++) {
michael@0 79 document.body.appendChild(debugHit[i]);
michael@0 80 }
michael@0 81
michael@0 82 var screenshot = SpecialPowers.snapshotWindow(window, true);
michael@0 83 dump('IMAGE:' + screenshot.toDataURL() + '\n');
michael@0 84 }
michael@0 85
michael@0 86 /*
michael@0 87 Setup the test environment: enabling event fluffing (all ui.* preferences),
michael@0 88 and enabling remote process.
michael@0 89 */
michael@0 90 function setupTest(cont) {
michael@0 91 SpecialPowers.addPermission("browser", true, document);
michael@0 92 SpecialPowers.pushPrefEnv({"set": prefs}, cont);
michael@0 93 }
michael@0 94
michael@0 95 function execTest() {
michael@0 96 /*
michael@0 97 Creating two iframes that mimics the attention screen behavior on the
michael@0 98 device:
michael@0 99 - the 'dialer' iframe is the attention screen you have when a call is
michael@0 100 in place. it is a green bar, so we copy it as green here too
michael@0 101 - the 'apps' iframe mimics another application that is being run, be it
michael@0 102 dialer, sms, ..., anything that the user might want to trigger during
michael@0 103 a call
michael@0 104
michael@0 105 The bug we intent to reproduce here is that in this case, if the user taps
michael@0 106 onto the top of the 'apps', the event fluffing code will in fact redirect
michael@0 107 the event to the 'dialer' iframe. In practice, this is bug 921928 where
michael@0 108 during a call the user wants to place a second call, and while typing the
michael@0 109 phone number, wants to tap onto the 'delete' key to erase a digit, but ends
michael@0 110 tapping and activating the dialer.
michael@0 111 */
michael@0 112 var dialer = document.createElement('iframe');
michael@0 113 dialer.id = 'dialer';
michael@0 114 dialer.src = '';
michael@0 115 // Force OOP
michael@0 116 dialer.setAttribute('mozbrowser', 'true');
michael@0 117 dialer.setAttribute('remote', 'true');
michael@0 118 document.body.appendChild(dialer);
michael@0 119
michael@0 120 var apps = document.createElement('iframe');
michael@0 121 apps.id = 'apps';
michael@0 122 apps.src = 'bug921928_event_target_iframe_apps_oop.html';
michael@0 123 // Force OOP
michael@0 124 apps.setAttribute('mozbrowser', 'true');
michael@0 125 apps.setAttribute('remote', 'true');
michael@0 126 document.body.appendChild(apps);
michael@0 127
michael@0 128 var handleEvent = function(event) {
michael@0 129 eventTarget = event.target;
michael@0 130
michael@0 131 // We draw a small red div to show where the event has tapped
michael@0 132 var hit = document.createElement('div');
michael@0 133 hit.style.left = (event.clientX - 1.5) + 'px';
michael@0 134 hit.style.top = (event.clientY - 1.5) + 'px';
michael@0 135 hit.classList.add('hit');
michael@0 136 debugHit.push(hit);
michael@0 137 };
michael@0 138
michael@0 139 // In real life, the 'dialer' has a 'mousedown', so we mimic one too,
michael@0 140 // to reproduce the same behavior
michael@0 141 dialer.addEventListener('mousedown', function(e) {});
michael@0 142
michael@0 143 // This event listener is just here to record what iframe has been hit,
michael@0 144 // and sets the 'eventTarget' to the iframe's id value so that the
michael@0 145 // testMouseClick() code can correctly check. We cannot add it on the
michael@0 146 // 'apps' otherwise it will alter the behavior of the test.
michael@0 147 document.addEventListener('mousedown', handleEvent);
michael@0 148
michael@0 149 // In the following, the coordinates are relative to the iframe
michael@0 150
michael@0 151 // First, we check that tapping onto the 'dialer' correctly triggers the
michael@0 152 // dialer.
michael@0 153 testMouseClick("dialer", 20, 1, "dialer", "correct hit on dialer with mouse input");
michael@0 154 testMouseClick("dialer", 20, 1, "dialer", "correct hit on dialer with touch input", {
michael@0 155 inputSource: SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH
michael@0 156 });
michael@0 157
michael@0 158 // Now this is it: we tap inside 'apps', but very close to the border between
michael@0 159 // 'apps' and 'dialer'. Without the fix from this bug, this test will fail.
michael@0 160 testMouseClick("apps", 20, 1, "apps", "apps <iframe mozbrowser remote> hit for mouse input");
michael@0 161 testMouseClick("apps", 20, 1, "apps", "apps <iframe mozbrowser remote> hit for touch input", {
michael@0 162 inputSource: SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH
michael@0 163 });
michael@0 164
michael@0 165 // Show small red spots of where the click happened
michael@0 166 // showDebug();
michael@0 167
michael@0 168 endTest();
michael@0 169 }
michael@0 170
michael@0 171 function runTest() {
michael@0 172 setupTest(execTest);
michael@0 173 }
michael@0 174
michael@0 175 addEventListener('load', function() { SimpleTest.executeSoon(runTest); });
michael@0 176 </script>
michael@0 177 </body>
michael@0 178 </html>

mercurial