Bug 1329631 - Only automatically open login manager autocomplete upon first marking. r=daleharvey draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 11 Jan 2017 18:03:42 -0800
changeset 459489 837aaf46c8d33756441da26064d71e39bb54c562
parent 457200 ab220a16bda2b85da7106362fb17f4af5c1cc6ef
child 541907 6d92294c4b82e76c1a375d3606b8745d30d0d4b3
push id41234
push usermozilla@noorenberghe.ca
push dateThu, 12 Jan 2017 02:04:45 +0000
reviewersdaleharvey
bugs1329631
milestone53.0a1
Bug 1329631 - Only automatically open login manager autocomplete upon first marking. r=daleharvey MozReview-Commit-ID: EnKmOSjs6G4
toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html
toolkit/components/satchel/nsFormFillController.cpp
--- a/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html
@@ -57,14 +57,33 @@ add_task(function* setup() {
   });
 
   iframeDoc = iframe.contentDocument;
 });
 
 add_task(function* test_initial_focus() {
   let results = yield notifyMenuChanged(2, "name");
   checkArrayValues(results, ["name", "name1"], "Two results");
+  doKey("down");
+  doKey("return");
+  yield promiseFormsProcessed();
+  is(iframeDoc.getElementById("form-basic-password").value, "pass", "Check first password filled")
+  let popupState = yield getPopupState();
+  is(popupState.open, false, "Check popup is now closed");
+});
+
+add_task(function* test_not_reopened_after_selecting() {
+  let formFillController = SpecialPowers.Cc["@mozilla.org/satchel/form-fill-controller;1"].
+                           getService(SpecialPowers.Ci.nsIFormFillController);
+let usernameField = iframeDoc.getElementById("form-basic-username");
+  listenForUnexpectedPopupShown()
+  formFillController.markAsLoginManagerField(usernameField);
+  SimpleTest.requestFlakyTimeout("Giving a chance for the unexpected popupshown to occur");
+  yield new Promise(resolve => setTimeout(resolve, 1000));
+
+  // cleanup
+  gPopupShownExpected = true;
 });
 
 </script>
 </pre>
 </body>
 </html>
--- a/toolkit/components/satchel/nsFormFillController.cpp
+++ b/toolkit/components/satchel/nsFormFillController.cpp
@@ -269,16 +269,22 @@ nsFormFillController::MarkAsLoginManager
    * The Login Manager can supply autocomplete results for username fields,
    * when a user has multiple logins stored for a site. It uses this
    * interface to indicate that the form manager shouldn't handle the
    * autocomplete. The form manager also checks for this tag when saving
    * form history (so it doesn't save usernames).
    */
   nsCOMPtr<nsINode> node = do_QueryInterface(aInput);
   NS_ENSURE_STATE(node);
+
+  // If the field was already marked, we don't want to show the popup again.
+  if (mPwmgrInputs.Get(node)) {
+    return NS_OK;
+  }
+
   mPwmgrInputs.Put(node, true);
   node->AddMutationObserverUnlessExists(this);
 
   nsFocusManager *fm = nsFocusManager::GetFocusManager();
   if (fm) {
     nsCOMPtr<nsIContent> focusedContent = fm->GetFocusedContent();
     if (SameCOMIdentity(focusedContent, node)) {
       nsCOMPtr<nsIDOMHTMLInputElement> input = do_QueryInterface(node);