summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvasilii <vasilii@chromium.org>2015-07-28 01:10:48 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-28 08:11:50 +0000
commit90fdd5c0d1db7d7bde09f133ed110a63e899e16a (patch)
treed4e1b45be322316b8e7a61f56eb7a1d616c96567
parentd09991c2ed2a097b39a29292e839912e4399985f (diff)
downloadchromium_src-90fdd5c0d1db7d7bde09f133ed110a63e899e16a.zip
chromium_src-90fdd5c0d1db7d7bde09f133ed110a63e899e16a.tar.gz
chromium_src-90fdd5c0d1db7d7bde09f133ed110a63e899e16a.tar.bz2
Do not close a bubble if it becomes a focus window.
On Cocoa BaseBubbleController closes the bubble if any window (the intent is to track the parent actually) looses focus. It makes no sense if the bubble itself is about to get focus. BUG=513313 Review URL: https://codereview.chromium.org/1253973002 Cr-Commit-Position: refs/heads/master@{#340653}
-rw-r--r--chrome/browser/ui/cocoa/base_bubble_controller.mm3
-rw-r--r--chrome/browser/ui/cocoa/base_bubble_controller_unittest.mm42
2 files changed, 44 insertions, 1 deletions
diff --git a/chrome/browser/ui/cocoa/base_bubble_controller.mm b/chrome/browser/ui/cocoa/base_bubble_controller.mm
index d22693ab..11b9212 100644
--- a/chrome/browser/ui/cocoa/base_bubble_controller.mm
+++ b/chrome/browser/ui/cocoa/base_bubble_controller.mm
@@ -359,7 +359,8 @@
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* notif) {
- if (![[notif object] isSheet])
+ if (![[notif object] isSheet] &&
+ [NSApp keyWindow] != [self window])
[self windowDidResignKey:note];
}];
}
diff --git a/chrome/browser/ui/cocoa/base_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/base_bubble_controller_unittest.mm
index ba5d911..91b8378 100644
--- a/chrome/browser/ui/cocoa/base_bubble_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/base_bubble_controller_unittest.mm
@@ -6,6 +6,7 @@
#include "base/mac/mac_util.h"
#import "base/mac/scoped_nsobject.h"
+#import "base/mac/scoped_objc_class_swizzler.h"
#import "base/mac/sdk_forward_declarations.h"
#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#import "chrome/browser/ui/cocoa/info_bubble_view.h"
@@ -17,6 +18,8 @@ const CGFloat kBubbleWindowWidth = 100;
const CGFloat kBubbleWindowHeight = 50;
const CGFloat kAnchorPointX = 400;
const CGFloat kAnchorPointY = 300;
+
+NSWindow* g_key_window = nil;
} // namespace
@interface ContextMenuController : NSObject<NSMenuDelegate> {
@@ -85,6 +88,18 @@ const CGFloat kAnchorPointY = 300;
@end
+// A helper class to swizzle [NSApplication keyWindow].
+@interface FakeKeyWindow : NSObject
+@property(readonly) NSWindow* keyWindow;
+@end
+
+@implementation FakeKeyWindow
+- (NSWindow*)keyWindow {
+ return g_key_window;
+}
+@end
+
+
class BaseBubbleControllerTest : public CocoaTest {
public:
BaseBubbleControllerTest() : controller_(nil) {}
@@ -424,3 +439,30 @@ TEST_F(BaseBubbleControllerTest, ExitFullscreen) {
EXPECT_FALSE([bubble_window_ isVisible]);
}
+
+// Tests that a bubble will not close when it's becoming a key window.
+TEST_F(BaseBubbleControllerTest, StayOnFocus) {
+ // The event tap is only installed on 10.7+.
+ if (!base::mac::IsOSLionOrLater())
+ return;
+
+ [controller_ setShouldOpenAsKeyWindow:NO];
+ base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble();
+
+ EXPECT_TRUE([bubble_window_ isVisible]);
+ EXPECT_TRUE([controller_ shouldCloseOnResignKey]); // Verify default value.
+
+ // Make the bubble a key window.
+ g_key_window = [controller_ window];
+ base::mac::ScopedObjCClassSwizzler swizzler(
+ [NSApplication class], [FakeKeyWindow class], @selector(keyWindow));
+
+ // Post the "resign key" notification for another window.
+ NSNotification* notif =
+ [NSNotification notificationWithName:NSWindowDidResignKeyNotification
+ object:test_window()];
+ [[NSNotificationCenter defaultCenter] postNotification:notif];
+
+ EXPECT_TRUE([bubble_window_ isVisible]);
+ g_key_window = nil;
+}