tor-browser

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

helper_programmatic_scroll_behavior.html (2298B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <script src="apz_test_utils.js"></script>
      6  <script src="apz_test_native_event_utils.js"></script>
      7  <script src="/tests/SimpleTest/EventUtils.js"></script>
      8  <script src="/tests/SimpleTest/paint_listener.js"></script>
      9  <style>
     10    html, body { margin: 0; }
     11 
     12    #big {
     13      height: 250vh;
     14      width: 100%;
     15    }
     16 
     17    #target {
     18      height: 500px;
     19      width: 100%;
     20      background: red;
     21    }
     22  </style>
     23 </head>
     24 <body>
     25  <div id="big">
     26  </div>
     27  <div id="target">
     28  </div>
     29 </body>
     30 <script>
     31 const searchParams = new URLSearchParams(location.search);
     32 
     33 async function test() {
     34  // Count the number of scroll events that occur. Instant scrolls should only
     35  // trigger one scroll event, so a scroll event count of 1 indicates that a
     36  // instant scroll was conducted.
     37  let scrollCount = 0;
     38  window.addEventListener("scroll", () => {
     39    scrollCount += 1;
     40  });
     41 
     42  let scrollendPromise = promiseScrollend();
     43 
     44  // Call the given programmatic scroll with behavior: smooth.
     45  switch (searchParams.get("action")) {
     46    case "scrollIntoView":
     47      target.scrollIntoView({behavior: "smooth"});
     48      break;
     49    case "scrollBy":
     50      document.scrollingElement.scrollBy({top: 500, behavior: "smooth"});
     51      break;
     52    case "scrollTo":
     53      document.scrollingElement.scrollTo({top: 500, behavior: "smooth"});
     54      break;
     55    case "scroll":
     56      document.scrollingElement.scroll({top: 500, behavior: "smooth"});
     57      break;
     58    default:
     59      ok(false, "Unsupported action: " + searchParams.get("action"));
     60      break;
     61  }
     62 
     63  await scrollendPromise;
     64 
     65  // If general.smoothScroll is set, the behavior of the scroll should be
     66  // "smooth". If general.smoothScroll is disabled, we should respect it and
     67  // the scrolls should instant regardless of the specified behavior.
     68  if (SpecialPowers.getBoolPref("general.smoothScroll")) {
     69    info("final enabled scroll count: " + scrollCount);
     70    ok(scrollCount > 1, "The programmatic scroll should create more than one scroll event");
     71  } else {
     72    info("final disabled scroll count: " + scrollCount);
     73    ok(scrollCount == 1, "The programmatic scroll should be instant with one scroll event");
     74  }
     75 }
     76 
     77 waitUntilApzStable()
     78 .then(test)
     79 .then(subtestDone, subtestFailed);
     80 </script>
     81 </html>