Backed out changeset ee5fc34ecac4 (bug 1834298) for xpcshell failures on test_collectFormFields.js. CLOSED TREE

This commit is contained in:
Cosmin Sabou 2023-05-24 12:31:19 +03:00
Родитель c42d78b362
Коммит a8effb1df1
6 изменённых файлов: 51 добавлений и 12 удалений

Просмотреть файл

@ -938,7 +938,7 @@ function verifySectionFieldDetails(sections, expectedSectionsInfo) {
* - part: The part of the field.
* - contactType: The contact type of the field.
* - addressType: The address type of the field.
* - autofill: Set the expected autofill value when running autofill test
* - autofill: Set to true when running autofill test
*
* For more information on the field object properties, refer to the FieldDetails class.
*

Просмотреть файл

@ -36,8 +36,8 @@ add_task(async function test_parseStreetAddress() {
for (const TEST of TESTCASES) {
let [address, expected] = TEST;
const result = AddressParser.parseStreetAddress(address);
if (!expected) {
Assert.equal(result, null, "Expect failure to parse this street address");
if (!result) {
Assert.equal(null, expected, "Expect fail to parse this street address");
continue;
}

Просмотреть файл

@ -1568,11 +1568,11 @@ export class AddressesBase extends AutofillRecords {
.map(s => s.trim());
}
for (let i = 0; i < 3; i++) {
address[`address-line${i + 1}`] = streetAddress[i] || "";
address["address-line" + (i + 1)] = streetAddress[i] || "";
}
if (streetAddress.length > 3) {
address["address-line3"] = lazy.FormAutofillUtils.toOneLineAddress(
streetAddress.slice(2)
streetAddress.splice(2)
);
}
hasNewComputedFields = true;

Просмотреть файл

@ -13,6 +13,45 @@ ChromeUtils.defineESModuleGetters(lazy, {
FormAutofillUtils: "resource://gre/modules/shared/FormAutofillUtils.sys.mjs",
});
export class FormSection {
static ADDRESS = "address";
static CREDIT_CARD = "creditCard";
#fieldDetails = [];
#name = "";
constructor(fieldDetails) {
if (!fieldDetails.length) {
throw new TypeError("A section should contain at least one field");
}
fieldDetails.forEach(field => this.addField(field));
const fieldName = fieldDetails[0].fieldName;
if (lazy.FormAutofillUtils.isAddressField(fieldName)) {
this.type = FormSection.ADDRESS;
} else if (lazy.FormAutofillUtils.isCreditCardField(fieldName)) {
this.type = FormSection.CREDIT_CARD;
} else {
throw new Error("Unknown field type to create a section.");
}
}
get fieldDetails() {
return this.#fieldDetails;
}
get name() {
return this.#name;
}
addField(fieldDetail) {
this.#name ||= fieldDetail.sectionName;
this.#fieldDetails.push(fieldDetail);
}
}
/**
* Represents the detailed information about a form field, including
* the inferred field name, the approach used for inferring, and additional metadata.

Просмотреть файл

@ -15,7 +15,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
FormAutofillHeuristics:
"resource://gre/modules/shared/FormAutofillHeuristics.sys.mjs",
FormLikeFactory: "resource://gre/modules/FormLikeFactory.sys.mjs",
FormSection: "resource://gre/modules/shared/FormAutofillHeuristics.sys.mjs",
FormSection: "resource://gre/modules/shared/FieldScanner.sys.mjs",
});
const { FIELD_STATES } = FormAutofillUtils;

Просмотреть файл

@ -44,7 +44,7 @@ const MULTI_N_FIELD_NAMES = {
"cc-number": 4,
};
export class FormSection {
class Section {
static ADDRESS = "address";
static CREDIT_CARD = "creditCard";
@ -61,9 +61,9 @@ export class FormSection {
const fieldName = fieldDetails[0].fieldName;
if (lazy.FormAutofillUtils.isAddressField(fieldName)) {
this.type = FormSection.ADDRESS;
this.type = Section.ADDRESS;
} else if (lazy.FormAutofillUtils.isCreditCardField(fieldName)) {
this.type = FormSection.CREDIT_CARD;
this.type = Section.CREDIT_CARD;
} else {
throw new Error("Unknown field type to create a section.");
}
@ -575,7 +575,7 @@ export const FormAutofillHeuristics = {
*
* @param {HTMLFormElement} form
* the elements in this form to be predicted the field info.
* @returns {Array<FormSection>}
* @returns {Array<Array<object>>}
* all sections within its field details in the form.
*/
getFormInfo(form) {
@ -641,7 +641,7 @@ export const FormAutofillHeuristics = {
* The result is an array contains the sections with its belonging field details.
*
* @param {Array<FieldDetails>} fieldDetails field detail array to be classified
* @returns {Array<FormSection>} The array with the sections.
* @returns {Array<Section>} The array with the sections.
*/
_classifySections(fieldDetails) {
let sections = [];
@ -718,7 +718,7 @@ export const FormAutofillHeuristics = {
}
// Create a new section
sections.push(new FormSection([fieldDetails[i]]));
sections.push(new Section([fieldDetails[i]]));
}
return sections;