browser_responsiveui_touch.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. const TEST_URI = "http://mochi.test:8888/browser/devtools/client/" +
  5. "responsivedesign/test/touch.html";
  6. const layoutReflowSynthMouseMove = "layout.reflow.synthMouseMove";
  7. const domViewportEnabled = "dom.meta-viewport.enabled";
  8. add_task(function* () {
  9. let tab = yield addTab(TEST_URI);
  10. let {rdm} = yield openRDM(tab);
  11. yield pushPrefs([layoutReflowSynthMouseMove, false]);
  12. yield testWithNoTouch();
  13. yield rdm.enableTouch();
  14. yield testWithTouch();
  15. yield rdm.disableTouch();
  16. yield testWithNoTouch();
  17. yield closeRDM(rdm);
  18. });
  19. function* testWithNoTouch() {
  20. let div = content.document.querySelector("div");
  21. let x = 0, y = 0;
  22. info("testWithNoTouch: Initial test parameter and mouse mouse outside div element");
  23. x = -1, y = -1;
  24. yield BrowserTestUtils.synthesizeMouse("div", x, y,
  25. { type: "mousemove", isSynthesized: false }, gBrowser.selectedBrowser);
  26. div.style.transform = "none";
  27. div.style.backgroundColor = "";
  28. info("testWithNoTouch: Move mouse into the div element");
  29. yield BrowserTestUtils.synthesizeMouseAtCenter("div", { type: "mousemove", isSynthesized: false },
  30. gBrowser.selectedBrowser);
  31. is(div.style.backgroundColor, "red", "mouseenter or mouseover should work");
  32. info("testWithNoTouch: Drag the div element");
  33. yield BrowserTestUtils.synthesizeMouseAtCenter("div", { type: "mousedown", isSynthesized: false },
  34. gBrowser.selectedBrowser);
  35. x = 100; y = 100;
  36. yield BrowserTestUtils.synthesizeMouse("div", x, y,
  37. { type: "mousemove", isSynthesized: false }, gBrowser.selectedBrowser);
  38. is(div.style.transform, "none", "touchmove shouldn't work");
  39. yield BrowserTestUtils.synthesizeMouse("div", x, y,
  40. { type: "mouseup", isSynthesized: false }, gBrowser.selectedBrowser);
  41. info("testWithNoTouch: Move mouse out of the div element");
  42. x = -1; y = -1;
  43. yield BrowserTestUtils.synthesizeMouse("div", x, y,
  44. { type: "mousemove", isSynthesized: false }, gBrowser.selectedBrowser);
  45. is(div.style.backgroundColor, "blue", "mouseout or mouseleave should work");
  46. info("testWithNoTouch: Click the div element");
  47. yield synthesizeClick(div);
  48. is(div.dataset.isDelay, "false", "300ms delay between touch events and mouse events should not work");
  49. }
  50. function* testWithTouch() {
  51. let div = content.document.querySelector("div");
  52. let x = 0, y = 0;
  53. info("testWithTouch: Initial test parameter and mouse mouse outside div element");
  54. x = -1, y = -1;
  55. yield BrowserTestUtils.synthesizeMouse("div", x, y,
  56. { type: "mousemove", isSynthesized: false }, gBrowser.selectedBrowser);
  57. div.style.transform = "none";
  58. div.style.backgroundColor = "";
  59. info("testWithTouch: Move mouse into the div element");
  60. yield BrowserTestUtils.synthesizeMouseAtCenter("div", { type: "mousemove", isSynthesized: false },
  61. gBrowser.selectedBrowser);
  62. isnot(div.style.backgroundColor, "red", "mouseenter or mouseover should not work");
  63. info("testWithTouch: Drag the div element");
  64. yield BrowserTestUtils.synthesizeMouseAtCenter("div", { type: "mousedown", isSynthesized: false },
  65. gBrowser.selectedBrowser);
  66. x = 100; y = 100;
  67. yield BrowserTestUtils.synthesizeMouse("div", x, y,
  68. { type: "mousemove", isSynthesized: false }, gBrowser.selectedBrowser);
  69. isnot(div.style.transform, "none", "touchmove should work");
  70. yield BrowserTestUtils.synthesizeMouse("div", x, y,
  71. { type: "mouseup", isSynthesized: false }, gBrowser.selectedBrowser);
  72. info("testWithTouch: Move mouse out of the div element");
  73. x = -1; y = -1;
  74. yield BrowserTestUtils.synthesizeMouse("div", x, y,
  75. { type: "mousemove", isSynthesized: false }, gBrowser.selectedBrowser);
  76. isnot(div.style.backgroundColor, "blue", "mouseout or mouseleave should not work");
  77. yield testWithMetaViewportEnabled();
  78. yield testWithMetaViewportDisabled();
  79. }
  80. function* testWithMetaViewportEnabled() {
  81. yield pushPrefs([domViewportEnabled, true]);
  82. let meta = content.document.querySelector("meta[name=viewport]");
  83. let div = content.document.querySelector("div");
  84. div.dataset.isDelay = "false";
  85. info("testWithMetaViewportEnabled: click the div element with <meta name='viewport'>");
  86. meta.content = "";
  87. yield synthesizeClick(div);
  88. is(div.dataset.isDelay, "true", "300ms delay between touch events and mouse events should work");
  89. info("testWithMetaViewportEnabled: click the div element with <meta name='viewport' content='user-scalable=no'>");
  90. meta.content = "user-scalable=no";
  91. yield synthesizeClick(div);
  92. is(div.dataset.isDelay, "false", "300ms delay between touch events and mouse events should not work");
  93. info("testWithMetaViewportEnabled: click the div element with <meta name='viewport' content='minimum-scale=maximum-scale'>");
  94. meta.content = "minimum-scale=maximum-scale";
  95. yield synthesizeClick(div);
  96. is(div.dataset.isDelay, "false", "300ms delay between touch events and mouse events should not work");
  97. info("testWithMetaViewportEnabled: click the div element with <meta name='viewport' content='width=device-width'>");
  98. meta.content = "width=device-width";
  99. yield synthesizeClick(div);
  100. is(div.dataset.isDelay, "false", "300ms delay between touch events and mouse events should not work");
  101. }
  102. function* testWithMetaViewportDisabled() {
  103. yield pushPrefs([domViewportEnabled, false]);
  104. let meta = content.document.querySelector("meta[name=viewport]");
  105. let div = content.document.querySelector("div");
  106. div.dataset.isDelay = "false";
  107. info("testWithMetaViewportDisabled: click the div element with <meta name='viewport'>");
  108. meta.content = "";
  109. yield synthesizeClick(div);
  110. is(div.dataset.isDelay, "true", "300ms delay between touch events and mouse events should work");
  111. }
  112. function synthesizeClick(element) {
  113. let waitForClickEvent = BrowserTestUtils.waitForEvent(element, "click");
  114. BrowserTestUtils.synthesizeMouseAtCenter(element, { type: "mousedown", isSynthesized: false },
  115. gBrowser.selectedBrowser);
  116. BrowserTestUtils.synthesizeMouseAtCenter(element, { type: "mouseup", isSynthesized: false },
  117. gBrowser.selectedBrowser);
  118. return waitForClickEvent;
  119. }
  120. function pushPrefs(...aPrefs) {
  121. let deferred = promise.defer();
  122. SpecialPowers.pushPrefEnv({"set": aPrefs}, deferred.resolve);
  123. return deferred.promise;
  124. }