| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/website_settings/permission_bubble_controller.h
" | 5 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_controller.h
" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #import "base/mac/scoped_objc_class_swizzler.h" | 10 #import "base/mac/scoped_objc_class_swizzler.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 @end | 41 @end |
| 42 | 42 |
| 43 @interface SplitBlockButton (ExposedForTesting) | 43 @interface SplitBlockButton (ExposedForTesting) |
| 44 - (NSMenu*)menu; | 44 - (NSMenu*)menu; |
| 45 @end | 45 @end |
| 46 | 46 |
| 47 @interface MockBubbleYesLocationBar : NSObject | 47 @interface MockBubbleYesLocationBar : NSObject |
| 48 @end | 48 @end |
| 49 | 49 |
| 50 @implementation MockBubbleYesLocationBar | 50 @implementation MockBubbleYesLocationBar |
| 51 - (bool)hasVisibleLocationBar { return true; } | 51 + (bool)hasVisibleLocationBarForBrowser:(Browser*)browser { return true; } |
| 52 @end | 52 @end |
| 53 | 53 |
| 54 @interface MockBubbleNoLocationBar : NSObject | 54 @interface MockBubbleNoLocationBar : NSObject |
| 55 @end | 55 @end |
| 56 | 56 |
| 57 @implementation MockBubbleNoLocationBar | 57 @implementation MockBubbleNoLocationBar |
| 58 - (bool)hasVisibleLocationBar { return false; } | 58 + (bool)hasVisibleLocationBarForBrowser:(Browser*)browser { return false; } |
| 59 @end | 59 @end |
| 60 | 60 |
| 61 namespace { | 61 namespace { |
| 62 const char* const kPermissionA = "Permission A"; | 62 const char* const kPermissionA = "Permission A"; |
| 63 const char* const kPermissionB = "Permission B"; | 63 const char* const kPermissionB = "Permission B"; |
| 64 const char* const kPermissionC = "Permission C"; | 64 const char* const kPermissionC = "Permission C"; |
| 65 } | 65 } |
| 66 | 66 |
| 67 class PermissionBubbleControllerTest : public CocoaProfileTest, | 67 class PermissionBubbleControllerTest : public CocoaProfileTest, |
| 68 public PermissionBubbleView::Delegate { | 68 public PermissionBubbleView::Delegate { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 346 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 347 [center postNotificationName:NSWindowWillExitFullScreenNotification | 347 [center postNotificationName:NSWindowWillExitFullScreenNotification |
| 348 object:test_window()]; | 348 object:test_window()]; |
| 349 | 349 |
| 350 EXPECT_TRUE([[controller_ window] isVisible]); | 350 EXPECT_TRUE([[controller_ window] isVisible]); |
| 351 } | 351 } |
| 352 | 352 |
| 353 TEST_F(PermissionBubbleControllerTest, AnchorPositionWithLocationBar) { | 353 TEST_F(PermissionBubbleControllerTest, AnchorPositionWithLocationBar) { |
| 354 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 354 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 355 [PermissionBubbleController class], [MockBubbleYesLocationBar class], | 355 [PermissionBubbleController class], [MockBubbleYesLocationBar class], |
| 356 @selector(hasVisibleLocationBar)); | 356 @selector(hasVisibleLocationBarForBrowser:)); |
| 357 | 357 |
| 358 NSPoint anchor = [controller_ getExpectedAnchorPoint]; | 358 NSPoint anchor = [controller_ getExpectedAnchorPoint]; |
| 359 | 359 |
| 360 // Expected anchor location will be the same as the page info bubble. | 360 // Expected anchor location will be the same as the page info bubble. |
| 361 NSWindow* window = browser()->window()->GetNativeWindow(); | 361 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 362 BrowserWindowController* controller = | 362 BrowserWindowController* controller = |
| 363 [BrowserWindowController browserWindowControllerForWindow:window]; | 363 [BrowserWindowController browserWindowControllerForWindow:window]; |
| 364 LocationBarViewMac* location_bar_bridge = [controller locationBarBridge]; | 364 LocationBarViewMac* location_bar_bridge = [controller locationBarBridge]; |
| 365 NSPoint expected = location_bar_bridge->GetPageInfoBubblePoint(); | 365 NSPoint expected = location_bar_bridge->GetPageInfoBubblePoint(); |
| 366 expected = ui::ConvertPointFromWindowToScreen(window, expected); | 366 expected = ui::ConvertPointFromWindowToScreen(window, expected); |
| 367 EXPECT_NSEQ(expected, anchor); | 367 EXPECT_NSEQ(expected, anchor); |
| 368 } | 368 } |
| 369 | 369 |
| 370 TEST_F(PermissionBubbleControllerTest, AnchorPositionWithoutLocationBar) { | 370 TEST_F(PermissionBubbleControllerTest, AnchorPositionWithoutLocationBar) { |
| 371 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 371 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 372 [PermissionBubbleController class], [MockBubbleNoLocationBar class], | 372 [PermissionBubbleController class], [MockBubbleNoLocationBar class], |
| 373 @selector(hasVisibleLocationBar)); | 373 @selector(hasVisibleLocationBarForBrowser:)); |
| 374 | 374 |
| 375 NSPoint anchor = [controller_ getExpectedAnchorPoint]; | 375 NSPoint anchor = [controller_ getExpectedAnchorPoint]; |
| 376 | 376 |
| 377 // Expected anchor location will be top center when there's no location bar. | 377 // Expected anchor location will be top center when there's no location bar. |
| 378 NSWindow* window = browser()->window()->GetNativeWindow(); | 378 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 379 NSRect frame = [window frame]; | 379 NSRect frame = [window frame]; |
| 380 NSPoint expected = NSMakePoint(frame.size.width / 2, frame.size.height); | 380 NSPoint expected = NSMakePoint(frame.size.width / 2, frame.size.height); |
| 381 expected = ui::ConvertPointFromWindowToScreen(window, expected); | 381 expected = ui::ConvertPointFromWindowToScreen(window, expected); |
| 382 EXPECT_NSEQ(expected, anchor); | 382 EXPECT_NSEQ(expected, anchor); |
| 383 } | 383 } |
| 384 | 384 |
| 385 TEST_F(PermissionBubbleControllerTest, | 385 TEST_F(PermissionBubbleControllerTest, |
| 386 AnchorPositionDifferentWithAndWithoutLocationBar) { | 386 AnchorPositionDifferentWithAndWithoutLocationBar) { |
| 387 NSPoint withLocationBar; | 387 NSPoint withLocationBar; |
| 388 { | 388 { |
| 389 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 389 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 390 [PermissionBubbleController class], [MockBubbleYesLocationBar class], | 390 [PermissionBubbleController class], [MockBubbleYesLocationBar class], |
| 391 @selector(hasVisibleLocationBar)); | 391 @selector(hasVisibleLocationBarForBrowser:)); |
| 392 withLocationBar = [controller_ getExpectedAnchorPoint]; | 392 withLocationBar = [controller_ getExpectedAnchorPoint]; |
| 393 } | 393 } |
| 394 | 394 |
| 395 NSPoint withoutLocationBar; | 395 NSPoint withoutLocationBar; |
| 396 { | 396 { |
| 397 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 397 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 398 [PermissionBubbleController class], [MockBubbleNoLocationBar class], | 398 [PermissionBubbleController class], [MockBubbleNoLocationBar class], |
| 399 @selector(hasVisibleLocationBar)); | 399 @selector(hasVisibleLocationBarForBrowser:)); |
| 400 withoutLocationBar = [controller_ getExpectedAnchorPoint]; | 400 withoutLocationBar = [controller_ getExpectedAnchorPoint]; |
| 401 } | 401 } |
| 402 | 402 |
| 403 // The bubble should be in different places depending if the location bar is | 403 // The bubble should be in different places depending if the location bar is |
| 404 // available or not. | 404 // available or not. |
| 405 EXPECT_NSNE(withLocationBar, withoutLocationBar); | 405 EXPECT_NSNE(withLocationBar, withoutLocationBar); |
| 406 } | 406 } |
| OLD | NEW |