Bug 1834298 - Some clean ups in formautofill r=credential-management-reviewers,sgalich

Differential Revision: https://phabricator.services.mozilla.com/D178655
This commit is contained in:
Dimi 2023-05-24 07:06:55 +00:00
Родитель a8effb1df1
Коммит 983f2fe411
6 изменённых файлов: 12 добавлений и 51 удалений

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

@ -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 to true when running autofill test
* - autofill: Set the expected autofill value 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 (!result) {
Assert.equal(null, expected, "Expect fail to parse this street address");
if (!expected) {
Assert.equal(result, null, "Expect failure 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.splice(2)
streetAddress.slice(2)
);
}
hasNewComputedFields = true;

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

@ -13,45 +13,6 @@ 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/FieldScanner.sys.mjs",
FormSection: "resource://gre/modules/shared/FormAutofillHeuristics.sys.mjs",
});
const { FIELD_STATES } = FormAutofillUtils;

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

@ -44,7 +44,7 @@ const MULTI_N_FIELD_NAMES = {
"cc-number": 4,
};
class Section {
export class FormSection {
static ADDRESS = "address";
static CREDIT_CARD = "creditCard";
@ -61,9 +61,9 @@ class Section {
const fieldName = fieldDetails[0].fieldName;
if (lazy.FormAutofillUtils.isAddressField(fieldName)) {
this.type = Section.ADDRESS;
this.type = FormSection.ADDRESS;
} else if (lazy.FormAutofillUtils.isCreditCardField(fieldName)) {
this.type = Section.CREDIT_CARD;
this.type = FormSection.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<Array<object>>}
* @returns {Array<FormSection>}
* 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<Section>} The array with the sections.
* @returns {Array<FormSection>} The array with the sections.
*/
_classifySections(fieldDetails) {
let sections = [];
@ -718,7 +718,7 @@ export const FormAutofillHeuristics = {
}
// Create a new section
sections.push(new Section([fieldDetails[i]]));
sections.push(new FormSection([fieldDetails[i]]));
}
return sections;