summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_tab_scroll_scrollIntoView.html
blob: 044b08eb0c4973330fb42d10930b686219e54122 (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
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <script src="apz_test_utils.js"></script>
  <script src="apz_test_native_event_utils.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <style>
.spacer {
  height: 200vh;
  width: 100%;
  background: green;
}
#target {
  height: 5vh;
  width: 100%;
  background: red;
}
  </style>
</head>
<body>
  <div class="spacer"></div>
  <button id="target"></button>
  <div class="spacer"></div>
</body>
<script>
async function test() {
  let scrollendPromise = promiseScrollend();

  window.synthesizeKey("KEY_Tab");

  await scrollendPromise;

  let tabScrollPosition = document.scrollingElement.scrollTop;

  target.scrollIntoView({block: "center", inline: "center"});

  let scrollIntoViewPosition = document.scrollingElement.scrollTop;

  // The scroll position after an explicit scrollIntoView call on the target
  // with block and inline set to "center" should be within +/- 1 of the
  // scroll position from the tab scroll.
  ok(tabScrollPosition >= scrollIntoViewPosition - 1 &&
     tabScrollPosition <= scrollIntoViewPosition + 1,
     "target element should be centered by tab scroll");
}
waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);
</script>
</html>