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