| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "chrome/browser/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
| 6 #include "chrome/browser/ui/browser_window.h" | 6 #include "chrome/browser/ui/browser_window.h" |
| 7 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 7 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 8 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 8 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 9 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" | 9 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" |
| 10 #include "chrome/browser/ui/website_settings/permission_bubble_browser_test_util
.h" | 10 #include "chrome/browser/ui/website_settings/permission_bubble_browser_test_util
.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #import "ui/base/cocoa/fullscreen_window_manager.h" | 12 #import "ui/base/cocoa/fullscreen_window_manager.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 class MockPermissionBubbleCocoa : public PermissionBubbleCocoa { | 15 class MockPermissionBubbleCocoa : public PermissionBubbleCocoa { |
| 16 public: | 16 public: |
| 17 MockPermissionBubbleCocoa(NSWindow* parent_window) | 17 MockPermissionBubbleCocoa(Browser* browser) |
| 18 : PermissionBubbleCocoa(parent_window) {} | 18 : PermissionBubbleCocoa(browser) {} |
| 19 | 19 |
| 20 MOCK_METHOD0(HasLocationBar, bool()); | 20 MOCK_METHOD0(HasLocationBar, bool()); |
| 21 | 21 |
| 22 private: | 22 private: |
| 23 DISALLOW_COPY_AND_ASSIGN(MockPermissionBubbleCocoa); | 23 DISALLOW_COPY_AND_ASSIGN(MockPermissionBubbleCocoa); |
| 24 }; | 24 }; |
| 25 } | 25 } |
| 26 | 26 |
| 27 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, HasLocationBarByDefault) { | 27 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, HasLocationBarByDefault) { |
| 28 PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow()); | 28 PermissionBubbleCocoa bubble(browser()); |
| 29 bubble.SetDelegate(test_delegate()); | 29 bubble.SetDelegate(test_delegate()); |
| 30 bubble.Show(requests(), accept_states()); | 30 bubble.Show(requests(), accept_states()); |
| 31 EXPECT_TRUE(bubble.HasLocationBar()); | 31 EXPECT_TRUE(bubble.HasLocationBar()); |
| 32 bubble.Hide(); | 32 bubble.Hide(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, FullscreenHasLocationBar) { | 35 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, FullscreenHasLocationBar) { |
| 36 PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow()); | 36 PermissionBubbleCocoa bubble(browser()); |
| 37 bubble.SetDelegate(test_delegate()); | 37 bubble.SetDelegate(test_delegate()); |
| 38 bubble.Show(requests(), accept_states()); | 38 bubble.Show(requests(), accept_states()); |
| 39 | 39 |
| 40 NSWindow* window = browser()->window()->GetNativeWindow(); | 40 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 41 base::scoped_nsobject<FullscreenWindowManager> manager( | 41 base::scoped_nsobject<FullscreenWindowManager> manager( |
| 42 [[FullscreenWindowManager alloc] initWithWindow:window | 42 [[FullscreenWindowManager alloc] initWithWindow:window |
| 43 desiredScreen:[NSScreen mainScreen]]); | 43 desiredScreen:[NSScreen mainScreen]]); |
| 44 EXPECT_TRUE(bubble.HasLocationBar()); | 44 EXPECT_TRUE(bubble.HasLocationBar()); |
| 45 [manager enterFullscreenMode]; | 45 [manager enterFullscreenMode]; |
| 46 EXPECT_TRUE(bubble.HasLocationBar()); | 46 EXPECT_TRUE(bubble.HasLocationBar()); |
| 47 [manager exitFullscreenMode]; | 47 [manager exitFullscreenMode]; |
| 48 EXPECT_TRUE(bubble.HasLocationBar()); | 48 EXPECT_TRUE(bubble.HasLocationBar()); |
| 49 bubble.Hide(); | 49 bubble.Hide(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 IN_PROC_BROWSER_TEST_F(PermissionBubbleAppBrowserTest, AppHasNoLocationBar) { | 52 IN_PROC_BROWSER_TEST_F(PermissionBubbleAppBrowserTest, AppHasNoLocationBar) { |
| 53 PermissionBubbleCocoa bubble(app_browser()->window()->GetNativeWindow()); | 53 PermissionBubbleCocoa bubble(app_browser()); |
| 54 bubble.SetDelegate(test_delegate()); | 54 bubble.SetDelegate(test_delegate()); |
| 55 bubble.Show(requests(), accept_states()); | 55 bubble.Show(requests(), accept_states()); |
| 56 EXPECT_FALSE(bubble.HasLocationBar()); | 56 EXPECT_FALSE(bubble.HasLocationBar()); |
| 57 bubble.Hide(); | 57 bubble.Hide(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // http://crbug.com/470724 | 60 // http://crbug.com/470724 |
| 61 // Kiosk mode on Mac has a location bar but it shouldn't. | 61 // Kiosk mode on Mac has a location bar but it shouldn't. |
| 62 IN_PROC_BROWSER_TEST_F(PermissionBubbleKioskBrowserTest, | 62 IN_PROC_BROWSER_TEST_F(PermissionBubbleKioskBrowserTest, |
| 63 DISABLED_KioskHasNoLocationBar) { | 63 DISABLED_KioskHasNoLocationBar) { |
| 64 PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow()); | 64 PermissionBubbleCocoa bubble(browser()); |
| 65 bubble.SetDelegate(test_delegate()); | 65 bubble.SetDelegate(test_delegate()); |
| 66 bubble.Show(requests(), accept_states()); | 66 bubble.Show(requests(), accept_states()); |
| 67 EXPECT_FALSE(bubble.HasLocationBar()); | 67 EXPECT_FALSE(bubble.HasLocationBar()); |
| 68 bubble.Hide(); | 68 bubble.Hide(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, | 71 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, |
| 72 AnchorPositionWithLocationBar) { | 72 AnchorPositionWithLocationBar) { |
| 73 testing::NiceMock<MockPermissionBubbleCocoa> bubble( | 73 testing::NiceMock<MockPermissionBubbleCocoa> bubble(browser()); |
| 74 browser()->window()->GetNativeWindow()); | |
| 75 bubble.SetDelegate(test_delegate()); | 74 bubble.SetDelegate(test_delegate()); |
| 76 bubble.Show(requests(), accept_states()); | 75 bubble.Show(requests(), accept_states()); |
| 77 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(true)); | 76 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(true)); |
| 78 | 77 |
| 79 NSPoint anchor = bubble.GetAnchorPoint(); | 78 NSPoint anchor = bubble.GetAnchorPoint(); |
| 80 | 79 |
| 81 // Expected anchor location will be the same as the page info bubble. | 80 // Expected anchor location will be the same as the page info bubble. |
| 82 NSWindow* window = browser()->window()->GetNativeWindow(); | 81 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 83 BrowserWindowController* controller = | 82 BrowserWindowController* controller = |
| 84 [BrowserWindowController browserWindowControllerForWindow:window]; | 83 [BrowserWindowController browserWindowControllerForWindow:window]; |
| 85 LocationBarViewMac* location_bar_bridge = [controller locationBarBridge]; | 84 LocationBarViewMac* location_bar_bridge = [controller locationBarBridge]; |
| 86 NSPoint expected = location_bar_bridge->GetPageInfoBubblePoint(); | 85 NSPoint expected = location_bar_bridge->GetPageInfoBubblePoint(); |
| 87 expected = [window convertBaseToScreen:expected]; | 86 expected = [window convertBaseToScreen:expected]; |
| 88 EXPECT_TRUE(NSEqualPoints(expected, anchor)); | 87 EXPECT_TRUE(NSEqualPoints(expected, anchor)); |
| 89 bubble.Hide(); | 88 bubble.Hide(); |
| 90 } | 89 } |
| 91 | 90 |
| 92 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, | 91 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, |
| 93 AnchorPositionWithoutLocationBar) { | 92 AnchorPositionWithoutLocationBar) { |
| 94 testing::NiceMock<MockPermissionBubbleCocoa> bubble( | 93 testing::NiceMock<MockPermissionBubbleCocoa> bubble(browser()); |
| 95 browser()->window()->GetNativeWindow()); | |
| 96 bubble.SetDelegate(test_delegate()); | 94 bubble.SetDelegate(test_delegate()); |
| 97 bubble.Show(requests(), accept_states()); | 95 bubble.Show(requests(), accept_states()); |
| 98 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(false)); | 96 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(false)); |
| 99 | 97 |
| 100 NSPoint anchor = bubble.GetAnchorPoint(); | 98 NSPoint anchor = bubble.GetAnchorPoint(); |
| 101 | 99 |
| 102 // Expected anchor location will be top center when there's no location bar. | 100 // Expected anchor location will be top center when there's no location bar. |
| 103 NSWindow* window = browser()->window()->GetNativeWindow(); | 101 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 104 NSRect frame = [window frame]; | 102 NSRect frame = [window frame]; |
| 105 NSPoint expected = NSMakePoint(frame.size.width / 2, frame.size.height); | 103 NSPoint expected = NSMakePoint(frame.size.width / 2, frame.size.height); |
| 106 expected = [window convertBaseToScreen:expected]; | 104 expected = [window convertBaseToScreen:expected]; |
| 107 EXPECT_TRUE(NSEqualPoints(expected, anchor)); | 105 EXPECT_TRUE(NSEqualPoints(expected, anchor)); |
| 108 bubble.Hide(); | 106 bubble.Hide(); |
| 109 } | 107 } |
| 110 | 108 |
| 111 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, | 109 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, |
| 112 AnchorPositionDifferentWithAndWithoutLocationBar) { | 110 AnchorPositionDifferentWithAndWithoutLocationBar) { |
| 113 testing::NiceMock<MockPermissionBubbleCocoa> bubble( | 111 testing::NiceMock<MockPermissionBubbleCocoa> bubble(browser()); |
| 114 browser()->window()->GetNativeWindow()); | |
| 115 bubble.SetDelegate(test_delegate()); | 112 bubble.SetDelegate(test_delegate()); |
| 116 bubble.Show(requests(), accept_states()); | 113 bubble.Show(requests(), accept_states()); |
| 117 | 114 |
| 118 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(true)); | 115 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(true)); |
| 119 NSPoint withLocationBar = bubble.GetAnchorPoint(); | 116 NSPoint withLocationBar = bubble.GetAnchorPoint(); |
| 120 | 117 |
| 121 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(false)); | 118 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(false)); |
| 122 NSPoint withoutLocationBar = bubble.GetAnchorPoint(); | 119 NSPoint withoutLocationBar = bubble.GetAnchorPoint(); |
| 123 | 120 |
| 124 // The bubble should be in different places depending if the location bar is | 121 // The bubble should be in different places depending if the location bar is |
| 125 // available or not. | 122 // available or not. |
| 126 EXPECT_FALSE(NSEqualPoints(withLocationBar, withoutLocationBar)); | 123 EXPECT_FALSE(NSEqualPoints(withLocationBar, withoutLocationBar)); |
| 127 bubble.Hide(); | 124 bubble.Hide(); |
| 128 } | 125 } |
| OLD | NEW |