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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/browser.h"
6 #include "chrome/browser/ui/browser_window.h"
7 #import "chrome/browser/ui/cocoa/browser_window_controller.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"
10 #include "chrome/browser/ui/website_settings/permission_bubble_browser_test_util.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #import "testing/gtest_mac.h"
13 #import "ui/base/cocoa/fullscreen_window_manager.h"
16 class MockPermissionBubbleCocoa : public PermissionBubbleCocoa {
18 MockPermissionBubbleCocoa(Browser* browser)
19 : PermissionBubbleCocoa(browser) {}
21 MOCK_METHOD0(HasLocationBar, bool());
24 DISALLOW_COPY_AND_ASSIGN(MockPermissionBubbleCocoa);
28 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, HasLocationBarByDefault) {
29 PermissionBubbleCocoa bubble(browser());
30 bubble.SetDelegate(test_delegate());
31 bubble.Show(requests(), accept_states());
32 EXPECT_TRUE(bubble.HasLocationBar());
36 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, FullscreenHasLocationBar) {
37 PermissionBubbleCocoa bubble(browser());
38 bubble.SetDelegate(test_delegate());
39 bubble.Show(requests(), accept_states());
41 NSWindow* window = browser()->window()->GetNativeWindow();
42 base::scoped_nsobject<FullscreenWindowManager> manager(
43 [[FullscreenWindowManager alloc] initWithWindow:window
44 desiredScreen:[NSScreen mainScreen]]);
45 EXPECT_TRUE(bubble.HasLocationBar());
46 [manager enterFullscreenMode];
47 EXPECT_TRUE(bubble.HasLocationBar());
48 [manager exitFullscreenMode];
49 EXPECT_TRUE(bubble.HasLocationBar());
53 IN_PROC_BROWSER_TEST_F(PermissionBubbleAppBrowserTest, AppHasNoLocationBar) {
54 PermissionBubbleCocoa bubble(app_browser());
55 bubble.SetDelegate(test_delegate());
56 bubble.Show(requests(), accept_states());
57 EXPECT_FALSE(bubble.HasLocationBar());
61 // http://crbug.com/470724
62 // Kiosk mode on Mac has a location bar but it shouldn't.
63 IN_PROC_BROWSER_TEST_F(PermissionBubbleKioskBrowserTest,
64 DISABLED_KioskHasNoLocationBar) {
65 PermissionBubbleCocoa bubble(browser());
66 bubble.SetDelegate(test_delegate());
67 bubble.Show(requests(), accept_states());
68 EXPECT_FALSE(bubble.HasLocationBar());
72 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest,
73 AnchorPositionWithLocationBar) {
74 testing::NiceMock<MockPermissionBubbleCocoa> bubble(browser());
75 bubble.SetDelegate(test_delegate());
76 bubble.Show(requests(), accept_states());
77 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(true));
79 NSPoint anchor = bubble.GetAnchorPoint();
81 // Expected anchor location will be the same as the page info bubble.
82 NSWindow* window = browser()->window()->GetNativeWindow();
83 BrowserWindowController* controller =
84 [BrowserWindowController browserWindowControllerForWindow:window];
85 LocationBarViewMac* location_bar_bridge = [controller locationBarBridge];
86 NSPoint expected = location_bar_bridge->GetPageInfoBubblePoint();
87 expected = [window convertBaseToScreen:expected];
88 EXPECT_NSEQ(expected, anchor);
92 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest,
93 AnchorPositionWithoutLocationBar) {
94 testing::NiceMock<MockPermissionBubbleCocoa> bubble(browser());
95 bubble.SetDelegate(test_delegate());
96 bubble.Show(requests(), accept_states());
97 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(false));
99 NSPoint anchor = bubble.GetAnchorPoint();
101 // Expected anchor location will be top center when there's no location bar.
102 NSWindow* window = browser()->window()->GetNativeWindow();
103 NSRect frame = [window frame];
104 NSPoint expected = NSMakePoint(frame.size.width / 2, frame.size.height);
105 expected = [window convertBaseToScreen:expected];
106 EXPECT_NSEQ(expected, anchor);
110 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest,
111 AnchorPositionDifferentWithAndWithoutLocationBar) {
112 testing::NiceMock<MockPermissionBubbleCocoa> bubble(browser());
113 bubble.SetDelegate(test_delegate());
114 bubble.Show(requests(), accept_states());
116 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(true));
117 NSPoint withLocationBar = bubble.GetAnchorPoint();
119 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(false));
120 NSPoint withoutLocationBar = bubble.GetAnchorPoint();
122 // The bubble should be in different places depending if the location bar is
124 EXPECT_NSNE(withLocationBar, withoutLocationBar);