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

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

mercurial