Skip to content

Commit

Permalink
Bug 1793742 - Disable autofill prefs when locked by policy. r=tgiles,…
Browse files Browse the repository at this point in the history
…credential-management-reviewers,sgalich

Differential Revision: https://phabricator.services.mozilla.com/D158676
  • Loading branch information
mkaply committed Oct 7, 2022
1 parent 39288a2 commit b94d158
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
});
}
);
});
14 changes: 14 additions & 0 deletions toolkit/components/formautofill/FormAutofill.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions toolkit/components/formautofill/FormAutofillPreferences.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b94d158

Please sign in to comment.