forked from mirrors/gecko-dev
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:
parent
e31798198b
commit
35dadda521
3 changed files with 86 additions and 21 deletions
|
|
@ -14,7 +14,10 @@ const { FormAutofill } = ChromeUtils.importESModule(
|
||||||
|
|
||||||
add_setup(async function () {
|
add_setup(async function () {
|
||||||
await SpecialPowers.pushPrefEnv({
|
await SpecialPowers.pushPrefEnv({
|
||||||
set: [["extensions.formautofill.addresses.experiments.enabled", false]],
|
set: [
|
||||||
|
["extensions.formautofill.addresses.experiments.enabled", false],
|
||||||
|
["extensions.formautofill.addresses.supportedCountries", "FR"],
|
||||||
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,21 +11,31 @@ const { FormAutofill } = ChromeUtils.importESModule(
|
||||||
"resource://autofill/FormAutofill.sys.mjs"
|
"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() {
|
add_task(async function test_defaultTestEnvironment() {
|
||||||
Assert.equal(
|
Assert.equal(
|
||||||
Services.prefs.getCharPref("extensions.formautofill.addresses.supported"),
|
Services.prefs.getCharPref("extensions.formautofill.addresses.supported"),
|
||||||
"on"
|
"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);
|
let addon = await AddonManager.getAddonByID(EXTENSION_ID);
|
||||||
await addon.reload();
|
await addon.reload();
|
||||||
|
|
||||||
|
|
@ -33,15 +43,44 @@ add_task(async function test_default_supported_address_region() {
|
||||||
Assert.equal(FormAutofill.isAutofillAddressesEnabled, true);
|
Assert.equal(FormAutofill.isAutofillAddressesEnabled, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(async function test_unsupported_address_region() {
|
add_task(
|
||||||
const addon = await AddonManager.getAddonByID(EXTENSION_ID);
|
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(
|
let addon = await AddonManager.getAddonByID(EXTENSION_ID);
|
||||||
"extensions.formautofill.addresses.experiments.enabled",
|
await addon.reload();
|
||||||
false
|
Assert.ok(
|
||||||
);
|
Services.prefs.getBoolPref("extensions.formautofill.creditCards.enabled")
|
||||||
|
);
|
||||||
await addon.reload();
|
Assert.equal(FormAutofill.isAutofillAddressesAvailable, false);
|
||||||
Assert.equal(FormAutofill.isAutofillAddressesAvailable, false);
|
Assert.equal(FormAutofill.isAutofillAddressesEnabled, false);
|
||||||
Assert.equal(FormAutofill.isAutofillAddressesEnabled, false);
|
}
|
||||||
});
|
);
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,29 @@ export const FormAutofill = {
|
||||||
FormAutofill._creditCardAutofillSupportedCountries
|
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.
|
* Determines if the user has enabled or disabled credit card autofill.
|
||||||
*
|
*
|
||||||
|
|
@ -262,7 +285,7 @@ XPCOMUtils.defineLazyPreferenceGetter(
|
||||||
|
|
||||||
XPCOMUtils.defineLazyPreferenceGetter(
|
XPCOMUtils.defineLazyPreferenceGetter(
|
||||||
FormAutofill,
|
FormAutofill,
|
||||||
"isAutofillAddressesAvailable",
|
"_isAutofillAddressesAvailableInExperiment",
|
||||||
"extensions.formautofill.addresses.experiments.enabled"
|
"extensions.formautofill.addresses.experiments.enabled"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue