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 draft
authorJared Wein <jwein@mozilla.com>
Wed, 19 Apr 2017 18:52:22 -0400
changeset 565498 5669b940057620d6f6fe4507aff07e866b3d9d30
parent 565395 396fcbf226af59d9f6330029e25f1f453c2910a3
child 625007 3be35344e14b0cc7f8687c9eda5e1e9d9b00e1bd
push id54885
push userbmo:jaws@mozilla.com
push dateWed, 19 Apr 2017 22:53:12 +0000
reviewersmossop
bugs1357905
milestone55.0a1
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
browser/components/preferences/in-content/privacy.js
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_masterpassword.js
--- 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);
+});