forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1740070 - Reset <select> elements when autofilled form is cleared…
…. r=sgalich,dimi Differential Revision: https://phabricator.services.mozilla.com/D133213
- Loading branch information
Showing
3 changed files
with
142 additions
and
6 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
browser/extensions/formautofill/test/unit/test_clearPopulatedForm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: `<form> | ||
<input id="given-name"> | ||
<input id="family-name"> | ||
<input id="street-addr"> | ||
<input id="city"> | ||
</form>`, | ||
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: `<form> | ||
<input id="given-name"> | ||
<input id="family-name"> | ||
<input id="street-addr"> | ||
<select id="state"> | ||
<option value="AL">Alabama</option> | ||
<option value="AK">Alaska</option> | ||
<option value="OH">Ohio</option> | ||
</select> | ||
</form>`, | ||
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: `<form> | ||
<input id="given-name"> | ||
<input id="family-name"> | ||
<input id="street-addr"> | ||
<select id="state"> | ||
<option value="AL">Alabama</option> | ||
<option selected value="AK">Alaska</option> | ||
<option value="OH">Ohio</option> | ||
</select> | ||
</form>`, | ||
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.import( | ||
"resource://autofill/FormAutofillHandler.jsm" | ||
); | ||
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` | ||
); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters