summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_long_tap.html
blob: 604d03d644611cea3e123ab7fff60f4c2f4c0fc3 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width; initial-scale=1.0">
  <title>Ensure we get a touch-cancel after a contextmenu comes up</title>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
  <script type="application/javascript">

function longPressLink() {
  synthesizeNativeTouch(document.getElementById('b'), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT, function() {
    dump("Finished synthesizing touch-start, waiting for events...\n");
  });
}

var eventsFired = 0;
function recordEvent(e) {
  if (getPlatform() == "windows") {
    // On Windows we get a mouselongtap event once the long-tap has been detected
    // by APZ, and that's what we use as the trigger to lift the finger. That then
    // triggers the contextmenu. This matches the platform convention.
    switch (eventsFired) {
      case 0: is(e.type, 'touchstart', 'Got a touchstart'); break;
      case 1:
        is(e.type, 'mouselongtap', 'Got a mouselongtap');
        synthesizeNativeTouch(document.getElementById('b'), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);
        break;
      case 2: is(e.type, 'touchend', 'Got a touchend'); break;
      case 3: is(e.type, 'contextmenu', 'Got a contextmenu'); e.preventDefault(); break;
      default: ok(false, 'Got an unexpected event of type ' + e.type); break;
    }
    eventsFired++;

    if (eventsFired == 4) {
      dump("Finished waiting for events, doing an APZ flush to see if any more unexpected events come through...\n");
      flushApzRepaints(function() {
        dump("Done APZ flush, ending test...\n");
        subtestDone();
      });
    }
  } else {
    // On non-Windows platforms we get a contextmenu event once the long-tap has
    // been detected. Since we prevent-default that, we don't get a mouselongtap
    // event at all, and instead get a touchcancel.
    switch (eventsFired) {
      case 0: is(e.type, 'touchstart', 'Got a touchstart'); break;
      case 1: is(e.type, 'contextmenu', 'Got a contextmenu'); e.preventDefault(); break;
      case 2: is(e.type, 'touchcancel', 'Got a touchcancel'); break;
      default: ok(false, 'Got an unexpected event of type ' + e.type); break;
    }
    eventsFired++;

    if (eventsFired == 3) {
      synthesizeNativeTouch(document.getElementById('b'), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE, function() {
        dump("Finished synthesizing touch-end, doing an APZ flush to see if any more unexpected events come through...\n");
        flushApzRepaints(function() {
          dump("Done APZ flush, ending test...\n");
          subtestDone();
        });
      });
    }
  }
}

window.addEventListener('touchstart', recordEvent, { passive: true, capture: true });
window.addEventListener('touchend', recordEvent, { passive: true, capture: true });
window.addEventListener('touchcancel', recordEvent, true);
window.addEventListener('contextmenu', recordEvent, true);
SpecialPowers.addChromeEventListener('mouselongtap', recordEvent, true);

waitUntilApzStable()
.then(longPressLink);

  </script>
</head>
<body>
 <a id="b" href="#">Link to nowhere</a>
</body>
</html>