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

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

Issue 986333006: Center permission bubble if location bar is hidden in MacOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply Feedback 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/test/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 // To be used when getting the anchor with a location bar. The bubble should be
16 // in the top-right corner.
17 const int kAnchorTop = 61;
groby-ooo-7-16 2015/04/10 20:58:55 Hrm. It works, but is fragile. Can you compute thi
hcarmona 2015/04/10 22:28:05 The size of the bubble doesn't affect the anchor.
groby-ooo-7-16 2015/04/10 23:00:33 OIC - Can we just test against location_bar_bridge
hcarmona 2015/04/13 19:11:58 Done.
18 const int kAnchorLeft = 105;
19 const int kTolerance = 5;
20
21 class MockPermissionBubbleCocoa : public PermissionBubbleCocoa {
22 public:
23 MockPermissionBubbleCocoa(NSWindow* parent_window)
24 : PermissionBubbleCocoa(parent_window) {}
25
26 MOCK_METHOD0(HasLocationBar, bool());
27
28 private:
29 DISALLOW_COPY_AND_ASSIGN(MockPermissionBubbleCocoa);
30 };
31 }
32
33 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest, HasLocationBarByDefault) {
34 PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow());
35 bubble.SetDelegate(test_delegate());
36 bubble.Show(requests(), accept_states());
37 EXPECT_TRUE(bubble.HasLocationBar());
38 }
39
40 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest, FullscreenHasLocationBar) {
41 PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow());
42 bubble.SetDelegate(test_delegate());
43 bubble.Show(requests(), accept_states());
44
45 NSWindow* window = browser()->window()->GetNativeWindow();
46 base::scoped_nsobject<FullscreenWindowManager> manager(
47 [[FullscreenWindowManager alloc] initWithWindow:window
48 desiredScreen:[NSScreen mainScreen]]);
49 EXPECT_TRUE(bubble.HasLocationBar());
50 [manager enterFullscreenMode];
51 EXPECT_TRUE(bubble.HasLocationBar());
52 [manager exitFullscreenMode];
53 EXPECT_TRUE(bubble.HasLocationBar());
54 }
55
56 IN_PROC_BROWSER_TEST_F(PermissionBubbleAppBrowsertest, AppHasNoLocationBar) {
57 PermissionBubbleCocoa bubble(app_browser()->window()->GetNativeWindow());
58 bubble.SetDelegate(test_delegate());
59 bubble.Show(requests(), accept_states());
60 EXPECT_FALSE(bubble.HasLocationBar());
61 }
62
63 // http://crbug.com/470724
64 // Kiosk mode on Mac has a location bar but it shouldn't.
65 IN_PROC_BROWSER_TEST_F(PermissionBubbleKioskBrowsertest,
66 DISABLED_KioskHasNoLocationBar) {
67 PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow());
68 bubble.SetDelegate(test_delegate());
69 bubble.Show(requests(), accept_states());
70 EXPECT_FALSE(bubble.HasLocationBar());
71 }
72
73 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest,
74 AnchorPositionWithLocationBar) {
75 testing::NiceMock<MockPermissionBubbleCocoa> bubble(
76 browser()->window()->GetNativeWindow());
77 bubble.SetDelegate(test_delegate());
78 bubble.Show(requests(), accept_states());
79 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(true));
80
81 NSPoint anchor = bubble.GetAnchorPoint();
82 NSWindow* window = browser()->window()->GetNativeWindow();
83 NSRect frame = [window frame];
84
85 // Expected anchor location will be top left when there's a location bar.
86 NSPoint expected =
87 NSMakePoint(NSMinX(frame) + kAnchorLeft, NSMaxY(frame) - kAnchorTop);
88
89 // Anchor should be close to the left of the screen.
90 ASSERT_NEAR(expected.x, anchor.x, kTolerance);
91
92 // Anchor should be close to the top of the screen.
93 ASSERT_NEAR(expected.y, anchor.y, kTolerance);
94 }
95
96 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest,
97 AnchorPositionWithoutLocationBar) {
98 testing::NiceMock<MockPermissionBubbleCocoa> bubble(
99 browser()->window()->GetNativeWindow());
100 bubble.SetDelegate(test_delegate());
101 bubble.Show(requests(), accept_states());
102 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(false));
103
104 NSPoint anchor = bubble.GetAnchorPoint();
105 NSWindow* window = browser()->window()->GetNativeWindow();
106 NSRect frame = [window frame];
107
108 // Expected anchor location will be top center when there's no location bar.
109 NSPoint expected = NSMakePoint(frame.size.width / 2, frame.size.height);
110 expected = [window convertBaseToScreen:expected];
111
112 // Anchor should be centered.
113 EXPECT_TRUE(NSEqualPoints(expected, anchor));
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698