gfx/layers/apz/test/mochitest/helper_tap_default_passive.html
author James Teh <jteh@mozilla.com>
Wed, 01 Feb 2023 05:02:01 +0000
changeset 651150 dd0fdd1daa69783be36acd5c50544f3694eaa8f9
parent 616557 918ef225713fa9fc188f42355a6cd4a2bfb3b64c
permissions -rw-r--r--
Bug 1813980: Check IsDoc before Parent in RemoteAccessibleBase::ApplyCrossDocOffset. r=morgan We call this function on every ancestor when calculating bounds. RemoteParent() currently requires a hash lookup, so it's more efficient to early return for !IsDoc() first. This is a micro-optimisation, but it might have some impact given that we call this on every ancestor, especially when hit testing, where we call Bounds() a lot. As a bit of drive-by cleanup, use RemoteParent() rather than calling Parent() and IsRemote/AsRemote(). Differential Revision: https://phabricator.services.mozilla.com/D168346

<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width; initial-scale=1.0">
  <title>Ensure APZ doesn't wait for passive listeners</title>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <script type="application/javascript">

var touchdownTime;

async function longPressLink() {
  await synthesizeNativeTouch(document.getElementById("b"), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT, function() {
    dump("Finished synthesizing touch-start, waiting for events...\n");
  });
}

var touchstartReceived = false;
function recordEvent(e) {
  if (!touchstartReceived) {
    touchstartReceived = true;
    is(e.type, "touchstart", "Got a touchstart");
    e.preventDefault(); // should be a no-op because it's a passive listener
    return;
  }

  // If APZ decides to wait for the content response on a particular input block,
  // it needs to wait until both the touchstart and touchmove event are handled
  // by the main thread. In this case there is no touchmove at all, so APZ would
  // end up waiting indefinitely and time out the test. The fact that we get this
  // contextmenu event (mouselongtap on Windows) at all means that APZ decided
  // not to wait for the content response, which is the desired behaviour, since
  // the touchstart listener was registered as a passive listener.
  if (getPlatform() == "windows") {
    is(e.type, "mouselongtap", "Got a mouselongtap");
  } else {
    is(e.type, "contextmenu", "Got a contextmenu");
  }
  e.preventDefault();

  setTimeout(async () => {
    await synthesizeNativeTouch(document.getElementById("b"), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE, function() {
      dump("Finished synthesizing touch-end to clear state; finishing test...\n");
      subtestDone();
    });
  }, 0);
}

function preventDefaultListener(e) {
  e.preventDefault();
}

// Note, not passing 'passive'.
window.addEventListener("touchstart", recordEvent, { capture: true });
window.ontouchstart = preventDefaultListener;
if (getPlatform() == "windows") {
  SpecialPowers.addChromeEventListener("mouselongtap", recordEvent, true);
} else {
  window.addEventListener("contextmenu", recordEvent, true);
}

waitUntilApzStable()
.then(longPressLink);

  </script>
</head>
<body>
  <a id="b" href="#">Link to nowhere</a>
  <script>
    document.addEventListener("touchstart", preventDefaultListener, { capture: true });
    document.ontouchstart = preventDefaultListener;
    document.documentElement.addEventListener("touchstart", preventDefaultListener, { capture: true });
    document.documentElement.ontouchstart = preventDefaultListener;
    document.body.addEventListener("touchstart", preventDefaultListener, { capture: true });
    document.body.ontouchstart = preventDefaultListener;
    document.body.setAttribute("ontouchstart", "event.preventDefault()");
  </script>
</body>
</html>