bug 1463797 - Added a method to hit enter to save passwords while password box is focused and test. r?MattN
MozReview-Commit-ID: GxyRyOP4dd6
--- a/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
+++ b/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
@@ -831,16 +831,17 @@ LoginManagerPrompter.prototype = {
});
let chromeDoc = browser.ownerDocument;
let currentNotification;
let updateButtonStatus = (element) => {
let mainActionButton = element.button;
+ this.mainActionButton = mainActionButton;
// Disable the main button inside the menu-button if the password field is empty.
if (login.password.length == 0) {
mainActionButton.setAttribute("disabled", true);
chromeDoc.getElementById("password-notification-password")
.classList.add("popup-notification-invalid-input");
} else {
mainActionButton.removeAttribute("disabled");
chromeDoc.getElementById("password-notification-password")
@@ -900,16 +901,22 @@ LoginManagerPrompter.prototype = {
chromeDoc.getElementById("password-notification-password").value;
};
let onInput = () => {
readDataFromUI();
updateButtonLabel();
};
+ let handleSubmit = (e) => {
+ if (e.keyCode == 13) {
+ this.mainActionButton.click();
+ }
+ };
+
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;
passwordField.setAttribute("type", commandEvent.target.checked ? "" : "password");
if (!passwordField.hasAttribute("focused")) {
return;
@@ -1022,16 +1029,18 @@ LoginManagerPrompter.prototype = {
chromeDoc.getElementById("password-notification-password")
.removeAttribute("focused");
chromeDoc.getElementById("password-notification-username")
.removeAttribute("focused");
chromeDoc.getElementById("password-notification-username")
.addEventListener("input", onInput);
chromeDoc.getElementById("password-notification-password")
.addEventListener("input", onInput);
+ chromeDoc.getElementById("password-notification-password")
+ .addEventListener("keyup", handleSubmit);
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());
}
@@ -1050,16 +1059,18 @@ LoginManagerPrompter.prototype = {
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")
.removeEventListener("command", onVisibilityToggle);
+ chromeDoc.getElementById("password-notification-password")
+ .removeEventListener("keyup", handleSubmit);
break;
}
return false;
},
}
);
},
--- a/toolkit/components/passwordmgr/test/browser/browser_capture_doorhanger.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_capture_doorhanger.js
@@ -568,16 +568,59 @@ add_task(async function test_recipeCaptu
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
is(login.username, "notifyu1", "Check the username unchanged");
is(login.password, "notifyp1", "Check the password unchanged");
is(login.timesUsed, 2, "Check times used incremented");
Services.logins.removeAllLogins();
});
+add_task(async function test_saveUsingEnter() {
+ await testSubmittingLoginForm("subtst_notifications_1.html", async function(fieldValues) {
+ is(fieldValues.username, "notifyu1", "Checking submitted username");
+ is(fieldValues.password, "notifyp1", "Checking submitted password");
+ let notif = getCaptureDoorhanger("password-save");
+ ok(notif, "got notification popup");
+
+ is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
+
+ await checkDoorhangerUsernamePassword("notifyu1", "notifyp1");
+ document.getElementById("password-notification-password").focus();
+ await EventUtils.synthesizeKey("KEY_Enter");
+
+ });
+
+ let logins = Services.logins.getAllLogins();
+ is(logins.length, 1, "Should only have 1 login");
+ let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
+ is(login.username, "notifyu1", "Check the username used on the new entry");
+ is(login.password, "notifyp1", "Check the password used on the new entry");
+ is(login.timesUsed, 1, "Check times used on new entry");
+
+ info("Make sure Remember took effect and we don't prompt for an existing login");
+ await testSubmittingLoginForm("subtst_notifications_1.html", function(fieldValues) {
+ is(fieldValues.username, "notifyu1", "Checking submitted username");
+ is(fieldValues.password, "notifyp1", "Checking submitted password");
+ let notif = getCaptureDoorhanger("password-save");
+ ok(!notif, "checking for no notification popup");
+ });
+
+ logins = Services.logins.getAllLogins();
+ is(logins.length, 1, "Should only have 1 login");
+ login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
+ is(login.username, "notifyu1", "Check the username used");
+ is(login.password, "notifyp1", "Check the password used");
+ is(login.timesUsed, 2, "Check times used incremented");
+
+ checkOnlyLoginWasUsedTwice({ justChanged: false });
+
+ // remove that login
+ Services.logins.removeLogin(login1);
+});
+
add_task(async function test_noShowPasswordOnDismissal() {
info("Check for no Show Password field when the doorhanger is dismissed");
await testSubmittingLoginForm("subtst_notifications_1.html", async function(fieldValues) {
info("Opening popup");
let notif = getCaptureDoorhanger("password-save");
let { panel } = PopupNotifications;