Bug 1357905 - Add missing _removeMasterPassword function that got lost in the re-org, as well as a test to confirm that the master password functionality works. r?mossop
I checked each function of the old security.js to make sure there weren't any other missing functions.
MozReview-Commit-ID: DpFcAYsfcyg
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -954,16 +954,37 @@ var gPrivacyPane = {
if (!checkbox.checked)
this._removeMasterPassword();
else
this.changeMasterPassword();
this._initMasterPasswordUI();
},
+ /**
+ * Displays the "remove master password" dialog to allow the user to remove
+ * the current master password. When the dialog is dismissed, master password
+ * UI is automatically updated.
+ */
+ _removeMasterPassword() {
+ var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].
+ getService(Ci.nsIPKCS11ModuleDB);
+ if (secmodDB.isFIPSEnabled) {
+ var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
+ getService(Ci.nsIPromptService);
+ var bundle = document.getElementById("bundlePreferences");
+ promptService.alert(window,
+ bundle.getString("pw_change_failed_title"),
+ bundle.getString("pw_change2empty_in_fips_mode"));
+ this._initMasterPasswordUI();
+ } else {
+ gSubDialog.open("chrome://mozapps/content/preferences/removemp.xul",
+ null, null, this._initMasterPasswordUI.bind(this));
+ }
+ },
/**
* Displays a dialog in which the master password may be changed.
*/
changeMasterPassword() {
gSubDialog.open("chrome://mozapps/content/preferences/changemp.xul",
"resizable=no", null, this._initMasterPasswordUI.bind(this));
},
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -24,16 +24,17 @@ skip-if = os != "win" # This test tests
[browser_connection.js]
[browser_connection_bug388287.js]
[browser_cookies_exceptions.js]
[browser_defaultbrowser_alwayscheck.js]
[browser_healthreport.js]
skip-if = true || !healthreport # Bug 1185403 for the "true"
[browser_homepages_filter_aboutpreferences.js]
[browser_layersacceleration.js]
+[browser_masterpassword.js]
[browser_notifications_do_not_disturb.js]
[browser_permissions_urlFieldHidden.js]
[browser_proxy_backup.js]
[browser_privacypane_1.js]
[browser_privacypane_3.js]
[browser_privacypane_4.js]
[browser_privacypane_5.js]
[browser_privacypane_8.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_masterpassword.js
@@ -0,0 +1,54 @@
+add_task(function*() {
+ let prefs = yield openPreferencesViaOpenPreferencesAPI("panePrivacy", {leaveOpen: true});
+ is(prefs.selectedPane, "panePrivacy", "Privacy pane was selected");
+
+ let doc = gBrowser.contentDocument;
+ // Fake the subdialog and LoginHelper
+ let win = doc.defaultView;
+ let dialogURL = "";
+ win.gSubDialog = {
+ open(aDialogURL, unused, unused2, aCallback) {
+ dialogURL = aDialogURL;
+ masterPasswordSet = masterPasswordNextState;
+ aCallback();
+ }
+ };
+ let masterPasswordSet = false;
+ win.LoginHelper = {
+ isMasterPasswordSet() {
+ return masterPasswordSet;
+ }
+ };
+
+ let checkbox = doc.querySelector("#useMasterPassword");
+ ok(!checkbox.checked, "master password checkbox should be unchecked by default");
+ let button = doc.getElementById("changeMasterPassword");
+ ok(button.disabled, "master password button should be disabled by default");
+
+ let masterPasswordNextState = true;
+ checkbox.click();
+ is(dialogURL,
+ "chrome://mozapps/content/preferences/changemp.xul",
+ "clicking on the checkbox should open the masterpassword dialog");
+ ok(!button.disabled, "master password button should now be enabled");
+ ok(checkbox.checked, "master password checkbox should be checked now");
+
+ dialogURL = "";
+ button.doCommand();
+ is(dialogURL,
+ "chrome://mozapps/content/preferences/changemp.xul",
+ "clicking on the button should open the masterpassword dialog");
+ ok(!button.disabled, "master password button should still be enabled");
+ ok(checkbox.checked, "master password checkbox should be checked still");
+
+ masterPasswordNextState = false;
+ dialogURL = "";
+ checkbox.click();
+ is(dialogURL,
+ "chrome://mozapps/content/preferences/removemp.xul",
+ "clicking on the checkbox to uncheck master password should show the removal dialog");
+ ok(button.disabled, "master password button should now be disabled");
+ ok(!checkbox.checked, "master password checkbox should now be unchecked");
+
+ yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});