Bug 1190938 - SHOW disappearing & password field staying selected under doorhanger; r?MattN draft
authorFred Lin <gasolin@mozilla.com>
Mon, 15 Aug 2016 14:58:22 +0800
changeset 400571 96f2b76e8ba48721b6b7008080dbba7a5657acaf
parent 400535 2e6551eb6c8e01fdff689b148d60ca7f2807b66b
child 528252 ebc3ddef93592eb85a6f05f1fdeeae8a9f7b5a6c
push id26201
push userbmo:gasolin@mozilla.com
push dateMon, 15 Aug 2016 07:04:57 +0000
reviewersMattN
bugs1190938
milestone51.0a1
Bug 1190938 - SHOW disappearing & password field staying selected under doorhanger; r?MattN MozReview-Commit-ID: 3gI809FgFJv
toolkit/components/passwordmgr/nsLoginManagerPrompter.js
toolkit/components/passwordmgr/test/browser/browser_capture_doorhanger.js
--- a/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
+++ b/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
@@ -816,41 +816,41 @@ LoginManagerPrompter.prototype = {
                     .find(n => n.notification == currentNotification);
       if (element) {
         element.setAttribute("buttonlabel", label);
         element.setAttribute("buttonaccesskey", accessKey);
         updateButtonStatus(element);
       }
     };
 
-    let writeDataToUI = () => {
+    let restoreDataToUI = () => {
       // setAttribute is used since the <textbox> binding may not be attached yet.
       chromeDoc.getElementById("password-notification-username")
                .setAttribute("placeholder", usernamePlaceholder);
       chromeDoc.getElementById("password-notification-username")
                .setAttribute("value", login.username);
 
       let toggleCheckbox = chromeDoc.getElementById("password-notification-visibilityToggle");
       toggleCheckbox.removeAttribute("checked");
       let passwordField = chromeDoc.getElementById("password-notification-password");
       // Ensure the type is reset so the field is masked.
       passwordField.setAttribute("type", "password");
       passwordField.setAttribute("value", login.password);
       updateButtonLabel();
     };
 
-    let readDataFromUI = () => {
+    let storeDataFromUI = () => {
       login.username =
         chromeDoc.getElementById("password-notification-username").value;
       login.password =
         chromeDoc.getElementById("password-notification-password").value;
     };
 
     let onInput = () => {
-      readDataFromUI();
+      storeDataFromUI();
       updateButtonLabel();
     };
 
     let onVisibilityToggle = (commandEvent) => {
       let passwordField = chromeDoc.getElementById("password-notification-password");
       // Gets the caret position before changing the type of the textbox
       let selectionStart = passwordField.selectionStart;
       let selectionEnd = passwordField.selectionEnd;
@@ -900,17 +900,17 @@ LoginManagerPrompter.prototype = {
       label: this._getLocalizedString(initialMsgNames.buttonLabel),
       accessKey: this._getLocalizedString(initialMsgNames.buttonAccessKey),
       callback: () => {
         histogram.add(PROMPT_ADD_OR_UPDATE);
         if (histogramName == "PWMGR_PROMPT_REMEMBER_ACTION")
         {
           Services.obs.notifyObservers(null, 'LoginStats:NewSavedPassword', null);
         }
-        readDataFromUI();
+        storeDataFromUI();
         persistData();
         browser.focus();
       }
     };
 
     // Include a "Never for this site" button when saving a new password.
     let secondaryActions = type == "password-save" ? [{
       label: this._getLocalizedString("notifyBarNeverRememberButtonText"),
@@ -939,38 +939,41 @@ LoginManagerPrompter.prototype = {
         displayURI: Services.io.newURI(login.hostname, null, null),
         persistWhileVisible: true,
         passwordNotificationType: type,
         eventCallback: function (topic) {
           switch (topic) {
             case "showing":
               currentNotification = this;
               chromeDoc.getElementById("password-notification-username")
+                       .removeAttribute("focused");
+              chromeDoc.getElementById("password-notification-password")
+                       .removeAttribute("focused");
+              chromeDoc.getElementById("password-notification-username")
                        .addEventListener("input", onInput);
               chromeDoc.getElementById("password-notification-password")
                        .addEventListener("input", onInput);
               let toggleBtn = chromeDoc.getElementById("password-notification-visibilityToggle");
 
               if (Services.prefs.getBoolPref("signon.rememberSignons.visibilityToggle")) {
                 toggleBtn.addEventListener("command", onVisibilityToggle);
                 toggleBtn.setAttribute("label", togglePasswordLabel);
                 toggleBtn.setAttribute("accesskey", togglePasswordAccessKey);
                 toggleBtn.setAttribute("hidden", LoginHelper.isMasterPasswordSet());
               }
-              if (this.wasDismissed) {
-                chromeDoc.getElementById("password-notification-visibilityToggle")
-                         .setAttribute("hidden", true);
-              }
               break;
             case "shown":
-              writeDataToUI();
+              restoreDataToUI();
               break;
             case "dismissed":
               this.wasDismissed = true;
-              readDataFromUI();
+
+              chromeDoc.getElementById("password-notification-visibilityToggle")
+                       .setAttribute("hidden", true);
+              storeDataFromUI();
               // Fall through.
             case "removed":
               currentNotification = null;
               chromeDoc.getElementById("password-notification-username")
                        .removeEventListener("input", onInput);
               chromeDoc.getElementById("password-notification-password")
                        .removeEventListener("input", onInput);
               chromeDoc.getElementById("password-notification-visibilityToggle")
--- a/toolkit/components/passwordmgr/test/browser/browser_capture_doorhanger.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_capture_doorhanger.js
@@ -569,17 +569,17 @@ add_task(function* test_noShowPasswordOn
     yield promiseHidden;
 
     info("Clicking on anchor to reshow popup.")
     let promiseShown = BrowserTestUtils.waitForEvent(panel, "popupshown");
     notif.anchorElement.click();
     yield promiseShown;
 
     let passwordVisiblityToggle = panel.querySelector("#password-notification-visibilityToggle");
-    is(passwordVisiblityToggle.hidden, true, "Check that the Show Password field is Hidden");
+    ok(!passwordVisiblityToggle.hidden, "Check that the Show Password field is shown");
   });
 });
 
 add_task(function* test_httpsUpgradeCaptureFields_noChange() {
   info("Check that we don't prompt to remember when capturing an upgraded login with no change");
   Services.logins.addLogin(login1);
   // Sanity check the HTTP login exists.
   let logins = Services.logins.getAllLogins();