tor-browser

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

test_getLastOverWindowPointerLocationInCSSPixels.html (2573B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4 <title>Test for Bug 1778486</title>
      5 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      6 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
      7 <script src="chrome://mochikit/content/tests/SimpleTest/paint_listener.js"></script>
      8 <script src="chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script>
      9 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
     10 <style>
     11 div {
     12  width: 50px;
     13  height: 50px;
     14 };
     15 </style>
     16 </head>
     17 <body>
     18 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1778486">Mozilla Bug 1778486</a>
     19 <p id="display"></p>
     20 <div id="target_mouse" style="background: red;"></div>
     21 <div id="target_touch" style="background: green;"></div>
     22 <script>
     23 
     24 function waitForEvent(aTarget, aEvent) {
     25  return new Promise(resolve => {
     26    aTarget.addEventListener(aEvent, resolve, { once: true });
     27  });
     28 }
     29 
     30 function getLastOverWindowPointerLocationScreenOffset() {
     31  let x = {};
     32  let y = {};
     33  let topWindow = window.browsingContext.topChromeWindow;
     34  topWindow.windowUtils.getLastOverWindowPointerLocationInCSSPixels(x, y);
     35  return {
     36    x: Math.trunc(x.value + topWindow.mozInnerScreenX),
     37    y: Math.trunc(y.value + topWindow.mozInnerScreenY),
     38  };
     39 }
     40 
     41 function getElementScreenOffsetAtCentral(aElement) {
     42  let rect = aElement.getBoundingClientRect();
     43  return {
     44    x: Math.trunc(rect.width / 2 + rect.left + mozInnerScreenX),
     45    y: Math.trunc(rect.height / 2 + rect.top + mozInnerScreenY),
     46  };
     47 }
     48 
     49 add_setup(async function() {
     50  await SpecialPowers.pushPrefEnv({ set: [["test.events.async.enabled", true]] });
     51  await waitUntilApzStable();
     52 });
     53 
     54 /** Test for Bug 1778486 */
     55 add_task(async function test_mouse() {
     56  let target = document.getElementById("target_mouse");
     57  let promise = waitForEvent(target, "click");
     58  synthesizeMouseAtCenter(target, {});
     59  await promise;
     60 
     61  isDeeply(
     62    getLastOverWindowPointerLocationScreenOffset(),
     63    getElementScreenOffsetAtCentral(target),
     64    "check last pointer location");
     65 });
     66 
     67 add_task(async function test_touch() {
     68  let target = document.getElementById("target_touch");
     69  let promise = waitForEvent(target, "pointerup");
     70  synthesizeTouchAtCenter(target, { type: "touchstart" });
     71  synthesizeTouchAtCenter(target, { type: "touchend" });
     72  await promise;
     73 
     74  isDeeply(
     75    getLastOverWindowPointerLocationScreenOffset(),
     76    getElementScreenOffsetAtCentral(target),
     77    "check last pointer location");
     78 });
     79 
     80 </script>
     81 </pre>
     82 </body>
     83 </html>