Backed out changeset f2d5c6c6d0cd (bug 1840584) for causing failures in browser_capture_name.js CLOSED TREE

This commit is contained in:
Noemi Erli 2023-07-07 16:43:50 +03:00
Родитель 1b3921b744
Коммит 00bbb7cd04
8 изменённых файлов: 9 добавлений и 478 удалений

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

@ -33,8 +33,6 @@ skip-if = ((os == "mac") || (os == 'linux') || (os == 'win'))
skip-if = ((!debug && os == "mac") || (os == 'linux') || (os == 'win'))
[browser_creditCard_heuristics.js]
skip-if = apple_silicon && !debug # Bug 1714221
[browser_creditCard_heuristics_autofill_name.js]
skip-if = apple_silicon && !debug # Bug 1714221
[browser_creditCard_heuristics_cc_type.js]
skip-if = apple_silicon && !debug # Bug 1714221
[browser_creditCard_submission_autodetect_type.js]

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

@ -1,215 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_PROFILE = {
"cc-name": "John Doe",
"cc-number": "4111111111111111",
// "cc-type" should be remove from proile after fixing Bug 1834768.
"cc-type": "visa",
"cc-exp-month": 4,
"cc-exp-year": new Date().getFullYear(),
};
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [
["extensions.formautofill.creditCards.supported", "on"],
["extensions.formautofill.creditCards.enabled", true],
],
});
});
add_autofill_heuristic_tests([
{
description: `cc-number + first name with autocomplete attribute`,
fixtureData: `
<form>
<input id="cc-number" autocomplete="cc-number">
<input id="name" autocomplete="given-name">
</form>`,
profile: TEST_PROFILE,
expectedResult: [
{
fields: [
{
fieldName: "cc-number",
reason: "autocomplete",
autofill: TEST_PROFILE["cc-number"],
},
],
},
{
invalid: true,
fields: [
{
fieldName: "given-name",
reason: "autocomplete",
},
],
},
],
},
{
description: `cc-number + first name`,
fixtureData: `
<form>
<input id="cc-number" autocomplete="cc-number">
<input id="name" placeholder="given-name">
</form>`,
profile: TEST_PROFILE,
expectedResult: [
{
fields: [
{
fieldName: "cc-number",
reason: "autocomplete",
autofill: TEST_PROFILE["cc-number"],
},
{
fieldName: "cc-name",
reason: "update-heuristic",
autofill: TEST_PROFILE["cc-name"],
},
],
},
],
},
{
description: `cc-exp + first name`,
fixtureData: `
<form>
<input id="cc-number" autocomplete="cc-number">
<input id="cc-exp" autocomplete="cc-exp">
<input id="name" placeholder="given-name">
</form>`,
profile: TEST_PROFILE,
expectedResult: [
{
fields: [
{
fieldName: "cc-number",
reason: "autocomplete",
autofill: TEST_PROFILE["cc-number"],
},
{
fieldName: "cc-exp",
reason: "autocomplete",
autofill: TEST_PROFILE["cc-exp"],
},
{
fieldName: "cc-name",
reason: "update-heuristic",
autofill: TEST_PROFILE["cc-name"],
},
],
},
],
},
{
description: `cc-number + first and last name with autocomplete attribute`,
fixtureData: `
<form>
<input id="cc-number" autocomplete="cc-number">
<input id="given" autocomplete="given-name">
<input id="family" autocomplete="family-name">
</form>`,
profile: TEST_PROFILE,
expectedResult: [
{
fields: [
{
fieldName: "cc-number",
reason: "autocomplete",
autofill: TEST_PROFILE["cc-number"],
},
],
},
{
invalid: true,
fields: [
{
fieldName: "given-name",
reason: "autocomplete",
},
{
fieldName: "family-name",
reason: "autocomplete",
},
],
},
],
},
{
description: `cc-number + first and last name`,
fixtureData: `
<form>
<input id="cc-number" autocomplete="cc-number">
<input id="given" placeholder="First Name">
<input id="family" placeholder="Last Name">
</form>`,
profile: TEST_PROFILE,
expectedResult: [
{
fields: [
{
fieldName: "cc-number",
reason: "autocomplete",
autofill: TEST_PROFILE["cc-number"],
},
{
fieldName: "cc-given-name",
reason: "update-heuristic",
autofill: "John",
},
{
fieldName: "cc-family-name",
reason: "update-heuristic",
autofill: "Doe",
},
],
},
],
},
{
description: `previous field is a credit card name field`,
fixtureData: `
<form>
<input id="cc-number" autocomplete="cc-number">
<input id="cc-name" autocomplete="cc-name">
<input id="given" placeholder="given-name">
<input id="family" placeholder="family-name">
<input id="address" placeholder="street-address">
<input id="country" placeholder="country">
</form>`,
profile: TEST_PROFILE,
expectedResult: [
{
fields: [
{
fieldName: "cc-number",
reason: "autocomplete",
autofill: TEST_PROFILE["cc-number"],
},
{
fieldName: "cc-name",
reason: "autocomplete",
autofill: TEST_PROFILE["cc-name"],
},
],
},
{
default: {
reason: "regex-heuristic",
},
fields: [
{ fieldName: "given-name" },
{ fieldName: "family-name" },
{ fieldName: "street-address" },
{ fieldName: "country" },
],
},
],
},
]);

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

