forked from mirrors/gecko-dev
Bug 1899326 - P2. Test that the FormHandler only listens for events related to form removals when another actor is interested in form removals r=dimi
Depends on D211885 Differential Revision: https://phabricator.services.mozilla.com/D212481
This commit is contained in:
parent
567f1a81d8
commit
89c27f522a
3 changed files with 143 additions and 6 deletions
|
|
@ -70,7 +70,7 @@ add_task(async function test_address_captured_after_form_removal() {
|
|||
info("Infer form removal");
|
||||
await SpecialPowers.spawn(browser, [], async function () {
|
||||
let form = content.document.getElementById("form");
|
||||
form.parentNode.remove(form);
|
||||
form.remove();
|
||||
});
|
||||
info("Wait for address doorhanger");
|
||||
await onPopupShown;
|
||||
|
|
@ -114,7 +114,7 @@ add_task(async function test_address_not_captured_without_prior_fetch() {
|
|||
info("Infer form removal");
|
||||
await SpecialPowers.spawn(browser, [], async function () {
|
||||
let form = content.document.getElementById("form");
|
||||
form.parentNode.remove(form);
|
||||
form.remove();
|
||||
});
|
||||
|
||||
info("Ensure that address doorhanger is not shown");
|
||||
|
|
@ -122,3 +122,115 @@ add_task(async function test_address_not_captured_without_prior_fetch() {
|
|||
}
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Tests that the FormHandler only listens for events related to form removal (and dispatches its own custom events related to form removal) \
|
||||
* when an actor registered their interest in form removals with the FormHandler. This is to avoid listening to form removal events unnecessarily.
|
||||
*/
|
||||
add_task(
|
||||
async function test_form_removals_events_dispatched_only_when_actor_interested_in_form_removals() {
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: "https://example.org/browser/browser/extensions/formautofill/test/fixtures/two_address_forms.html",
|
||||
},
|
||||
async function (browser) {
|
||||
info("Update identified address fields");
|
||||
// We don't submit the form
|
||||
await focusUpdateSubmitForm(
|
||||
browser,
|
||||
{
|
||||
formId: "form-filled",
|
||||
focusSelector: "#given-name",
|
||||
newValues: {
|
||||
"#given-name": ADDRESS_FIELD_VALUES["given-name"],
|
||||
"#organization": ADDRESS_FIELD_VALUES.organization,
|
||||
"#street-address": ADDRESS_FIELD_VALUES["street-address"],
|
||||
},
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
const domDocFetchSuccessPromise = BrowserTestUtils.waitForContentEvent(
|
||||
browser,
|
||||
"DOMDocFetchSuccess"
|
||||
);
|
||||
|
||||
const beforeFormSubmissionPromise =
|
||||
BrowserTestUtils.waitForContentEvent(
|
||||
browser,
|
||||
"before-form-submission"
|
||||
);
|
||||
|
||||
info("Infer a successfull fetch request");
|
||||
await SpecialPowers.spawn(browser, [], async () => {
|
||||
await content.fetch(
|
||||
"https://example.org/browser/browser/extensions/formautofill/test/browser/empty.html"
|
||||
);
|
||||
});
|
||||
|
||||
// FormAutofill has registered an interest in form removals, so the FormHandler should have set a flag on
|
||||
// the document to enable the doc to dispatch the event DOMDocFetchSuccess to notify of xhr/fetch requests
|
||||
info("Wait for DOMDocFetchSuccess event");
|
||||
await domDocFetchSuccessPromise;
|
||||
|
||||
// The FormHandler should dispatch the event before-form-submission when being notified of a DOMDocFetchSuccess event
|
||||
info("Wait for before-form-submission event");
|
||||
await beforeFormSubmissionPromise;
|
||||
|
||||
const domFormRemovedPromise = BrowserTestUtils.waitForContentEvent(
|
||||
browser,
|
||||
"DOMFormRemoved"
|
||||
);
|
||||
|
||||
const formSubmissionDetectedPromise =
|
||||
BrowserTestUtils.waitForContentEvent(
|
||||
browser,
|
||||
"form-submission-detected"
|
||||
);
|
||||
|
||||
info("Remove address form from DOM");
|
||||
await SpecialPowers.spawn(browser, [], async function () {
|
||||
let form = content.document.getElementById("form-filled");
|
||||
form.remove();
|
||||
});
|
||||
|
||||
info("Wait for DOMFormRemoved event");
|
||||
await domFormRemovedPromise;
|
||||
|
||||
info("Wait for form-submission-detected event");
|
||||
await formSubmissionDetectedPromise;
|
||||
// FormAutofill unregisters their interest in form removals after processing the form submission
|
||||
|
||||
// Because FormAutofill has no interest in form removals anymore, the FormHandler should have
|
||||
// removed the listeners for the events DOMDocFetchSuccess and DOMFormRemoved. Therefore it should also not
|
||||
// dispatch the events before-form-submission and form-submission-detected itself.
|
||||
await SpecialPowers.spawn(browser, [], async () => {
|
||||
content.document.addEventListener("DOMDocFetchSuccess", () =>
|
||||
is(false, "Should not dispatch DOMDocFetchSuccess event")
|
||||
);
|
||||
content.document.addEventListener("before-form-submission", () =>
|
||||
is(false, "Should not dispatch before-form-submission event")
|
||||
);
|
||||
content.document.addEventListener("DOMFormRemoved", () =>
|
||||
is(false, "Should not dispatch DOMFormRemoved event")
|
||||
);
|
||||
content.document.addEventListener("form-submission-detected", () =>
|
||||
is(false, "Should not dispatch form-submission-detected event")
|
||||
);
|
||||
});
|
||||
|
||||
info(
|
||||
"Infer another successfull fetch request and remove another form form the DOM"
|
||||
);
|
||||
await SpecialPowers.spawn(browser, [], async () => {
|
||||
await content.fetch(
|
||||
"https://example.org/browser/browser/extensions/formautofill/test/browser/empty.html"
|
||||
);
|
||||
let form = content.document.getElementById("form-not-filled");
|
||||
form.remove();
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
|
|||
28
browser/extensions/formautofill/test/fixtures/two_address_forms.html
vendored
Normal file
28
browser/extensions/formautofill/test/fixtures/two_address_forms.html
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Two address forms</title>
|
||||
</head>
|
||||
<body>
|
||||
<form id="form-filled">
|
||||
<p><label>givenname: <input type="text" id="given-name" name="given-name" autocomplete="given-name" /></label></p>
|
||||
<p><label>familyname: <input type="text" id="family-name" name="family-name" autocomplete="family-name" /></label></p>
|
||||
<p><label>organization: <input type="text" id="organization" name="organization" autocomplete="organization" /></label></p>
|
||||
<p><label>streetAddress: <input type="text" id="street-address" name="street-address" autocomplete="street-address" /></label></p>
|
||||
<p><label>addressLevel2: <input type="text" id="address-level2" name="address-level2" autocomplete="address-level2" /></label></p>
|
||||
<p><label>addressLevel1: <input type="text" id="address-level1" name="address-level1" autocomplete="address-level1" /></label></p>
|
||||
<p><label>postalCode: <input type="text" id="postal-code" name="postal-code" autocomplete="postal-code" /></label></p>
|
||||
<p><label>country: <input type="text" id="country" name="country" autocomplete="country" /></label></p>
|
||||
<p><label>tel: <input type="text" id="tel" name="tel" autocomplete="tel" /></label></p>
|
||||
<p><label>email: <input type="text" id="email" name="email" autocomplete="email" /></label></p>
|
||||
<p>
|
||||
<input type="submit"/>
|
||||
<button type="reset">Reset</button>
|
||||
</p>
|
||||
</form>
|
||||
<form id="form-not-filled">
|
||||
<p><label>email: <input type="text" id="email" name="email" autocomplete="email" /></label></p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -5,15 +5,12 @@ support-files = [
|
|||
]
|
||||
|
||||
["browser_autocomplete.js"]
|
||||
lineno = "7"
|
||||
|
||||
["browser_close_tab.js"]
|
||||
lineno = "10"
|
||||
|
||||
|
||||
["browser_popup_mouseover.js"]
|
||||
skip-if = ["verify"]
|
||||
lineno = "13"
|
||||
|
||||
["browser_privbrowsing_perwindowpb.js"]
|
||||
skip-if = ["verify"]
|
||||
lineno = "17"
|
||||
|
|
|
|||
Loading…
Reference in a new issue