diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /browser/base/content/test/general/browser_newwindow_focus.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/general/browser_newwindow_focus.js')
-rw-r--r-- | browser/base/content/test/general/browser_newwindow_focus.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/browser/base/content/test/general/browser_newwindow_focus.js b/browser/base/content/test/general/browser_newwindow_focus.js new file mode 100644 index 0000000000..fa0f5c3d79 --- /dev/null +++ b/browser/base/content/test/general/browser_newwindow_focus.js @@ -0,0 +1,93 @@ +"use strict"; + +/** + * These tests are for the auto-focus behaviour on the initial browser + * when a window is opened from content. + */ + +const PAGE = `data:text/html,<a id="target" href="%23" onclick="window.open('http://www.example.com', '_blank', 'width=100,height=100');">Click me</a>`; + +/** + * Test that when a new window is opened from content, focus moves + * to the initial browser in that window once the window has finished + * painting. + */ +add_task(async function test_focus_browser() { + await BrowserTestUtils.withNewTab( + { + url: PAGE, + gBrowser, + }, + async function(browser) { + let newWinPromise = BrowserTestUtils.domWindowOpenedAndLoaded(null); + let delayedStartupPromise = BrowserTestUtils.waitForNewWindow(); + + await BrowserTestUtils.synthesizeMouseAtCenter("#target", {}, browser); + let newWin = await newWinPromise; + await BrowserTestUtils.waitForContentEvent( + newWin.gBrowser.selectedBrowser, + "MozAfterPaint" + ); + await delayedStartupPromise; + + let focusedElement = Services.focus.getFocusedElementForWindow( + newWin, + false, + {} + ); + + Assert.equal( + focusedElement, + newWin.gBrowser.selectedBrowser, + "Initial browser should be focused" + ); + + await BrowserTestUtils.closeWindow(newWin); + } + ); +}); + +/** + * Test that when a new window is opened from content and focus + * shifts in that window before the content has a chance to paint + * that we _don't_ steal focus once content has painted. + */ +add_task(async function test_no_steal_focus() { + await BrowserTestUtils.withNewTab( + { + url: PAGE, + gBrowser, + }, + async function(browser) { + let newWinPromise = BrowserTestUtils.domWindowOpenedAndLoaded(null); + let delayedStartupPromise = BrowserTestUtils.waitForNewWindow(); + + await BrowserTestUtils.synthesizeMouseAtCenter("#target", {}, browser); + let newWin = await newWinPromise; + + // Because we're switching focus, we shouldn't steal it once + // content paints. + newWin.gURLBar.focus(); + + await BrowserTestUtils.waitForContentEvent( + newWin.gBrowser.selectedBrowser, + "MozAfterPaint" + ); + await delayedStartupPromise; + + let focusedElement = Services.focus.getFocusedElementForWindow( + newWin, + false, + {} + ); + + Assert.equal( + focusedElement, + newWin.gURLBar.inputField, + "URLBar should be focused" + ); + + await BrowserTestUtils.closeWindow(newWin); + } + ); +}); |