Bug 1371219 - Add a test for touchmode on toolbar menus. r=mikedeboer draft
authorJohann Hofmann <jhofmann@mozilla.com>
Mon, 17 Jul 2017 16:42:14 +0200
changeset 609814 048febf8ffa70691594f48d2cb3c157bcb4e58d0
parent 609813 a58035d044d7ccb11fc4cdc3bd6cd379e57aae34
child 637673 85dd93a296d0087c911c2d89a2392d5e66ad8f56
push id68688
push userbmo:jhofmann@mozilla.com
push dateMon, 17 Jul 2017 14:57:38 +0000
reviewersmikedeboer
bugs1371219
milestone56.0a1
Bug 1371219 - Add a test for touchmode on toolbar menus. r=mikedeboer MozReview-Commit-ID: 3mptWhq4fF6
browser/base/content/test/touch/browser.ini
browser/base/content/test/touch/browser_menu_touch.js
browser/base/moz.build
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/touch/browser.ini
@@ -0,0 +1,4 @@
+[DEFAULT]
+
+[browser_menu_touch.js]
+skip-if = !(os == 'win' && os_version == '10.0')
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/touch/browser_menu_touch.js
@@ -0,0 +1,109 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* This test checks that toolbar menus are in touchmode
+ * when opened through a touch event. */
+
+async function openAndCheckMenu(menu, target) {
+  is(menu.state, "closed", "Menu panel is initally closed.");
+
+  let popupshown = BrowserTestUtils.waitForEvent(menu, "popupshown");
+  EventUtils.synthesizeNativeTapAtCenter(target);
+  await popupshown;
+
+  is(menu.state, "open", "Menu panel is open.");
+  is(menu.getAttribute("touchmode"), "true", "Menu panel is in touchmode.");
+
+  menu.hidePopup();
+
+  popupshown = BrowserTestUtils.waitForEvent(menu, "popupshown");
+  EventUtils.synthesizeMouseAtCenter(target, {});
+  await popupshown;
+
+  is(menu.state, "open", "Menu panel is open.");
+  ok(!menu.hasAttribute("touchmode"), "Menu panel is not in touchmode.");
+
+  menu.hidePopup();
+}
+
+// The customization UI menu is not attached to the document when it is
+// closed and hence requires special attention.
+async function openAndCheckCustomizationUIMenu(target) {
+  EventUtils.synthesizeNativeTapAtCenter(target);
+
+  await BrowserTestUtils.waitForCondition(() =>
+      document.getElementById("customizationui-widget-panel") != null);
+  let menu = document.getElementById("customizationui-widget-panel");
+
+  if (menu.state != "open") {
+    await BrowserTestUtils.waitForEvent(menu, "popupshown");
+    is(menu.state, "open", "Menu is open");
+  }
+
+  is(menu.getAttribute("touchmode"), "true", "Menu is in touchmode.");
+
+  menu.hidePopup();
+
+  EventUtils.synthesizeMouseAtCenter(target, {});
+
+  await BrowserTestUtils.waitForCondition(() =>
+      document.getElementById("customizationui-widget-panel") != null);
+  menu = document.getElementById("customizationui-widget-panel");
+
+  if (menu.state != "open") {
+    await BrowserTestUtils.waitForEvent(menu, "popupshown");
+    is(menu.state, "open", "Menu is open");
+  }
+
+  ok(!menu.hasAttribute("touchmode"), "Menu is not in touchmode.");
+
+  menu.hidePopup();
+}
+
+// Test main ("hamburger") menu.
+add_task(async function test_main_menu_touch() {
+  if (!gPhotonStructure) {
+    ok(true, "Skipping test because we're not in Photon mode");
+    return;
+  }
+
+  let mainMenu = document.getElementById("appMenu-popup");
+  let target = document.getElementById("PanelUI-menu-button");
+  await openAndCheckMenu(mainMenu, target);
+});
+
+// Test the page action menu.
+add_task(async function test_page_action_panel_touch() {
+  if (!gPhotonStructure) {
+    ok(true, "Skipping test because we're not in Photon mode");
+    return;
+  }
+
+  let pageActionPanel = document.getElementById("page-action-panel");
+  let target = document.getElementById("urlbar-page-action-button");
+  await openAndCheckMenu(pageActionPanel, target);
+});
+
+// Test the customizationUI panel, which is used for various menus
+// such as library, history, sync, developer and encoding.
+add_task(async function test_customizationui_panel_touch() {
+  if (!gPhotonStructure) {
+    ok(true, "Skipping test because we're not in Photon mode");
+    return;
+  }
+
+  CustomizableUI.addWidgetToArea("library-button", CustomizableUI.AREA_NAVBAR);
+  CustomizableUI.addWidgetToArea("history-panelmenu", CustomizableUI.AREA_NAVBAR);
+
+  await BrowserTestUtils.waitForCondition(() =>
+      CustomizableUI.getPlacementOfWidget("library-button").area == "nav-bar");
+
+  let target = document.getElementById("library-button");
+  await openAndCheckCustomizationUIMenu(target);
+
+  target = document.getElementById("history-panelmenu");
+  await openAndCheckCustomizationUIMenu(target);
+
+  CustomizableUI.reset();
+});
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -31,16 +31,17 @@ BROWSER_CHROME_MANIFESTS += [
     'content/test/sidebar/browser.ini',
     'content/test/siteIdentity/browser.ini',
     'content/test/social/browser.ini',
     'content/test/static/browser.ini',
     'content/test/sync/browser.ini',
     'content/test/tabcrashed/browser.ini',
     'content/test/tabPrompts/browser.ini',
     'content/test/tabs/browser.ini',
+    'content/test/touch/browser.ini',
     'content/test/urlbar/browser.ini',
     'content/test/webextensions/browser.ini',
     'content/test/webrtc/browser.ini',
 ]
 
 DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
 DEFINES['MOZ_APP_VERSION_DISPLAY'] = CONFIG['MOZ_APP_VERSION_DISPLAY']