| 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" |
| 11 #include "base/mac/sdk_forward_declarations.h" | 11 #include "base/mac/sdk_forward_declarations.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | 17 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 18 #import "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 18 #import "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 19 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 19 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 20 #include "chrome/browser/ui/cocoa/run_loop_testing.h" | 20 #include "chrome/browser/ui/cocoa/run_loop_testing.h" |
| 21 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" | 21 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" |
| 22 #import "chrome/browser/ui/cocoa/website_settings/split_block_button.h" | 22 #import "chrome/browser/ui/cocoa/website_settings/split_block_button.h" |
| 23 #include "chrome/browser/ui/website_settings/mock_permission_bubble_request.h" | 23 #include "chrome/browser/ui/website_settings/mock_permission_bubble_request.h" |
| 24 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
| 25 #include "grit/components_strings.h" | 25 #include "grit/components_strings.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #import "testing/gtest_mac.h" | 27 #import "testing/gtest_mac.h" |
| 28 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/base/l10n/l10n_util_mac.h" | 30 #include "ui/base/l10n/l10n_util_mac.h" |
| 30 #import "ui/events/test/cocoa_test_event_utils.h" | 31 #import "ui/events/test/cocoa_test_event_utils.h" |
| 31 | 32 |
| 32 @class ConstrainedWindowButton; | 33 @class ConstrainedWindowButton; |
| 33 | 34 |
| 34 @interface PermissionBubbleController (ExposedForTesting) | 35 @interface PermissionBubbleController (ExposedForTesting) |
| 35 - (void)ok:(id)sender; | 36 - (void)ok:(id)sender; |
| 36 - (void)onAllow:(id)sender; | 37 - (void)onAllow:(id)sender; |
| 37 - (void)onBlock:(id)sender; | 38 - (void)onBlock:(id)sender; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 @selector(hasLocationBar)); | 357 @selector(hasLocationBar)); |
| 357 | 358 |
| 358 NSPoint anchor = [controller_ getExpectedAnchorPoint]; | 359 NSPoint anchor = [controller_ getExpectedAnchorPoint]; |
| 359 | 360 |
| 360 // Expected anchor location will be the same as the page info bubble. | 361 // Expected anchor location will be the same as the page info bubble. |
| 361 NSWindow* window = browser()->window()->GetNativeWindow(); | 362 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 362 BrowserWindowController* controller = | 363 BrowserWindowController* controller = |
| 363 [BrowserWindowController browserWindowControllerForWindow:window]; | 364 [BrowserWindowController browserWindowControllerForWindow:window]; |
| 364 LocationBarViewMac* location_bar_bridge = [controller locationBarBridge]; | 365 LocationBarViewMac* location_bar_bridge = [controller locationBarBridge]; |
| 365 NSPoint expected = location_bar_bridge->GetPageInfoBubblePoint(); | 366 NSPoint expected = location_bar_bridge->GetPageInfoBubblePoint(); |
| 366 expected = [window convertBaseToScreen:expected]; | 367 expected = ui::ConvertPointFromWindowToScreen(window, expected); |
| 367 EXPECT_NSEQ(expected, anchor); | 368 EXPECT_NSEQ(expected, anchor); |
| 368 } | 369 } |
| 369 | 370 |
| 370 TEST_F(PermissionBubbleControllerTest, AnchorPositionWithoutLocationBar) { | 371 TEST_F(PermissionBubbleControllerTest, AnchorPositionWithoutLocationBar) { |
| 371 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 372 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 372 [PermissionBubbleController class], | 373 [PermissionBubbleController class], |
| 373 [MockBubbleNoLocationBar class], | 374 [MockBubbleNoLocationBar class], |
| 374 @selector(hasLocationBar)); | 375 @selector(hasLocationBar)); |
| 375 | 376 |
| 376 NSPoint anchor = [controller_ getExpectedAnchorPoint]; | 377 NSPoint anchor = [controller_ getExpectedAnchorPoint]; |
| 377 | 378 |
| 378 // Expected anchor location will be top center when there's no location bar. | 379 // Expected anchor location will be top center when there's no location bar. |
| 379 NSWindow* window = browser()->window()->GetNativeWindow(); | 380 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 380 NSRect frame = [window frame]; | 381 NSRect frame = [window frame]; |
| 381 NSPoint expected = NSMakePoint(frame.size.width / 2, frame.size.height); | 382 NSPoint expected = NSMakePoint(frame.size.width / 2, frame.size.height); |
| 382 expected = [window convertBaseToScreen:expected]; | 383 expected = ui::ConvertPointFromWindowToScreen(window, expected); |
| 383 EXPECT_NSEQ(expected, anchor); | 384 EXPECT_NSEQ(expected, anchor); |
| 384 } | 385 } |
| 385 | 386 |
| 386 TEST_F(PermissionBubbleControllerTest, | 387 TEST_F(PermissionBubbleControllerTest, |
| 387 AnchorPositionDifferentWithAndWithoutLocationBar) { | 388 AnchorPositionDifferentWithAndWithoutLocationBar) { |
| 388 NSPoint withLocationBar; | 389 NSPoint withLocationBar; |
| 389 { | 390 { |
| 390 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 391 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 391 [PermissionBubbleController class], | 392 [PermissionBubbleController class], |
| 392 [MockBubbleYesLocationBar class], | 393 [MockBubbleYesLocationBar class], |
| 393 @selector(hasLocationBar)); | 394 @selector(hasLocationBar)); |
| 394 withLocationBar = [controller_ getExpectedAnchorPoint]; | 395 withLocationBar = [controller_ getExpectedAnchorPoint]; |
| 395 } | 396 } |
| 396 | 397 |
| 397 NSPoint withoutLocationBar; | 398 NSPoint withoutLocationBar; |
| 398 { | 399 { |
| 399 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 400 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 400 [PermissionBubbleController class], | 401 [PermissionBubbleController class], |
| 401 [MockBubbleNoLocationBar class], | 402 [MockBubbleNoLocationBar class], |
| 402 @selector(hasLocationBar)); | 403 @selector(hasLocationBar)); |
| 403 withoutLocationBar = [controller_ getExpectedAnchorPoint]; | 404 withoutLocationBar = [controller_ getExpectedAnchorPoint]; |
| 404 } | 405 } |
| 405 | 406 |
| 406 // The bubble should be in different places depending if the location bar is | 407 // The bubble should be in different places depending if the location bar is |
| 407 // available or not. | 408 // available or not. |
| 408 EXPECT_NSNE(withLocationBar, withoutLocationBar); | 409 EXPECT_NSNE(withLocationBar, withoutLocationBar); |
| 409 } | 410 } |
| OLD | NEW |