tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug1420589_3.html (3942B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1420589
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1420589</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <script src="/tests/SimpleTest/EventUtils.js"></script>
     11  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1420589">Mozilla Bug 1420589</a>
     15 <p id="display"></p>
     16 <div id="div1" style="width: 50px; height: 50px; background: green"></div>
     17 <iframe id="iframe1" src="./bug_1420589_iframe1.html">
     18 </iframe>
     19 <script type="text/javascript">
     20 /*
     21  Test for Bug 1420589. This test is similar to test_bug1420589_2.html but the
     22  first touch point hit the div element and the second point hits the iframe.
     23 
     24  We stop dispatching touch events to a target when we can't find any ancestor
     25  document that is the same as the document of the existing target. This test
     26  expects that we only dispatch touch events to the iframe document.
     27 
     28  We dispatch pointer events to the hit targets even when there aren't in the
     29  same document. This test expects that pointer events are dispatched to the div
     30  element and the iframe document.
     31 */
     32 SimpleTest.waitForExplicitFinish();
     33 
     34 var rx = 1;
     35 var ry = 1;
     36 var angle = 0;
     37 var force = 1;
     38 var modifiers = 0;
     39 var test1PointerId = 1;
     40 var test2PointerId = 2;
     41 
     42 function withoutImplicitlyPointerCaptureForTouch() {
     43  let expectedEvents = [
     44    // messages from the document of iframe1
     45    "iframe1 pointerdown",
     46    "iframe1 pointermove",
     47    "iframe1 pointerup",
     48    "iframe1 touchstart",
     49    "iframe1 touchmove",
     50    "iframe1 touchend",
     51 
     52    // messages from the parent document
     53    "div1 pointerdown",
     54    "div1 pointermove",
     55    "div1 pointerup",
     56  ];
     57 
     58  window.addEventListener('message',function(e) {
     59    ok(expectedEvents.includes(e.data), " don't expect " + e.data);
     60    expectedEvents = expectedEvents.filter(item => item !== e.data);
     61    if (e.data == "iframe1 touchend") {
     62      ok(!expectedEvents.length, " expect " + expectedEvents);
     63      SimpleTest.finish();
     64    }
     65  })
     66 
     67  let iframe1 = document.getElementById('iframe1');
     68  let div1 = document.getElementById('div1');
     69 
     70  let events = ["touchstart", "touchmove", "touchend", "pointerdown", "pointermove", "pointerup"];
     71  events.forEach((event) => {
     72    div1.addEventListener(event, (e) => {
     73      postMessage("div1 " + e.type, "*");
     74    }, { once: true });
     75    iframe1.addEventListener(event, (e) => {
     76      postMessage("iframe " + e.type, "*");
     77    }, { once: true });
     78  });
     79 
     80  let rect1 = div1.getBoundingClientRect();
     81  let rect2 = iframe1.getBoundingClientRect();
     82 
     83  let left1 = rect1.left + 5;
     84  let left2 = rect2.left + 5;
     85 
     86  let top1 = rect1.top + 5;
     87  let top2 = rect2.top + 5;
     88 
     89  var utils = SpecialPowers.getDOMWindowUtils(window);
     90  utils.sendTouchEvent('touchstart', [test1PointerId, test2PointerId],
     91                       [left1, left2], [top1, top2], [rx, rx], [ry, ry],
     92                       [angle, angle], [force, force], [0, 0], [0, 0],
     93                       [0, 0], modifiers);
     94 
     95  // Move the touch pointers so that we dispatch all of them to content.
     96  left1++;
     97  left2++;
     98  utils.sendTouchEvent('touchmove', [test1PointerId, test2PointerId],
     99                       [left1, left2], [top1, top2], [rx, rx], [ry, ry],
    100                       [angle, angle], [force, force], [0, 0], [0, 0],
    101                       [0, 0], modifiers);
    102  utils.sendTouchEvent('touchend', [test1PointerId, test2PointerId],
    103                       [left1, left2], [top1, top2], [rx, rx], [ry, ry],
    104                       [angle, angle], [force, force], [0, 0], [0, 0],
    105                       [0, 0], modifiers);
    106 }
    107 
    108 SimpleTest.waitForFocus(() => {
    109  SpecialPowers.pushPrefEnv({"set": [["dom.w3c_pointer_events.implicit_capture", false]]},
    110                            withoutImplicitlyPointerCaptureForTouch);
    111 });
    112 
    113 </script>
    114 </body>
    115 </html>