tor-browser

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

helper_keyboard_scrollend.html (3764B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <meta name="viewport" content="initial-scale=1,width=device-width">
      6  <script src="apz_test_utils.js"></script>
      7  <script src="apz_test_native_event_utils.js"></script>
      8  <script src="/tests/SimpleTest/EventUtils.js"></script>
      9  <script src="/tests/SimpleTest/NativeKeyCodes.js"></script>
     10  <script src="/tests/SimpleTest/paint_listener.js"></script>
     11  <style>
     12 #scroller {
     13  height: 50vh;
     14  width: 50vw;
     15  overflow: scroll;
     16  overscroll-behavior: none;
     17 }
     18 
     19 #spacer {
     20  height: 200vh;
     21  width: 200vw;
     22 }
     23  </style>
     24 </head>
     25 <body>
     26  <div id="scroller">
     27    <div id="spacer">
     28    </div>
     29  </div>
     30 </body>
     31 <script>
     32 const searchParams = new URLSearchParams(location.search);
     33 
     34 async function test() {
     35  var scrollendCount = 0;
     36 
     37  // Add a scrollend event listener that counts the number of scrollend
     38  // events fired to the scrollable element.
     39  scroller.addEventListener("scrollend", () => {
     40    scrollendCount += 1;
     41  });
     42 
     43  // Move the mouse over the scroller and perform a mouse click.
     44  await promiseNativeMouseEventWithAPZ({
     45    target: scroller,
     46    offsetX: 10,
     47    offsetY: 10,
     48    type: "mousemove",
     49  });
     50 
     51  await promiseNativeMouseEventWithAPZ({
     52    target: scroller,
     53    offsetX: 10,
     54    offsetY: 10,
     55    type: "mousedown",
     56  });
     57 
     58  await promiseNativeMouseEventWithAPZ({
     59    target: scroller,
     60    offsetX: 10,
     61    offsetY: 10,
     62    type: "mouseup",
     63  });
     64 
     65  // Determine the arrow key value based on the value of "direction".
     66  let key = null;
     67  let direction = searchParams.get("direction");
     68  switch (direction) {
     69    case "up":
     70      key = nativeArrowUpKey();
     71      break;
     72    case "down":
     73      key = nativeArrowDownKey();
     74      break;
     75    default:
     76      ok(false, "Unsupported direction value: " + direction);
     77      break;
     78  }
     79 
     80  is(scrollendCount, 0, "A scrollend event should not be triggered yet");
     81  is(scroller.scrollTop, 0, "No scroll should have occured yet");
     82 
     83  // In order to exercise handling of keyboard events in APZ, we may
     84  // want to flush repaints before the key input.
     85  if (searchParams.has("flush-before-key")) {
     86    await promiseApzFlushedRepaints();
     87  }
     88  await promiseFrame();
     89 
     90  let transformEndPromise = promiseTransformEnd();
     91 
     92  let scrollPromise = new Promise(resolve => scroller.addEventListener("scroll", resolve));
     93  await new Promise(resolve => {
     94    synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, key, {},
     95                        "", "", resolve);
     96  });
     97 
     98  await promiseApzFlushedRepaints();
     99 
    100  if (direction == "up") {
    101    if (SpecialPowers.getBoolPref("general.smoothScroll")) {
    102      // The smooth scroll animation with no distance should not be longer than
    103      // half a second.
    104      await new Promise(resolve => setTimeout(resolve, 500));
    105    } else {
    106      await promiseFrame();
    107    }
    108    is(scroller.scrollTop, 0, "No scroll should have occured");
    109    is(scrollendCount, 0, "A user gesture with no scroll should have no scrollend");
    110  } else {
    111    await scrollPromise;
    112    if (SpecialPowers.getBoolPref("general.smoothScroll")) {
    113      // If smooth scrolling is enabled and there is room to scroll, wait for the
    114      // transform end notification.
    115      await transformEndPromise;
    116    }
    117    await promiseFrame();
    118    isnot(scroller.scrollTop, 0, "A scroll should have occured");
    119    is(scrollendCount, 1, "A user gesture with a scroll should trigger a scrollend");
    120  }
    121 }
    122 
    123 function isOnChaosMode() {
    124  return SpecialPowers.Services.env.get("MOZ_CHAOSMODE");
    125 }
    126 
    127 if ((getPlatform() == "mac" || getPlatform() == "windows") &&
    128    !isOnChaosMode()) {
    129  waitUntilApzStable()
    130  .then(test)
    131  .then(subtestDone, subtestFailed);
    132 } else {
    133  ok(true, "Skipping test, native key events are not supported on " +
    134     getPlatform());
    135  subtestDone();
    136 }
    137 </script>
    138 </html>