Bug 1793742 - Disable autofill prefs when locked by policy. r=tgiles,credential-management-reviewers,sgalich

Differential Revision: https://phabricator.services.mozilla.com/D158676
This commit is contained in:
Mike Kaply 2022-10-07 16:40:42 +00:00
parent 39288a2957
commit b94d158f96
3 changed files with 54 additions and 0 deletions

View file

@ -434,3 +434,37 @@ add_task(async function test_addressAutofillNotAvailableViaRegion() {
await SpecialPowers.popPrefEnv();
});
// Checkboxes should be disabled based on whether or not they are locked.
add_task(async function test_aboutPreferencesPrivacy() {
Services.prefs.lockPref(ENABLED_AUTOFILL_ADDRESSES_PREF);
Services.prefs.lockPref(ENABLED_AUTOFILL_CREDITCARDS_PREF);
registerCleanupFunction(function() {
Services.prefs.unlockPref(ENABLED_AUTOFILL_ADDRESSES_PREF);
Services.prefs.unlockPref(ENABLED_AUTOFILL_CREDITCARDS_PREF);
});
let finalPrefPaneLoaded = TestUtils.topicObserved(
"sync-pane-loaded",
() => true
);
await BrowserTestUtils.withNewTab(
{ gBrowser, url: PAGE_PRIVACY },
async function(browser) {
await finalPrefPaneLoaded;
await SpecialPowers.spawn(browser, [SELECTORS], selectors => {
is(
content.document.querySelector(selectors.addressAutofillCheckbox)
.disabled,
true,
"Autofill addresses checkbox should be disabled"
);
is(
content.document.querySelector(selectors.creditCardAutofillCheckbox)
.disabled,
true,
"Autofill credit cards checkbox should be disabled"
);
});
}
);
});

View file

@ -147,6 +147,13 @@ var FormAutofill = {
FormAutofill._isAutofillCreditCardsEnabled
);
},
/**
* Determines if credit card autofill is locked by policy.
* @returns {boolean} `true` if credit card autofill is locked
*/
get isAutofillCreditCardsLocked() {
return Services.prefs.prefIsLocked(ENABLED_AUTOFILL_CREDITCARDS_PREF);
},
/**
* Determines if the user has enabled or disabled address autofill.
* @returns {boolean} `true` if address autofill is enabled
@ -157,6 +164,13 @@ var FormAutofill = {
FormAutofill._isAutofillAddressesEnabled
);
},
/**
* Determines if address autofill is locked by policy.
* @returns {boolean} `true` if address autofill is locked
*/
get isAutofillAddressesLocked() {
return Services.prefs.prefIsLocked(ENABLED_AUTOFILL_ADDRESSES_PREF);
},
defineLogGetter(scope, logPrefix) {
scope.debug = debug;

View file

@ -164,6 +164,9 @@ FormAutofillPreferences.prototype = {
if (FormAutofill.isAutofillAddressesEnabled) {
addressAutofillCheckbox.setAttribute("checked", true);
}
if (FormAutofill.isAutofillAddressesLocked) {
addressAutofillCheckbox.disabled = true;
}
addressAutofillCheckboxGroup.setAttribute("align", "center");
addressAutofillCheckboxGroup.setAttribute("flex", "1");
@ -229,6 +232,9 @@ FormAutofillPreferences.prototype = {
if (FormAutofill.isAutofillCreditCardsEnabled) {
creditCardAutofillCheckbox.setAttribute("checked", true);
}
if (FormAutofill.isAutofillCreditCardsLocked) {
creditCardAutofillCheckbox.disabled = true;
}
creditCardAutofillCheckboxGroup.setAttribute("align", "center");
creditCardAutofillCheckboxGroup.setAttribute("flex", "1");