summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_scroll_anchoring_on_wheel.html
blob: 9f439a8ce3b2fdd1521ef00d7d19d199429314be (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
<!DOCTYPE HTML>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0">
<title>Tests scroll anchoring updates in-progress wheel scrolling __relatively__</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: 1000vh"></div>
<script>
  const targetElement = document.getElementById("target");

  async function test() {
    // Fistly send a wheel event to measure the scroll amount of one event.
    let transformEndPromise = promiseTransformEnd();
    await synthesizeNativeWheel(window, 50, 50, 0, -50);
    await transformEndPromise;

    ok(window.scrollY > 0, "Should be scrolled to some amount");

    const firstScrollAmount = window.scrollY;

    // Now send a wheel event again.
    transformEndPromise = promiseTransformEnd();
    await synthesizeNativeWheel(window, 50, 50, 0, -50);
    await promiseApzFlushedRepaints();

    // And insert an element during the wheel scrolling is still in progress.
    targetElement.appendChild(document.createElement("div"));

    await transformEndPromise;

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

    // Though in an ideal environment, the expected total scroll amount should
    // be `firstScrollAmount * 2 + 500`, we don't expect it on our CIs, so we
    // assume here;
    // 1) it's greater than double of the first scroll amount since it should
    //     include the height of the inserted element.
    // 2) it's greater than the first scroll amount + the height of the inserted
    //    element.
    ok(window.scrollY > firstScrollAmount * 2,
       `the scroll amount ${window.scrollY} should be greater than double of the first scroll amount ${firstScrollAmount*2}`);
    ok(window.scrollY > firstScrollAmount + 500,
       `the scroll amount ${window.scrollY} should also be greater than the first scroll amount + the inserted element height  ${firstScrollAmount+500}`);
  }

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