Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: chrome/browser/ui/cocoa/base_bubble_controller_unittest.mm

Issue 9732012: [Mac] Have BaseBubbleController dismiss bubbles when they would lose key state on 10.8. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
6 6
7 #include "base/memory/scoped_nsobject.h" 7 #include "base/mac/mac_util.h"
8 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" 8 #import "base/memory/scoped_nsobject.h"
9 #include "chrome/browser/ui/cocoa/info_bubble_view.h" 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
10 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
11 #import "chrome/browser/ui/cocoa/run_loop_testing.h"
12 #import "ui/base/test/cocoa_test_event_utils.h"
10 13
11 namespace { 14 namespace {
12 const CGFloat kBubbleWindowWidth = 100; 15 const CGFloat kBubbleWindowWidth = 100;
13 const CGFloat kBubbleWindowHeight = 50; 16 const CGFloat kBubbleWindowHeight = 50;
14 const CGFloat kAnchorPointX = 400; 17 const CGFloat kAnchorPointX = 400;
15 const CGFloat kAnchorPointY = 300; 18 const CGFloat kAnchorPointY = 300;
16 } // namespace 19 } // namespace
17 20
18 class BaseBubbleControllerTest : public CocoaTest { 21 class BaseBubbleControllerTest : public CocoaTest {
19 public: 22 public:
20 virtual void SetUp() OVERRIDE { 23 virtual void SetUp() OVERRIDE {
21 bubbleWindow_.reset([[NSWindow alloc] 24 bubbleWindow_.reset([[NSWindow alloc]
22 initWithContentRect:NSMakeRect(0, 0, kBubbleWindowWidth, 25 initWithContentRect:NSMakeRect(0, 0, kBubbleWindowWidth,
23 kBubbleWindowHeight) 26 kBubbleWindowHeight)
24 styleMask:NSBorderlessWindowMask 27 styleMask:NSBorderlessWindowMask
25 backing:NSBackingStoreBuffered 28 backing:NSBackingStoreBuffered
26 defer:YES]); 29 defer:YES]);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 106
104 NSRect frame = [[controller_ window] frame]; 107 NSRect frame = [[controller_ window] frame];
105 // Make sure the bubble size hasn't changed. 108 // Make sure the bubble size hasn't changed.
106 EXPECT_EQ(frame.size.width, kBubbleWindowWidth); 109 EXPECT_EQ(frame.size.width, kBubbleWindowWidth);
107 EXPECT_EQ(frame.size.height, kBubbleWindowHeight); 110 EXPECT_EQ(frame.size.height, kBubbleWindowHeight);
108 // Make sure the bubble arrow points to the anchor. 111 // Make sure the bubble arrow points to the anchor.
109 EXPECT_EQ(NSMaxX(frame) - info_bubble::kBubbleArrowXOffset - 112 EXPECT_EQ(NSMaxX(frame) - info_bubble::kBubbleArrowXOffset -
110 floorf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX); 113 floorf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX);
111 EXPECT_GE(NSMaxY(frame), kAnchorPointY); 114 EXPECT_GE(NSMaxY(frame), kAnchorPointY);
112 } 115 }
116
117 // Tests that when a new window gets key state (and the bubble resigns) that
118 // the key window changes.
119 TEST_F(BaseBubbleControllerTest, ResignKeyCloses) {
120 // Closing the bubble will autorelease the controller.
121 scoped_nsobject<BaseBubbleController> keep_alive([controller_ retain]);
122
123 NSWindow* bubble_window = [controller_ window];
124 EXPECT_FALSE([bubble_window isVisible]);
125
126 scoped_nsobject<NSWindow> other_window(
127 [[NSWindow alloc] initWithContentRect:NSMakeRect(500, 500, 500, 500)
128 styleMask:NSTitledWindowMask
129 backing:NSBackingStoreBuffered
130 defer:YES]);
131 EXPECT_FALSE([other_window isVisible]);
132
133 [controller_ showWindow:nil];
134 EXPECT_TRUE([bubble_window isVisible]);
135 EXPECT_FALSE([other_window isVisible]);
136
137 [other_window makeKeyAndOrderFront:nil];
138 // Fake the key state notification. Because unit_tests is a "daemon" process
139 // type, its windows can never become key (nor can the app become active).
140 // Instead of the hacks below, one could make a browser_test or transform the
141 // process type, but this seems easiest and is best suited to a unit test.
142 //
143 // On Lion and above, which have the event taps, simply post a notification
144 // that will cause the controller to call |-windowDidResignKey:|. Earlier
145 // OSes can call through directly.
146 NSNotification* notif =
147 [NSNotification notificationWithName:NSWindowDidResignKeyNotification
148 object:bubble_window];
149 if (base::mac::IsOSLionOrLater())
150 [[NSNotificationCenter defaultCenter] postNotification:notif];
151 else
152 [controller_ windowDidResignKey:notif];
153
154
155 EXPECT_FALSE([bubble_window isVisible]);
156 EXPECT_TRUE([other_window isVisible]);
157 }
158
159 // Test that clicking outside the window causes the bubble to close.
160 TEST_F(BaseBubbleControllerTest, LionClickOutsideCloses) {
161 // The event tap is only installed on 10.7+.
162 if (!base::mac::IsOSLionOrLater())
163 return;
164
165 // Closing the bubble will autorelease the controller.
166 scoped_nsobject<BaseBubbleController> keep_alive([controller_ retain]);
167 NSWindow* window = [controller_ window];
168
169 EXPECT_FALSE([window isVisible]);
170
171 [controller_ showWindow:nil];
172
173 EXPECT_TRUE([window isVisible]);
174
175 NSEvent* event = cocoa_test_event_utils::LeftMouseDownAtPointInWindow(
176 NSMakePoint(10, 10), test_window());
177 [NSApp sendEvent:event];
178 chrome::testing::NSRunLoopRunAllPending();
179
180 EXPECT_FALSE([window isVisible]);
181 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/base_bubble_controller.mm ('k') | chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698