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"
10 #import "testing/gtest_mac.h"
12 class BrowserWindowLayoutTest : public testing::Test {
14 BrowserWindowLayoutTest() {}
15 void SetUp() override {
16 layout.reset([[BrowserWindowLayout alloc] init]);
18 [layout setContentViewSize:NSMakeSize(600, 600)];
19 [layout setWindowSize:NSMakeSize(600, 622)];
20 [layout setInAnyFullscreen:NO];
21 [layout setHasTabStrip:YES];
22 [layout setFullscreenButtonFrame:NSMakeRect(575, 596, 16, 17)];
23 [layout setShouldShowAvatar:YES];
24 [layout setShouldUseNewAvatar:YES];
25 [layout setAvatarSize:NSMakeSize(63, 28)];
26 [layout setAvatarLineWidth:1];
27 [layout setHasToolbar:YES];
28 [layout setToolbarHeight:32];
29 [layout setPlaceBookmarkBarBelowInfoBar:NO];
30 [layout setBookmarkBarHidden:NO];
31 [layout setBookmarkBarHeight:26];
32 [layout setInfoBarHeight:72];
33 [layout setPageInfoBubblePointY:13];
34 [layout setHasDownloadShelf:YES];
35 [layout setDownloadShelfHeight:44];
36 [layout setOSYosemiteOrLater:NO];
39 base::scoped_nsobject<BrowserWindowLayout> layout;
41 // Updates the layout parameters with the state associated with a typical
42 // fullscreened window.
43 void ApplyStandardFullscreenLayoutParameters() {
44 // Content view has same size as window in AppKit Fullscreen.
45 [layout setContentViewSize:NSMakeSize(600, 622)];
46 [layout setInAnyFullscreen:YES];
47 [layout setFullscreenSlidingStyle:fullscreen_mac::OMNIBOX_TABS_PRESENT];
48 [layout setFullscreenMenubarOffset:0];
49 [layout setFullscreenToolbarFraction:0];
50 [layout setFullscreenButtonFrame:NSZeroRect];
54 DISALLOW_COPY_AND_ASSIGN(BrowserWindowLayoutTest);
57 TEST_F(BrowserWindowLayoutTest, TestAllViews) {
58 chrome::LayoutOutput output = [layout computeLayout];
60 EXPECT_NSEQ(NSMakeRect(0, 585, 600, 37), output.tabStripLayout.frame);
61 EXPECT_NSEQ(NSMakeRect(502, 589, 63, 28), output.tabStripLayout.avatarFrame);
62 EXPECT_EQ(70, output.tabStripLayout.leftIndent);
63 EXPECT_EQ(98, output.tabStripLayout.rightIndent);
64 EXPECT_NSEQ(NSMakeRect(0, 553, 600, 32), output.toolbarFrame);
65 EXPECT_NSEQ(NSMakeRect(0, 527, 600, 26), output.bookmarkFrame);
66 EXPECT_NSEQ(NSZeroRect, output.fullscreenBackingBarFrame);
67 EXPECT_EQ(527, output.findBarMaxY);
68 EXPECT_NSEQ(NSMakeRect(0, 455, 600, 111), output.infoBarFrame);
69 EXPECT_NSEQ(NSMakeRect(0, 0, 600, 44), output.downloadShelfFrame);
70 EXPECT_NSEQ(NSMakeRect(0, 44, 600, 411), output.contentAreaFrame);
73 TEST_F(BrowserWindowLayoutTest, TestAllViewsFullscreen) {
74 ApplyStandardFullscreenLayoutParameters();
76 chrome::LayoutOutput output = [layout computeLayout];
78 EXPECT_NSEQ(NSMakeRect(0, 585, 600, 37), output.tabStripLayout.frame);
79 EXPECT_NSEQ(NSMakeRect(533, 589, 63, 28), output.tabStripLayout.avatarFrame);
80 EXPECT_EQ(0, output.tabStripLayout.leftIndent);
81 EXPECT_FALSE(output.tabStripLayout.addCustomWindowControls);
82 EXPECT_EQ(67, output.tabStripLayout.rightIndent);
83 EXPECT_NSEQ(NSMakeRect(0, 553, 600, 32), output.toolbarFrame);
84 EXPECT_NSEQ(NSMakeRect(0, 527, 600, 26), output.bookmarkFrame);
85 EXPECT_NSEQ(NSMakeRect(0, 527, 600, 95), output.fullscreenBackingBarFrame);
86 EXPECT_EQ(527, output.findBarMaxY);
87 EXPECT_EQ(527, output.fullscreenExitButtonMaxY);
88 EXPECT_NSEQ(NSMakeRect(0, 455, 600, 111), output.infoBarFrame);
89 EXPECT_NSEQ(NSMakeRect(0, 0, 600, 44), output.downloadShelfFrame);
90 EXPECT_NSEQ(NSMakeRect(0, 44, 600, 411), output.contentAreaFrame);
93 // In fullscreen mode for Yosemite, the tab strip's left indent should be
94 // sufficiently large to accomodate the addition of traffic light buttons.
95 TEST_F(BrowserWindowLayoutTest, TestYosemiteFullscreenTrafficLights) {
96 ApplyStandardFullscreenLayoutParameters();
97 [layout setOSYosemiteOrLater:YES];
99 chrome::LayoutOutput output = [layout computeLayout];
101 EXPECT_EQ(70, output.tabStripLayout.leftIndent);
102 EXPECT_TRUE(output.tabStripLayout.addCustomWindowControls);
105 TEST_F(BrowserWindowLayoutTest, TestAllViewsFullscreenMenuBarShowing) {
106 ApplyStandardFullscreenLayoutParameters();
107 [layout setFullscreenMenubarOffset:-10];
109 chrome::LayoutOutput output = [layout computeLayout];
111 EXPECT_NSEQ(NSMakeRect(0, 575, 600, 37), output.tabStripLayout.frame);
112 EXPECT_NSEQ(NSMakeRect(533, 579, 63, 28), output.tabStripLayout.avatarFrame);
113 EXPECT_EQ(0, output.tabStripLayout.leftIndent);
114 EXPECT_FALSE(output.tabStripLayout.addCustomWindowControls);
115 EXPECT_EQ(67, output.tabStripLayout.rightIndent);
116 EXPECT_NSEQ(NSMakeRect(0, 543, 600, 32), output.toolbarFrame);
117 EXPECT_NSEQ(NSMakeRect(0, 517, 600, 26), output.bookmarkFrame);
118 EXPECT_NSEQ(NSMakeRect(0, 517, 600, 95), output.fullscreenBackingBarFrame);
119 EXPECT_EQ(517, output.findBarMaxY);
120 EXPECT_EQ(517, output.fullscreenExitButtonMaxY);
121 EXPECT_NSEQ(NSMakeRect(0, 445, 600, 111), output.infoBarFrame);
122 EXPECT_NSEQ(NSMakeRect(0, 0, 600, 44), output.downloadShelfFrame);
123 EXPECT_NSEQ(NSMakeRect(0, 44, 600, 411), output.contentAreaFrame);
126 TEST_F(BrowserWindowLayoutTest, TestPopupWindow) {
127 [layout setHasTabStrip:NO];
128 [layout setHasToolbar:NO];
129 [layout setHasLocationBar:YES];
130 [layout setBookmarkBarHidden:YES];
131 [layout setHasDownloadShelf:NO];
133 chrome::LayoutOutput output = [layout computeLayout];
135 EXPECT_NSEQ(NSZeroRect, output.tabStripLayout.frame);
136 EXPECT_NSEQ(NSZeroRect, output.tabStripLayout.avatarFrame);
137 EXPECT_EQ(0, output.tabStripLayout.leftIndent);
138 EXPECT_EQ(0, output.tabStripLayout.rightIndent);
139 EXPECT_NSEQ(NSMakeRect(1, 568, 598, 32), output.toolbarFrame);
140 EXPECT_NSEQ(NSZeroRect, output.bookmarkFrame);
141 EXPECT_NSEQ(NSZeroRect, output.fullscreenBackingBarFrame);
142 EXPECT_EQ(567, output.findBarMaxY);
143 EXPECT_NSEQ(NSMakeRect(0, 495, 600, 72), output.infoBarFrame);
144 EXPECT_NSEQ(NSZeroRect, output.downloadShelfFrame);
145 EXPECT_NSEQ(NSMakeRect(0, 0, 600, 495), output.contentAreaFrame);
148 // Old style avatar button is on the right of the fullscreen button.
149 // The tab strip's right indent goes up to the left side of the fullscreen
151 TEST_F(BrowserWindowLayoutTest, TestOldStyleAvatarButton) {
152 NSRect fullscreenButtonFrame = NSMakeRect(510, 596, 16, 17);
153 [layout setFullscreenButtonFrame:fullscreenButtonFrame];
154 [layout setShouldUseNewAvatar:NO];
156 chrome::TabStripLayout tabStripLayout = [layout computeLayout].tabStripLayout;
158 EXPECT_LE(NSMaxX(fullscreenButtonFrame), NSMinX(tabStripLayout.avatarFrame));
159 EXPECT_EQ(NSWidth(tabStripLayout.frame) - NSMinX(fullscreenButtonFrame),
160 tabStripLayout.rightIndent);
163 // New style avatar button is on the left of the fullscreen button.
164 // The tab strip's right indent goes up to the left side of the avatar button.
165 TEST_F(BrowserWindowLayoutTest, TestNewStyleAvatarButton) {
166 NSRect fullscreenButtonFrame = NSMakeRect(575, 596, 16, 17);
167 [layout setFullscreenButtonFrame:fullscreenButtonFrame];
168 [layout setShouldUseNewAvatar:YES];
170 chrome::TabStripLayout tabStripLayout = [layout computeLayout].tabStripLayout;
172 EXPECT_LE(NSMaxX(tabStripLayout.avatarFrame), NSMinX(fullscreenButtonFrame));
173 EXPECT_EQ(NSWidth(tabStripLayout.frame) - NSMinX(tabStripLayout.avatarFrame),
174 tabStripLayout.rightIndent);
177 // There is no fullscreen button when in fullscreen mode.
178 // The tab strip's right indent goes up to the left side of the avatar
180 TEST_F(BrowserWindowLayoutTest, TestAvatarButtonFullscreen) {
181 [layout setInAnyFullscreen:YES];
182 [layout setFullscreenButtonFrame:NSZeroRect];
184 [layout setShouldUseNewAvatar:YES];
185 chrome::TabStripLayout tabStripLayout = [layout computeLayout].tabStripLayout;
186 EXPECT_EQ(NSWidth(tabStripLayout.frame) - NSMinX(tabStripLayout.avatarFrame),
187 tabStripLayout.rightIndent);
189 [layout setShouldUseNewAvatar:NO];
190 tabStripLayout = [layout computeLayout].tabStripLayout;
191 EXPECT_EQ(NSWidth(tabStripLayout.frame) - NSMinX(tabStripLayout.avatarFrame),
192 tabStripLayout.rightIndent);
195 TEST_F(BrowserWindowLayoutTest, TestInfobarLayoutWithoutToolbarOrLocationBar) {
196 [layout setHasTabStrip:NO];
197 [layout setHasToolbar:NO];
198 [layout setHasLocationBar:NO];
199 [layout setBookmarkBarHidden:YES];
200 [layout setHasDownloadShelf:NO];
202 chrome::LayoutOutput output = [layout computeLayout];
204 EXPECT_NSEQ(NSMakeRect(0, 528, 600, 72), output.infoBarFrame);
207 // Tests that the avatar button is not aligned on the half pixel.
208 TEST_F(BrowserWindowLayoutTest, TestAvatarButtonPixelAlignment) {
209 [layout setAvatarSize:NSMakeSize(28, 28)];
211 chrome::LayoutOutput output = [layout computeLayout];
213 EXPECT_NSEQ(NSMakeRect(537, 589, 28, 28), output.tabStripLayout.avatarFrame);