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

https://github.com/rillian/firefox · HTML · 143 lines · 129 code · 14 blank · 0 comment · 0 complexity · fc9a89f4671cf49ac2d326730f9534b1 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>Complex touch-action test</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 checkScroll(target, x, y, desc) {
  12. is(target.scrollLeft, x, desc + " - x axis");
  13. is(target.scrollTop, y, desc + " - y axis");
  14. }
  15. function resetConfiguration(config, testDriver) {
  16. // Cycle through all the configuration_X elements, setting them to display:none
  17. // except for when X == config, in which case set it to display:block
  18. var i = 0;
  19. while (true) {
  20. i++;
  21. var element = document.getElementById('configuration_' + i);
  22. if (element == null) {
  23. if (i <= config) {
  24. ok(false, "The configuration requested was not encountered!");
  25. }
  26. break;
  27. }
  28. if (i == config) {
  29. element.style.display = 'block';
  30. } else {
  31. element.style.display = 'none';
  32. }
  33. }
  34. // Also reset the scroll position on the scrollframe
  35. var s = document.getElementById('scrollframe');
  36. s.scrollLeft = 0;
  37. s.scrollTop = 0;
  38. return waitForAllPaints(function() {
  39. flushApzRepaints(testDriver);
  40. });
  41. }
  42. function* test(testDriver) {
  43. var scrollframe = document.getElementById('scrollframe');
  44. document.body.addEventListener('touchend', testDriver, { passive: true });
  45. // Helper function for the tests below.
  46. // Touch-pan configuration |configuration| towards scroll offset (dx, dy) with
  47. // the pan touching down at (x, y). Check that the final scroll offset is
  48. // (ex, ey). |desc| is some description string.
  49. function* scrollAndCheck(configuration, x, y, dx, dy, ex, ey, desc) {
  50. // Start with a clean slate
  51. yield resetConfiguration(configuration, testDriver);
  52. // Figure out the panning deltas
  53. if (dx != 0) {
  54. dx = -(dx + TOUCH_SLOP);
  55. }
  56. if (dy != 0) {
  57. dy = -(dy + TOUCH_SLOP);
  58. }
  59. // Do the pan
  60. yield ok(synthesizeNativeTouchDrag(scrollframe, x, y, dx, dy),
  61. "Synthesized drag of (" + dx + ", " + dy + ") on configuration " + configuration);
  62. yield waitForAllPaints(function() {
  63. flushApzRepaints(testDriver);
  64. });
  65. // Check for expected scroll position
  66. checkScroll(scrollframe, ex, ey, 'configuration ' + configuration + ' ' + desc);
  67. }
  68. // Test configuration_1, which contains two sibling elements that are
  69. // overlapping. The touch-action from the second sibling (which is on top)
  70. // should be used for the overlapping area.
  71. yield* scrollAndCheck(1, 25, 75, 20, 0, 20, 0, "first element horizontal scroll");
  72. yield* scrollAndCheck(1, 25, 75, 0, 50, 0, 0, "first element vertical scroll");
  73. yield* scrollAndCheck(1, 75, 75, 50, 0, 0, 0, "overlap horizontal scroll");
  74. yield* scrollAndCheck(1, 75, 75, 0, 50, 0, 50, "overlap vertical scroll");
  75. yield* scrollAndCheck(1, 125, 75, 20, 0, 0, 0, "second element horizontal scroll");
  76. yield* scrollAndCheck(1, 125, 75, 0, 50, 0, 50, "second element vertical scroll");
  77. // Test configuration_2, which contains two overlapping elements with a
  78. // parent/child relationship. The parent has pan-x and the child has pan-y,
  79. // which means that panning on the parent should work horizontally only, and
  80. // on the child no panning should occur at all.
  81. yield* scrollAndCheck(2, 125, 125, 50, 50, 0, 0, "child scroll");
  82. yield* scrollAndCheck(2, 75, 75, 50, 50, 0, 0, "overlap scroll");
  83. yield* scrollAndCheck(2, 25, 75, 0, 50, 0, 0, "parent vertical scroll");
  84. yield* scrollAndCheck(2, 75, 25, 50, 0, 50, 0, "parent horizontal scroll");
  85. // Test configuration_3, which is the same as configuration_2, except the child
  86. // has a rotation transform applied. This forces the event regions on the two
  87. // elements to be built separately and then get merged.
  88. yield* scrollAndCheck(3, 125, 125, 50, 50, 0, 0, "child scroll");
  89. yield* scrollAndCheck(3, 75, 75, 50, 50, 0, 0, "overlap scroll");
  90. yield* scrollAndCheck(3, 25, 75, 0, 50, 0, 0, "parent vertical scroll");
  91. yield* scrollAndCheck(3, 75, 25, 50, 0, 50, 0, "parent horizontal scroll");
  92. // Test configuration_4 has two elements, one above the other, not overlapping,
  93. // and the second element is a child of the first. The parent has pan-x, the
  94. // child has pan-y, but that means panning horizontally on the parent should
  95. // work and panning in any direction on the child should not do anything.
  96. yield* scrollAndCheck(4, 75, 75, 50, 50, 50, 0, "parent diagonal scroll");
  97. yield* scrollAndCheck(4, 75, 150, 50, 50, 0, 0, "child diagonal scroll");
  98. }
  99. waitUntilApzStable()
  100. .then(runContinuation(test))
  101. .then(subtestDone);
  102. </script>
  103. </head>
  104. <body>
  105. <div id="scrollframe" style="width: 300px; height: 300px; overflow:scroll">
  106. <div id="scrolled_content" style="width: 1000px; height: 1000px; background-color: green">
  107. </div>
  108. <div id="configuration_1" style="display:none; position: relative; top: -1000px">
  109. <div style="touch-action: pan-x; width: 100px; height: 100px; background-color: blue"></div>
  110. <div style="touch-action: pan-y; width: 100px; height: 100px; position: relative; top: -100px; left: 50px; background-color: yellow"></div>
  111. </div>
  112. <div id="configuration_2" style="display:none; position: relative; top: -1000px">
  113. <div style="touch-action: pan-x; width: 100px; height: 100px; background-color: blue">
  114. <div style="touch-action: pan-y; width: 100px; height: 100px; position: relative; top: 50px; left: 50px; background-color: yellow"></div>
  115. </div>
  116. </div>
  117. <div id="configuration_3" style="display:none; position: relative; top: -1000px">
  118. <div style="touch-action: pan-x; width: 100px; height: 100px; background-color: blue">
  119. <div style="touch-action: pan-y; width: 100px; height: 100px; position: relative; top: 50px; left: 50px; background-color: yellow; transform: rotate(90deg)"></div>
  120. </div>
  121. </div>
  122. <div id="configuration_4" style="display:none; position: relative; top: -1000px">
  123. <div style="touch-action: pan-x; width: 100px; height: 100px; background-color: blue">
  124. <div style="touch-action: pan-y; width: 100px; height: 100px; position: relative; top: 125px; background-color: yellow"></div>
  125. </div>
  126. </div>
  127. </div>
  128. </body>
  129. </html>