Bug 1707141 - [win7] Remove theme screen from upgrade onboarding r=pdahiya
authorEd Lee <edilee@mozilla.com>
Thu, 29 Apr 2021 06:30:11 +0000
changeset 577956 0ba8c82320e1fc66292547bf856292a02ad61313
parent 577955 36de91ab59b93fecadebd915220833ba0de4ddaa
child 577957 8e0781058d1595fca8b5df1e641989302c8a5fb6
push id142170
push userelee@mozilla.com
push dateThu, 29 Apr 2021 06:32:34 +0000
treeherderautoland@0ba8c82320e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspdahiya
bugs1707141
milestone90.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1707141 - [win7] Remove theme screen from upgrade onboarding r=pdahiya Detect old windows version to change content reusing an asrouter "Okay" string for now. Differential Revision: https://phabricator.services.mozilla.com/D113583
browser/base/content/upgradeDialog.js
browser/components/tests/browser/browser_browserGlue_upgradeDialog.js
--- a/browser/base/content/upgradeDialog.js
+++ b/browser/base/content/upgradeDialog.js
@@ -1,14 +1,15 @@
 /* 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/. */
 
 const {
   AddonManager,
+  AppConstants,
   document: gDoc,
   getShellService,
   Services,
 } = window.docShell.chromeEventHandler.ownerGlobal;
 
 const SHELL = getShellService();
 const IS_DEFAULT = SHELL.isDefaultBrowser();
 const NEED_PIN = SHELL.doesAppNeedPin();
