tor-browser

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

helper_bug1719855.html (3421B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>preventDefault() in touchmove prevents scrolling even after a long tap event</title>
      5  <meta name="viewport" content="width=device-width,initial-scale=1">
      6  <script type="application/javascript" src="apz_test_utils.js"></script>
      7  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
      8  <script src="/tests/SimpleTest/paint_listener.js"></script>
      9 </head>
     10 <body>
     11  <!-- An anchor to open a context menu -->
     12  <a href="about:blank" style="position:absolute; top: 100px; left: 100px;">about:blank</a>
     13  <!-- make the root scroll container scrollable -->
     14  <div style="height: 200vh;"></div>
     15 </body>
     16 <script type="application/javascript">
     17 
     18 const searchParams = new URLSearchParams(location.search);
     19 
     20 const isAndroid = getPlatform() == "android";
     21 
     22 async function test() {
     23  // Setup a touchmove event listener where we do preventDefault() to prevent
     24  // scrolling.
     25  let touchmoveCount = 0;
     26  document.scrollingElement.addEventListener("touchmove", e => {
     27    info("Got a touchmove");
     28    touchmoveCount++;
     29    e.preventDefault();
     30  }, { passive: false });
     31 
     32  // Setup touchstart/touchend event listeners just for debugging purpose.
     33  document.scrollingElement.addEventListener("touchstart", () => {
     34    info("Got a touchstart");
     35  }, { passive: false });
     36  document.scrollingElement.addEventListener("touchend", () => {
     37    info("Got a touchend");
     38  }, { passive: false });
     39 
     40  window.addEventListener("scroll", () => {
     41    ok(false, "The content should never be scrolled");
     42  });
     43 
     44  let contextmenuPromise = promiseOneEvent(window, "contextmenu", e => {
     45    if (searchParams.get("prevent") == "contextmenu") {
     46      e.preventDefault();
     47    }
     48    return true;
     49  });
     50 
     51  // Ensure that the setup-ed information has reached to APZ.
     52  await promiseApzFlushedRepaints();
     53 
     54  // Start a touch on the anchor.
     55  await synthesizeNativeTouch(window, 100, 100, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
     56 
     57  // And wait for a contextmenu event (i.e. a long-tap event)
     58  await contextmenuPromise;
     59 
     60  // Extend apz.content_response_timeout to avoid timeout on waiting the content
     61  // response.
     62  await SpecialPowers.pushPrefEnv({ set: [["apz.content_response_timeout", 40000]] });
     63 
     64  // Make sure the touch start does nothing.
     65  is(window.scrollY, 0, "The original scroll position is zero");
     66 
     67  // Try to scroll down by touch moving.
     68  for (let i = 1; i < 50; i++) {
     69    synthesizeNativeTouch(window, 100, 100 - i, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
     70  }
     71  await synthesizeNativeTouch(window, 100, 50, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);
     72 
     73  await waitToClearOutAnyPotentialScrolls();
     74 
     75  if (searchParams.get("prevent") == "contextmenu") {
     76    ok(touchmoveCount > 0, "There should be at least one touch-move event");
     77  } else {
     78    is(touchmoveCount, 0, "There should be no touch-move event when the context menu opened");
     79  }
     80  is(window.scrollY, 0, "The scroll position should stay the original position");
     81 
     82  if (searchParams.get("prevent") != "contextmenu") {
     83    // If we've opened the context menu, close it.
     84    await closeContextMenu();
     85  }
     86 }
     87 
     88 if (getPlatform() == "windows") {
     89  // On Windows every context menu on touch screens opens __after__ lifting the
     90  // finger.
     91  ok(true, "Test doesn't need to run on Windows");
     92  subtestDone();
     93 } else {
     94  waitUntilApzStable()
     95  .then(test)
     96  .then(subtestDone, subtestFailed);
     97 }
     98 
     99 </script>
    100 </html>