diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/tests/browser/browser_cancel_keydown_keypress_event.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/tests/browser/browser_cancel_keydown_keypress_event.js')
-rw-r--r-- | dom/tests/browser/browser_cancel_keydown_keypress_event.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/dom/tests/browser/browser_cancel_keydown_keypress_event.js b/dom/tests/browser/browser_cancel_keydown_keypress_event.js new file mode 100644 index 0000000000..de08aa17e9 --- /dev/null +++ b/dom/tests/browser/browser_cancel_keydown_keypress_event.js @@ -0,0 +1,41 @@ +const URL = + "https://example.com/browser/dom/tests/browser/prevent_return_key.html"; + +const { PromptTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/PromptTestUtils.sys.mjs" +); + +// Wait for alert dialog and dismiss it immediately. +function awaitAndCloseAlertDialog(browser) { + return PromptTestUtils.handleNextPrompt( + browser, + { modalType: Services.prompt.MODAL_TYPE_CONTENT, promptType: "alert" }, + { buttonNumClick: 0 } + ); +} + +add_task(async function () { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL); + let browser = tab.linkedBrowser; + + // Focus and enter random text on input. + await SpecialPowers.spawn(browser, [], async function () { + let input = content.document.getElementById("input"); + input.focus(); + input.value = "abcd"; + }); + + // Send return key (cross process) to submit the form implicitly. + let dialogShown = awaitAndCloseAlertDialog(browser); + EventUtils.synthesizeKey("KEY_Enter"); + await dialogShown; + + // Check that the form should not have been submitted. + await SpecialPowers.spawn(browser, [], async function () { + let result = content.document.getElementById("result").innerHTML; + info("submit result: " + result); + is(result, "not submitted", "form should not have submitted"); + }); + + gBrowser.removeCurrentTab(); +}); |