summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_scroll_linked_effect_by_wheel.html
blob: f9303253b8148c5097f2c847f0192e2756051f05 (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
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<script src="apz_test_utils.js"></script>
<script src="apz_test_native_event_utils.js"></script>
<title>A scroll linked effect scrolled by wheel events</title>
<style>
html, body { margin: 0; }
body {
  height: 1000vh;
}
#target {
  position: absolute;
  height: 800px;
  background-color: #cc00cc;
  top: 0;
  left: 0;
  right: 0;
}
</style>
<div id="target"></div>
<script>
// Set up a scroll linked effect element.
window.addEventListener("scroll", () => {
  target.style.top = window.scrollY + "px";
});

async function test() {
  let rect = rectRelativeToScreen(target);
  // We only care the top 10px here since the scroll linked effect on the
  // main-thread can't keep up with the async scrolling by wheel events so that
  // the position absolute element is often partially scrolled out.
  rect.height = 10.0;
  const initialSnapshot = await getSnapshot(rect);

  let snapshots = [];
  for (let i = 0; i < 10; i++) {
    await synthesizeNativeWheel(window, 50, 50, 0, -10);
    snapshots.push(await getSnapshot(rect));
  }

  const sampledData = collectSampledScrollOffsets(document.scrollingElement);
  const hasPoint5FractionalOffset = sampledData.some(data => {
    return SpecialPowers.wrap(data).scrollOffsetY.toString().split(".")?.[1] === "5"
  });

  if (hasPoint5FractionalOffset) {
    todo(false, "Bug 1752789: There's at least one sampled scroll offset " +
         "having .5 fractional part in such cases scroll linked effects can " +
         "not be rendered at the same position of the async scroll offset");
    return;
  }

  snapshots.forEach(snapshot => {
    is(initialSnapshot, snapshot);
  });
}

pushPrefs([["apz.test.logging_enabled", true]])
.then(waitUntilApzStable)
.then(test)
.then(subtestDone, subtestFailed);
</script>