/* * Test for form auto fill content helper fill all inputs function. */ "use strict"; var FormAutofillHandler; add_task(async function () { ({ FormAutofillHandler } = ChromeUtils.importESModule( "resource://gre/modules/shared/FormAutofillHandler.sys.mjs" )); }); const DEFAULT_ADDRESS_RECORD = { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "address-line1": "2 Harrison St", "address-line2": "line2", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }; const ADDRESS_RECORD_2 = { guid: "address2", "given-name": "John", "additional-name": "Middle", "family-name": "Doe", "postal-code": "940012345", }; const DEFAULT_CREDITCARD_RECORD = { guid: "123", "cc-exp-month": 1, "cc-exp-year": 2025, "cc-exp": "2025-01", }; const DEFAULT_EXPECTED_CREDITCARD_RECORD = { guid: "123", "cc-exp-month": 1, "cc-exp-year": 2025, "cc-exp": "01/2025", }; const getCCExpMonthFormatted = () => { return DEFAULT_CREDITCARD_RECORD["cc-exp-month"].toString().padStart(2, "0"); }; const getCCExpYearFormatted = () => { return DEFAULT_CREDITCARD_RECORD["cc-exp-year"].toString().substring(2); }; // Bug 1767130: If a form has separate inputs for expiry month and year, // we will always transform month into MM const DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY = { ...DEFAULT_CREDITCARD_RECORD, "cc-exp-month-formatted": getCCExpMonthFormatted(), }; const TESTCASES = [ { description: "Address form with street-address", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St line2 line3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], }, { description: "Address form with street-address, address-line[1, 2, 3]", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St line2 line3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], }, { description: "Address form with street-address, address-line1", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St line2 line3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St line2 line3", "address-line2": "line2", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], }, { description: "Address form with street-address, address-line[1, 2]", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St line2 line3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2 line3", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], }, { description: "Address form with street-address, address-line[1, 3]" + ", determined by autocomplete attr", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St line2 line3", "-moz-street-address-one-line": "2 Harrison St line2 line3", // Since the form is missing address-line2 field, the value of // address-line1 should contain line2 value as well. "address-line1": "2 Harrison St line2", "address-line2": "line2", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], }, { description: "Address form with street-address, address-line[1, 3]" + ", determined by heuristics", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St line2 line3", "-moz-street-address-one-line": "2 Harrison St line2 line3", // Since the form is missing address-line2 field, the value of // address-line1 should contain line2 value as well. "address-line1": "2 Harrison St line2", "address-line2": "line2", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], }, { description: "Address form with exact matching options in select", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], expectedOptionElements: [ { "address-level1": "option-address-level1-CA", country: "option-country-US", }, ], }, { description: "Address form with inexact matching options in select", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], expectedOptionElements: [ { "address-level1": "option-address-level1-OO", country: "option-country-OO", }, ], }, { description: "Address form with value-omitted options in select", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], expectedOptionElements: [ { "address-level1": "option-address-level1-2", country: "option-country-2", }, ], }, { description: "Address form with options with the same value in select ", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], expectedOptionElements: [ { "address-level1": "option-address-level1-same2", country: "option-country-same2", }, ], }, { description: "Address form without matching options in select for address-level1 and country", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2", "address-line3": "line3", tel: "+19876543210", "tel-national": "9876543210", }, ], }, { description: "Change the tel value of a profile to tel-national for a field without pattern and maxlength.", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2 line3", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "9876543210", "tel-national": "9876543210", }, ], }, { description: 'Do not change the profile for an autocomplete="tel" field without patern and maxlength.', document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2 line3", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], }, { description: 'autocomplete="tel" field with `maxlength` can be filled with `tel` value.', document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2 line3", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], }, { description: "Still fill `tel-national` in a `tel` field with `maxlength` can be filled with `tel` value.", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2 line3", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "9876543210", "tel-national": "9876543210", }, ], }, { description: "`tel` field with `maxlength` can be filled with `tel-national` value.", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2 line3", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "9876543210", "tel-national": "9876543210", }, ], }, { description: "`tel` field with `pattern` attr can be filled with `tel` value.", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2 line3", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "+19876543210", "tel-national": "9876543210", }, ], }, { description: "Change the tel value of a profile to tel-national one when the pattern is matched.", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2 line3", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "9876543210", "tel-national": "9876543210", }, ], }, { description: 'Matching pattern when a field is with autocomplete="tel".', document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2 line3", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "9876543210", "tel-national": "9876543210", }, ], }, { description: "Checking maxlength of tel field first when a field is with maxlength.", document: `
`, profileData: [{ ...DEFAULT_ADDRESS_RECORD }], expectedResult: [ { guid: "123", "street-address": "2 Harrison St\nline2\nline3", "-moz-street-address-one-line": "2 Harrison St line2 line3", "address-line1": "2 Harrison St", "address-line2": "line2 line3", "address-line3": "line3", "address-level1": "CA", country: "US", tel: "9876543210", "tel-national": "9876543210", }, ], }, { description: "Address form with maxlength restriction", document: `
`, profileData: [{ ...ADDRESS_RECORD_2 }], expectedResult: [ { guid: "address2", "given-name": "J", "additional-name": "M", "family-name": "D", "postal-code": "94001", }, ], }, { description: "Address form with the special cases of the maxlength restriction", document: `
`, profileData: [{ ...ADDRESS_RECORD_2 }], expectedResult: [ { guid: "address2", "given-name": "John", "family-name": "D", "postal-code": "940012345", }, ], }, { description: "Credit card form with separate fields for expiration month and year", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_CREDITCARD_RECORD], expectedOptionElements: [ { "cc-exp-month": "option-cc-exp-month-01", "cc-exp-year": "option-cc-exp-year-25", }, ], }, { description: "Credit Card form with matching options which contain labels", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_CREDITCARD_RECORD], expectedOptionElements: [ { "cc-exp-month": "option-cc-exp-month-01", "cc-exp-year": "option-cc-exp-year-25", }, ], }, { description: "Compound cc-exp: {MON1}/{YEAR2}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {MON1}/{YEAR4}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {MON2}/{YEAR2}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {MON2}/{YEAR4}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {MON1}-{YEAR2}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {MON1}-{YEAR4}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {MON2}-{YEAR2}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {MON2}-{YEAR4}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {YEAR2}-{MON2}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {YEAR4}-{MON2}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {YEAR4}/{MON2}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {MON2}{YEAR2}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Compound cc-exp: {YEAR2}{MON2}", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], expectedOptionElements: [{ "cc-exp": "selected-cc-exp" }], }, { description: "Fill a cc-exp without cc-exp-month value in the profile", document: `
`, profileData: [ { guid: "123", "cc-exp-year": 2025, }, ], expectedResult: [ { guid: "123", "cc-exp-year": 2025, }, ], expectedOptionElements: [], }, { description: "Fill a cc-exp without cc-exp-year value in the profile", document: `
`, profileData: [ { guid: "123", "cc-exp-month": 1, }, ], expectedResult: [ { guid: "123", "cc-exp-month": 1, }, ], expectedOptionElements: [], }, { description: "Fill a cc-exp* without cc-exp-month value in the profile", document: `
`, profileData: [ { guid: "123", "cc-exp-year": 2025, }, ], expectedResult: [ { guid: "123", "cc-exp-year": 2025, }, ], expectedOptionElements: [], }, { description: "Fill a cc-exp* without cc-exp-year value in the profile", document: `
`, profileData: [ { guid: "123", "cc-exp-month": 1, }, ], expectedResult: [ { guid: "123", "cc-exp-month": 1, }, ], expectedOptionElements: [], }, { description: "Fill a cc-exp field using adjacent label (MM/YY) as expiry string placeholder", document: `
`, profileData: [DEFAULT_CREDITCARD_RECORD], expectedResult: [ { ...DEFAULT_EXPECTED_CREDITCARD_RECORD, "cc-exp": "01/25" }, ], }, { description: "Fill a cc-exp field using adjacent label (MM - YY) as expiry string placeholder", document: `
`, profileData: [DEFAULT_CREDITCARD_RECORD], expectedResult: [ { ...DEFAULT_EXPECTED_CREDITCARD_RECORD, "cc-exp": "01-25" }, ], }, { description: "Fill a cc-exp field correctly while ignoring unrelated label", document: `
`, profileData: [DEFAULT_CREDITCARD_RECORD], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], }, { description: "Fill a cc-exp without placeholder on the cc-exp field", document: `
`, profileData: [DEFAULT_CREDITCARD_RECORD], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], }, { description: "Fill a cc-exp with whitespace placeholder on the cc-exp field", document: `
`, profileData: [DEFAULT_CREDITCARD_RECORD], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], }, { description: "Use placeholder to adjust cc-exp format [mm/yy].", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { ...DEFAULT_CREDITCARD_RECORD, "cc-exp": "01/25", }, ], }, { description: "Use placeholder to adjust cc-exp format [mm / yy].", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { ...DEFAULT_CREDITCARD_RECORD, "cc-exp": "01/25", }, ], }, { description: "Use placeholder to adjust cc-exp format [MM / YY].", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { ...DEFAULT_CREDITCARD_RECORD, "cc-exp": "01/25", }, ], }, { description: "Use placeholder to adjust cc-exp format [mm / yyyy].", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { ...DEFAULT_CREDITCARD_RECORD, "cc-exp": "01/2025", }, ], }, { description: "Use placeholder to adjust cc-exp format [mm - yyyy].", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { ...DEFAULT_CREDITCARD_RECORD, "cc-exp": "01-2025", }, ], }, { description: "Use placeholder to adjust cc-exp format [yyyy-mm].", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { ...DEFAULT_CREDITCARD_RECORD, "cc-exp": "2025-01", }, ], }, { description: "Use placeholder to adjust cc-exp format [mmm yyyy].", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], }, { description: "Use placeholder to adjust cc-exp format [mm foo yyyy].", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], }, { description: "Use placeholder to adjust cc-exp format [mm - - yyyy].", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD], }, { description: "Use placeholder to adjust cc-exp-month field [mm].", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { ...DEFAULT_CREDITCARD_RECORD, "cc-exp-month-formatted": getCCExpMonthFormatted(), }, ], }, { description: "Use placeholder to adjust cc-exp-year field [yy].", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { ...DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY, "cc-exp-year-formatted": getCCExpYearFormatted(), }, ], }, { description: "Test maxlength=2 on numeric fields.", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { ...DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY, "cc-exp-year": 25, }, ], }, { description: "Test maxlength=4 on numeric fields.", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY], }, // Bug 1687679: The default value of an expiration month, when filled in an input element, // is a two character length string. Because of this, testing a maxlength of 1 is invalid. { description: "Test maxlength=1 on numeric fields.", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { ...DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY, "cc-exp-year": 5, "cc-exp-month": 1, }, ], }, { description: "Test maxlength=0 on numeric fields.", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { guid: DEFAULT_CREDITCARD_RECORD.guid, "cc-exp": DEFAULT_CREDITCARD_RECORD["cc-exp"], }, ], }, { // It appears that negative values do not get propagated. description: "Test maxlength=-2 on numeric fields.", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY], }, { description: "Test maxlength=10 on numeric fields.", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY], }, { description: "Test (special case) maxlength=5 on cc-exp field.", document: `
`, profileData: [{ ...DEFAULT_CREDITCARD_RECORD }], expectedResult: [ { ...DEFAULT_CREDITCARD_RECORD, "cc-exp": "01/25", }, ], }, ]; for (let testcase of TESTCASES) { add_task(async function () { info("Starting testcase: " + testcase.description); let doc = MockDocument.createTestDocument( "http://localhost:8080/test/", testcase.document ); let form = doc.querySelector("form"); let formLike = FormLikeFactory.createFromForm(form); let handler = new FormAutofillHandler(formLike); handler.collectFormFields(); handler.focusedInput = form.elements[0]; let adaptedRecords = handler.activeSection.getAdaptedProfiles( testcase.profileData ); Assert.deepEqual(adaptedRecords, testcase.expectedResult); if (testcase.expectedOptionElements) { testcase.expectedOptionElements.forEach((expectedOptionElement, i) => { for (let field in expectedOptionElement) { let select = form.querySelector(`[autocomplete=${field}]`); let expectedOption = doc.getElementById(expectedOptionElement[field]); Assert.notEqual(expectedOption, null); let value = testcase.profileData[i][field]; let cache = handler.activeSection._cacheValue.matchingSelectOption.get(select); let targetOption = cache[value] && cache[value].get(); Assert.notEqual(targetOption, null); Assert.equal(targetOption, expectedOption); } }); } }); }