Skip to content

Commit 16fd06a

Browse files
dualfrozmtigley@mozilla.com
authored andcommitted
Bug 1996443 - Focus the browser window when opening about:logins via LoginHelper.openPasswordManager. r=mtigley,credential-management-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D332854
1 parent 59e3787 commit 16fd06a

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎browser/base/content/test/browser-pageinfo/browser_pageinfo_security.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,45 @@ add_task(async function test_SavedPasswords() {
497497
}
498498
});
499499

500+
// Test that "View Saved Passwords" opens about:logins in a focused browser window.
501+
add_task(async function test_ViewSavedPasswords_focusesBrowserWindow() {
502+
await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function () {
503+
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN, "securityTab");
504+
await BrowserTestUtils.waitForEvent(pageInfo, "load");
505+
await SimpleTest.promiseFocus(pageInfo);
506+
let pageInfoDoc = pageInfo.document;
507+
let viewPasswordsButton = pageInfoDoc.getElementById(
508+
"security-view-password"
509+
);
510+
await TestUtils.waitForCondition(
511+
() => BrowserTestUtils.isVisible(viewPasswordsButton),
512+
"View Saved Passwords button should be visible."
513+
);
514+
is(
515+
Services.focus.activeWindow,
516+
pageInfo,
517+
"Page Info window is focused before clicking the button"
518+
);
519+
520+
let tabPromise = BrowserTestUtils.waitForNewTab(
521+
gBrowser,
522+
"about:logins?filter=example.com&entryPoint=Pageinfo"
523+
);
524+
viewPasswordsButton.click();
525+
let tab = await tabPromise;
526+
527+
is(gBrowser.selectedTab, tab, "about:logins tab is selected");
528+
await TestUtils.waitForCondition(
529+
() => Services.focus.activeWindow == window,
530+
"Browser window containing about:logins should be focused"
531+
);
532+
ok(!pageInfo.closed, "Page Info window stays open");
533+
534+
BrowserTestUtils.removeTab(tab);
535+
pageInfo.close();
536+
});
537+
});
538+
500539
// Clean up in case we missed anything...
501540
add_task(async function cleanup() {
502541
await SiteDataTestUtils.clear();

‎toolkit/components/passwordmgr/LoginHelper.sys.mjs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,8 @@ export const LoginHelper = {
12311231
},
12321232

12331233
/**
1234-
* Open the password manager window.
1234+
* Open the password manager in a new tab and bring the browser window
1235+
* containing it to the foreground.
12351236
*
12361237
* @param {Window} window
12371238
* the window from where we want to open the dialog
@@ -1272,6 +1273,10 @@ export const LoginHelper = {
12721273
});
12731274

12741275
tab.setAttribute("preselect-login", preselectedLogin);
1276+
1277+
// The caller may live in a different window (e.g. Page Info), so bring
1278+
// the browser window showing about:logins to the foreground.
1279+
browser.documentGlobal.focus();
12751280
},
12761281

12771282
/**

0 commit comments

Comments
 (0)