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 --- .../creditCard/browser_creditCard_heuristics.js | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 browser/extensions/formautofill/test/browser/creditCard/browser_creditCard_heuristics.js (limited to 'browser/extensions/formautofill/test/browser/creditCard/browser_creditCard_heuristics.js') diff --git a/browser/extensions/formautofill/test/browser/creditCard/browser_creditCard_heuristics.js b/browser/extensions/formautofill/test/browser/creditCard/browser_creditCard_heuristics.js new file mode 100644 index 0000000000..3801239234 --- /dev/null +++ b/browser/extensions/formautofill/test/browser/creditCard/browser_creditCard_heuristics.js @@ -0,0 +1,165 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const TESTCASES = [ + { + description: "@autocomplete - all fields in the same form", + document: `
+ + + +
`, + idsToShowPopup: ["cc-number", "cc-name", "cc-exp"], + }, + { + description: "without @autocomplete - all fields in the same form", + document: `
+ + + +
`, + idsToShowPopup: ["cc-number", "cc-name", "cc-exp"], + }, + { + description: "@autocomplete - each field in its own form", + document: `
+
+
`, + idsToShowPopup: ["cc-number", "cc-name", "cc-exp"], + }, + { + description: + "without @autocomplete - each field in its own form (high-confidence cc-number & cc-name)", + document: `
+
+
`, + prefs: [ + [ + "extensions.formautofill.creditCards.heuristics.fathom.highConfidenceThreshold", + "0.9", + ], + [ + "extensions.formautofill.creditCards.heuristics.fathom.testConfidence", + "0.95", + ], + ], + idsToShowPopup: ["cc-number", "cc-name"], + idsWithNoPopup: ["cc-exp"], + }, + { + description: + "without @autocomplete - each field in its own form (normal-confidence cc-number & cc-name)", + document: `
+
+
`, + prefs: [ + [ + "extensions.formautofill.creditCards.heuristics.fathom.highConfidenceThreshold", + "0.9", + ], + [ + "extensions.formautofill.creditCards.heuristics.fathom.testConfidence", + "0.8", + ], + ], + idsWithNoPopup: ["cc-number", "cc-name", "cc-exp"], + }, + { + description: + "with @autocomplete - cc-number/cc-name and another in a form", + document: `
+ + +
+
+ + +
`, + idsToShowPopup: ["cc-number", "cc-name"], + }, + { + description: + "without @autocomplete - high-confidence cc-number/cc-name and another in a form", + document: `
+ + +
+
+ + +
`, + idsWithNoPopup: ["cc-number", "cc-name"], + }, + { + description: + "without @autocomplete - high-confidence cc-number/cc-name and another hidden in a form", + document: `
+ + +
+
+ + +
`, + prefs: [ + [ + "extensions.formautofill.creditCards.heuristics.fathom.highConfidenceThreshold", + "0.9", + ], + [ + "extensions.formautofill.creditCards.heuristics.fathom.testConfidence", + "0.95", + ], + ], + idsToShowPopup: ["cc-number", "cc-name"], + }, +]; + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["extensions.formautofill.creditCards.supported", "on"], + ["extensions.formautofill.creditCards.enabled", true], + ], + }); + + await setStorage(TEST_CREDIT_CARD_1); +}); + +add_task(async function test_heuristics() { + for (const TEST of TESTCASES) { + info(`Test ${TEST.description}`); + if (TEST.prefs) { + await SpecialPowers.pushPrefEnv({ set: TEST.prefs }); + } + + 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 ids = TEST.idsToShowPopup ?? []; + for (const id of ids) { + await runAndWaitForAutocompletePopupOpen(browser, async () => { + await focusAndWaitForFieldsIdentified(browser, `#${id}`); + }); + ok(true, `popup is opened on `); + } + + ids = TEST.idsWithNoPopup ?? []; + for (const id of ids) { + await focusAndWaitForFieldsIdentified(browser, `#${id}`); + await ensureNoAutocompletePopup(browser); + } + }); + + if (TEST.prefs) { + await SpecialPowers.popPrefEnv(); + } + } +}); -- cgit v1.2.3