Bug 1350264 - Allow users to re-enable form autofill feature after all populated fields were cleared manually, r=lchang draft
authorsteveck-chung <schung@mozilla.com>
Thu, 15 Jun 2017 16:31:51 +0800
changeset 594636 cbf258fd4a61959b04c6fde7e754a4479279c2e7
parent 593198 5293e5f8935831e2e0d91ac9b69c1b473b3c0177
child 633479 e741f6de29859932de09427a2eee5551ec9886f7
push id64092
push userbmo:schung@mozilla.com
push dateThu, 15 Jun 2017 08:32:25 +0000
reviewerslchang
bugs1350264
milestone56.0a1
Bug 1350264 - Allow users to re-enable form autofill feature after all populated fields were cleared manually, r=lchang MozReview-Commit-ID: DG31YXJuT2t
browser/extensions/formautofill/FormAutofillHandler.jsm
browser/extensions/formautofill/test/mochitest/test_basic_autocomplete_form.html
--- a/browser/extensions/formautofill/FormAutofillHandler.jsm
+++ b/browser/extensions/formautofill/FormAutofillHandler.jsm
@@ -171,20 +171,21 @@ FormAutofillHandler.prototype = {
 
         if (e.target == element || (e.target == element.form && e.type == "reset")) {
           this.changeFieldState(fieldDetail, "NORMAL");
         }
 
         hasFilledFields |= (fieldDetail.state == "AUTO_FILLED");
       }
 
-      // Unregister listeners once no field is in AUTO_FILLED state.
+      // Unregister listeners and clear guid once no field is in AUTO_FILLED state.
       if (!hasFilledFields) {
         this.form.rootElement.removeEventListener("input", onChangeHandler);
         this.form.rootElement.removeEventListener("reset", onChangeHandler);
+        this.filledProfileGUID = null;
       }
     };
 
     this.form.rootElement.addEventListener("input", onChangeHandler);
     this.form.rootElement.addEventListener("reset", onChangeHandler);
   },
 
   /**
--- a/browser/extensions/formautofill/test/mochitest/test_basic_autocomplete_form.html
+++ b/browser/extensions/formautofill/test/mochitest/test_basic_autocomplete_form.html
@@ -150,16 +150,28 @@ add_task(async function check_fields_aft
 // Fallback to history search after autofill address.
 add_task(async function check_fallback_after_form_autofill() {
   await setInput("#tel", "");
   doKey("down");
   await expectPopup();
   checkMenuEntries(["1-234-567-890"]);
 });
 
+// Resume form autofill once all the autofilled fileds are changed.
+add_task(async function check_form_autofill_resume() {
+  document.querySelector("#tel").blur();
+  document.querySelector("#form1").reset();
+  await setInput("#tel", "");
+  doKey("down");
+  await expectPopup();
+  checkMenuEntries(MOCK_STORAGE.map(address =>
+    JSON.stringify({primary: address.tel, secondary: address["street-address"]})
+  ));
+});
+
 registerPopupShownListener(popupShownListener);
 
 </script>
 
 <p id="display"></p>
 
 <div id="content">