Bug 1419724 - Explicitly make searchString consistent with autocompleteController as form autofill goes different route to fill the value. r=MattN
MozReview-Commit-ID: BpoGAyWlT7q
--- a/browser/extensions/formautofill/FormAutofillContent.jsm
+++ b/browser/extensions/formautofill/FormAutofillContent.jsm
@@ -27,16 +27,19 @@ XPCOMUtils.defineLazyModuleGetter(this,
"resource://formautofill/FormAutofillHandler.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "FormLikeFactory",
"resource://gre/modules/FormLikeFactory.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "InsecurePasswordUtils",
"resource://gre/modules/InsecurePasswordUtils.jsm");
const formFillController = Cc["@mozilla.org/satchel/form-fill-controller;1"]
.getService(Ci.nsIFormFillController);
+const autocompleteController = Cc["@mozilla.org/autocomplete/controller;1"]
+ .getService(Ci.nsIAutoCompleteController);
+
const {ADDRESSES_COLLECTION_NAME, CREDITCARDS_COLLECTION_NAME, FIELD_STATES} = FormAutofillUtils;
// Register/unregister a constructor as a factory.
function AutocompleteFactory() {}
AutocompleteFactory.prototype = {
register(targetConstructor) {
let proto = targetConstructor.prototype;
this._classID = proto.classID;
@@ -288,19 +291,22 @@ let ProfileAutocomplete = {
let selectedIndex = this._getSelectedIndex(focusedInput.ownerGlobal);
if (selectedIndex == -1 ||
!this.lastProfileAutoCompleteResult ||
this.lastProfileAutoCompleteResult.getStyleAt(selectedIndex) != "autofill-profile") {
return;
}
let profile = JSON.parse(this.lastProfileAutoCompleteResult.getCommentAt(selectedIndex));
+ let {fieldName} = FormAutofillContent.getInputDetails(focusedInput);
let formHandler = FormAutofillContent.getFormHandler(focusedInput);
- formHandler.autofillFormFields(profile, focusedInput);
+ formHandler.autofillFormFields(profile, focusedInput).then(() => {
+ autocompleteController.searchString = profile[fieldName];
+ });
},
_clearProfilePreview() {
let focusedInput = formFillController.focusedInput || this.lastProfileAutoCompleteFocusedInput;
if (!focusedInput || !FormAutofillContent.getFormDetails(focusedInput)) {
return;
}
@@ -516,16 +522,17 @@ var FormAutofillContent = {
clearForm() {
let focusedInput = formFillController.focusedInput || ProfileAutocomplete._lastAutoCompleteFocusedInput;
if (!focusedInput) {
return;
}
let formHandler = this.getFormHandler(focusedInput);
formHandler.clearPopulatedForm(focusedInput);
+ autocompleteController.searchString = "";
},
previewProfile(doc) {
let docWin = doc.ownerGlobal;
let selectedIndex = ProfileAutocomplete._getSelectedIndex(docWin);
let lastAutoCompleteResult = ProfileAutocomplete.lastProfileAutoCompleteResult;
let focusedInput = formFillController.focusedInput;
let mm = this._messageManagerFromWindow(docWin);
--- a/browser/extensions/formautofill/test/mochitest/test_basic_autocomplete_form.html
+++ b/browser/extensions/formautofill/test/mochitest/test_basic_autocomplete_form.html
@@ -137,27 +137,29 @@ add_task(async function check_search_res
await expectPopup();
checkMenuEntries(["+1234567890"], false);
await SpecialPowers.popPrefEnv();
});
// Autofill the address from dropdown menu.
add_task(async function check_fields_after_form_autofill() {
- await setInput("#organization", "Moz");
+ const focusedInput = await setInput("#organization", "Moz");
doKey("down");
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(address =>
JSON.stringify({
primary: address.organization,
secondary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
})
).slice(1));
doKey("down");
await triggerAutofillAndCheckProfile(MOCK_STORAGE[1]);
+ doKey("escape");
+ is(focusedInput.value, "Mozilla", "Filled field shouldn't be reverted by ESC key");
});
// Fallback to history search after autofill address.
add_task(async function check_fallback_after_form_autofill() {
await setInput("#tel", "", true);
doKey("down");
await expectPopup();
checkMenuEntries(["+1234567890"], false);