зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1819618 - P1. Run autofill heuristic tests via browser test r=credential-management-reviewers,sgalich
Differential Revision: https://phabricator.services.mozilla.com/D178929
This commit is contained in:
Родитель
304366f03a
Коммит
cbd92f80a7
|
@ -14,6 +14,7 @@ skip-if = verify
|
|||
skip-if =
|
||||
verify && (os == "win")
|
||||
os == "mac"
|
||||
[browser_autofill_duplicate_fields.js]
|
||||
[browser_check_installed.js]
|
||||
[browser_dropdown_layout.js]
|
||||
[browser_editAddressDialog.js]
|
||||
|
|
|
@ -17,7 +17,7 @@ const TEST_PROFILE = {
|
|||
email: "address@mozilla.org",
|
||||
};
|
||||
|
||||
runAutofillHeuristicsTest([
|
||||
add_autofill_heuristic_tests([
|
||||
{
|
||||
fixtureData: `
|
||||
<html><body>
|
|
@ -1054,7 +1054,7 @@ async function add_heuristic_tests(
|
|||
if (obj.verifyAutofill) {
|
||||
for (const section of sections) {
|
||||
section.focusedInput = section.fieldDetails[0].element;
|
||||
await section.autofillFields(testPattern.profile);
|
||||
await section.autofillFields(obj.testPattern.profile);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
|
@ -1075,7 +1075,7 @@ async function add_heuristic_tests(
|
|||
});
|
||||
}
|
||||
|
||||
async function runAutofillHeuristicsTest(patterns, fixturePathPrefix = "") {
|
||||
async function add_autofill_heuristic_tests(patterns, fixturePathPrefix = "") {
|
||||
add_heuristic_tests(patterns, fixturePathPrefix, { testAutofill: true });
|
||||
}
|
||||
|
||||
|
|
|
@ -276,157 +276,6 @@ function autofillFieldSelector(doc) {
|
|||
return doc.querySelectorAll("input, select");
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs heuristics test for form autofill on given patterns.
|
||||
*
|
||||
* @param {Array<object>} patterns - An array of test patterns to run the heuristics test on.
|
||||
* @param {string} pattern.description - Description of this heuristic test
|
||||
* @param {string} pattern.fixurePath - The path of the test document
|
||||
* @param {string} pattern.fixureData - Test document by string. Use either fixurePath or fixtureData.
|
||||
* @param {object} pattern.profile - The profile to autofill. This is required only when running autofill test
|
||||
* @param {Array} pattern.expectedResult - The expected result of this heuristic test. See below for detailed explanation
|
||||
*
|
||||
* @param {string} [fixturePathPrefix=""] - The prefix to the path of fixture files.
|
||||
* @param {object} [options={ testAutofill: false }] - An options object containing additional configuration for running the test.
|
||||
* @param {boolean} [options.testAutofill=false] - A boolean indicating whether to run the test for autofill or not.
|
||||
* @returns {Promise} A promise that resolves when all the tests are completed.
|
||||
*
|
||||
* The `patterns.expectedResult` array contains test data for different address or credit card sections.
|
||||
* Each section in the array is represented by an object and can include the following properties:
|
||||
* - description (optional): A string describing the section, primarily used for debugging purposes.
|
||||
* - default (optional): An object that sets the default values for all the fields within this section.
|
||||
* The default object contains the same keys as the individual field objects.
|
||||
* - fields: An array of field details (class FieldDetails) within the section.
|
||||
*
|
||||
* Each field object can have the following keys:
|
||||
* - fieldName: The name of the field (e.g., "street-name", "cc-name" or "cc-number").
|
||||
* - reason: The reason for the field value (e.g., "autocomplete", "regex-heuristic" or "fathom").
|
||||
* - section: The section to which the field belongs (e.g., "billing", "shipping").
|
||||
* - 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
|
||||
*
|
||||
* For more information on the field object properties, refer to the FieldDetails class.
|
||||
*
|
||||
* Example test data:
|
||||
* runHeuristicsTest(
|
||||
* [{
|
||||
* description: "first test pattern",
|
||||
* fixuturePath: "autocomplete_off.html",
|
||||
* profile: {organization: "Mozilla", country: "US", tel: "123"},
|
||||
* expectedResult: [
|
||||
* {
|
||||
* description: "First section"
|
||||
* fields: [
|
||||
* { fieldName: "organization", reason: "autocomplete", autofill: "Mozilla" },
|
||||
* { fieldName: "country", reason: "regex-heuristic", autofill: "US" },
|
||||
* { fieldName: "tel", reason: "regex-heuristic", autofill: "123" },
|
||||
* ]
|
||||
* },
|
||||
* {
|
||||
* default: {
|
||||
* reason: "regex-heuristic",
|
||||
* section: "billing",
|
||||
* },
|
||||
* fields: [
|
||||
* { fieldName: "cc-number", reason: "fathom" },
|
||||
* { fieldName: "cc-nane" },
|
||||
* { fieldName: "cc-exp" },
|
||||
* ],
|
||||
* }],
|
||||
* },
|
||||
* {
|
||||
* // second test pattern //
|
||||
* }
|
||||
* ],
|
||||
* "/fixturepath",
|
||||
* {testAutofill: true} // test options
|
||||
* )
|
||||
*/
|
||||
|
||||
async function runHeuristicsTest(
|
||||
patterns,
|
||||
fixturePathPrefix = "",
|
||||
options = { testAutofill: false }
|
||||
) {
|
||||
add_setup(async () => {
|
||||
({ FormAutofillHeuristics } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/shared/FormAutofillHeuristics.sys.mjs"
|
||||
));
|
||||
({ AddressDataLoader, FormAutofillUtils } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/shared/FormAutofillUtils.sys.mjs"
|
||||
));
|
||||
({ LabelUtils } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/shared/LabelUtils.sys.mjs"
|
||||
));
|
||||
});
|
||||
|
||||
patterns.forEach(testPattern => {
|
||||
add_task(async function () {
|
||||
info(`Starting test fixture: ${testPattern.fixturePath ?? ""}`);
|
||||
if (testPattern.description) {
|
||||
info(`test "${testPattern.description}"`);
|
||||
}
|
||||
|
||||
if (testPattern.prefs) {
|
||||
testPattern.prefs.forEach(pref => SetPref(pref[0], pref[1]));
|
||||
}
|
||||
|
||||
const url = "http://localhost:8080/test/";
|
||||
const doc = testPattern.fixtureData
|
||||
? MockDocument.createTestDocument(url, testPattern.fixtureData)
|
||||
: MockDocument.createTestDocumentFromFile(
|
||||
url,
|
||||
do_get_file(fixturePathPrefix + testPattern.fixturePath)
|
||||
);
|
||||
|
||||
let forms = [...doc.querySelectorAll("input, select")].reduce(
|
||||
(acc, field) => {
|
||||
const formLike = FormLikeFactory.createFromField(field);
|
||||
if (!acc.some(form => form.rootElement === formLike.rootElement)) {
|
||||
acc.push(formLike);
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const sections = forms.flatMap(form => {
|
||||
const handler = new FormAutofillHandler(form);
|
||||
handler.collectFormFields(false /* ignoreInvalid */);
|
||||
return handler.sections;
|
||||
});
|
||||
|
||||
Assert.equal(
|
||||
sections.length,
|
||||
testPattern.expectedResult.length,
|
||||
"Expected section count."
|
||||
);
|
||||
|
||||
verifySectionFieldDetails(sections, testPattern.expectedResult);
|
||||
|
||||
if (options.testAutofill) {
|
||||
for (const section of sections) {
|
||||
section.focusedInput = section.fieldDetails[0].element;
|
||||
await section.autofillFields(testPattern.profile);
|
||||
}
|
||||
verifySectionAutofillResult(sections, testPattern.expectedResult);
|
||||
}
|
||||
|
||||
if (testPattern.prefs) {
|
||||
testPattern.prefs.forEach(pref =>
|
||||
Services.prefs.clearUserPref(pref[0])
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function runAutofillHeuristicsTest(patterns, fixturePathPrefix = "") {
|
||||
runHeuristicsTest(patterns, fixturePathPrefix, { testAutofill: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Sync change counter for a profile storage record. Synced records
|
||||
* store additional metadata for tracking changes and resolving merge conflicts.
|
||||
|
|
|
@ -32,7 +32,6 @@ head = head_addressComponent.js
|
|||
[test_addressRecords.js]
|
||||
skip-if =
|
||||
apple_silicon # bug 1729554
|
||||
[test_autofill_duplicate_fields.js]
|
||||
[test_autofillFormFields.js]
|
||||
skip-if =
|
||||
tsan # Times out, bug 1612707
|
||||
|
|
Загрузка…
Ссылка в новой задаче