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

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

Issue 1917973002: mac: Remove IsOSLion(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tapted Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/mac/mac_util.h"
8 #import "base/mac/scoped_nsobject.h" 7 #import "base/mac/scoped_nsobject.h"
9 #import "base/mac/scoped_objc_class_swizzler.h" 8 #import "base/mac/scoped_objc_class_swizzler.h"
10 #import "base/mac/sdk_forward_declarations.h" 9 #import "base/mac/sdk_forward_declarations.h"
11 #include "base/macros.h" 10 #include "base/macros.h"
12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
13 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 12 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
14 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 13 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
15 #import "ui/events/test/cocoa_test_event_utils.h" 14 #import "ui/events/test/cocoa_test_event_utils.h"
16 15
17 namespace { 16 namespace {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 [controller_ showWindow:nil]; 138 [controller_ showWindow:nil];
140 EXPECT_TRUE([bubble_window_ isVisible]); 139 EXPECT_TRUE([bubble_window_ isVisible]);
141 return keep_alive; 140 return keep_alive;
142 } 141 }
143 142
144 // Fake the key state notification. Because unit_tests is a "daemon" process 143 // Fake the key state notification. Because unit_tests is a "daemon" process
145 // type, its windows can never become key (nor can the app become active). 144 // type, its windows can never become key (nor can the app become active).
146 // Instead of the hacks below, one could make a browser_test or transform the 145 // Instead of the hacks below, one could make a browser_test or transform the
147 // process type, but this seems easiest and is best suited to a unit test. 146 // process type, but this seems easiest and is best suited to a unit test.
148 // 147 //
149 // On Lion and above, which have the event taps, simply post a notification 148 // Simply post a notification that will cause the controller to call
150 // that will cause the controller to call |-windowDidResignKey:|. Earlier 149 // |-windowDidResignKey:|.
151 // OSes can call through directly.
152 void SimulateKeyStatusChange() { 150 void SimulateKeyStatusChange() {
153 NSNotification* notif = 151 NSNotification* notif =
154 [NSNotification notificationWithName:NSWindowDidResignKeyNotification 152 [NSNotification notificationWithName:NSWindowDidResignKeyNotification
155 object:[controller_ window]]; 153 object:[controller_ window]];
156 if (base::mac::IsOSLionOrLater()) 154 [[NSNotificationCenter defaultCenter] postNotification:notif];
157 [[NSNotificationCenter defaultCenter] postNotification:notif];
158 else
159 [controller_ windowDidResignKey:notif];
160 } 155 }
161 156
162 protected: 157 protected:
163 base::scoped_nsobject<InfoBubbleWindow> bubble_window_; 158 base::scoped_nsobject<InfoBubbleWindow> bubble_window_;
164 BaseBubbleController* controller_; 159 BaseBubbleController* controller_;
165 160
166 private: 161 private:
167 DISALLOW_COPY_AND_ASSIGN(BaseBubbleControllerTest); 162 DISALLOW_COPY_AND_ASSIGN(BaseBubbleControllerTest);
168 }; 163 };
169 164
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 [other_window makeKeyAndOrderFront:nil]; 273 [other_window makeKeyAndOrderFront:nil];
279 SimulateKeyStatusChange(); 274 SimulateKeyStatusChange();
280 275
281 EXPECT_FALSE([bubble_window_ isVisible]); 276 EXPECT_FALSE([bubble_window_ isVisible]);
282 EXPECT_TRUE([other_window isVisible]); 277 EXPECT_TRUE([other_window isVisible]);
283 } 278 }
284 279
285 // Test that clicking outside the window causes the bubble to close if 280 // Test that clicking outside the window causes the bubble to close if
286 // shouldCloseOnResignKey is YES. 281 // shouldCloseOnResignKey is YES.
287 TEST_F(BaseBubbleControllerTest, LionClickOutsideClosesWithoutContextMenu) { 282 TEST_F(BaseBubbleControllerTest, LionClickOutsideClosesWithoutContextMenu) {
288 // The event tap is only installed on 10.7+.
289 if (!base::mac::IsOSLionOrLater())
290 return;
291
292 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble(); 283 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble();
293 NSWindow* window = [controller_ window]; 284 NSWindow* window = [controller_ window];
294 285
295 EXPECT_TRUE([controller_ shouldCloseOnResignKey]); // Verify default value. 286 EXPECT_TRUE([controller_ shouldCloseOnResignKey]); // Verify default value.
296 [controller_ setShouldCloseOnResignKey:NO]; 287 [controller_ setShouldCloseOnResignKey:NO];
297 NSEvent* event = cocoa_test_event_utils::LeftMouseDownAtPointInWindow( 288 NSEvent* event = cocoa_test_event_utils::LeftMouseDownAtPointInWindow(
298 NSMakePoint(10, 10), test_window()); 289 NSMakePoint(10, 10), test_window());
299 [NSApp sendEvent:event]; 290 [NSApp sendEvent:event];
300 291
301 EXPECT_TRUE([window isVisible]); 292 EXPECT_TRUE([window isVisible]);
(...skipping 18 matching lines...) Expand all
320 event = cocoa_test_event_utils::RightMouseDownAtPointInWindow( 311 event = cocoa_test_event_utils::RightMouseDownAtPointInWindow(
321 NSMakePoint(10, 10), test_window()); 312 NSMakePoint(10, 10), test_window());
322 [NSApp sendEvent:event]; 313 [NSApp sendEvent:event];
323 314
324 EXPECT_FALSE([window isVisible]); 315 EXPECT_FALSE([window isVisible]);
325 } 316 }
326 317
327 // Test that right-clicking the window with displaying a context menu causes 318 // Test that right-clicking the window with displaying a context menu causes
328 // the bubble to close. 319 // the bubble to close.
329 TEST_F(BaseBubbleControllerTest, LionRightClickOutsideClosesWithContextMenu) { 320 TEST_F(BaseBubbleControllerTest, LionRightClickOutsideClosesWithContextMenu) {
330 // The event tap is only installed on 10.7+.
331 if (!base::mac::IsOSLionOrLater())
332 return;
333
334 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble(); 321 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble();
335 NSWindow* window = [controller_ window]; 322 NSWindow* window = [controller_ window];
336 323
337 base::scoped_nsobject<NSMenu> context_menu( 324 base::scoped_nsobject<NSMenu> context_menu(
338 [[NSMenu alloc] initWithTitle:@""]); 325 [[NSMenu alloc] initWithTitle:@""]);
339 [context_menu addItemWithTitle:@"ContextMenuTest" 326 [context_menu addItemWithTitle:@"ContextMenuTest"
340 action:nil 327 action:nil
341 keyEquivalent:@""]; 328 keyEquivalent:@""];
342 base::scoped_nsobject<ContextMenuController> menu_controller( 329 base::scoped_nsobject<ContextMenuController> menu_controller(
343 [[ContextMenuController alloc] initWithMenu:context_menu 330 [[ContextMenuController alloc] initWithMenu:context_menu
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // Post the "exit fullscreen" notification. 423 // Post the "exit fullscreen" notification.
437 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 424 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
438 [center postNotificationName:NSWindowWillExitFullScreenNotification 425 [center postNotificationName:NSWindowWillExitFullScreenNotification
439 object:test_window()]; 426 object:test_window()];
440 427
441 EXPECT_FALSE([bubble_window_ isVisible]); 428 EXPECT_FALSE([bubble_window_ isVisible]);
442 } 429 }
443 430
444 // Tests that a bubble will not close when it's becoming a key window. 431 // Tests that a bubble will not close when it's becoming a key window.
445 TEST_F(BaseBubbleControllerTest, StayOnFocus) { 432 TEST_F(BaseBubbleControllerTest, StayOnFocus) {
446 // The event tap is only installed on 10.7+.
447 if (!base::mac::IsOSLionOrLater())
448 return;
449
450 [controller_ setShouldOpenAsKeyWindow:NO]; 433 [controller_ setShouldOpenAsKeyWindow:NO];
451 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble(); 434 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble();
452 435
453 EXPECT_TRUE([bubble_window_ isVisible]); 436 EXPECT_TRUE([bubble_window_ isVisible]);
454 EXPECT_TRUE([controller_ shouldCloseOnResignKey]); // Verify default value. 437 EXPECT_TRUE([controller_ shouldCloseOnResignKey]); // Verify default value.
455 438
456 // Make the bubble a key window. 439 // Make the bubble a key window.
457 g_key_window = [controller_ window]; 440 g_key_window = [controller_ window];
458 base::mac::ScopedObjCClassSwizzler swizzler( 441 base::mac::ScopedObjCClassSwizzler swizzler(
459 [NSApplication class], [FakeKeyWindow class], @selector(keyWindow)); 442 [NSApplication class], [FakeKeyWindow class], @selector(keyWindow));
460 443
461 // Post the "resign key" notification for another window. 444 // Post the "resign key" notification for another window.
462 NSNotification* notif = 445 NSNotification* notif =
463 [NSNotification notificationWithName:NSWindowDidResignKeyNotification 446 [NSNotification notificationWithName:NSWindowDidResignKeyNotification
464 object:test_window()]; 447 object:test_window()];
465 [[NSNotificationCenter defaultCenter] postNotification:notif]; 448 [[NSNotificationCenter defaultCenter] postNotification:notif];
466 449
467 EXPECT_TRUE([bubble_window_ isVisible]); 450 EXPECT_TRUE([bubble_window_ isVisible]);
468 g_key_window = nil; 451 g_key_window = nil;
469 } 452 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/base_bubble_controller.mm ('k') | chrome/browser/ui/cocoa/browser_window_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698