summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_bug1719855_pointercancel_on_touchmove_after_contextmenu_prevented.html
blob: af4118eeb1ccadc0a103d7d25c6089d53e234fc0 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta name="viewport" content="width=device-width; initial-scale=1.0">
  <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>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
</head>
<body>
  <!-- make the root scroll container scrollable -->
  <div style="height: 200vh;"></div>
</body>
<script type="application/javascript">

async function test() {
  let pointercancelCount = 0;
  let pointercancelPromise = new Promise(resolve => {
    window.addEventListener("pointercancel", () => {
      pointercancelCount++;
      resolve();
    });
  });

  let scrollendCount = 0;
  let scrollendPromise = new Promise(resolve => {
    window.addEventListener("scrollend", () => {
      scrollendCount++;
      resolve();
    });
  });

  let contextmenuPromise = promiseOneEvent(window, "contextmenu", e => {
    // Do preventDefault() to prevent opening a context menu, it will suppress
    // a pointercancel event triggered by the context menu.
    e.preventDefault();
    return true;
  });

  // Ensure that above setup-ed information has reached to APZ.
  await promiseApzFlushedRepaints();

  // Start a touch.
  await synthesizeNativeTouch(window, 100, 100, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);

  // And wait for a contextmenu event (i.e. a long-tap event)
  await contextmenuPromise;

  // Try to scroll down by touch moving.
  for (let i = 1; i < 50; i++) {
    synthesizeNativeTouch(window, 100, 100 - i, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
  }
  await synthesizeNativeTouch(window, 100, 50, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);

  // Now the content should have been scrolled and there should be a
  // pointercancel event.
  await Promise.all([ pointercancelPromise, scrollendPromise ]);
  is(pointercancelCount, 1, "There should be only one pointercancel event");
  is(scrollendCount, 1, "There should be only one scrollend event");
}

if (getPlatform() == "windows") {
  // On Windows every context menu on touch screens opens __after__ lifting the
  // finger.
  ok(true, "Test doesn't need to run on Windows");
  subtestDone();
} else {
  waitUntilApzStable()
  .then(test)
  .then(subtestDone, subtestFailed);
}

</script>
</html>