Bug 1350210 - Part 2 - Add a test for UI density settings in customize mode. r=jaws draft
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 29 Jun 2017 10:14:46 -0700
changeset 602725 367bd560b09f8b2fd3edab415af95ebcb3162c26
parent 602724 9802bba188043c04796cf13e0741396ec1447a8d
child 602726 25df9dc0edc97bf614b362f4bf23f48c4b067e3f
child 602757 e8aa4141f294433ab6f070f3d0e4fe4c42e073ea
push id66517
push userbmo:jhofmann@mozilla.com
push dateFri, 30 Jun 2017 17:21:58 +0000
reviewersjaws
bugs1350210
milestone56.0a1
Bug 1350210 - Part 2 - Add a test for UI density settings in customize mode. r=jaws MozReview-Commit-ID: CxL0CNpg3A9
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_customizemode_uidensity.js
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -142,16 +142,17 @@ skip-if = os == "linux" # crashing on Li
 tags = fullscreen
 skip-if = os == "mac"
 [browser_1087303_button_preferences.js]
 [browser_1089591_still_customizable_after_reset.js]
 [browser_1096763_seen_widgets_post_reset.js]
 [browser_1161838_inserted_new_default_buttons.js]
 [browser_bootstrapped_custom_toolbar.js]
 [browser_customizemode_contextmenu_menubuttonstate.js]
+[browser_customizemode_uidensity.js]
 [browser_exit_background_customize_mode.js]
 [browser_overflow_use_subviews.js]
 [browser_panel_keyboard_navigation.js]
 [browser_panel_toggle.js]
 [browser_panelUINotifications.js]
 [browser_panelUINotifications_fullscreen.js]
 tags = fullscreen
 skip-if = os == "mac"
