tor-browser

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

helper_event_during_fast_fling.html (4258B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <meta name="viewport" content="width=width-device; initial-scale=1.0">
      6  <title>Test that events are not delivered during a fast fling</title>
      7  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
      8  <script type="application/javascript" src="apz_test_utils.js"></script>
      9  <script src="/tests/SimpleTest/paint_listener.js"></script>
     10 </head>
     11 <body style="height:2000vh">
     12 </body>
     13 <script type="application/javascript">
     14 
     15 SimpleTest.requestFlakyTimeout(
     16  "Wait for a period of the time where touch events trigger a fast fling"
     17 );
     18 
     19 const isAndroid = getPlatform() == "android";
     20 async function synthesizeNativeTouchOnWindow(aX, aY, aType) {
     21  // We use `synthesizeNativeTouch` directly here since with
     22  // `synthesizeNativeTouchSequences` we can't do fast fling because
     23  // every time stamp difference of each touch event becomes smaller than
     24  // `MIN_VELOCITY_SAMPLE_TIME` (50ms) on desktops.
     25  await synthesizeNativeTouch(document.documentElement, aX, aY, aType);
     26  if (!isAndroid) {
     27    // Wait 50ms.
     28    await new Promise(resolve => setTimeout(resolve, 50));
     29  }
     30 }
     31 
     32 async function test() {
     33  let scrollEventPromise = waitForScrollEvent(window);
     34  let touchendEventPromise = promiseOneEvent(window, "touchend");
     35 
     36  // Do a fast fling.
     37  await synthesizeNativeTouchOnWindow(
     38                              100, 400,
     39                              SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
     40 
     41  // Call promiseApzFlushedRepaints to make sure the response from the
     42  // main-thread has been received in APZ.
     43  await promiseApzFlushedRepaints();
     44 
     45  await synthesizeNativeTouchOnWindow(
     46                              100, 390,
     47                              SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
     48  await synthesizeNativeTouchOnWindow(
     49                              100, 380,
     50                              SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
     51  await synthesizeNativeTouchOnWindow(
     52                              100, 370,
     53                              SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
     54  await synthesizeNativeTouchOnWindow(
     55                              100, 100,
     56                              SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);
     57 
     58  await Promise.all([ scrollEventPromise, touchendEventPromise ]);
     59 
     60  // Now we should be in a fast-fling state so that there should be no event observed.
     61  window.addEventListener("touchstart", () => {
     62    ok(false, "touchstart event should not be delivered.");
     63  });
     64  window.addEventListener("touchmove", () => {
     65    ok(false, "touchmove event should not be delivered.");
     66  });
     67  window.addEventListener("touchend", () => {
     68    ok(false, "touchend event should not be delivered.");
     69  });
     70  window.addEventListener("contextmenu", () => {
     71    ok(false, "contextmenu event should not be delivered.");
     72  });
     73 
     74  await synthesizeNativeTouch(window, 100, 200,
     75                              SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
     76 
     77  const context_menus_delay = SpecialPowers.getIntPref("ui.click_hold_context_menus.delay");
     78  // Waiting for a period of the time that a contextmenu event would be fired.
     79  await new Promise(resolve => setTimeout(resolve, context_menus_delay));
     80 
     81  scrollEventPromise = waitForScrollEvent(window);
     82  await synthesizeNativeTouch(window, 100, 200,
     83                              SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
     84  await synthesizeNativeTouch(window, 100, 150,
     85                              SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
     86  await synthesizeNativeTouch(window, 100, 100,
     87                              SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);
     88  await scrollEventPromise;
     89 }
     90 
     91 if (getPlatform() == "windows") {
     92  ok(true, "Test doesn't run on Windows since it frequently fais probably " +
     93           "due to the difference of contextmenu event");
     94  subtestDone();
     95 } else if (getPlatform() == "android" && SpecialPowers.isDebugBuild) {
     96  ok(true, "Test doesn't run on Android debug builds since processing each " +
     97           "touch event sometimes takes over AssumePointerMoveStoppedTime in " +
     98           "AndroidVelocityTracker.cpp");
     99  subtestDone();
    100 } else {
    101  waitUntilApzStable()
    102  .then(test)
    103  .then(subtestDone, subtestFailed);
    104 }
    105 </script>
    106 </html>