summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_scroll_snap_on_page_down_scroll.html
blob: d0779cdb2d5835a5fbeb3e01b1aa256259f12055 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Page scroll snaps a snap point in the same page rather than the one in the next page</title>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <style>
    div {
      position: absolute;
      margin: 0px;
    }
    body {
      margin: 0px;
    }
    html {
      overflow-y: scroll;
      scroll-snap-type: y mandatory;
    }
    .snap {
      scroll-snap-align: start;
      background: green;
    }
  </style>
</head>
<body>
  <div class="snap" style="top:   0vh; width: 100%; height: 20px;">1</div>
  <div class="snap" style="top:  50vh; width: 100%; height: 20px;">2</div>
  <div class="snap" style="top: 102vh; width: 100%; height: 20px;">3</div>
  <div class="snap" style="top: 300vh; width: 100%; height: 20px;">4</div>
  <div class="snap" style="top: 400vh; width: 100%; height: 20px;">5</div>

  <script type="application/javascript">
    async function test() {
      const expectedPosition =
        document.querySelectorAll(".snap")[1].getBoundingClientRect().top;

      const keyPromise = promiseOneEvent(window, "keydown", null);
      window.synthesizeKey("KEY_PageDown");
      await keyPromise;

      let startedScroll = false;
      let sameScrollPosition = false;
      let prevScrollPos = window.scrollY;
      while (true) {
        // Flush APZ repaints to ensure that scroll offset changes from
        // a compositor sample reach the content process.
        await promiseApzFlushedRepaints();

        let scrollPos = window.scrollY;
        if (scrollPos == prevScrollPos) {
          if (startedScroll) {
            // If we had the same scroll position in two frames consecutively,
            // we consider scroll has finished.
            if (sameScrollPosition) {
              break;
            }
            sameScrollPosition = true;
          }
        } else {
          sameScrollPosition = false;
        }

        if (!startedScroll && scrollPos > 0) {
          startedScroll = true;
        }
        prevScrollPos = scrollPos;
      }

      is(window.scrollY, expectedPosition,
         "Snaps to the second snap point rather than the third snap point " +
         "which was initially out of the scrollport even if it's closer to " +
         "the top of the next page than the second snap point");
    }

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