new file mode 100644
--- /dev/null
+++ b/browser/components/customizableui/test/browser_customizemode_uidensity.js
@@ -0,0 +1,171 @@
+/* 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/. */
+
+"use strict";
+
+const PREF_UI_DENSITY = "browser.uidensity";
+const PREF_AUTO_TOUCH_MODE = "browser.touchmode.auto";
+
+async function testModeButton(mode, modePref) {
+  await startCustomizing();
+
+  let win = document.getElementById("main-window");
+  let popupButton = document.getElementById("customization-uidensity-button");
+  let popup = document.getElementById("customization-uidensity-menu");
+
+  // Show the popup.
+  let popupShownPromise = popupShown(popup);
+  EventUtils.synthesizeMouseAtCenter(popupButton, {});
+  await popupShownPromise;
+
+  let button = document.getElementById("customization-uidensity-menu-button-" + mode);
+  let normalButton = document.getElementById("customization-uidensity-menu-button-normal");
+
+  is(normalButton.getAttribute("active"), "true",
+     "Normal mode button should be active by default.");
+
+  // Hover over the mode button and wait until the UI density is updated.
+  EventUtils.synthesizeMouseAtCenter(button, { type: "mouseover" });
+  await BrowserTestUtils.waitForAttribute("uidensity", win, mode);
+
+  is(win.getAttribute("uidensity"), mode,
+     `UI Density should be set to ${mode} on ${mode} button hover.`);
+
+  is(Services.prefs.getIntPref(PREF_UI_DENSITY), window.gUIDensity.MODE_NORMAL,
+     `UI Density pref should still be set to normal on ${mode} button hover.`);
+
+  // Hover the normal button again and check that the UI density reset to normal.
+  EventUtils.synthesizeMouseAtCenter(normalButton, { type: "mouseover" });
+  await BrowserTestUtils.waitForCondition(() => !win.hasAttribute("uidensity"));
+
+  ok(!win.hasAttribute("uidensity"),
+     `UI Density should be reset when no longer hovering the ${mode} button.`);
+
+  // Select the custom UI density and wait for the popup to be hidden.
+  let popupHiddenPromise = popupHidden(popup);
+  EventUtils.synthesizeMouseAtCenter(button, {});
+  await popupHiddenPromise;
+
+  // Check that the click permanently changed the UI density.
+  is(win.getAttribute("uidensity"), mode,
+     `UI Density should be set to ${mode} on ${mode} button click.`);
+  is(Services.prefs.getIntPref(PREF_UI_DENSITY), modePref,
+     `UI Density pref should be set to ${mode} when clicking the ${mode} button.`);
+
+  // Open the popup again.
+  popupShownPromise = popupShown(popup);
+  EventUtils.synthesizeMouseAtCenter(popupButton, {});
+  await popupShownPromise;
+
+  // Check that the button is still active after opening and closing the popup.
+  is(button.getAttribute("active"), "true", `${mode} mode button should be active.`);
+
+  // Hide the popup again.
+  popupHiddenPromise = popupHidden(popup);
+  EventUtils.synthesizeMouseAtCenter(popupButton, {});
+  await popupHiddenPromise;
+
+  // Check that the button is still active after re-opening customize mode.
+  await endCustomizing();
+  await startCustomizing();
+
+  popupShownPromise = popupShown(popup);
+  EventUtils.synthesizeMouseAtCenter(popupButton, {});
+  await popupShownPromise;
+
+  is(button.getAttribute("active"), "true",
+     `${mode} mode button should be active after entering and exiting customize mode.`);
+
+  // Click the normal button and check that the density is reset.
+  popupHiddenPromise = popupHidden(popup);
+  EventUtils.synthesizeMouseAtCenter(normalButton, {});
+  await popupHiddenPromise;
+
+  ok(!win.hasAttribute("uidensity"),
+     "UI Density should be reset when clicking the normal button.");
+
+  is(Services.prefs.getIntPref(PREF_UI_DENSITY), window.gUIDensity.MODE_NORMAL,
+     "UI Density pref should be set to normal.");
+
+  // Show the popup and click on the mode button again to test the
+  // reset default feature.
+  popupShownPromise = popupShown(popup);
+  EventUtils.synthesizeMouseAtCenter(popupButton, {});
+  await popupShownPromise;
+
+  popupHiddenPromise = popupHidden(popup);
+  EventUtils.synthesizeMouseAtCenter(button, {});
+  await popupHiddenPromise;
+
+  is(win.getAttribute("uidensity"), mode,
+     `UI Density should be set to ${mode} on ${mode} button click.`);
+
+  is(Services.prefs.getIntPref(PREF_UI_DENSITY), modePref,
+     `UI Density pref should be set to ${mode} when clicking the ${mode} button.`);
+
+  await gCustomizeMode.reset();
+
+  ok(!win.hasAttribute("uidensity"),
+     "UI Density should be reset when clicking the normal button.");
+
+  is(Services.prefs.getIntPref(PREF_UI_DENSITY), window.gUIDensity.MODE_NORMAL,
+     "UI Density pref should be set to normal.");
+
+  await endCustomizing();
+}
+
+add_task(async function test_compact_mode_button() {
+  await testModeButton("compact", window.gUIDensity.MODE_COMPACT);
+});
+
+add_task(async function test_touch_mode_button() {
+  // OSX doesn't get touch mode for now.
+  if (AppConstants.platform == "macosx") {
+    is(document.getElementById("customization-uidensity-menu-button-touch"), null,
+       "There's no touch option on Mac OSX");
+    return;
+  }
+
+  await testModeButton("touch", window.gUIDensity.MODE_TOUCH);
+
+  // Test the checkbox for automatic Touch Mode transition
+  // in Windows 10 Tablet Mode.
+  if (AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
+    await startCustomizing();
+
+    let popupButton = document.getElementById("customization-uidensity-button");
+    let popup = document.getElementById("customization-uidensity-menu");
+    let popupShownPromise = popupShown(popup);
+    EventUtils.synthesizeMouseAtCenter(popupButton, {});
+    await popupShownPromise;
+
+    let checkbox = document.getElementById("customization-uidensity-autotouchmode-checkbox");
+    ok(checkbox.checked, "Checkbox should be checked by default");
+
+    // Test toggling the checkbox.
+    EventUtils.synthesizeMouseAtCenter(checkbox, {});
+    is(Services.prefs.getBoolPref(PREF_AUTO_TOUCH_MODE), false,
+       "Automatic Touch Mode is off when the checkbox is unchecked.");
+
+    EventUtils.synthesizeMouseAtCenter(checkbox, {});
+    is(Services.prefs.getBoolPref(PREF_AUTO_TOUCH_MODE), true,
+       "Automatic Touch Mode is on when the checkbox is checked.");
+
+    // Test reset to defaults.
+    EventUtils.synthesizeMouseAtCenter(checkbox, {});
+    is(Services.prefs.getBoolPref(PREF_AUTO_TOUCH_MODE), false,
+       "Automatic Touch Mode is off when the checkbox is unchecked.");
+
+    await gCustomizeMode.reset();
+    is(Services.prefs.getBoolPref(PREF_AUTO_TOUCH_MODE), true,
+       "Automatic Touch Mode is on when the checkbox is checked.");
+  }
+});
+
+add_task(async function cleanup() {
+  await endCustomizing();
+
+  Services.prefs.clearUserPref(PREF_UI_DENSITY);
+  Services.prefs.clearUserPref(PREF_AUTO_TOUCH_MODE);
+});