tor-browser

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

test_scroll_space_no_range_overflow_scroll.html (2888B)


      1 <!doctype html>
      2 <title>Test for bug 1567237</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/tests/SimpleTest/EventUtils.js"></script>
      6 <script type="text/javascript" src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script>
      7 <style>
      8  .spacer { height: 200vh; }
      9  .scroller { height: 300px; overflow: scroll; }
     10 </style>
     11 <div id="unscrollable" class="scroller" tabindex=0></div>
     12 <div id="scrollable" class="scroller" tabindex=0>
     13  <div class="spacer"></div>
     14 </div>
     15 <div class="spacer"></div>
     16 <script>
     17 function waitForScrollEvent(target) {
     18  return new Promise(resolve => {
     19    target.addEventListener("scroll", resolve, { once: true });
     20  });
     21 }
     22 
     23 let selectionController =
     24  SpecialPowers.wrap(window)
     25             .docShell
     26             .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
     27             .getInterface(SpecialPowers.Ci.nsISelectionDisplay)
     28             .QueryInterface(SpecialPowers.Ci.nsISelectionController);
     29 
     30 function doPageDown(targetExpectedToScroll) {
     31  let promise = waitForScrollEvent(targetExpectedToScroll);
     32  selectionController.pageMove(true, false);
     33  return promise;
     34 }
     35 
     36 promise_test(async function() {
     37  await SpecialPowers.pushPrefEnv({"set": [["general.smoothScroll", false]]});
     38 
     39  const rootScroller = document.documentElement;
     40  const scrollable = document.querySelector("#scrollable");
     41  const unscrollable = document.querySelector("#unscrollable");
     42 
     43  assert_equals(rootScroller.scrollTop, 0, "Root should start unscrolled");
     44  assert_equals(scrollable.scrollTop, 0, "#scrollable should start unscrolled");
     45  assert_equals(unscrollable.scrollTop, 0, "#unscrollable should not be able to scroll at all");
     46 
     47  assert_true(rootScroller.scrollTopMax > 0, "Should be able to scroll the document element");
     48  assert_true(scrollable.scrollTopMax > 0, "Should be able to scroll #scrollable");
     49  assert_equals(unscrollable.scrollTopMax, 0, "#unscrollable should not be able to scroll at all (checking scrollTopMax)");
     50 
     51  scrollable.focus();
     52  await waitToClearOutAnyPotentialScrolls(window);
     53  await doPageDown(scrollable);
     54  assert_not_equals(scrollable.scrollTop, 0, "Should have scrolled when pressing space");
     55 
     56  unscrollable.focus();
     57  await waitToClearOutAnyPotentialScrolls(window);
     58  let rootScrollTop = rootScroller.scrollTop; // Could've scrolled to scroll `scrollable` into view before.
     59  await doPageDown(window);
     60  assert_equals(unscrollable.scrollTop, 0, "Should not be able to scroll the unscrollable div");
     61  assert_not_equals(rootScroller.scrollTop, rootScrollTop, "Root should be able to scroll");
     62 
     63  // Null out the controller. Otherwise we leak the whole window because
     64  // PresShell is not cycle-collectable. See bug 1567237.
     65  selectionController = null;
     66 }, "Overflow scroll without range doesn't block scrolling of the main document");
     67 </script>