Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <style>
    #target {
      margin-top: 1000px;
      width: 100px;
      height: 100px;
    }
  </style>
</head>
<body>
  <div id="target">
  <script type="application/javascript">
async function test() {
  let utils = SpecialPowers.getDOMWindowUtils(window);
  // Do a large visual scroll to scroll the visual viewport to the bottom
  // of the layout viewport.
  let visualScrollPromise = new Promise(resolve => {
    window.visualViewport.addEventListener("scroll", resolve, { once: true });
  });
  utils.scrollToVisual(0, 900, utils.UPDATE_TYPE_MAIN_THREAD,
                       utils.SCROLL_MODE_INSTANT);
  await visualScrollPromise;
  await promiseApzFlushedRepaints();
  // Simulate a long-tap on the target. We do this by simply synthesizing
  // a touch-start event; eventually, the long-tap timeout will be triggered
  // and the "contextmenu" will be fired (on non-Windows platforms).
  let target = document.getElementById("target");
  let contextmenuEvent = null;
  let contextmenuPromise = new Promise(resolve => {
    window.addEventListener("contextmenu", function(e) {
      contextmenuEvent = e;
      // Don't actually open a context menu; it messes up subsequent
      // tests unless we take additional action to close it.
      e.preventDefault();
      resolve();
    });
  });
  await synthesizeNativeTouch(target, 10, 10, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
  await contextmenuPromise;
  // Check that the "contextmenu" event targets the correct element.
  is(contextmenuEvent.target, target, "contextmenu event targeted the correct element");
  // button and buttons should be touch contact.
  is(contextmenuEvent.button, 0,
     "The button property of contextmenu event should be touch contact");
  is(contextmenuEvent.buttons, 1,
     "The buttons property of contextmenu event should be touch contact");
  // Clean up by firing a touch-end to clear the APZ gesture state.
  await new Promise(resolve => {
    synthesizeNativeTouch(target, 10, 10, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE,
                          resolve);
  });
}
if (getPlatform() == "windows") {
  // On Windows, contextmenu events work differently (e.g. they are fired
  // after the touch-end) which makes them more involved to synthesize.
  // We don't gain much value in terms of extra test coverage from running
  // this subtest on windows, so just skip it.
  ok(true, "Skipping this subtest on windows");
  subtestDone();
} else {
  SpecialPowers.getDOMWindowUtils(window).setResolutionAndScaleTo(2.0);
  waitUntilApzStable()
  .then(test)
  .then(subtestDone, subtestFailed);
}
  </script>
</body>
</html>