@ -845,7 +845,7 @@ function verifySectionAutofillResult(sections, expectedSectionsInfo) {
Assert.equal(
field.element.value,
expeceted.autofill ?? "",
expeceted.autofill,
`Autofilled value for element(id=${field.element.id}, field name=${field.fieldName}) should be equal`
);
});
@ -1060,10 +1060,6 @@ async function add_heuristic_tests(
if (obj.verifyAutofill) {
for (const section of sections) {
if (!section.isValidSection()) {
continue;
}
section.focusedInput = section.fieldDetails[0].element;
await section.autofillFields(
section.getAdaptedProfiles([obj.testPattern.profile])[0]

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

@ -7,7 +7,6 @@ support-files =
[browser_autocomplete_off_on_form.js]
[browser_autocomplete_off_on_inputs.js]
[browser_basic.js]
[browser_capture_name.js]
[browser_cc_exp.js]
[browser_de_fields.js]
[browser_fr_fields.js]

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

@ -1,150 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* import-globals-from ../head.js */
"use strict";
const TESTCASES = [
{
description: `cc fields + first name with autocomplete attribute`,
document: `<form id="form">
<input id="cc-number" autocomplete="cc-number">
<input id="cc-exp" autocomplete="cc-exp">
<input id="name" autocomplete="given-name">
<input type="submit"/>
</form>`,
fillValues: {
"#cc-number": "4111111111111111",
"#cc-exp": "12/24",
"#name": "John Doe",
},
expected: undefined,
},
{
description: `cc fields + first name without autocomplete attribute`,
document: `<form id="form">
<input id="cc-number" autocomplete="cc-number">
<input id="cc-exp" autocomplete="cc-exp">
<input id="name" placeholder="given-name">
<input type="submit"/>
</form>`,
fillValues: {
"#cc-number": "4111111111111111",
"#cc-exp": "12/24",
"#name": "John Doe",
},
expected: "John Doe",
},
{
description: `cc fields + first and last name with autocomplete attribute`,
document: `<form id="form">
<input id="cc-number" autocomplete="cc-number">
<input id="cc-exp" autocomplete="cc-exp">
<input id="given" autocomplete="given-name">
<input id="family" autocomplete="family-name">
<input type="submit"/>
</form>`,
fillValues: {
"#cc-number": "4111111111111111",
"#cc-exp": "12/24",
"#given": "John",
"#family": "Doe",
},
expected: undefined,
},
{
description: `cc fields + first and last name without autocomplete attribute`,
document: `<form id="form">
<input id="cc-number" autocomplete="cc-number">
<input id="cc-exp" autocomplete="cc-exp">
<input id="given" placeholder="given-name">
<input id="family" placeholder="family-name">
<input type="submit"/>
</form>`,
fillValues: {
"#cc-number": "4111111111111111",
"#cc-exp": "12/24",
"#given": "John",
"#family": "Doe",
},
expected: "John Doe",
},
{
description: `cc fields + cc-name + first and last name`,
document: `<form id="form">
<input id="cc-number" autocomplete="cc-number">
<input id="cc-name" autocomplete="cc-name">
<input id="cc-exp" autocomplete="cc-exp">
<input id="given" placeholder="given-name">
<input id="family" placeholder="family-name">
<input type="submit"/>
</form>`,
fillValues: {
"#cc-number": "4111111111111111",
"#cc-name": "Jane Poe",
"#cc-exp": "12/24",
"#given": "John",
"#family": "Doe",
},
expected: "Jane Poe",
},
{
description: `first and last name + cc fields`,
document: `<form id="form">
<input id="given" placeholder="given-name">
<input id="family" placeholder="family-name">
<input id="cc-number" autocomplete="cc-number">
<input id="cc-exp" autocomplete="cc-exp">
<input type="submit"/>
</form>`,
fillValues: {
"#cc-number": "4111111111111111",
"#cc-exp": "12/24",
"#given": "John",
"#family": "Doe",
},
expected: undefined,
},
];
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [
["extensions.formautofill.creditCards.supported", "on"],
["extensions.formautofill.creditCards.enabled", true],
],
});
});
add_task(async function test_save_doorhanger_click_save() {
for (const TEST of TESTCASES) {
info(`Test ${TEST.description}`);
let onChanged = waitForStorageChangedEvents("add");
await BrowserTestUtils.withNewTab(EMPTY_URL, async function (browser) {
await SpecialPowers.spawn(browser, [TEST.document], doc => {
// eslint-disable-next-line no-unsanitized/property
content.document.body.innerHTML = doc;
});
await SimpleTest.promiseFocus(browser);
let onPopupShown = waitForPopupShown();
await focusUpdateSubmitForm(browser, {
focusSelector: "#cc-number",
newValues: TEST.fillValues,
});
await onPopupShown;
await clickDoorhangerButton(MAIN_BUTTON);
});
await onChanged;
let creditCards = await getCreditCards();
is(creditCards.length, 1, "1 credit card in storage");
is(creditCards[0]["cc-name"], TEST.expected, "Verify the name field");
await removeAllRecords();
}
});

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

