Bug 1996443 - Focus the browser window when opening about:logins via LoginHelper.openPasswordManager. r?mtigley

Differential Revision: https://phabricator.services.mozilla.com/D332854
This commit is contained in:
dualfroz committed 2026-10-12 14:29:09 +02:00
1 parent 9ba8a90bce
commit edfad4e281
2 files changed
+45 -1

No files matched your search

@@ -497,6 +497,45 @@ add_task(async function test_SavedPasswords() {
}
});
// Test that "View Saved Passwords" opens about:logins in a focused browser window.
add_task(async function test_ViewSavedPasswords_focusesBrowserWindow() {
await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function () {
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN, "securityTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
await SimpleTest.promiseFocus(pageInfo);
let pageInfoDoc = pageInfo.document;
let viewPasswordsButton = pageInfoDoc.getElementById(
"security-view-password"
);
await TestUtils.waitForCondition(
() => BrowserTestUtils.isVisible(viewPasswordsButton),
"View Saved Passwords button should be visible."
);
is(
Services.focus.activeWindow,
pageInfo,
"Page Info window is focused before clicking the button"
);
let tabPromise = BrowserTestUtils.waitForNewTab(
gBrowser,
"about:logins?filter=example.com&entryPoint=Pageinfo"
);
viewPasswordsButton.click();
let tab = await tabPromise;
is(gBrowser.selectedTab, tab, "about:logins tab is selected");
await TestUtils.waitForCondition(
() => Services.focus.activeWindow == window,
"Browser window containing about:logins should be focused"
);
ok(!pageInfo.closed, "Page Info window stays open");
BrowserTestUtils.removeTab(tab);
pageInfo.close();
});
});
// Clean up in case we missed anything...
add_task(async function cleanup() {
await SiteDataTestUtils.clear();
@@ -1231,7 +1231,8 @@ export const LoginHelper = {
},
/**
* Open the password manager window.
* Open the password manager in a new tab and bring the browser window
* containing it to the foreground.
*
* @param {Window} window
* the window from where we want to open the dialog
@@ -1272,6 +1273,10 @@ export const LoginHelper = {
});
tab.setAttribute("preselect-login", preselectedLogin);
// The caller may live in a different window (e.g. Page Info), so bring
// the browser window showing about:logins to the foreground.
browser.documentGlobal.focus();
},
/**