tor-browser

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

helper_bug1638458_contextmenu.html (3149B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1638458
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <meta name="viewport" content="width=device-width, initial-scale=1.0">
      9  <title>Test for Bug 1638458</title>
     10  <script src="/tests/SimpleTest/paint_listener.js"></script>
     11  <script src="/tests/SimpleTest/EventUtils.js"></script>
     12  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
     13  <script type="application/javascript" src="apz_test_utils.js"></script>
     14  <style>
     15    #target {
     16      margin-top: 1000px;
     17      width: 100px;
     18      height: 100px;
     19    }
     20  </style>
     21 </head>
     22 <body>
     23  <div id="target">
     24  <script type="application/javascript">
     25 
     26 async function test() {
     27  let utils = SpecialPowers.getDOMWindowUtils(window);
     28 
     29  // Do a large visual scroll to scroll the visual viewport to the bottom
     30  // of the layout viewport.
     31  let visualScrollPromise = new Promise(resolve => {
     32    window.visualViewport.addEventListener("scroll", resolve, { once: true });
     33  });
     34  utils.scrollToVisual(0, 900, utils.UPDATE_TYPE_MAIN_THREAD,
     35                       utils.SCROLL_MODE_INSTANT);
     36  await visualScrollPromise;
     37  await promiseApzFlushedRepaints();
     38 
     39  // Simulate a long-tap on the target. We do this by simply synthesizing
     40  // a touch-start event; eventually, the long-tap timeout will be triggered
     41  // and the "contextmenu" will be fired (on non-Windows platforms).
     42  let target = document.getElementById("target");
     43  let contextmenuEvent = null;
     44  let contextmenuPromise = new Promise(resolve => {
     45    window.addEventListener("contextmenu", function(e) {
     46      contextmenuEvent = e;
     47      // Don't actually open a context menu; it messes up subsequent
     48      // tests unless we take additional action to close it.
     49      e.preventDefault();
     50      resolve();
     51    });
     52  });
     53  await synthesizeNativeTouch(target, 10, 10, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
     54  await contextmenuPromise;
     55 
     56  // Check that the "contextmenu" event targets the correct element.
     57  is(contextmenuEvent.target, target, "contextmenu event targeted the correct element");
     58 
     59  // button and buttons should be touch contact.
     60  is(contextmenuEvent.button, 0,
     61     "The button property of contextmenu event should be touch contact");
     62  is(contextmenuEvent.buttons, 1,
     63     "The buttons property of contextmenu event should be touch contact");
     64 
     65  // Clean up by firing a touch-end to clear the APZ gesture state.
     66  await new Promise(resolve => {
     67    synthesizeNativeTouch(target, 10, 10, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE,
     68                          resolve);
     69  });
     70 }
     71 
     72 if (getPlatform() == "windows") {
     73  // On Windows, contextmenu events work differently (e.g. they are fired
     74  // after the touch-end) which makes them more involved to synthesize.
     75  // We don't gain much value in terms of extra test coverage from running
     76  // this subtest on windows, so just skip it.
     77  ok(true, "Skipping this subtest on windows");
     78  subtestDone();
     79 } else {
     80  SpecialPowers.getDOMWindowUtils(window).setResolutionAndScaleTo(2.0);
     81  waitUntilApzStable()
     82  .then(test)
     83  .then(subtestDone, subtestFailed);
     84 }
     85 
     86  </script>
     87 </body>
     88 </html>