Bug 1612161 - Don't treat tab in username/password field as auto-completion when the field value is empty. r=MattN
authorSam Foster <sfoster@mozilla.com>
Sat, 15 Feb 2020 01:49:20 +0000
changeset 514164 4e23ae638ed5dd2ec29250d979e6822336aa1934
parent 514163 9db39cd56bbaca8884e6c74f543dc85295598bf6
child 514165 73e8de4ba422027abe7d077d44628587bfb5ed5f
push id37125
push usershindli@mozilla.com
push dateSat, 15 Feb 2020 09:56:17 +0000
treeherdermozilla-central@02b1aa498dd2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1612161
milestone75.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1612161 - Don't treat tab in username/password field as auto-completion when the field value is empty. r=MattN Differential Revision: https://phabricator.services.mozilla.com/D61933
toolkit/components/passwordmgr/LoginManagerChild.jsm
toolkit/components/passwordmgr/test/mochitest/test_autocomplete_tab_between_fields.html
--- a/toolkit/components/passwordmgr/LoginManagerChild.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerChild.jsm
@@ -276,18 +276,19 @@ const observer = {
             docState.fieldModificationsByRootElement.set(formLikeRoot, true);
           }
         }
         break;
       }
 
       case "keydown": {
         if (
-          aEvent.keyCode == aEvent.DOM_VK_TAB ||
-          aEvent.keyCode == aEvent.DOM_VK_RETURN
+          aEvent.target.value &&
+          (aEvent.keyCode == aEvent.DOM_VK_TAB ||
+            aEvent.keyCode == aEvent.DOM_VK_RETURN)
         ) {
           LoginManagerChild.forWindow(window).onUsernameAutocompleted(
             aEvent.target
           );
         }
         break;
       }
 
--- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_tab_between_fields.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_tab_between_fields.html
@@ -43,16 +43,18 @@ async function prepareLogins(logins = []
   is(count, logins.length, "All logins were added");
 }
 
 const availableLogins = {
   "exampleUser1": new nsLoginInfo("https://example.com", "https://autofill", null,
                               "user1", "pass1", "uname", "pword"),
   "subdomainUser1": new nsLoginInfo("https://sub.example.com", "https://autofill", null,
                               "user1", "pass1", "uname", "pword"),
+  "emptyUsername": new nsLoginInfo("https://example.com", "https://autofill", null,
+                              "", "pass2", "uname", "pword"),
 }
 
 const tests = [
   {
     name: "single_login_exact_origin_no_inputs",
     logins: ["exampleUser1"],
     expectedAutofillUsername: "user1",
     expectedAutofillPassword: "pass1",
@@ -96,16 +98,26 @@ const tests = [
     logins: ["subdomainUser1"],
     expectedAutofillUsername: "",
     expectedAutofillPassword: "",
     expectedACLabels: ["user1"],
     typeUsername: "user1",
     expectedTabbedUsername: "user1",
     expectedTabbedPassword: "",
   },
+  {
+    name: "two_logins_one_with_empty_username",
+    logins: ["exampleUser1", "emptyUsername"],
+    expectedAutofillUsername: "user1",
+    expectedAutofillPassword: "pass1",
+    expectedACLabels: ["user1"],
+    typeUsername: "",
+    expectedTabbedUsername: "",
+    expectedTabbedPassword: "",
+  },
 ];
 
 add_task(async function setup() {
   await SpecialPowers.pushPrefEnv({"set": [["signon.includeOtherSubdomainsInLookup", true]]});
   ok(readyPromise, "check promise is available");
   await readyPromise;
 });