Commit 6d967268 authored by Nipun Shukla's avatar Nipun Shukla
Browse files

Bug 1893341 - Change Firefox launch on login to use Windows StartupTask...

Bug 1893341 - Change Firefox launch on login to use Windows StartupTask functions on MSIX r=nalexander,nrishel,settings-reviewers,omc-reviewers,firefox-desktop-core-reviewers ,aminomancer

Differential Revision: https://phabricator.services.mozilla.com/D208567
parent b2052c98
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -1312,9 +1312,11 @@ BrowserGlue.prototype = {
            );
          }
          Services.prefs.setBoolPref(launchOnLoginPref, false);
          // Only remove registry key, not shortcut here as we can assume
          // if a user manually created a shortcut they want this behavior.
          await lazy.WindowsLaunchOnLogin.removeLaunchOnLoginRegistryKey();
          // To reduce confusion when running multiple Gecko profiles,
          // delete launch on login shortcuts and registry keys so that
          // users are not presented with the outdated profile selector
          // dialog.
          lazy.WindowsLaunchOnLogin.removeLaunchOnLogin();
        }
        break;
      }
+2 −2
Original line number Diff line number Diff line
@@ -986,7 +986,7 @@ const BASE_MESSAGES = () => [
    targeting: `source == 'newtab'
    && 'browser.startup.windowsLaunchOnLogin.disableLaunchOnLoginPrompt'|preferenceValue == false
    && 'browser.startup.windowsLaunchOnLogin.enabled'|preferenceValue == true && isDefaultBrowser && !activeNotifications
    && !launchOnLoginEnabled && !isMSIX`,
    && !launchOnLoginEnabled`,
  },
  {
    id: "INFOBAR_LAUNCH_ON_LOGIN_FINAL",
@@ -1054,7 +1054,7 @@ const BASE_MESSAGES = () => [
    && messageImpressions.INFOBAR_LAUNCH_ON_LOGIN[messageImpressions.INFOBAR_LAUNCH_ON_LOGIN | length - 1]
    && messageImpressions.INFOBAR_LAUNCH_ON_LOGIN[messageImpressions.INFOBAR_LAUNCH_ON_LOGIN | length - 1] <
      currentDate|date - ${FOURTEEN_DAYS_IN_MS}
    && !launchOnLoginEnabled && !isMSIX`,
    && !launchOnLoginEnabled`,
  },
  {
    id: "FOX_DOODLE_SET_DEFAULT",
+18 −12
Original line number Diff line number Diff line
@@ -439,8 +439,7 @@ var gMainPane = {
      if (
        Cc["@mozilla.org/toolkit/profile-service;1"].getService(
          Ci.nsIToolkitProfileService
        ).startWithLastProfile &&
        !Services.sysinfo.getProperty("hasWinPackageId", false)
        ).startWithLastProfile
      ) {
        NimbusFeatures.windowsLaunchOnLogin.recordExposureEvent({
          once: true,
@@ -693,12 +692,16 @@ var gMainPane = {
        let launchOnLoginCheckbox = document.getElementById(
          "windowsLaunchOnLogin"
        );
        launchOnLoginCheckbox.checked =
          WindowsLaunchOnLogin.getLaunchOnLoginEnabled();
        let approvedByWindows = WindowsLaunchOnLogin.getLaunchOnLoginApproved();
        WindowsLaunchOnLogin.getLaunchOnLoginEnabled().then(enabled => {
          launchOnLoginCheckbox.checked = enabled;
        });
        WindowsLaunchOnLogin.getLaunchOnLoginApproved().then(
          approvedByWindows => {
            launchOnLoginCheckbox.disabled = !approvedByWindows;
            document.getElementById("windowsLaunchOnLoginDisabledBox").hidden =
              approvedByWindows;
          }
        );

        // On Windows, the Application Update setting is an installation-
        // specific preference, not a profile-specific one. Show a warning to
@@ -1647,16 +1650,19 @@ var gMainPane = {
      return;
    }
    if (event.target.checked) {
      // windowsLaunchOnLogin has been checked: create registry key
      WindowsLaunchOnLogin.createLaunchOnLoginRegistryKey();
      // windowsLaunchOnLogin has been checked: create registry key or shortcut
      // The shortcut is created with the same AUMID as Firefox itself. However,
      // this is not set during browser tests and the fallback of checking the
      // registry fails. As such we pass an arbitrary AUMID for the purpose
      // of testing.
      await WindowsLaunchOnLogin.createLaunchOnLogin();
      Services.prefs.setBoolPref(
        "browser.startup.windowsLaunchOnLogin.disableLaunchOnLoginPrompt",
        true
      );
    } else {
      // windowsLaunchOnLogin has been unchecked: delete registry key and shortcut
      WindowsLaunchOnLogin.removeLaunchOnLoginRegistryKey();
      await WindowsLaunchOnLogin.removeLaunchOnLoginShortcuts();
      await WindowsLaunchOnLogin.removeLaunchOnLogin();
    }
  },

+4 −1
Original line number Diff line number Diff line
@@ -296,4 +296,7 @@ support-files = [
["browser_warning_permanent_private_browsing.js"]

["browser_windows_launch_on_login.js"]
run-if = ["(os == 'win' && !msix)"] # Disabled for MSIX due to https://bugzilla.mozilla.org/show_bug.cgi?id=1888263
run-if = ["(os == 'win' && !msix)"]

["browser_windows_launch_on_login_msix.js"]
run-if = ["(os == 'win' && msix)"]
+31 −20
Original line number Diff line number Diff line
@@ -18,7 +18,25 @@ const { ExperimentFakes } = ChromeUtils.importESModule(
  "resource://testing-common/NimbusTestUtils.sys.mjs"
);

add_task(async function test_check_checkbox() {
const { MockRegistry } = ChromeUtils.importESModule(
  "resource://testing-common/MockRegistry.sys.mjs"
);

let registry = null;
add_setup(() => {
  registry = new MockRegistry();
  registry.setValue(
    Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
    "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
    "",
    ""
  );
  registerCleanupFunction(() => {
    registry.shutdown();
  });
});

add_task(async function test_check_uncheck_checkbox() {
  await ExperimentAPI.ready();
  let doCleanup = await ExperimentFakes.enrollWithFeatureConfig({
    featureId: "windowsLaunchOnLogin",
@@ -40,25 +58,6 @@ add_task(async function test_check_checkbox() {
      "Key exists"
    );

    gBrowser.removeCurrentTab();
  });
  await doCleanup();
});

add_task(async function test_uncheck_checkbox() {
  await ExperimentAPI.ready();
  let doCleanup = await ExperimentFakes.enrollWithFeatureConfig({
    featureId: "windowsLaunchOnLogin",
    value: { enabled: true },
  });
  await WindowsLaunchOnLogin.withLaunchOnLoginRegistryKey(async wrk => {
    // Open preferences to general pane
    await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
      leaveOpen: true,
    });
    let doc = gBrowser.contentDocument;

    let launchOnLoginCheckbox = doc.getElementById("windowsLaunchOnLogin");
    launchOnLoginCheckbox.click();
    ok(!launchOnLoginCheckbox.checked, "Autostart checkbox unchecked");

@@ -73,12 +72,20 @@ add_task(async function test_uncheck_checkbox() {
});

add_task(async function create_external_regkey() {
  if (Services.sysinfo.getProperty("hasWinPackageId")) {
    return;
  }
  await ExperimentAPI.ready();
  let doCleanup = await ExperimentFakes.enrollWithFeatureConfig({
    featureId: "windowsLaunchOnLogin",
    value: { enabled: true },
  });
  await WindowsLaunchOnLogin.withLaunchOnLoginRegistryKey(async wrk => {
    // Delete any existing entries before testing
    // Both functions are install specific so it's safe to run them
    // like this.
    wrk.removeValue(WindowsLaunchOnLogin.getLaunchOnLoginRegistryName());
    await WindowsLaunchOnLogin.removeLaunchOnLoginShortcuts();
    // Create registry key without using settings pane to check if
    // this is reflected in the settings
    let autostartPath =
@@ -108,6 +115,9 @@ add_task(async function create_external_regkey() {
});

add_task(async function delete_external_regkey() {
  if (Services.sysinfo.getProperty("hasWinPackageId")) {
    return;
  }
  await ExperimentAPI.ready();
  let doCleanup = await ExperimentFakes.enrollWithFeatureConfig({
    featureId: "windowsLaunchOnLogin",
@@ -136,6 +146,7 @@ add_task(async function delete_external_regkey() {
});

registerCleanupFunction(async function () {
  await WindowsLaunchOnLogin.removeLaunchOnLoginShortcuts();
  await WindowsLaunchOnLogin.withLaunchOnLoginRegistryKey(async wrk => {
    let registryName = WindowsLaunchOnLogin.getLaunchOnLoginRegistryName();
    if (wrk.hasValue(registryName)) {
Loading