summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_scroll_anchoring_smooth_scroll_with_set_timeout.html
blob: 07ba816c36935b4ca998ea93b28491d9ca4d6ad5 (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
<!DOCTYPE HTML>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0">
<title>Tests scroll anchoring interaction with smooth visual scrolling with set timeout.</title>
<script src="apz_test_utils.js"></script>
<script src="apz_test_native_event_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<style>
  body { margin: 0 }
  #target > div {
    height: 500px;
  }
</style>
<div id="target"></div>
<div class="spacer" style="height: 200vh"></div>
<script>
  const utils = SpecialPowers.DOMWindowUtils;
  const targetElement = document.getElementById("target");

  async function test() {
    const destY = window.scrollMaxY;
    ok(destY > 0, "Should have some scroll range");

    // Scroll to the bottom of the page.
    window.scrollTo(0, destY);

    is(window.scrollY, window.scrollMaxY, "Should be at the bottom");

    // Register a TransformEnd observer so we can tell when the smooth scroll
    // animation stops.
    let transformEndPromise = promiseTransformEnd();

    // Trigger smooth scrolling, and insert an element which takes space into
    // the DOM in a 20ms setTimeout callback.
    //
    // It is important that it actually takes space so as to trigger scroll
    // anchoring.
    targetElement.scrollIntoView({ behavior: "smooth" });
    setTimeout(() => {
      targetElement.appendChild(document.createElement("div"));
    }, 20);

    // Wait for the TransformEnd.
    await transformEndPromise;

    // Give scroll offsets a chance to sync.
    await promiseApzFlushedRepaints();

    // Check that the async smooth scroll finished.
    is(window.scrollY, 0, "Should've completed the smooth scroll without getting interrupted by scroll anchoring");
  }

  waitUntilApzStable()
  .then(test)
  .then(subtestDone, subtestFailed);
</script>