From edf52b9061079fd376de7e8af8a9c1b5331f37da Mon Sep 17 00:00:00 2001 From: Jared Wein Date: Wed, 19 Apr 2017 18:52:22 -0400 Subject: [PATCH] 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 --HG-- extra : rebase_source : 5d1b25ebde5a0cf8849210315c773bf25c10e7a3 --- .../preferences/in-content/privacy.js | 21 ++++++++ .../preferences/in-content/tests/browser.ini | 1 + .../tests/browser_masterpassword.js | 54 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 browser/components/preferences/in-content/tests/browser_masterpassword.js diff --git a/browser/components/preferences/in-content/privacy.js b/browser/components/preferences/in-content/privacy.js index 97d0a1c6cdfd..f2801b79f423 100644 --- a/browser/components/preferences/in-content/privacy.js +++ b/browser/components/preferences/in-content/privacy.js @@ -959,6 +959,27 @@ var gPrivacyPane = { 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. diff --git a/browser/components/preferences/in-content/tests/browser.ini b/browser/components/preferences/in-content/tests/browser.ini index 58aaa4a22c33..c45b9cf9fc58 100644 --- a/browser/components/preferences/in-content/tests/browser.ini +++ b/browser/components/preferences/in-content/tests/browser.ini @@ -29,6 +29,7 @@ skip-if = os != "win" # This test tests the windows-specific app selection dialo 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] diff --git a/browser/components/preferences/in-content/tests/browser_masterpassword.js b/browser/components/preferences/in-content/tests/browser_masterpassword.js new file mode 100644 index 000000000000..e30b99b76e8d --- /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); +});