Chromium Code Reviews| 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/permission_bubble/permission_bubble_controller. h" | 5 #import "chrome/browser/ui/cocoa/permission_bubble/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 21 matching lines...) Expand all Loading... | |
| 32 #import "ui/events/test/cocoa_test_event_utils.h" | 32 #import "ui/events/test/cocoa_test_event_utils.h" |
| 33 | 33 |
| 34 @class ConstrainedWindowButton; | 34 @class ConstrainedWindowButton; |
| 35 | 35 |
| 36 @interface PermissionBubbleController (ExposedForTesting) | 36 @interface PermissionBubbleController (ExposedForTesting) |
| 37 - (void)ok:(id)sender; | 37 - (void)ok:(id)sender; |
| 38 - (void)onAllow:(id)sender; | 38 - (void)onAllow:(id)sender; |
| 39 - (void)onBlock:(id)sender; | 39 - (void)onBlock:(id)sender; |
| 40 - (void)onCustomize:(id)sender; | 40 - (void)onCustomize:(id)sender; |
| 41 - (void)onCheckboxChanged:(id)sender; | 41 - (void)onCheckboxChanged:(id)sender; |
| 42 + (NSInteger)getFullscreenLeftOffset; | |
| 43 @end | 42 @end |
| 44 | 43 |
| 45 @interface SplitBlockButton (ExposedForTesting) | 44 @interface SplitBlockButton (ExposedForTesting) |
| 46 - (NSMenu*)menu; | 45 - (NSMenu*)menu; |
| 47 @end | 46 @end |
| 48 | 47 |
| 49 @interface MockBubbleYesLocationBar : NSObject | 48 @interface MockBubbleYesLocationBar : NSObject |
| 50 @end | 49 @end |
| 51 | 50 |
| 52 @implementation MockBubbleYesLocationBar | 51 @implementation MockBubbleYesLocationBar |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 NSWindow* window = browser()->window()->GetNativeWindow(); | 385 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 387 BrowserWindowController* controller = | 386 BrowserWindowController* controller = |
| 388 [BrowserWindowController browserWindowControllerForWindow:window]; | 387 [BrowserWindowController browserWindowControllerForWindow:window]; |
| 389 LocationBarViewMac* location_bar_bridge = [controller locationBarBridge]; | 388 LocationBarViewMac* location_bar_bridge = [controller locationBarBridge]; |
| 390 NSPoint expected = location_bar_bridge->GetPageInfoBubblePoint(); | 389 NSPoint expected = location_bar_bridge->GetPageInfoBubblePoint(); |
| 391 expected = ui::ConvertPointFromWindowToScreen(window, expected); | 390 expected = ui::ConvertPointFromWindowToScreen(window, expected); |
| 392 EXPECT_NSEQ(expected, anchor); | 391 EXPECT_NSEQ(expected, anchor); |
| 393 } | 392 } |
| 394 | 393 |
| 395 TEST_F(PermissionBubbleControllerTest, AnchorPositionWithoutLocationBar) { | 394 TEST_F(PermissionBubbleControllerTest, AnchorPositionWithoutLocationBar) { |
| 395 // Constant offset from the left to use for fullscreen permission bubbles. | |
|
tapted
2017/05/03 09:09:11
See bubble_anchor_helper.mm?
varkha
2017/05/03 09:22:40
Done.
| |
| 396 const NSInteger kFullscreenLeftOffset = 40; | |
| 397 | |
| 396 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 398 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 397 [PermissionBubbleController class], [MockBubbleNoLocationBar class], | 399 [PermissionBubbleController class], [MockBubbleNoLocationBar class], |
| 398 @selector(hasVisibleLocationBarForBrowser:)); | 400 @selector(hasVisibleLocationBarForBrowser:)); |
| 399 | 401 |
| 400 NSPoint anchor = [controller_ getExpectedAnchorPoint]; | 402 NSPoint anchor = [controller_ getExpectedAnchorPoint]; |
| 401 | 403 |
| 402 // Expected anchor location will be top left when there's no location bar. | 404 // Expected anchor location will be top left when there's no location bar. |
| 403 NSWindow* window = browser()->window()->GetNativeWindow(); | 405 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 404 NSRect frame = [[window contentView] frame]; | 406 NSRect frame = [[window contentView] frame]; |
| 405 NSPoint expected = NSMakePoint( | 407 NSPoint expected = |
| 406 NSMinX(frame) + [PermissionBubbleController getFullscreenLeftOffset], | 408 NSMakePoint(NSMinX(frame) + kFullscreenLeftOffset, NSMaxY(frame)); |
| 407 NSMaxY(frame)); | |
| 408 expected = ui::ConvertPointFromWindowToScreen(window, expected); | 409 expected = ui::ConvertPointFromWindowToScreen(window, expected); |
| 409 EXPECT_NSEQ(expected, anchor); | 410 EXPECT_NSEQ(expected, anchor); |
| 410 } | 411 } |
| 411 | 412 |
| 412 TEST_F(PermissionBubbleControllerTest, | 413 TEST_F(PermissionBubbleControllerTest, |
| 413 AnchorPositionDifferentWithAndWithoutLocationBar) { | 414 AnchorPositionDifferentWithAndWithoutLocationBar) { |
| 414 NSPoint withLocationBar; | 415 NSPoint withLocationBar; |
| 415 { | 416 { |
| 416 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 417 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 417 [PermissionBubbleController class], [MockBubbleYesLocationBar class], | 418 [PermissionBubbleController class], [MockBubbleYesLocationBar class], |
| 418 @selector(hasVisibleLocationBarForBrowser:)); | 419 @selector(hasVisibleLocationBarForBrowser:)); |
| 419 withLocationBar = [controller_ getExpectedAnchorPoint]; | 420 withLocationBar = [controller_ getExpectedAnchorPoint]; |
| 420 } | 421 } |
| 421 | 422 |
| 422 NSPoint withoutLocationBar; | 423 NSPoint withoutLocationBar; |
| 423 { | 424 { |
| 424 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 425 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 425 [PermissionBubbleController class], [MockBubbleNoLocationBar class], | 426 [PermissionBubbleController class], [MockBubbleNoLocationBar class], |
| 426 @selector(hasVisibleLocationBarForBrowser:)); | 427 @selector(hasVisibleLocationBarForBrowser:)); |
| 427 withoutLocationBar = [controller_ getExpectedAnchorPoint]; | 428 withoutLocationBar = [controller_ getExpectedAnchorPoint]; |
| 428 } | 429 } |
| 429 | 430 |
| 430 // The bubble should be in different places depending if the location bar is | 431 // The bubble should be in different places depending if the location bar is |
| 431 // available or not. | 432 // available or not. |
| 432 EXPECT_NSNE(withLocationBar, withoutLocationBar); | 433 EXPECT_NSNE(withLocationBar, withoutLocationBar); |
| 433 } | 434 } |
| OLD | NEW |