summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/test_abort_smooth_scroll_by_instant_scroll.html
blob: 650c21cac716bb11c111ba3c895248592ce29d8f (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
<!DOCTYPE HTML>
<html>
<head>
    <title>Test to make sure an on-going smooth scroll is aborted by a new
           instant absolute scroll operation</title>
    <meta charset="utf-8">
    <script src="/tests/SimpleTest/SimpleTest.js"></script>
    <script src="/tests/SimpleTest/paint_listener.js"></script>
    <script src="apz_test_utils.js"></script>
    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<div style="height: 100000px;"></div>
<script type="application/javascript">
async function test() {
  // Trigger a smooth scroll.
  document.scrollingElement.scrollTo({ top: 90000, behavior: "smooth" });
  // Need to wait for a scroll event here since with the very small
  // layout.css.scroll-behavior.spring-constant value it's possible that the
  // scroll position hasn't yet been changed after a promiseApzFlushedRepaints
  // call.
  await waitForScrollEvent(window);
  await promiseApzFlushedRepaints();

  ok(document.scrollingElement.scrollTop > 0,
     "Should have scrolled. scroll position: " + document.scrollingElement.scrollTop);

  // Trigger an instant scroll.
  document.scrollingElement.scrollTo({ top: 0, behavior: "instant" });
  is(document.scrollingElement.scrollTop,  0,
     "The previous smooth scroll operation should have been superseded by " +
     "the instant scroll");

  // Double check after a repaint request.
  await promiseApzFlushedRepaints();
  is(document.scrollingElement.scrollTop,  0,
     "The scroll postion should have stayed after a repaint request");
}

SimpleTest.waitForExplicitFinish();

// Use a very small spring constant value for smooth scrolling so that the
// smooth scrollling keeps running at least for a few seconds.
pushPrefs([["layout.css.scroll-behavior.spring-constant", 1]])
.then(waitUntilApzStable)
.then(test)
.then(SimpleTest.finish, SimpleTest.finishWithFailure);

</script>
</body>
</html>