@ -41,9 +41,6 @@ add_heuristic_tests(
fields: [
{ fieldName: "cc-exp-month" },
{ fieldName: "cc-exp-year" },
// TODO: Consider using neghbor address fields as an indicator these are not cc fields
{ fieldName: "cc-given-name", reason: "update-heuristic" },
{ fieldName: "cc-family-name", reason: "update-heuristic" },
{ fieldName: "cc-number" },
],
},
@ -52,6 +49,8 @@ add_heuristic_tests(
reason: "regex-heuristic",
},
fields: [
{ fieldName: "given-name" },
{ fieldName: "family-name" },
{ fieldName: "organization" },
{ fieldName: "address-line1" },
{ fieldName: "address-line2" },

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

@ -393,6 +393,9 @@ export const FormAutofillHeuristics = {
return true;
},
// The old heuristics can be removed when we fully adopt fathom, so disable the
// esline complexity check for now
/* eslint-disable complexity */
/**
* Try to look for expiration date fields and revise the field names if needed.
*
@ -453,73 +456,6 @@ export const FormAutofillHeuristics = {
return false;
},
/**
* Look for cc-*-name fields when *-name field is present
*
* @param {FieldScanner} scanner
* The current parsing status for all elements
* @returns {boolean}
* Return true if there is any field can be recognized in the parser,
* otherwise false.
*/
_parseCreditCardNameFields(scanner, fieldDetail) {
const INTERESTED_FIELDS = [
"name",
"given-name",
"additional-name",
"family-name",
];
if (!INTERESTED_FIELDS.includes(fieldDetail.fieldName)) {
return false;
}
const fields = [];
for (let idx = scanner.parsingIndex; !scanner.parsingFinished; idx++) {
const detail = scanner.getFieldDetailByIndex(idx);
if (!INTERESTED_FIELDS.includes(detail?.fieldName)) {
break;
}
fields.push(detail);
}
const prevCCFields = [];
for (
let idx = scanner.parsingIndex - 1;
scanner.parsingFinished >= 0;
idx--
) {
const detail = scanner.getFieldDetailByIndex(idx);
if (
lazy.FormAutofillUtils.getCategoryFromFieldName(detail?.fieldName) !=
"creditCard"
) {
break;
}
prevCCFields.push(detail.fieldName);
}
// If the previous elements are credit card fields and there is no cc-name field,
// we assume the name field is a cc-name field
if (!prevCCFields.length || prevCCFields.includes("cc-name")) {
return false;
}
// If there is only one field, assume the name field a `cc-name` field
if (fields.length == 1) {
scanner.updateFieldName(scanner.parsingIndex, `cc-name`);
scanner.parsingIndex += 1;
} else {
// update *-name to cc-*-name
for (const field of fields) {
scanner.updateFieldName(scanner.parsingIndex, `cc-${field.fieldName}`);
scanner.parsingIndex += 1;
}
}
return true;
},
/**
* This function should provide all field details of a form which are placed
* in the belonging section. The details contain the autocomplete info
@ -565,8 +501,7 @@ export const FormAutofillHeuristics = {
this._parsePhoneFields(scanner, fieldDetail) ||
this._parseStreetAddressFields(scanner, fieldDetail) ||
this._parseAddressFields(scanner, fieldDetail) ||
this._parseCreditCardExpiryFields(scanner, fieldDetail) ||
this._parseCreditCardNameFields(scanner, fieldDetail)
this._parseCreditCardExpiryFields(scanner, fieldDetail)
) {
continue;
}

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

@ -11,8 +11,6 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
AutofillTelemetry: "resource://autofill/AutofillTelemetry.sys.mjs",
CreditCard: "resource://gre/modules/CreditCard.sys.mjs",
FormAutofillNameUtils:
"resource://gre/modules/shared/FormAutofillNameUtils.sys.mjs",
LabelUtils: "resource://gre/modules/shared/LabelUtils.sys.mjs",
});
@ -371,6 +369,7 @@ export class FormAutofillSection {
// the month is less than 10, since the input is expected a zero-padded string.
// See Bug 1722941 for follow up.
const value = this.getFilledValueFromProfile(fieldDetail, profile);
if (HTMLInputElement.isInstance(element) && value) {
// For the focused input element, it will be filled with a valid value
// anyway.
@ -1179,36 +1178,6 @@ export class FormAutofillCreditCardSection extends FormAutofillSection {
}
}
/**
* Handles credit card name transformation when the name exists in
* the separate cc-given-name, cc-middle-name, and cc-family name fields
*
* @param {object} profile
* @memberof FormAutofillCreditCardSection
*/
creditCardNameTransformer(profile) {
const name = profile["cc-name"];
if (!name) {
return;
}
const given = this.getFieldDetailByName("cc-given-name");
const middle = this.getFieldDetailByName("cc-middle-name");
const family = this.getFieldDetailByName("cc-family-name");
if (given || middle || family) {
const nameParts = lazy.FormAutofillNameUtils.splitName(name);
if (given && nameParts.given) {
profile["cc-given-name"] = nameParts.given;
}
if (middle && nameParts.middle) {
profile["cc-middle-name"] = nameParts.middle;
}
if (family && nameParts.family) {
profile["cc-family-name"] = nameParts.family;
}
}
}
async _decrypt(cipherText, reauth) {
// Get the window for the form field.
let window;
@ -1244,7 +1213,6 @@ export class FormAutofillCreditCardSection extends FormAutofillSection {
// correctly when dealing with option elements.
this.creditCardExpiryDateTransformer(profile);
this.creditCardExpMonthAndYearTransformer(profile);
this.creditCardNameTransformer(profile);
this.matchSelectOptions(profile);
this.adaptFieldMaxLength(profile);
}
@ -1350,6 +1318,7 @@ export class FormAutofillCreditCardSection extends FormAutofillSection {
creditCard.record["cc-number"] = lazy.CreditCard.normalizeCardNumber(
creditCard.record["cc-number"]
);
// Normalize cc-exp-month and cc-exp-year
let { month, year } = lazy.CreditCard.normalizeExpiration({
expirationString: creditCard.record["cc-exp"],