From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../test/unit/test_getAdaptedProfiles_locales.js | 272 +++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 browser/extensions/formautofill/test/unit/test_getAdaptedProfiles_locales.js (limited to 'browser/extensions/formautofill/test/unit/test_getAdaptedProfiles_locales.js') diff --git a/browser/extensions/formautofill/test/unit/test_getAdaptedProfiles_locales.js b/browser/extensions/formautofill/test/unit/test_getAdaptedProfiles_locales.js new file mode 100644 index 0000000000..476559c43d --- /dev/null +++ b/browser/extensions/formautofill/test/unit/test_getAdaptedProfiles_locales.js @@ -0,0 +1,272 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* + * Test to ensure locale specific placeholders for credit card fields are properly used + * to transform various values in the profile. + */ + +"use strict"; + +const DEFAULT_CREDITCARD_RECORD = { + guid: "123", + "cc-exp-month": 1, + "cc-exp-year": 2025, + "cc-exp": "2025-01", +}; + +const getCCExpYearFormatted = () => { + return DEFAULT_CREDITCARD_RECORD["cc-exp-year"].toString().substring(2); +}; + +const getCCExpMonthFormatted = () => { + return DEFAULT_CREDITCARD_RECORD["cc-exp-month"].toString().padStart(2, "0"); +}; + +const DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY_FIELDS = { + ...DEFAULT_CREDITCARD_RECORD, + "cc-exp-month-formatted": getCCExpMonthFormatted(), + "cc-exp-year-formatted": getCCExpYearFormatted(), +}; + +const FR_TESTCASES = [ + { + description: "Use placeholder to adjust cc-exp format [mm/aa].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01/25", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [mm / aa].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01/25", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [MM / AA].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01/25", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [mm / aaaa].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01/2025", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [mm - aaaa].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01-2025", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [aaaa-mm].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "2025-01", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp-year field [aa].", + document: `
+ + + +
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + { ...DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY_FIELDS }, + ], + }, +]; + +const DE_TESTCASES = [ + { + description: "Use placeholder to adjust cc-exp format [mm / jj].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01/25", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [MM / JJ].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01/25", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [mm / jjjj].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01/2025", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [MM / JJJJ].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01/2025", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [mm - jj].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01-25", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [MM - JJ].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01-25", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [mm - jjjj].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01-2025", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [MM - JJJJ].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "01-2025", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp format [jjjj - mm].", + document: `
+
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + Object.assign({}, DEFAULT_CREDITCARD_RECORD, { + "cc-exp": "2025-01", + }), + ], + }, + { + description: "Use placeholder to adjust cc-exp-year field [jj].", + document: `
+ + + +
`, + profileData: [Object.assign({}, DEFAULT_CREDITCARD_RECORD)], + expectedResult: [ + { ...DEFAULT_EXPECTED_CREDITCARD_RECORD_SEPARATE_EXPIRY_FIELDS }, + ], + }, +]; + +const TESTCASES = [FR_TESTCASES, DE_TESTCASES]; + +for (let localeTests of TESTCASES) { + for (let testcase of localeTests) { + 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); + } + }); + } + }); + } +} -- cgit v1.2.3