summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_basic_scrollend.html
blob: 9d71fe6251506fee051d103a46006b6ad58e3863 (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
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <script src="apz_test_utils.js"></script>
  <script src="apz_test_native_event_utils.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <style>
    html, body { margin: 0; }

    body {
      height: 10000px;
    }
  </style>
  <script>
const searchParams = new URLSearchParams(location.search);

async function test() {
  var scrollendCount = 0;

  function onScrollend(e) {
    scrollendCount += 1;
  }

  switch (searchParams.get("chrome-only")) {
    case "true":
      // Add chrome-only event listener.
      SpecialPowers.addChromeEventListener("scrollend", onScrollend, true);
      break;
    case "false":
      // Add document event listener.
      document.addEventListener("scrollend", onScrollend);
      break;
    default:
      ok(false, "Unsupported chrome-only value: " + searchParams.get("chrome-only"));
      break;
  }

  is(scrollendCount, 0, "A scrollend event should not be triggered yet");

  await promiseFrame();

  let wheelScrollTransformEndPromise = promiseTransformEnd();

  await promiseMoveMouseAndScrollWheelOver(document.scrollingElement, 100, 100);

  await wheelScrollTransformEndPromise;

  await promiseFrame();

  is(scrollendCount, 1, "A scrollend event should be triggered after user scroll");

  scrollendCount = 0;

  // Call the scrollTo function without behavior: smooth to trigger an instant
  // programatic scroll.
  scrollTo({ top: 500, left: 0 });

  // Ensure the refresh driver has ticked.
  await promiseFrame();

  // A scrollend event should be posted after the refresh driver has ticked.
  is(scrollendCount, 1, "A scrollend event should be triggered after instant scroll");

  // If smooth scrolls are enabled, repeat the test with a smooth scroll.
  if (SpecialPowers.getBoolPref("general.smoothScroll")) {

    scrollendCount = 0;

    let smoothScrollTransformEndPromise = promiseTransformEnd();

    // Call the scrollTo function with behavior: smooth to trigger a programmatic
    // scroll that should require some form of async transform.
    scrollTo({ top: 1000, left: 0, behavior: "smooth" });

    // Ensure the smooth scroll transform has finished.
    await smoothScrollTransformEndPromise;

    await promiseFrame();

    is(scrollendCount, 1, "A scrollend event should be triggered after smooth scroll");
  }
}
waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);
  </script>
</head>
<body>
</body>
</html>