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

Side by Side Diff: ui/views/layout/align_layout_unittest.cc

Issue 2230913003: Experimental alignment layout manager using a property on the views Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed AlignAttribute and associated types to FillAttribute Created 4 years, 2 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
« no previous file with comments | « ui/views/layout/align_layout.cc ('k') | ui/views/layout/anchor_layout_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 <stddef.h>
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 #include "ui/views/fill_attribute.h"
10 #include "ui/views/layout/align_layout.h"
11 #include "ui/views/test/test_views.h"
12 #include "ui/views/view.h"
13
14 namespace views {
15
16 namespace {
17
18 class AlignLayoutTest : public testing::Test {
19 public:
20 void SetUp() override { host_.reset(new View); }
21
22 std::unique_ptr<View> host_;
23 };
24
25 } // namespace
26
27 TEST_F(AlignLayoutTest, Empty) {
28 AlignLayout* layout = new AlignLayout();
29 host_->SetLayoutManager(layout);
30 EXPECT_EQ(gfx::Size(0, 0), layout->GetPreferredSize(host_.get()));
31 }
32
33 TEST_F(AlignLayoutTest, FillTop) {
34 AlignLayout* layout = new AlignLayout();
35 host_->SetLayoutManager(layout);
36 View* v1 = new View();
37 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
38 v1->SetBounds(0, 0, 0, 10);
39 host_->AddChildView(v1);
40 host_->SetBounds(0, 0, 20, 20);
41 host_->Layout();
42 EXPECT_EQ(gfx::Rect(0, 0, 20, 10), v1->bounds());
43 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds());
44 host_->SetBounds(0, 0, 30, 20);
45 host_->Layout();
46 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v1->bounds());
47 EXPECT_EQ(gfx::Rect(0, 0, 30, 20), host_->bounds());
48 }
49
50 TEST_F(AlignLayoutTest, FillBottom) {
51 AlignLayout* layout = new AlignLayout();
52 host_->SetLayoutManager(layout);
53 View* v1 = new View();
54 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
55 v1->SetBounds(0, 0, 0, 10);
56 host_->AddChildView(v1);
57 host_->SetBounds(0, 0, 20, 20);
58 host_->Layout();
59 EXPECT_EQ(gfx::Rect(0, 10, 20, 10), v1->bounds());
60 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds());
61 host_->SetBounds(0, 0, 30, 20);
62 host_->Layout();
63 EXPECT_EQ(gfx::Rect(0, 10, 30, 10), v1->bounds());
64 EXPECT_EQ(gfx::Rect(0, 0, 30, 20), host_->bounds());
65 }
66
67 TEST_F(AlignLayoutTest, FillLeft) {
68 AlignLayout* layout = new AlignLayout();
69 host_->SetLayoutManager(layout);
70 View* v1 = new View();
71 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
72 v1->SetBounds(0, 0, 10, 0);
73 host_->AddChildView(v1);
74 host_->SetBounds(0, 0, 20, 20);
75 host_->Layout();
76 EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds());
77 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds());
78 host_->SetBounds(0, 0, 20, 30);
79 host_->Layout();
80 EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds());
81 EXPECT_EQ(gfx::Rect(0, 0, 20, 30), host_->bounds());
82 }
83
84 TEST_F(AlignLayoutTest, FillRight) {
85 AlignLayout* layout = new AlignLayout();
86 host_->SetLayoutManager(layout);
87 View* v1 = new View();
88 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
89 v1->SetBounds(0, 0, 10, 0);
90 host_->AddChildView(v1);
91 host_->SetBounds(0, 0, 20, 20);
92 host_->Layout();
93 EXPECT_EQ(gfx::Rect(10, 0, 10, 20), v1->bounds());
94 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds());
95 host_->SetBounds(0, 0, 20, 30);
96 host_->Layout();
97 EXPECT_EQ(gfx::Rect(10, 0, 10, 30), v1->bounds());
98 EXPECT_EQ(gfx::Rect(0, 0, 20, 30), host_->bounds());
99 }
100
101 TEST_F(AlignLayoutTest, FillContent) {
102 AlignLayout* layout = new AlignLayout();
103 host_->SetLayoutManager(layout);
104 View* v1 = new View();
105 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Content)));
106 v1->SetBounds(0, 0, 0, 0);
107 host_->AddChildView(v1);
108 host_->SetBounds(0, 0, 20, 20);
109 host_->Layout();
110 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), v1->bounds());
111 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds());
112 host_->SetBounds(0, 0, 30, 30);
113 host_->Layout();
114 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), v1->bounds());
115 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
116 }
117
118 TEST_F(AlignLayoutTest, FillLeftTop) {
119 AlignLayout* layout = new AlignLayout();
120 host_->SetLayoutManager(layout);
121 View* v1 = new View();
122 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
123 v1->SetBounds(0, 0, 10, 0);
124 host_->AddChildView(v1);
125 View* v2 = new View();
126 v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
127 v2->SetBounds(0, 0, 0, 10);
128 host_->AddChildView(v2);
129 host_->SetBounds(0, 0, 40, 40);
130 host_->Layout();
131 EXPECT_EQ(gfx::Rect(0, 10, 10, 30), v1->bounds());
132 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds());
133 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
134 host_->SetBounds(0, 0, 30, 30);
135 host_->Layout();
136 EXPECT_EQ(gfx::Rect(0, 10, 10, 20), v1->bounds());
137 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds());
138 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
139 }
140
141 TEST_F(AlignLayoutTest, FillLeftTopRight) {
142 AlignLayout* layout = new AlignLayout();
143 host_->SetLayoutManager(layout);
144 View* v1 = new View();
145 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
146 v1->SetBounds(0, 0, 10, 0);
147 host_->AddChildView(v1);
148 View* v2 = new View();
149 v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
150 v2->SetBounds(0, 0, 0, 10);
151 host_->AddChildView(v2);
152 View* v3 = new View();
153 v3->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
154 v3->SetBounds(0, 0, 10, 0);
155 host_->AddChildView(v3);
156 host_->SetBounds(0, 0, 40, 40);
157 host_->Layout();
158 EXPECT_EQ(gfx::Rect(0, 10, 10, 30), v1->bounds());
159 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds());
160 EXPECT_EQ(gfx::Rect(30, 10, 10, 30), v3->bounds());
161 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
162 host_->SetBounds(0, 0, 30, 30);
163 host_->Layout();
164 EXPECT_EQ(gfx::Rect(0, 10, 10, 20), v1->bounds());
165 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds());
166 EXPECT_EQ(gfx::Rect(20, 10, 10, 20), v3->bounds());
167 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
168 }
169
170 TEST_F(AlignLayoutTest, FillTopRight) {
171 AlignLayout* layout = new AlignLayout();
172 host_->SetLayoutManager(layout);
173 View* v1 = new View();
174 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
175 v1->SetBounds(0, 0, 10, 0);
176 host_->AddChildView(v1);
177 View* v2 = new View();
178 v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
179 v2->SetBounds(0, 0, 0, 10);
180 host_->AddChildView(v2);
181 host_->SetBounds(0, 0, 40, 40);
182 host_->Layout();
183 EXPECT_EQ(gfx::Rect(30, 10, 10, 30), v1->bounds());
184 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds());
185 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
186 host_->SetBounds(0, 0, 30, 30);
187 host_->Layout();
188 EXPECT_EQ(gfx::Rect(20, 10, 10, 20), v1->bounds());
189 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds());
190 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
191 }
192
193 TEST_F(AlignLayoutTest, FillLeftBottomRight) {
194 AlignLayout* layout = new AlignLayout();
195 host_->SetLayoutManager(layout);
196 View* v1 = new View();
197 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
198 v1->SetBounds(0, 0, 10, 0);
199 host_->AddChildView(v1);
200 View* v2 = new View();
201 v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
202 v2->SetBounds(0, 0, 0, 10);
203 host_->AddChildView(v2);
204 View* v3 = new View();
205 v3->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
206 v3->SetBounds(0, 0, 10, 0);
207 host_->AddChildView(v3);
208 host_->SetBounds(0, 0, 40, 40);
209 host_->Layout();
210 EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds());
211 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds());
212 EXPECT_EQ(gfx::Rect(30, 0, 10, 30), v3->bounds());
213 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
214 host_->SetBounds(0, 0, 30, 30);
215 host_->Layout();
216 EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds());
217 EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds());
218 EXPECT_EQ(gfx::Rect(20, 0, 10, 20), v3->bounds());
219 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
220 }
221
222 TEST_F(AlignLayoutTest, FillBottomRight) {
223 AlignLayout* layout = new AlignLayout();
224 host_->SetLayoutManager(layout);
225 View* v1 = new View();
226 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
227 v1->SetBounds(0, 0, 10, 0);
228 host_->AddChildView(v1);
229 View* v2 = new View();
230 v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
231 v2->SetBounds(0, 0, 0, 10);
232 host_->AddChildView(v2);
233 host_->SetBounds(0, 0, 40, 40);
234 host_->Layout();
235 EXPECT_EQ(gfx::Rect(30, 0, 10, 30), v1->bounds());
236 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds());
237 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
238 host_->SetBounds(0, 0, 30, 30);
239 host_->Layout();
240 EXPECT_EQ(gfx::Rect(20, 0, 10, 20), v1->bounds());
241 EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds());
242 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
243 }
244
245 TEST_F(AlignLayoutTest, FillLeftBottom) {
246 AlignLayout* layout = new AlignLayout();
247 host_->SetLayoutManager(layout);
248 View* v1 = new View();
249 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
250 v1->SetBounds(0, 0, 10, 0);
251 host_->AddChildView(v1);
252 View* v2 = new View();
253 v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
254 v2->SetBounds(0, 0, 0, 10);
255 host_->AddChildView(v2);
256 host_->SetBounds(0, 0, 40, 40);
257 host_->Layout();
258 EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds());
259 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds());
260 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
261 host_->SetBounds(0, 0, 30, 30);
262 host_->Layout();
263 EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds());
264 EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds());
265 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
266 }
267
268 TEST_F(AlignLayoutTest, FillLeftTopRightBottomContent) {
269 AlignLayout* layout = new AlignLayout();
270 host_->SetLayoutManager(layout);
271 View* vc = new View();
272 vc->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Content)));
273 vc->SetBounds(0, 0, 0, 0);
274 host_->AddChildView(vc);
275 host_->SetBounds(0, 0, 60, 60);
276 host_->Layout();
277 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), vc->bounds());
278 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds());
279 View* vl = new View();
280 vl->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
281 vl->SetBounds(0, 0, 10, 0);
282 host_->AddChildView(vl);
283 host_->Layout();
284 EXPECT_EQ(gfx::Rect(0, 0, 10, 60), vl->bounds());
285 EXPECT_EQ(gfx::Rect(10, 0, 50, 60), vc->bounds());
286 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds());
287 View* vr = new View();
288 vr->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
289 vr->SetBounds(0, 0, 10, 0);
290 host_->AddChildView(vr);
291 host_->Layout();
292 EXPECT_EQ(gfx::Rect(0, 0, 10, 60), vl->bounds());
293 EXPECT_EQ(gfx::Rect(50, 0, 10, 60), vr->bounds());
294 EXPECT_EQ(gfx::Rect(10, 0, 40, 60), vc->bounds());
295 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds());
296 View* vt = new View();
297 vt->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
298 vt->SetBounds(0, 0, 0, 10);
299 host_->AddChildView(vt);
300 host_->Layout();
301 EXPECT_EQ(gfx::Rect(0, 10, 10, 50), vl->bounds());
302 EXPECT_EQ(gfx::Rect(50, 10, 10, 50), vr->bounds());
303 EXPECT_EQ(gfx::Rect(0, 0, 60, 10), vt->bounds());
304 EXPECT_EQ(gfx::Rect(10, 10, 40, 50), vc->bounds());
305 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds());
306 View* vb = new View();
307 vb->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
308 vb->SetBounds(0, 0, 0, 10);
309 host_->AddChildView(vb);
310 host_->Layout();
311 EXPECT_EQ(gfx::Rect(0, 10, 10, 40), vl->bounds());
312 EXPECT_EQ(gfx::Rect(50, 10, 10, 40), vr->bounds());
313 EXPECT_EQ(gfx::Rect(0, 0, 60, 10), vt->bounds());
314 EXPECT_EQ(gfx::Rect(0, 50, 60, 10), vb->bounds());
315 EXPECT_EQ(gfx::Rect(10, 10, 40, 40), vc->bounds());
316 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds());
317 }
318
319 TEST_F(AlignLayoutTest, FillStackedTop) {
320 AlignLayout* layout = new AlignLayout();
321 host_->SetLayoutManager(layout);
322 View* v1 = new View();
323 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
324 v1->SetBounds(0, 0, 0, 10);
325 host_->AddChildView(v1);
326 host_->SetBounds(0, 0, 40, 40);
327 host_->Layout();
328 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v1->bounds());
329 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
330 View* v2 = new View();
331 v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
332 v2->SetBounds(0, 0, 0, 10);
333 host_->AddChildView(v2);
334 host_->Layout();
335 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v1->bounds());
336 EXPECT_EQ(gfx::Rect(0, 10, 40, 10), v2->bounds());
337 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
338 }
339
340 TEST_F(AlignLayoutTest, FillStackedBottom) {
341 AlignLayout* layout = new AlignLayout();
342 host_->SetLayoutManager(layout);
343 View* v1 = new View();
344 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
345 v1->SetBounds(0, 0, 0, 10);
346 host_->AddChildView(v1);
347 host_->SetBounds(0, 0, 40, 40);
348 host_->Layout();
349 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v1->bounds());
350 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
351 View* v2 = new View();
352 v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
353 v2->SetBounds(0, 0, 0, 10);
354 host_->AddChildView(v2);
355 host_->Layout();
356 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v1->bounds());
357 EXPECT_EQ(gfx::Rect(0, 20, 40, 10), v2->bounds());
358 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
359 }
360
361 TEST_F(AlignLayoutTest, FillStackedLeft) {
362 AlignLayout* layout = new AlignLayout();
363 host_->SetLayoutManager(layout);
364 View* v1 = new View();
365 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
366 v1->SetBounds(0, 0, 10, 0);
367 host_->AddChildView(v1);
368 host_->SetBounds(0, 0, 40, 40);
369 host_->Layout();
370 EXPECT_EQ(gfx::Rect(0, 0, 10, 40), v1->bounds());
371 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
372 View* v2 = new View();
373 v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
374 v2->SetBounds(0, 0, 10, 0);
375 host_->AddChildView(v2);
376 host_->Layout();
377 EXPECT_EQ(gfx::Rect(0, 0, 10, 40), v1->bounds());
378 EXPECT_EQ(gfx::Rect(10, 0, 10, 40), v2->bounds());
379 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
380 }
381
382 TEST_F(AlignLayoutTest, FillStackedRight) {
383 AlignLayout* layout = new AlignLayout();
384 host_->SetLayoutManager(layout);
385 View* v1 = new View();
386 v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
387 v1->SetBounds(0, 0, 10, 0);
388 host_->AddChildView(v1);
389 host_->SetBounds(0, 0, 40, 40);
390 host_->Layout();
391 EXPECT_EQ(gfx::Rect(30, 0, 10, 40), v1->bounds());
392 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
393 View* v2 = new View();
394 v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
395 v2->SetBounds(0, 0, 10, 0);
396 host_->AddChildView(v2);
397 host_->Layout();
398 EXPECT_EQ(gfx::Rect(30, 0, 10, 40), v1->bounds());
399 EXPECT_EQ(gfx::Rect(20, 0, 10, 40), v2->bounds());
400 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
401 }
402
403 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/layout/align_layout.cc ('k') | ui/views/layout/anchor_layout_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698