Commit a640bbd7 authored by Tim Giles's avatar Tim Giles
Browse files

Bug 1745248 - Add form autofill pref migration and tests. r=dimi,sgalich

Depends on D133820

Differential Revision: https://phabricator.services.mozilla.com/D135553
parent aa79b283
Loading
Loading
Loading
Loading
+37 −1
Original line number Diff line number Diff line
@@ -3404,7 +3404,7 @@ BrowserGlue.prototype = {
  _migrateUI: function BG__migrateUI() {
    // Use an increasing number to keep track of the current migration state.
    // Completely unrelated to the current Firefox release number.
    const UI_VERSION = 122;
    const UI_VERSION = 124;
    const BROWSER_DOCURL = AppConstants.BROWSER_CHROME_URL;

    const PROFILE_DIR = Services.dirsvc.get("ProfD", Ci.nsIFile).path;
@@ -4126,6 +4126,42 @@ BrowserGlue.prototype = {
    // Bug 1745248: Due to multiple backouts, do not use UI Version 123
    // as this version is most likely set for the Nightly channel

    if (currentUIVersion < 124) {
      // Migrate "extensions.formautofill.available" and
      // "extensions.formautofill.creditCards.available" from old to new prefs
      const oldFormAutofillModule = "extensions.formautofill.available";
      const oldCreditCardsAvailable =
        "extensions.formautofill.creditCards.available";
      const newCreditCardsAvailable =
        "extensions.formautofill.creditCards.supported";
      const newAddressesAvailable =
        "extensions.formautofill.addresses.supported";
      if (Services.prefs.prefHasUserValue(oldFormAutofillModule)) {
        let moduleAvailability = Services.prefs.getCharPref(
          oldFormAutofillModule
        );
        if (moduleAvailability == "on") {
          Services.prefs.setCharPref(newAddressesAvailable, moduleAvailability);
          Services.prefs.setCharPref(
            newCreditCardsAvailable,
            Services.prefs.getBoolPref(oldCreditCardsAvailable) ? "on" : "off"
          );
        }

        if (moduleAvailability == "off") {
          Services.prefs.setCharPref(
            newCreditCardsAvailable,
            moduleAvailability
          );
          Services.prefs.setCharPref(newAddressesAvailable, moduleAvailability);
        }
      }

      // after migrating, clear old prefs so we can remove them later.
      Services.prefs.clearUserPref(oldFormAutofillModule);
      Services.prefs.clearUserPref(oldCreditCardsAvailable);
    }

    // Update the migration version.
    Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
  },
+142 −0
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TOPIC_BROWSERGLUE_TEST = "browser-glue-test";
const TOPICDATA_BROWSERGLUE_TEST = "force-ui-migration";

const gBrowserGlue = Cc["@mozilla.org/browser/browserglue;1"].getService(
  Ci.nsIObserver
);
const UI_VERSION = 124;

function ensureOldPrefsAreCleared() {
  Assert.ok(
    !Services.prefs.prefHasUserValue("extensions.formautofill.available"),
    "main module available pref should have been cleared"
  );
  Assert.ok(
    !Services.prefs.prefHasUserValue(
      "extensions.formautofill.creditCards.available"
    ),
    "old credit card available pref should have been cleared"
  );
}

add_task(async function setup() {
  registerCleanupFunction(() => {
    Services.prefs.clearUserPref("browser.migration.version");
    Services.prefs.clearUserPref("extensions.formautofill.available");
    Services.prefs.clearUserPref(
      "extensions.formautofill.creditCards.available"
    );
    Services.prefs.clearUserPref(
      "extensions.formautofill.creditCards.supported"
    );
  });
});

add_task(async function test_check_form_autofill_module_detect() {
  Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1);
  Services.prefs.setCharPref("extensions.formautofill.available", "detect");
  // Simulate a migration.
  gBrowserGlue.observe(
    null,
    TOPIC_BROWSERGLUE_TEST,
    TOPICDATA_BROWSERGLUE_TEST
  );
  // old credit card available should migrate to "detect" due to
  // "extensions.formautofill.available" being "detect".
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"),
    "detect"
  );
  // old address available pref follows the main module pref
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.addresses.supported"),
    "detect"
  );
  ensureOldPrefsAreCleared();
});

add_task(async function test_check_old_form_autofill_module_off() {
  Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1);
  Services.prefs.setCharPref("extensions.formautofill.available", "off");

  // Simulate a migration.
  gBrowserGlue.observe(
    null,
    TOPIC_BROWSERGLUE_TEST,
    TOPICDATA_BROWSERGLUE_TEST
  );

  // old credit card available should migrate to off due to
  // "extensions.formautofill.available" being off.
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"),
    "off"
  );
  // old address available pref follows the main module pref
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.addresses.supported"),
    "off"
  );
  ensureOldPrefsAreCleared();
});

add_task(async function test_check_old_form_autofill_module_on_cc_on() {
  Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1);
  Services.prefs.setCharPref("extensions.formautofill.available", "on");
  Services.prefs.setBoolPref(
    "extensions.formautofill.creditCards.available",
    true
  );

  // Simulate a migration.
  gBrowserGlue.observe(
    null,
    TOPIC_BROWSERGLUE_TEST,
    TOPICDATA_BROWSERGLUE_TEST
  );

  // old credit card available should migrate to "on" due to
  // "extensions.formautofill.available" being on and
  // "extensions.formautofill.creditCards.available" having a default value of true.
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"),
    "on"
  );
  // old address available pref follows the main module pref
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.addresses.supported"),
    "on"
  );
  ensureOldPrefsAreCleared();
});

add_task(async function test_check_old_form_autofill_module_on_cc_off() {
  Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1);
  Services.prefs.setCharPref("extensions.formautofill.available", "on");
  Services.prefs.setBoolPref(
    "extensions.formautofill.creditCards.available",
    false
  );

  // Simulate a migration.
  gBrowserGlue.observe(
    null,
    TOPIC_BROWSERGLUE_TEST,
    TOPICDATA_BROWSERGLUE_TEST
  );

  // old credit card available should migrate to "off" due to
  // "extensions.formautofill.available" being on and
  // "extensions.formautofill.creditCards.available" having a user set value of false.
  Assert.equal(
    Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"),
    "off"
  );

  ensureOldPrefsAreCleared();
});
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ skip-if = toolkit == 'android' # bug 1730213
support-files =
  distribution.ini

[test_browserGlue_migration_formautofill.js]
[test_browserGlue_migration_places_xulstore.js]
[test_browserGlue_migration_ctrltab_recently_used_order.js]
[test_distribution.js]
+2 −1
Original line number Diff line number Diff line
@@ -21,7 +21,8 @@ skip-if =
  (!debug && os == "mac") # perma-fail see Bug 1600059
  win10_2004 # Bug 1723573
[browser_first_time_use_doorhanger.js]
skip-if = verify || (!debug && os == "mac") # perma-fail see Bug 1600059
skip-if = 
  verify || (!debug && os == "mac") # perma-fail see Bug 1600059
[browser_manageAddressesDialog.js]
skip-if = !debug && os == "mac" # perma-fail see Bug 1600059
[browser_privacyPreferences.js]