commit af4baca06e2a8299a31a4a9fc74fa988d9ce0686
parent b5c06a3466c1396daf4b73ae4ef4528bb121a6c6
Author: Mike Conley <mike.d.conley@gmail.com>
Date: Mon, 15 Dec 2025 22:17:30 +0000
Bug 2002330 - Wait for focus event in browser_newwindow_focus.js to fix race condition. r=emilio
The test was checking for the focused element immediately after paint/startup events, but
the browser's focus logic also waits for these events and the content paint event before
setting focus. Bug 2000504's paint refactoring changed event timing, probably exposing
this pre-existing race condition. We fix this by explicitly waiting for the focus event
before checking on the focused element.
Differential Revision: https://phabricator.services.mozilla.com/D276561
Diffstat:
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/browser/base/content/test/general/browser.toml b/browser/base/content/test/general/browser.toml
@@ -362,9 +362,6 @@ https_first_disabled = true
["browser_newwindow_focus.js"]
https_first_disabled = true
-skip-if = [
- "os == 'linux' && os_version == '24.04' && processor == 'x86_64' && opt", # Bug 2002330
-]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
["browser_printpreview.js"]
diff --git a/browser/base/content/test/general/browser_newwindow_focus.js b/browser/base/content/test/general/browser_newwindow_focus.js
@@ -30,6 +30,10 @@ add_task(async function test_focus_browser() {
await BrowserTestUtils.synthesizeMouseAtCenter("#target", {}, browser);
let newWin = await newWinPromise;
+
+ // Set up listener for focus event to bubble up on the window
+ let focusPromise = BrowserTestUtils.waitForEvent(newWin, "focus", true);
+
await BrowserTestUtils.waitForContentEvent(
newWin.gBrowser.selectedBrowser,
"MozAfterPaint"
@@ -42,6 +46,9 @@ add_task(async function test_focus_browser() {
"Delayed startup timings in correct order."
);
+ // Wait for the focus event to occur
+ await focusPromise;
+
let focusedElement = Services.focus.getFocusedElementForWindow(
newWin,
false,