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_test_focus_after_modal_state.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.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_test_focus_after_modal_state.js')
-rw-r--r-- | dom/tests/browser/browser_test_focus_after_modal_state.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/dom/tests/browser/browser_test_focus_after_modal_state.js b/dom/tests/browser/browser_test_focus_after_modal_state.js new file mode 100644 index 0000000000..2193d8fdc4 --- /dev/null +++ b/dom/tests/browser/browser_test_focus_after_modal_state.js @@ -0,0 +1,71 @@ +const TEST_URL = + "https://example.com/browser/dom/tests/browser/focus_after_prompt.html"; + +const { PromptTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/PromptTestUtils.sys.mjs" +); + +function awaitAndClosePrompt(browser) { + return PromptTestUtils.handleNextPrompt( + browser, + { modalType: Services.prompt.MODAL_TYPE_CONTENT, promptType: "prompt" }, + { buttonNumClick: 0 } + ); +} + +add_task(async function () { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL); + let browser = tab.linkedBrowser; + + // Focus on editable iframe. + await BrowserTestUtils.synthesizeMouseAtCenter("#edit", {}, browser); + await SpecialPowers.spawn(browser, [], async function () { + is( + content.document.activeElement, + content.document.getElementById("edit"), + "Focus should be on iframe element" + ); + }); + + let focusBlurPromise = SpecialPowers.spawn(browser, [], async function () { + let focusOccurred = false; + let blurOccurred = false; + + return new Promise(resolve => { + let doc = content.document.getElementById("edit").contentDocument; + doc.addEventListener("focus", function (event) { + focusOccurred = true; + if (blurOccurred) { + resolve(true); + } + }); + + doc.addEventListener("blur", function (event) { + blurOccurred = true; + if (focusOccurred) { + resolve(false); + } + }); + }); + }); + + // Click on div that triggers a prompt, and then check that focus is back on + // the editable iframe. + let dialogShown = awaitAndClosePrompt(browser); + await SpecialPowers.spawn(browser, [], async function () { + let div = content.document.getElementById("clickMeDiv"); + div.click(); + }); + await dialogShown; + let blurCameFirst = await focusBlurPromise; + await SpecialPowers.spawn(browser, [], async function () { + is( + content.document.activeElement, + content.document.getElementById("edit"), + "Focus should be back on iframe element" + ); + }); + ok(blurCameFirst, "Should receive blur and then focus event"); + + BrowserTestUtils.removeTab(tab); +}); |