summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/test_scroll_space_no_range_overflow_scroll.html
blob: deed8f4ced6be7a8fb806fd755b0286527df848f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!doctype html>
<title>Test for bug 1567237</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script>
<style>
  .spacer { height: 200vh; }
  .scroller { height: 300px; overflow: scroll; }
</style>
<div id="unscrollable" class="scroller" tabindex=0></div>
<div id="scrollable" class="scroller" tabindex=0>
  <div class="spacer"></div>
</div>
<div class="spacer"></div>
<script>
function waitForScrollEvent(target) {
  return new Promise(resolve => {
    target.addEventListener("scroll", resolve, { once: true });
  });
}

let selectionController =
  SpecialPowers.wrap(window)
             .docShell
             .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
             .getInterface(SpecialPowers.Ci.nsISelectionDisplay)
             .QueryInterface(SpecialPowers.Ci.nsISelectionController);

function doPageDown(targetExpectedToScroll) {
  let promise = waitForScrollEvent(targetExpectedToScroll);
  selectionController.pageMove(true, false);
  return promise;
}

promise_test(async function() {
  await SpecialPowers.pushPrefEnv({"set": [["general.smoothScroll", false]]});

  const rootScroller = document.documentElement;
  const scrollable = document.querySelector("#scrollable");
  const unscrollable = document.querySelector("#unscrollable");

  assert_equals(rootScroller.scrollTop, 0, "Root should start unscrolled");
  assert_equals(scrollable.scrollTop, 0, "#scrollable should start unscrolled");
  assert_equals(unscrollable.scrollTop, 0, "#unscrollable should not be able to scroll at all");

  assert_true(rootScroller.scrollTopMax > 0, "Should be able to scroll the document element");
  assert_true(scrollable.scrollTopMax > 0, "Should be able to scroll #scrollable");
  assert_equals(unscrollable.scrollTopMax, 0, "#unscrollable should not be able to scroll at all (checking scrollTopMax)");

  scrollable.focus();
  await waitToClearOutAnyPotentialScrolls(window);
  await doPageDown(scrollable);
  assert_not_equals(scrollable.scrollTop, 0, "Should have scrolled when pressing space");

  unscrollable.focus();
  await waitToClearOutAnyPotentialScrolls(window);
  let rootScrollTop = rootScroller.scrollTop; // Could've scrolled to scroll `scrollable` into view before.
  await doPageDown(window);
  assert_equals(unscrollable.scrollTop, 0, "Should not be able to scroll the unscrollable div");
  assert_not_equals(rootScroller.scrollTop, rootScrollTop, "Root should be able to scroll");

  // Null out the controller. Otherwise we leak the whole window because
  // PresShell is not cycle-collectable. See bug 1567237.
  selectionController = null;
}, "Overflow scroll without range doesn't block scrolling of the main document");
</script>