Index: chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa_unittest.mm |
diff --git a/chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa_unittest.mm b/chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa_unittest.mm |
index 82eb43084dc22a475e5aaa58844a3132d8760a5e..5db7f0222cff0bf12d3520dda94e91fbf882c1a0 100644 |
--- a/chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa_unittest.mm |
+++ b/chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa_unittest.mm |
@@ -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()); |
+} |