Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa_browser_test.mm

Issue 1092933006: Revert of Center permission bubble if location bar is hidden in MacOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
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 "ui/base/cocoa/fullscreen_window_manager.h"
13
14 namespace {
15 class MockPermissionBubbleCocoa : public PermissionBubbleCocoa {
16 public:
17 MockPermissionBubbleCocoa(NSWindow* parent_window)
18 : PermissionBubbleCocoa(parent_window) {}
19
20 MOCK_METHOD0(HasLocationBar, bool());
21
22 private:
23 DISALLOW_COPY_AND_ASSIGN(MockPermissionBubbleCocoa);
24 };
25 }
26
27 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, HasLocationBarByDefault) {
28 PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow());
29 bubble.SetDelegate(test_delegate());
30 bubble.Show(requests(), accept_states());
31 EXPECT_TRUE(bubble.HasLocationBar());
32 }
33
34 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest, FullscreenHasLocationBar) {
35 PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow());
36 bubble.SetDelegate(test_delegate());
37 bubble.Show(requests(), accept_states());
38
39 NSWindow* window = browser()->window()->GetNativeWindow();
40 base::scoped_nsobject<FullscreenWindowManager> manager(
41 [[FullscreenWindowManager alloc] initWithWindow:window
42 desiredScreen:[NSScreen mainScreen]]);
43 EXPECT_TRUE(bubble.HasLocationBar());
44 [manager enterFullscreenMode];
45 EXPECT_TRUE(bubble.HasLocationBar());
46 [manager exitFullscreenMode];
47 EXPECT_TRUE(bubble.HasLocationBar());
48 }
49
50 IN_PROC_BROWSER_TEST_F(PermissionBubbleAppBrowserTest, AppHasNoLocationBar) {
51 PermissionBubbleCocoa bubble(app_browser()->window()->GetNativeWindow());
52 bubble.SetDelegate(test_delegate());
53 bubble.Show(requests(), accept_states());
54 EXPECT_FALSE(bubble.HasLocationBar());
55 }
56
57 // http://crbug.com/470724
58 // Kiosk mode on Mac has a location bar but it shouldn't.
59 IN_PROC_BROWSER_TEST_F(PermissionBubbleKioskBrowserTest,
60 DISABLED_KioskHasNoLocationBar) {
61 PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow());
62 bubble.SetDelegate(test_delegate());
63 bubble.Show(requests(), accept_states());
64 EXPECT_FALSE(bubble.HasLocationBar());
65 }
66
67 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest,
68 AnchorPositionWithLocationBar) {
69 testing::NiceMock<MockPermissionBubbleCocoa> bubble(
70 browser()->window()->GetNativeWindow());
71 bubble.SetDelegate(test_delegate());
72 bubble.Show(requests(), accept_states());
73 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(true));
74
75 NSPoint anchor = bubble.GetAnchorPoint();
76
77 // Expected anchor location will be the same as the page info bubble.
78 NSWindow* window = browser()->window()->GetNativeWindow();
79 BrowserWindowController* controller =
80 [BrowserWindowController browserWindowControllerForWindow:window];
81 LocationBarViewMac* location_bar_bridge = [controller locationBarBridge];
82 NSPoint expected = location_bar_bridge->GetPageInfoBubblePoint();
83 expected = [window convertBaseToScreen:expected];
84 EXPECT_TRUE(NSEqualPoints(expected, anchor));
85 }
86
87 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest,
88 AnchorPositionWithoutLocationBar) {
89 testing::NiceMock<MockPermissionBubbleCocoa> bubble(
90 browser()->window()->GetNativeWindow());
91 bubble.SetDelegate(test_delegate());
92 bubble.Show(requests(), accept_states());
93 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(false));
94
95 NSPoint anchor = bubble.GetAnchorPoint();
96
97 // Expected anchor location will be top center when there's no location bar.
98 NSWindow* window = browser()->window()->GetNativeWindow();
99 NSRect frame = [window frame];
100 NSPoint expected = NSMakePoint(frame.size.width / 2, frame.size.height);
101 expected = [window convertBaseToScreen:expected];
102 EXPECT_TRUE(NSEqualPoints(expected, anchor));
103 }
104
105 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowserTest,
106 AnchorPositionDifferentWithAndWithoutLocationBar) {
107 testing::NiceMock<MockPermissionBubbleCocoa> bubble(
108 browser()->window()->GetNativeWindow());
109 bubble.SetDelegate(test_delegate());
110 bubble.Show(requests(), accept_states());
111
112 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(true));
113 NSPoint withLocationBar = bubble.GetAnchorPoint();
114
115 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(false));
116 NSPoint withoutLocationBar = bubble.GetAnchorPoint();
117
118 // The bubble should be in different places depending if the location bar is
119 // available or not.
120 EXPECT_FALSE(NSEqualPoints(withLocationBar, withoutLocationBar));
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698