@@ -100,16 +101,19 @@ function closeDialog(reason) {
 // as otherwise gDialogBox queues the prompt as these share the same display.
 const QUIT_TOPIC = "quit-application-requested";
 const QUIT_OBSERVER = () => closeDialog(QUIT_TOPIC);
 Services.obs.addObserver(QUIT_OBSERVER, QUIT_TOPIC);
 CLEANUP.push(() => Services.obs.removeObserver(QUIT_OBSERVER, QUIT_TOPIC));
 
 // Hook up dynamic behaviors of the dialog.
 function onLoad(ready) {
+  // Change content for Windows 7 because non-light themes aren't quite right.
+  const win7Content = AppConstants.isPlatformAndVersionAtMost("win", "6.1");
+
   const title = document.getElementById("title");
   const subtitle = document.getElementById("subtitle");
   const items = document.querySelector(".items");
   const themes = document.querySelector(".themes");
   const primary = document.getElementById("primary");
   const secondary = document.getElementById("secondary");
   const steps = document.querySelector(".steps");
 
@@ -122,30 +126,52 @@ function onLoad(ready) {
     }
 
     // Move to the next screen and perform screen-specific behavior.
     switch (++current) {
       case 0:
         // Wait for main button clicks on each screen.
         primary.addEventListener("click", advance);
         secondary.addEventListener("click", advance);
+
+        // Windows 7 has a single screen so hide steps.
+        if (win7Content) {
+          steps.style.visibility = "hidden";
+
+          // If already default, reuse "Okay" for primary and hide secondary.
+          if (IS_DEFAULT) {
+            const { head } = document;
+            head.appendChild(
+              head.querySelector("[rel=localization]").cloneNode()
+            ).href = "browser/newtab/asrouter.ftl";
+            SCREEN_STRINGS[current].primary =
+              "cfr-doorhanger-doh-primary-button-2";
+            secondary.style.display = "none";
+          }
+        }
         break;
 
       case 1:
         // Handle first screen conditional actions.
         if (target === primary) {
           if (!IS_DEFAULT) {
             SHELL.setAsDefault();
           }
           SHELL.pinToTaskbar();
         } else if (target === secondary && IS_DEFAULT && !(await NEED_PIN)) {
           closeDialog("early");
           return;
         }
 
+        // First screen is the only screen for Windows 7.
+        if (win7Content) {
+          closeDialog("win7");
+          return;
+        }
+
         // Prepare the initial theme selection and wait for theme button clicks.
         const { id, swatch } = await gPrevTheme;
         themes.children[THEME_IDS.indexOf(id)].checked = true;
         themes.addEventListener("click", ({ target: button }) => {
           // Ignore clicks on whitespace of the container around theme buttons.
           if (button.parentNode === themes) {
             // Enable the theme of the corresponding button position.
             const index = [...themes.children].indexOf(button);
--- a/browser/components/tests/browser/browser_browserGlue_upgradeDialog.js
+++ b/browser/components/tests/browser/browser_browserGlue_upgradeDialog.js
@@ -8,16 +8,28 @@ const { ExperimentFakes } = ChromeUtils.
 );
 const { NimbusFeatures, ExperimentFeature } = ChromeUtils.import(
   "resource://nimbus/ExperimentAPI.jsm"
 );
 
 const BROWSER_GLUE = Cc["@mozilla.org/browser/browserglue;1"].getService()
   .wrappedJSObject;
 
+function mockAppConstants({ isWin7 }) {
+  if (mockAppConstants.value === undefined) {
+    const stub = sinon.stub(window, "AppConstants").value({
+      isPlatformAndVersionAtMost() {
+        return mockAppConstants.value;
+      },
+    });
+    registerCleanupFunction(() => stub.restore());
+  }
+  mockAppConstants.value = isWin7;
+}
+
 function waitForDialog(callback = win => win.close()) {
   return BrowserTestUtils.promiseAlertDialog(
     null,
     "chrome://browser/content/upgradeDialog.html",
     { callback, isSubDialog: true }
   );
 }
 
@@ -39,16 +51,17 @@ add_task(async function open_close_dialo
   mockShell();
 
   await showAndWaitForDialog();
 
   Assert.ok(true, "Upgrade dialog opened and closed");
 });
 
 add_task(async function set_as_default() {
+  mockAppConstants({ isWin7: false });
   const mock = mockShell();
 
   await showAndWaitForDialog(async win => {
     await BrowserTestUtils.waitForEvent(win, "ready");
     win.document.getElementById("primary").click();
     await BrowserTestUtils.waitForEvent(win, "ready");
     win.close();
   });
@@ -206,17 +219,52 @@ add_task(async function exit_early() {
     "Displayed theme button and skipped",
     ["content", "show", "0"],
     ["content", "show", "upgrade-dialog-new-primary-theme-button"],
     ["content", "button", "upgrade-dialog-new-secondary-button"],
     ["content", "close", "early"]
   );
 });
 
+add_task(async function win7_okay() {
+  mockAppConstants({ isWin7: true });
+
+  await showAndWaitForDialog(async win => {
+    await BrowserTestUtils.waitForEvent(win, "ready");
+    win.document.getElementById("primary").click();
+  });
+
+  AssertEvents(
+    "Dialog uses special windows 7 primary button",
+    ["content", "show", "0"],
+    ["content", "show", "cfr-doorhanger-doh-primary-button-2"],
+    ["content", "button", "cfr-doorhanger-doh-primary-button-2"],
+    ["content", "close", "win7"]
+  );
+});
+
+add_task(async function win7_1screen() {
+  mockShell();
+
+  await showAndWaitForDialog(async win => {
+    await BrowserTestUtils.waitForEvent(win, "ready");
+    win.document.getElementById("secondary").click();
+  });
+
+  AssertEvents(
+    "Dialog closed after Windows 7's only screen",
+    ["content", "show", "0"],
+    ["content", "show", "upgrade-dialog-new-primary-default-button"],
+    ["content", "button", "upgrade-dialog-new-secondary-button"],
+    ["content", "close", "win7"]
+  );
+});
+
 add_task(async function quit_app() {
+  mockAppConstants({ isWin7: false });
   mockShell();
 
   await showAndWaitForDialog(async win => {
     await BrowserTestUtils.waitForEvent(win, "ready");
     const cancelled = Cc["@mozilla.org/supports-PRBool;1"].createInstance(
       Ci.nsISupportsPRBool
     );
     cancelled.data = true;