/gfx/layers/apz/test/mochitest/helper_long_tap.html

https://github.com/rillian/firefox · HTML · 81 lines · 74 code · 7 blank · 0 comment · 0 complexity · 9a064ed3c1fdb4dc2ffea0d25cd452b7 MD5 · raw file

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width; initial-scale=1.0">
  6. <title>Ensure we get a touch-cancel after a contextmenu comes up</title>
  7. <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  8. <script type="application/javascript" src="apz_test_utils.js"></script>
  9. <script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
  10. <script type="application/javascript">
  11. function longPressLink() {
  12. synthesizeNativeTouch(document.getElementById('b'), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT, function() {
  13. dump("Finished synthesizing touch-start, waiting for events...\n");
  14. });
  15. }
  16. var eventsFired = 0;
  17. function recordEvent(e) {
  18. if (getPlatform() == "windows") {
  19. // On Windows we get a mouselongtap event once the long-tap has been detected
  20. // by APZ, and that's what we use as the trigger to lift the finger. That then
  21. // triggers the contextmenu. This matches the platform convention.
  22. switch (eventsFired) {
  23. case 0: is(e.type, 'touchstart', 'Got a touchstart'); break;
  24. case 1:
  25. is(e.type, 'mouselongtap', 'Got a mouselongtap');
  26. synthesizeNativeTouch(document.getElementById('b'), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);
  27. break;
  28. case 2: is(e.type, 'touchend', 'Got a touchend'); break;
  29. case 3: is(e.type, 'contextmenu', 'Got a contextmenu'); e.preventDefault(); break;
  30. default: ok(false, 'Got an unexpected event of type ' + e.type); break;
  31. }
  32. eventsFired++;
  33. if (eventsFired == 4) {
  34. dump("Finished waiting for events, doing an APZ flush to see if any more unexpected events come through...\n");
  35. flushApzRepaints(function() {
  36. dump("Done APZ flush, ending test...\n");
  37. subtestDone();
  38. });
  39. }
  40. } else {
  41. // On non-Windows platforms we get a contextmenu event once the long-tap has
  42. // been detected. Since we prevent-default that, we don't get a mouselongtap
  43. // event at all, and instead get a touchcancel.
  44. switch (eventsFired) {
  45. case 0: is(e.type, 'touchstart', 'Got a touchstart'); break;
  46. case 1: is(e.type, 'contextmenu', 'Got a contextmenu'); e.preventDefault(); break;
  47. case 2: is(e.type, 'touchcancel', 'Got a touchcancel'); break;
  48. default: ok(false, 'Got an unexpected event of type ' + e.type); break;
  49. }
  50. eventsFired++;
  51. if (eventsFired == 3) {
  52. synthesizeNativeTouch(document.getElementById('b'), 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE, function() {
  53. dump("Finished synthesizing touch-end, doing an APZ flush to see if any more unexpected events come through...\n");
  54. flushApzRepaints(function() {
  55. dump("Done APZ flush, ending test...\n");
  56. subtestDone();
  57. });
  58. });
  59. }
  60. }
  61. }
  62. window.addEventListener('touchstart', recordEvent, { passive: true, capture: true });
  63. window.addEventListener('touchend', recordEvent, { passive: true, capture: true });
  64. window.addEventListener('touchcancel', recordEvent, true);
  65. window.addEventListener('contextmenu', recordEvent, true);
  66. SpecialPowers.addChromeEventListener('mouselongtap', recordEvent, true);
  67. waitUntilApzStable()
  68. .then(longPressLink);
  69. </script>
  70. </head>
  71. <body>
  72. <a id="b" href="#">Link to nowhere</a>
  73. </body>
  74. </html>