Bug 1882587 - Check supportedRegions as well as experiment flags for address autofill. r=dimi

Differential Revision: https://phabricator.services.mozilla.com/D203034
This commit is contained in:
Issam Mani 2024-02-29 09:16:16 +00:00
parent e31798198b
commit 35dadda521
3 changed files with 86 additions and 21 deletions

View file

@ -14,7 +14,10 @@ const { FormAutofill } = ChromeUtils.importESModule(
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [["extensions.formautofill.addresses.experiments.enabled", false]],
set: [
["extensions.formautofill.addresses.experiments.enabled", false],
["extensions.formautofill.addresses.supportedCountries", "FR"],
],
});
});

View file

@ -11,21 +11,31 @@ const { FormAutofill } = ChromeUtils.importESModule(
"resource://autofill/FormAutofill.sys.mjs"
);
add_setup(async () => {
Services.prefs.setBoolPref(
"extensions.formautofill.addresses.experiments.enabled",
false
);
registerCleanupFunction(function cleanupRegion() {
Services.prefs.clearUserPref(
"extensions.formautofill.addresses.experiments.enabled"
);
});
});
add_task(async function test_defaultTestEnvironment() {
Assert.equal(
Services.prefs.getCharPref("extensions.formautofill.addresses.supported"),
"on"
);
Assert.equal(
Services.prefs.getBoolPref(
"extensions.formautofill.addresses.experiments.enabled"
),
true
);
});
add_task(async function test_default_supported_address_region() {
add_task(async function test_default_supported_module_and_autofill_region() {
Services.prefs.setCharPref("browser.search.region", "US");
registerCleanupFunction(function cleanupRegion() {
Services.prefs.clearUserPref("browser.search.region");
});
let addon = await AddonManager.getAddonByID(EXTENSION_ID);
await addon.reload();
@ -33,15 +43,44 @@ add_task(async function test_default_supported_address_region() {
Assert.equal(FormAutofill.isAutofillAddressesEnabled, true);
});
add_task(async function test_unsupported_address_region() {
const addon = await AddonManager.getAddonByID(EXTENSION_ID);
add_task(
async function test_supported_creditCard_region_unsupported_address_region() {
Services.prefs.setCharPref(
"extensions.formautofill.addresses.supported",
"detect"
);
Services.prefs.setCharPref(
"extensions.formautofill.creditCards.supported",
"detect"
);
Services.prefs.setCharPref("browser.search.region", "FR");
Services.prefs.setCharPref(
"extensions.formautofill.addresses.supportedCountries",
"US,CA"
);
Services.prefs.setCharPref(
"extensions.formautofill.creditCards.supportedCountries",
"US,CA,FR"
);
registerCleanupFunction(function cleanupPrefs() {
Services.prefs.clearUserPref("browser.search.region");
Services.prefs.clearUserPref(
"extensions.formautofill.addresses.supportedCountries"
);
Services.prefs.clearUserPref(
"extensions.formautofill.addresses.supported"
);
Services.prefs.clearUserPref(
"extensions.formautofill.creditCards.supported"
);
});
Services.prefs.setBoolPref(
"extensions.formautofill.addresses.experiments.enabled",
false
);
await addon.reload();
Assert.equal(FormAutofill.isAutofillAddressesAvailable, false);
Assert.equal(FormAutofill.isAutofillAddressesEnabled, false);
});
let addon = await AddonManager.getAddonByID(EXTENSION_ID);
await addon.reload();
Assert.ok(
Services.prefs.getBoolPref("extensions.formautofill.creditCards.enabled")
);
Assert.equal(FormAutofill.isAutofillAddressesAvailable, false);
Assert.equal(FormAutofill.isAutofillAddressesEnabled, false);
}
);

View file

@ -98,6 +98,29 @@ export const FormAutofill = {
FormAutofill._creditCardAutofillSupportedCountries
);
},
/**
* Determines if the address autofill feature is available to use in the browser.
* If the feature is not available, then there are no user facing ways to enable it.
* Two conditions must be met for the autofill feature to be considered available:
* 1. Address autofill support is confirmed when:
* - `extensions.formautofill.addresses.supported` is set to `on`.
* - The user is located in a region supported by the feature
* (`extensions.formautofill.creditCards.supportedCountries`).
* 2. Address autofill is enabled through a Nimbus experiment:
* - The experiment pref `extensions.formautofill.addresses.experiments.enabled` is set to true.
*
* @returns {boolean} `true` if address autofill is available
*/
get isAutofillAddressesAvailable() {
const isUserInSupportedRegion = this._isSupportedRegion(
FormAutofill._isAutofillAddressesAvailable,
FormAutofill._addressAutofillSupportedCountries
);
return (
isUserInSupportedRegion ||
FormAutofill._isAutofillAddressesAvailableInExperiment
);
},
/**
* Determines if the user has enabled or disabled credit card autofill.
*
@ -262,7 +285,7 @@ XPCOMUtils.defineLazyPreferenceGetter(
XPCOMUtils.defineLazyPreferenceGetter(
FormAutofill,
"isAutofillAddressesAvailable",
"_isAutofillAddressesAvailableInExperiment",
"extensions.formautofill.addresses.experiments.enabled"
);