Bug 1411190 - Collect and parse only eligible fields in form autofill heuristics. r=seanlee, lchang
MozReview-Commit-ID: GWp0cU5jt6k
--- a/browser/extensions/formautofill/FormAutofillHeuristics.jsm
+++ b/browser/extensions/formautofill/FormAutofillHeuristics.jsm
@@ -534,21 +534,24 @@ this.FormAutofillHeuristics = {
* the elements in this form to be predicted the field info.
* @param {boolean} allowDuplicates
* true to remain any duplicated field details otherwise to remove the
* duplicated ones.
* @returns {Array<Object>}
* all field details in the form.
*/
getFormInfo(form, allowDuplicates = false) {
- if (form.elements.length <= 0) {
+ const eligibleFields = Array.from(form.elements)
+ .filter(elem => FormAutofillUtils.isFieldEligibleForAutofill(elem));
+
+ if (eligibleFields.length <= 0) {
return [];
}
- let fieldScanner = new FieldScanner(form.elements);
+ let fieldScanner = new FieldScanner(eligibleFields);
while (!fieldScanner.parsingFinished) {
let parsedPhoneFields = this._parsePhoneFields(fieldScanner);
let parsedAddressFields = this._parseAddressFields(fieldScanner);
let parsedExpirationDateFields = this._parseCreditCardExpirationDateFields(fieldScanner);
// If there is no any field parsed, the parsing cursor can be moved
// forward to the next one.
if (!parsedPhoneFields && !parsedAddressFields && !parsedExpirationDateFields) {
@@ -624,20 +627,16 @@ this.FormAutofillHeuristics = {
FormAutofillUtils.isAutofillCreditCardsAvailable,
isSelectElem
);
return regexps;
},
getInfo(element) {
- if (!FormAutofillUtils.isFieldEligibleForAutofill(element)) {
- return null;
- }
-
let info = element.getAutocompleteInfo();
// An input[autocomplete="on"] will not be early return here since it stll
// needs to find the field name.
if (info && info.fieldName && info.fieldName != "on" && info.fieldName != "off") {
info._reason = "autocomplete";
return info;
}
--- a/browser/extensions/formautofill/test/unit/test_getInfo.js
+++ b/browser/extensions/formautofill/test/unit/test_getInfo.js
@@ -153,22 +153,16 @@ const TESTCASES = [
expectedReturnValue: {
fieldName: "name",
section: "",
addressType: "",
contactType: "",
},
},
{
- description: "non-input element",
- document: `<label id="targetElement">street</label>`,
- elementId: "targetElement",
- expectedReturnValue: null,
- },
- {
description: "input element with \"submit\" type",
document: `<input id="targetElement" type="submit" />`,
elementId: "targetElement",
expectedReturnValue: null,
},
{
description: "The signature in 'name' attr of an email input",
document: `<input id="targetElement" name="email" type="number">`,