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
3 // found in the LICENSE file.
5 #import <Cocoa/Cocoa.h>
7 #include "base/mac/scoped_nsobject.h"
8 #import "chrome/browser/ui/cocoa/browser_window_layout.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 class BrowserWindowLayoutTest : public testing::Test {
13 BrowserWindowLayoutTest() {}
14 void SetUp() override {
15 layout.reset([[BrowserWindowLayout alloc] init]);
17 [layout setContentViewSize:NSMakeSize(600, 600)];
18 [layout setWindowSize:NSMakeSize(600, 622)];
19 [layout setInAnyFullscreen:NO];
20 [layout setHasTabStrip:YES];
21 [layout setFullscreenButtonFrame:NSMakeRect(575, 596, 16, 17)];
22 [layout setShouldShowAvatar:YES];
23 [layout setShouldUseNewAvatar:YES];
24 [layout setAvatarSize:NSMakeSize(63, 28)];
25 [layout setAvatarLineWidth:1];
26 [layout setHasToolbar:YES];
27 [layout setToolbarHeight:32];
28 [layout setPlaceBookmarkBarBelowInfoBar:NO];
29 [layout setBookmarkBarHidden:NO];
30 [layout setBookmarkBarHeight:26];
31 [layout setInfoBarHeight:72];
32 [layout setPageInfoBubblePointY:13];
33 [layout setHasDownloadShelf:YES];
34 [layout setDownloadShelfHeight:44];
35 [layout setOSYosemiteOrLater:NO];
38 base::scoped_nsobject<BrowserWindowLayout> layout;
40 // Updates the layout parameters with the state associated with a typical
41 // fullscreened window.
42 void ApplyStandardFullscreenLayoutParameters() {
43 // Content view has same size as window in AppKit Fullscreen.
44 [layout setContentViewSize:NSMakeSize(600, 622)];
45 [layout setInAnyFullscreen:YES];
46 [layout setFullscreenSlidingStyle:fullscreen_mac::OMNIBOX_TABS_PRESENT];
47 [layout setFullscreenMenubarOffset:0];
48 [layout setFullscreenToolbarFraction:0];
49 [layout setFullscreenButtonFrame:NSZeroRect];
53 DISALLOW_COPY_AND_ASSIGN(BrowserWindowLayoutTest);
56 TEST_F(BrowserWindowLayoutTest, TestAllViews) {
57 chrome::LayoutOutput output = [layout computeLayout];
60 NSEqualRects(NSMakeRect(0, 585, 600, 37), output.tabStripLayout.frame));
61 EXPECT_TRUE(NSEqualRects(NSMakeRect(502, 589, 63, 28),
62 output.tabStripLayout.avatarFrame));
63 EXPECT_EQ(70, output.tabStripLayout.leftIndent);
64 EXPECT_EQ(98, output.tabStripLayout.rightIndent);
65 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 553, 600, 32), output.toolbarFrame));
66 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 527, 600, 26), output.bookmarkFrame));
67 EXPECT_TRUE(NSEqualRects(NSZeroRect, output.fullscreenBackingBarFrame));
68 EXPECT_EQ(527, output.findBarMaxY);
69 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 455, 600, 111), output.infoBarFrame));
71 NSEqualRects(NSMakeRect(0, 0, 600, 44), output.downloadShelfFrame));
73 NSEqualRects(NSMakeRect(0, 44, 600, 411), output.contentAreaFrame));
76 TEST_F(BrowserWindowLayoutTest, TestAllViewsFullscreen) {
77 ApplyStandardFullscreenLayoutParameters();
79 chrome::LayoutOutput output = [layout computeLayout];
82 NSEqualRects(NSMakeRect(0, 585, 600, 37), output.tabStripLayout.frame));
83 EXPECT_TRUE(NSEqualRects(NSMakeRect(533, 589, 63, 28),
84 output.tabStripLayout.avatarFrame));
85 EXPECT_EQ(0, output.tabStripLayout.leftIndent);
86 EXPECT_FALSE(output.tabStripLayout.addCustomWindowControls);
87 EXPECT_EQ(67, output.tabStripLayout.rightIndent);
88 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 553, 600, 32), output.toolbarFrame));
89 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 527, 600, 26), output.bookmarkFrame));
90 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 527, 600, 95),
91 output.fullscreenBackingBarFrame));
92 EXPECT_EQ(527, output.findBarMaxY);
93 EXPECT_EQ(527, output.fullscreenExitButtonMaxY);
94 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 455, 600, 111), output.infoBarFrame));
96 NSEqualRects(NSMakeRect(0, 0, 600, 44), output.downloadShelfFrame));
98 NSEqualRects(NSMakeRect(0, 44, 600, 411), output.contentAreaFrame));
101 // In fullscreen mode for Yosemite, the tab strip's left indent should be
102 // sufficiently large to accomodate the addition of traffic light buttons.
103 TEST_F(BrowserWindowLayoutTest, TestYosemiteFullscreenTrafficLights) {
104 ApplyStandardFullscreenLayoutParameters();
105 [layout setOSYosemiteOrLater:YES];
107 chrome::LayoutOutput output = [layout computeLayout];
109 EXPECT_EQ(70, output.tabStripLayout.leftIndent);
110 EXPECT_TRUE(output.tabStripLayout.addCustomWindowControls);
113 TEST_F(BrowserWindowLayoutTest, TestAllViewsFullscreenMenuBarShowing) {
114 ApplyStandardFullscreenLayoutParameters();
115 [layout setFullscreenMenubarOffset:-10];
117 chrome::LayoutOutput output = [layout computeLayout];
120 NSEqualRects(NSMakeRect(0, 575, 600, 37), output.tabStripLayout.frame));
121 EXPECT_TRUE(NSEqualRects(NSMakeRect(533, 579, 63, 28),
122 output.tabStripLayout.avatarFrame));
123 EXPECT_EQ(0, output.tabStripLayout.leftIndent);
124 EXPECT_FALSE(output.tabStripLayout.addCustomWindowControls);
125 EXPECT_EQ(67, output.tabStripLayout.rightIndent);
126 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 543, 600, 32), output.toolbarFrame));
127 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 517, 600, 26), output.bookmarkFrame));
128 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 517, 600, 95),
129 output.fullscreenBackingBarFrame));
130 EXPECT_EQ(517, output.findBarMaxY);
131 EXPECT_EQ(517, output.fullscreenExitButtonMaxY);
132 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 445, 600, 111), output.infoBarFrame));
134 NSEqualRects(NSMakeRect(0, 0, 600, 44), output.downloadShelfFrame));
136 NSEqualRects(NSMakeRect(0, 44, 600, 411), output.contentAreaFrame));
139 TEST_F(BrowserWindowLayoutTest, TestPopupWindow) {
140 [layout setHasTabStrip:NO];
141 [layout setHasToolbar:NO];
142 [layout setHasLocationBar:YES];
143 [layout setBookmarkBarHidden:YES];
144 [layout setHasDownloadShelf:NO];
146 chrome::LayoutOutput output = [layout computeLayout];
148 EXPECT_TRUE(NSEqualRects(NSZeroRect, output.tabStripLayout.frame));
149 EXPECT_TRUE(NSEqualRects(NSZeroRect, output.tabStripLayout.avatarFrame));
150 EXPECT_EQ(0, output.tabStripLayout.leftIndent);
151 EXPECT_EQ(0, output.tabStripLayout.rightIndent);
152 EXPECT_TRUE(NSEqualRects(NSMakeRect(1, 568, 598, 32), output.toolbarFrame));
153 EXPECT_TRUE(NSEqualRects(NSZeroRect, output.bookmarkFrame));
154 EXPECT_TRUE(NSEqualRects(NSZeroRect, output.fullscreenBackingBarFrame));
155 EXPECT_EQ(567, output.findBarMaxY);
156 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 495, 600, 72), output.infoBarFrame));
157 EXPECT_TRUE(NSEqualRects(NSZeroRect, output.downloadShelfFrame));
159 NSEqualRects(NSMakeRect(0, 0, 600, 495), output.contentAreaFrame));
162 // Old style avatar button is on the right of the fullscreen button.
163 // The tab strip's right indent goes up to the left side of the fullscreen
165 TEST_F(BrowserWindowLayoutTest, TestOldStyleAvatarButton) {
166 NSRect fullscreenButtonFrame = NSMakeRect(510, 596, 16, 17);
167 [layout setFullscreenButtonFrame:fullscreenButtonFrame];
168 [layout setShouldUseNewAvatar:NO];
170 chrome::TabStripLayout tabStripLayout = [layout computeLayout].tabStripLayout;
172 EXPECT_LE(NSMaxX(fullscreenButtonFrame), NSMinX(tabStripLayout.avatarFrame));
173 EXPECT_EQ(NSWidth(tabStripLayout.frame) - NSMinX(fullscreenButtonFrame),
174 tabStripLayout.rightIndent);
177 // New style avatar button is on the left of the fullscreen button.
178 // The tab strip's right indent goes up to the left side of the avatar button.
179 TEST_F(BrowserWindowLayoutTest, TestNewStyleAvatarButton) {
180 NSRect fullscreenButtonFrame = NSMakeRect(575, 596, 16, 17);
181 [layout setFullscreenButtonFrame:fullscreenButtonFrame];
182 [layout setShouldUseNewAvatar:YES];
184 chrome::TabStripLayout tabStripLayout = [layout computeLayout].tabStripLayout;
186 EXPECT_LE(NSMaxX(tabStripLayout.avatarFrame), NSMinX(fullscreenButtonFrame));
187 EXPECT_EQ(NSWidth(tabStripLayout.frame) - NSMinX(tabStripLayout.avatarFrame),
188 tabStripLayout.rightIndent);
191 // There is no fullscreen button when in fullscreen mode.
192 // The tab strip's right indent goes up to the left side of the avatar
194 TEST_F(BrowserWindowLayoutTest, TestAvatarButtonFullscreen) {
195 [layout setInAnyFullscreen:YES];
196 [layout setFullscreenButtonFrame:NSZeroRect];
198 [layout setShouldUseNewAvatar:YES];
199 chrome::TabStripLayout tabStripLayout = [layout computeLayout].tabStripLayout;
200 EXPECT_EQ(NSWidth(tabStripLayout.frame) - NSMinX(tabStripLayout.avatarFrame),
201 tabStripLayout.rightIndent);
203 [layout setShouldUseNewAvatar:NO];
204 tabStripLayout = [layout computeLayout].tabStripLayout;
205 EXPECT_EQ(NSWidth(tabStripLayout.frame) - NSMinX(tabStripLayout.avatarFrame),
206 tabStripLayout.rightIndent);
209 TEST_F(BrowserWindowLayoutTest, TestInfobarLayoutWithoutToolbarOrLocationBar) {
210 [layout setHasTabStrip:NO];
211 [layout setHasToolbar:NO];
212 [layout setHasLocationBar:NO];
213 [layout setBookmarkBarHidden:YES];
214 [layout setHasDownloadShelf:NO];
216 chrome::LayoutOutput output = [layout computeLayout];
218 EXPECT_TRUE(NSEqualRects(NSMakeRect(0, 528, 600, 72), output.infoBarFrame));
221 // Tests that the avatar button is not aligned on the half pixel.
222 TEST_F(BrowserWindowLayoutTest, TestAvatarButtonPixelAlignment) {
223 [layout setAvatarSize:NSMakeSize(28, 28)];
225 chrome::LayoutOutput output = [layout computeLayout];
227 EXPECT_TRUE(NSEqualRects(NSMakeRect(537, 589, 28, 28),
228 output.tabStripLayout.avatarFrame));