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_clearPopulatedForm.js | 116 +++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 browser/extensions/formautofill/test/unit/test_clearPopulatedForm.js (limited to 'browser/extensions/formautofill/test/unit/test_clearPopulatedForm.js') diff --git a/browser/extensions/formautofill/test/unit/test_clearPopulatedForm.js b/browser/extensions/formautofill/test/unit/test_clearPopulatedForm.js new file mode 100644 index 0000000000..db8ccb7621 --- /dev/null +++ b/browser/extensions/formautofill/test/unit/test_clearPopulatedForm.js @@ -0,0 +1,116 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const TESTCASES = [ + { + description: "Clear populated address form with text inputs", + document: `
+ + + + +
`, + focusedInputId: "given-name", + profileData: { + "given-name": "John", + "family-name": "Doe", + "street-addr": "1000 Main Street", + city: "Nowhere", + }, + expectedResult: { + "given-name": "", + "family-name": "", + "street-addr": "", + city: "", + }, + }, + { + description: "Clear populated address form with select and text inputs", + document: `
+ + + + +
`, + focusedInputId: "given-name", + profileData: { + "given-name": "John", + "family-name": "Doe", + "street-addr": "1000 Main Street", + state: "OH", + }, + expectedResult: { + "given-name": "", + "family-name": "", + "street-addr": "", + state: "AL", + }, + }, + { + description: + "Clear populated address form with select element with selected attribute and text inputs", + document: `
+ + + + +
`, + focusedInputId: "given-name", + profileData: { + "given-name": "John", + "family-name": "Doe", + "street-addr": "1000 Main Street", + state: "OH", + }, + expectedResult: { + "given-name": "", + "family-name": "", + "street-addr": "", + state: "AK", + }, + }, +]; + +add_task(async function do_test() { + let { FormAutofillHandler } = ChromeUtils.importESModule( + "resource://gre/modules/shared/FormAutofillHandler.sys.mjs" + ); + for (let test of TESTCASES) { + info("Test case: " + test.description); + let testDoc = MockDocument.createTestDocument( + "http://localhost:8080/test", + test.document + ); + let form = testDoc.querySelector("form"); + let formLike = FormLikeFactory.createFromForm(form); + let handler = new FormAutofillHandler(formLike); + handler.collectFormFields(); + let focusedInput = testDoc.getElementById(test.focusedInputId); + handler.focusedInput = focusedInput; + let [adaptedProfile] = handler.activeSection.getAdaptedProfiles([ + test.profileData, + ]); + await handler.autofillFormFields(adaptedProfile, focusedInput); + + handler.activeSection.clearPopulatedForm(); + handler.activeSection.fieldDetails.forEach(detail => { + let element = detail.elementWeakRef.get(); + let id = element.id; + Assert.equal( + element.value, + test.expectedResult[id], + `Check the ${id} field was restored to the correct value` + ); + }); + } +}); -- cgit v1.2.3