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_markAsAutofillField.js | 201 +++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 browser/extensions/formautofill/test/unit/test_markAsAutofillField.js (limited to 'browser/extensions/formautofill/test/unit/test_markAsAutofillField.js') diff --git a/browser/extensions/formautofill/test/unit/test_markAsAutofillField.js b/browser/extensions/formautofill/test/unit/test_markAsAutofillField.js new file mode 100644 index 0000000000..72960fcaf2 --- /dev/null +++ b/browser/extensions/formautofill/test/unit/test_markAsAutofillField.js @@ -0,0 +1,201 @@ +"use strict"; + +const TESTCASES = [ + { + description: "Form containing 8 fields with autocomplete attribute.", + document: `
+ + + + + + + + + + +
`, + targetElementId: "given-name", + expectedResult: [ + "given-name", + "additional-name", + "family-name", + "street-addr", + "city", + "country", + "email", + "tel", + ], + }, + { + description: "Form containing only 2 fields with autocomplete attribute.", + document: `
+ + + + +
`, + targetElementId: "street-addr", + expectedResult: [], + }, + { + description: "Fields without form element.", + document: ` + + + + + + `, + targetElementId: "street-addr", + expectedResult: ["street-addr", "city", "country", "email", "tel"], + }, + { + description: "Form containing credit card autocomplete attributes.", + document: `
+ + + + +
`, + targetElementId: "cc-number", + expectedResult: ["cc-number", "cc-name", "cc-exp-month", "cc-exp-year"], + }, + { + description: + "Form containing multiple cc-number fields without autocomplete attributes.", + document: `
+ + + + + + + +
`, + targetElementId: "cc-number1", + expectedResult: [ + "cc-number1", + "cc-number2", + "cc-number3", + "cc-number4", + "cc-name", + "cc-exp-month", + "cc-exp-year", + ], + }, + { + description: + "Invalid form containing three consecutive cc-number fields without autocomplete attributes.", + document: `
+ + + +
`, + targetElementId: "cc-number1", + expectedResult: [], + prefs: [ + [ + "extensions.formautofill.creditCards.heuristics.fathom.testConfidence", + "1.0", + ], + ], + }, + { + description: + "Invalid form containing five consecutive cc-number fields without autocomplete attributes.", + document: `
+ + + + + +
`, + targetElementId: "cc-number1", + expectedResult: [], + prefs: [ + [ + "extensions.formautofill.creditCards.heuristics.fathom.testConfidence", + "1.0", + ], + ], + }, + { + description: + "Valid form containing three consecutive cc-number fields without autocomplete attributes.", + document: `
+ + + + + + +
`, + targetElementId: "cc-number1", + expectedResult: ["cc-number3", "cc-name", "cc-exp-month", "cc-exp-year"], + prefs: [ + [ + "extensions.formautofill.creditCards.heuristics.fathom.testConfidence", + "1.0", + ], + ], + }, + { + description: + "Valid form containing five consecutive cc-number fields without autocomplete attributes.", + document: `
+ + + + + + + + +
`, + targetElementId: "cc-number1", + expectedResult: ["cc-number5", "cc-name", "cc-exp-month", "cc-exp-year"], + }, +]; + +let markedFieldId = []; + +var FormAutofillContent; +add_setup(async () => { + ({ FormAutofillContent } = ChromeUtils.importESModule( + "resource://autofill/FormAutofillContent.sys.mjs" + )); + + FormAutofillContent._markAsAutofillField = function (field) { + markedFieldId.push(field.id); + }; +}); + +TESTCASES.forEach(testcase => { + add_task(async function () { + info("Starting testcase: " + testcase.description); + + if (testcase.prefs) { + testcase.prefs.forEach(pref => SetPref(pref[0], pref[1])); + } + + markedFieldId = []; + + let doc = MockDocument.createTestDocument( + "http://localhost:8080/test/", + testcase.document + ); + let element = doc.getElementById(testcase.targetElementId); + FormAutofillContent.identifyAutofillFields(element); + + Assert.deepEqual( + markedFieldId, + testcase.expectedResult, + "Check the fields were marked correctly." + ); + + if (testcase.prefs) { + testcase.prefs.forEach(pref => Services.prefs.clearUserPref(pref[0])); + } + }); +}); -- cgit v1.2.3