Commit a912b886 authored by dconnelly's avatar dconnelly Committed by Commit bot

Don't try to show the Mac password bubble on an inactive tab.

Thanks to vabr@ for reproducing.

BUG=409589
TBR=rohitrao

Review URL: https://codereview.chromium.org/528213004

Cr-Commit-Position: refs/heads/master@{#293118}
parent 9e4f7967
......@@ -51,6 +51,10 @@ void ShowManagePasswordsBubble(content::WebContents* webContents) {
ManagePasswordsUIController* controller =
ManagePasswordsUIController::FromWebContents(webContents);
NSWindow* window = webContents->GetTopLevelNativeWindow();
if (!window) {
// The tab isn't active right now.
return;
}
BrowserWindowController* bwc =
[BrowserWindowController browserWindowControllerForWindow:window];
ManagePasswordsBubbleCocoa::ShowBubble(
......
......@@ -34,8 +34,7 @@ class ManagePasswordsBubbleCocoaTest : public CocoaProfileTest {
// Create the WebContents.
siteInstance_ = content::SiteInstance::Create(profile());
webContents_ = content::WebContents::Create(
content::WebContents::CreateParams(profile(), siteInstance_.get()));
webContents_ = CreateWebContents();
browser()->tab_strip_model()->AppendWebContents(
webContents_, /*foreground=*/true);
......@@ -49,19 +48,19 @@ class ManagePasswordsBubbleCocoaTest : public CocoaProfileTest {
content::WebContents* webContents() { return webContents_; }
content::WebContents* CreateWebContents() {
return content::WebContents::Create(
content::WebContents::CreateParams(profile(), siteInstance_.get()));
}
void ShowBubble() {
NSWindow* nativeWindow = browser()->window()->GetNativeWindow();
BrowserWindowController* bwc =
[BrowserWindowController browserWindowControllerForWindow:nativeWindow];
ManagePasswordsIcon* icon =
[bwc locationBarBridge]->manage_passwords_decoration()->icon();
ManagePasswordsBubbleCocoa::ShowBubble(
webContents(), ManagePasswordsBubble::DisplayReason::AUTOMATIC, icon);
// Disable animations so that closing happens immediately.
InfoBubbleWindow* bubbleWindow = base::mac::ObjCCast<InfoBubbleWindow>(
[ManagePasswordsBubbleCocoa::instance()->controller_ window]);
[bubbleWindow setAllowedAnimations:info_bubble::kAnimateNone];
chrome::ShowManagePasswordsBubble(webContents());
if (ManagePasswordsBubbleCocoa::instance()) {
// Disable animations so that closing happens immediately.
InfoBubbleWindow* bubbleWindow = base::mac::ObjCCast<InfoBubbleWindow>(
[ManagePasswordsBubbleCocoa::instance()->controller_ window]);
[bubbleWindow setAllowedAnimations:info_bubble::kAnimateNone];
}
}
void CloseBubble() {
......@@ -104,3 +103,19 @@ TEST_F(ManagePasswordsBubbleCocoaTest, BackgroundCloseShouldDeleteBubble) {
EXPECT_FALSE(ManagePasswordsBubbleCocoa::instance());
EXPECT_FALSE([bubbleWindow() isVisible]);
}
TEST_F(ManagePasswordsBubbleCocoaTest, ShowBubbleOnInactiveTabShouldDoNothing) {
// Start in the tab that we'll try to show the bubble on.
EXPECT_TRUE(webContents()->GetTopLevelNativeWindow());
// Open a second tab and make it active.
content::WebContents* webContents2 = CreateWebContents();
browser()->tab_strip_model()->AppendWebContents(webContents2,
/*foreground=*/true);
EXPECT_FALSE(webContents()->GetTopLevelNativeWindow());
EXPECT_TRUE(webContents2->GetTopLevelNativeWindow());
// Try to show the bubble on the inactive tab. Nothing should happen.
ShowBubble();
EXPECT_FALSE(ManagePasswordsBubbleCocoa::instance());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment