Bug 1329631 - Only automatically open login manager autocomplete upon first marking. r=daleharvey
MozReview-Commit-ID: EnKmOSjs6G4
--- 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);