Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / views / layout / grid_layout_unittest.cc
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 "ui/views/layout/grid_layout.h"
6
7 #include "base/compiler_specific.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/views/view.h"
10
11 namespace views {
12
13 void ExpectViewBoundsEquals(int x, int y, int w, int h,
14                             const View* view) {
15   EXPECT_EQ(x, view->x());
16   EXPECT_EQ(y, view->y());
17   EXPECT_EQ(w, view->width());
18   EXPECT_EQ(h, view->height());
19 }
20
21 class SettableSizeView : public View {
22  public:
23   explicit SettableSizeView(const gfx::Size& pref) {
24     pref_ = pref;
25   }
26
27   gfx::Size GetPreferredSize() const override { return pref_; }
28
29  private:
30    gfx::Size pref_;
31 };
32
33 // A view with fixed circumference that trades height for width.
34 class FlexibleView : public View {
35  public:
36   explicit FlexibleView(int circumference) {
37     circumference_ = circumference;
38   }
39
40   gfx::Size GetPreferredSize() const override {
41     return gfx::Size(0, circumference_ / 2);
42   }
43
44   int GetHeightForWidth(int width) const override {
45     return std::max(0, circumference_ / 2 - width);
46   }
47
48  private:
49    int circumference_;
50 };
51
52 class GridLayoutTest : public testing::Test {
53  public:
54   GridLayoutTest() : layout(&host) {}
55
56   void RemoveAll() {
57     for (int i = host.child_count() - 1; i >= 0; i--)
58       host.RemoveChildView(host.child_at(i));
59   }
60
61   void GetPreferredSize() {
62     pref = layout.GetPreferredSize(&host);
63   }
64
65   gfx::Size pref;
66   gfx::Rect bounds;
67   View host;
68   GridLayout layout;
69 };
70
71 class GridLayoutAlignmentTest : public testing::Test {
72  public:
73    GridLayoutAlignmentTest()
74        : v1(gfx::Size(10, 20)),
75          layout(&host) {}
76
77   void RemoveAll() {
78     for (int i = host.child_count() - 1; i >= 0; i--)
79       host.RemoveChildView(host.child_at(i));
80   }
81
82   void TestAlignment(GridLayout::Alignment alignment, gfx::Rect* bounds) {
83     ColumnSet* c1 = layout.AddColumnSet(0);
84     c1->AddColumn(alignment, alignment, 1, GridLayout::USE_PREF, 0, 0);
85     layout.StartRow(1, 0);
86     layout.AddView(&v1);
87     gfx::Size pref = layout.GetPreferredSize(&host);
88     EXPECT_EQ(gfx::Size(10, 20), pref);
89     host.SetBounds(0, 0, 100, 100);
90     layout.Layout(&host);
91     *bounds = v1.bounds();
92     RemoveAll();
93   }
94
95   View host;
96   SettableSizeView v1;
97   GridLayout layout;
98 };
99
100 TEST_F(GridLayoutAlignmentTest, Fill) {
101   gfx::Rect bounds;
102   TestAlignment(GridLayout::FILL, &bounds);
103   EXPECT_EQ(gfx::Rect(0, 0, 100, 100), bounds);
104 }
105
106 TEST_F(GridLayoutAlignmentTest, Leading) {
107   gfx::Rect bounds;
108   TestAlignment(GridLayout::LEADING, &bounds);
109   EXPECT_EQ(gfx::Rect(0, 0, 10, 20), bounds);
110 }
111
112 TEST_F(GridLayoutAlignmentTest, Center) {
113   gfx::Rect bounds;
114   TestAlignment(GridLayout::CENTER, &bounds);
115   EXPECT_EQ(gfx::Rect(45, 40, 10, 20), bounds);
116 }
117
118 TEST_F(GridLayoutAlignmentTest, Trailing) {
119   gfx::Rect bounds;
120   TestAlignment(GridLayout::TRAILING, &bounds);
121   EXPECT_EQ(gfx::Rect(90, 80, 10, 20), bounds);
122 }
123
124 TEST_F(GridLayoutTest, TwoColumns) {
125   SettableSizeView v1(gfx::Size(10, 20));
126   SettableSizeView v2(gfx::Size(20, 20));
127   ColumnSet* c1 = layout.AddColumnSet(0);
128   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
129                 0, GridLayout::USE_PREF, 0, 0);
130   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
131                 0, GridLayout::USE_PREF, 0, 0);
132   layout.StartRow(0, 0);
133   layout.AddView(&v1);
134   layout.AddView(&v2);
135
136   GetPreferredSize();
137   EXPECT_EQ(gfx::Size(30, 20), pref);
138
139   host.SetBounds(0, 0, pref.width(), pref.height());
140   layout.Layout(&host);
141   ExpectViewBoundsEquals(0, 0, 10, 20, &v1);
142   ExpectViewBoundsEquals(10, 0, 20, 20, &v2);
143
144   RemoveAll();
145 }
146
147 TEST_F(GridLayoutTest, ColSpan1) {
148   SettableSizeView v1(gfx::Size(100, 20));
149   SettableSizeView v2(gfx::Size(10, 40));
150   ColumnSet* c1 = layout.AddColumnSet(0);
151   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
152                 0, GridLayout::USE_PREF, 0, 0);
153   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
154                 1, GridLayout::USE_PREF, 0, 0);
155   layout.StartRow(0, 0);
156   layout.AddView(&v1, 2, 1);
157   layout.StartRow(0, 0);
158   layout.AddView(&v2);
159
160   GetPreferredSize();
161   EXPECT_EQ(gfx::Size(100, 60), pref);
162
163   host.SetBounds(0, 0, pref.width(), pref.height());
164   layout.Layout(&host);
165   ExpectViewBoundsEquals(0, 0, 100, 20, &v1);
166   ExpectViewBoundsEquals(0, 20, 10, 40, &v2);
167
168   RemoveAll();
169 }
170
171 TEST_F(GridLayoutTest, ColSpan2) {
172   SettableSizeView v1(gfx::Size(100, 20));
173   SettableSizeView v2(gfx::Size(10, 20));
174   ColumnSet* c1 = layout.AddColumnSet(0);
175   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
176                 1, GridLayout::USE_PREF, 0, 0);
177   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
178                 0, GridLayout::USE_PREF, 0, 0);
179   layout.StartRow(0, 0);
180   layout.AddView(&v1, 2, 1);
181   layout.StartRow(0, 0);
182   layout.SkipColumns(1);
183   layout.AddView(&v2);
184
185   GetPreferredSize();
186   EXPECT_EQ(gfx::Size(100, 40), pref);
187
188   host.SetBounds(0, 0, pref.width(), pref.height());
189   layout.Layout(&host);
190   ExpectViewBoundsEquals(0, 0, 100, 20, &v1);
191   ExpectViewBoundsEquals(90, 20, 10, 20, &v2);
192
193   RemoveAll();
194 }
195
196 TEST_F(GridLayoutTest, ColSpan3) {
197   SettableSizeView v1(gfx::Size(100, 20));
198   SettableSizeView v2(gfx::Size(10, 20));
199   SettableSizeView v3(gfx::Size(10, 20));
200   ColumnSet* c1 = layout.AddColumnSet(0);
201   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
202                 0, GridLayout::USE_PREF, 0, 0);
203   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
204                 0, GridLayout::USE_PREF, 0, 0);
205   layout.StartRow(0, 0);
206   layout.AddView(&v1, 2, 1);
207   layout.StartRow(0, 0);
208   layout.AddView(&v2);
209   layout.AddView(&v3);
210
211   GetPreferredSize();
212   EXPECT_EQ(gfx::Size(100, 40), pref);
213
214   host.SetBounds(0, 0, pref.width(), pref.height());
215   layout.Layout(&host);
216   ExpectViewBoundsEquals(0, 0, 100, 20, &v1);
217   ExpectViewBoundsEquals(0, 20, 10, 20, &v2);
218   ExpectViewBoundsEquals(50, 20, 10, 20, &v3);
219
220   RemoveAll();
221 }
222
223
224 TEST_F(GridLayoutTest, ColSpan4) {
225   ColumnSet* set = layout.AddColumnSet(0);
226
227   set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,
228                  GridLayout::USE_PREF, 0, 0);
229   set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,
230                  GridLayout::USE_PREF, 0, 0);
231
232   SettableSizeView v1(gfx::Size(10, 10));
233   SettableSizeView v2(gfx::Size(10, 10));
234   SettableSizeView v3(gfx::Size(25, 20));
235   layout.StartRow(0, 0);
236   layout.AddView(&v1);
237   layout.AddView(&v2);
238   layout.StartRow(0, 0);
239   layout.AddView(&v3, 2, 1);
240
241   GetPreferredSize();
242   EXPECT_EQ(gfx::Size(25, 30), pref);
243
244   host.SetBounds(0, 0, pref.width(), pref.height());
245   layout.Layout(&host);
246   ExpectViewBoundsEquals(0, 0, 10, 10, &v1);
247   ExpectViewBoundsEquals(12, 0, 10, 10, &v2);
248   ExpectViewBoundsEquals(0, 10, 25, 20, &v3);
249
250   RemoveAll();
251 }
252
253 // Verifies the sizing of a view that doesn't start in the first column
254 // and has a column span > 1 (crbug.com/254092).
255 TEST_F(GridLayoutTest, ColSpanStartSecondColumn) {
256   ColumnSet* set = layout.AddColumnSet(0);
257
258   set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0,
259                  GridLayout::USE_PREF, 0, 0);
260   set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0,
261                  GridLayout::USE_PREF, 0, 0);
262   set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0,
263                  GridLayout::FIXED, 10, 0);
264
265   SettableSizeView v1(gfx::Size(10, 10));
266   SettableSizeView v2(gfx::Size(20, 10));
267
268   layout.StartRow(0, 0);
269   layout.AddView(&v1);
270   layout.AddView(&v2, 2, 1);
271
272   GetPreferredSize();
273   EXPECT_EQ(gfx::Size(30, 10), pref);
274
275   host.SetBounds(0, 0, pref.width(), pref.height());
276   layout.Layout(&host);
277   ExpectViewBoundsEquals(0, 0, 10, 10, &v1);
278   ExpectViewBoundsEquals(10, 0, 20, 10, &v2);
279
280   RemoveAll();
281 }
282
283 TEST_F(GridLayoutTest, SameSizeColumns) {
284   SettableSizeView v1(gfx::Size(50, 20));
285   SettableSizeView v2(gfx::Size(10, 10));
286   ColumnSet* c1 = layout.AddColumnSet(0);
287   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
288                 0, GridLayout::USE_PREF, 0, 0);
289   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
290                 0, GridLayout::USE_PREF, 0, 0);
291   c1->LinkColumnSizes(0, 1, -1);
292   layout.StartRow(0, 0);
293   layout.AddView(&v1);
294   layout.AddView(&v2);
295
296   gfx::Size pref = layout.GetPreferredSize(&host);
297   EXPECT_EQ(gfx::Size(100, 20), pref);
298
299   host.SetBounds(0, 0, pref.width(), pref.height());
300   layout.Layout(&host);
301   ExpectViewBoundsEquals(0, 0, 50, 20, &v1);
302   ExpectViewBoundsEquals(50, 0, 10, 10, &v2);
303
304   RemoveAll();
305 }
306
307 TEST_F(GridLayoutTest, HorizontalResizeTest1) {
308   SettableSizeView v1(gfx::Size(50, 20));
309   SettableSizeView v2(gfx::Size(10, 10));
310   ColumnSet* c1 = layout.AddColumnSet(0);
311   c1->AddColumn(GridLayout::FILL, GridLayout::LEADING,
312                 1, GridLayout::USE_PREF, 0, 0);
313   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
314                 0, GridLayout::USE_PREF, 0, 0);
315   layout.StartRow(0, 0);
316   layout.AddView(&v1);
317   layout.AddView(&v2);
318
319   host.SetBounds(0, 0, 110, 20);
320   layout.Layout(&host);
321   ExpectViewBoundsEquals(0, 0, 100, 20, &v1);
322   ExpectViewBoundsEquals(100, 0, 10, 10, &v2);
323
324   RemoveAll();
325 }
326
327 TEST_F(GridLayoutTest, HorizontalResizeTest2) {
328   SettableSizeView v1(gfx::Size(50, 20));
329   SettableSizeView v2(gfx::Size(10, 10));
330   ColumnSet* c1 = layout.AddColumnSet(0);
331   c1->AddColumn(GridLayout::FILL, GridLayout::LEADING,
332                 1, GridLayout::USE_PREF, 0, 0);
333   c1->AddColumn(GridLayout::TRAILING, GridLayout::LEADING,
334                 1, GridLayout::USE_PREF, 0, 0);
335   layout.StartRow(0, 0);
336   layout.AddView(&v1);
337   layout.AddView(&v2);
338
339   host.SetBounds(0, 0, 120, 20);
340   layout.Layout(&host);
341   ExpectViewBoundsEquals(0, 0, 80, 20, &v1);
342   ExpectViewBoundsEquals(110, 0, 10, 10, &v2);
343
344   RemoveAll();
345 }
346
347 // Tests that space leftover due to rounding is distributed to the last
348 // resizable column.
349 TEST_F(GridLayoutTest, HorizontalResizeTest3) {
350   SettableSizeView v1(gfx::Size(10, 10));
351   SettableSizeView v2(gfx::Size(10, 10));
352   SettableSizeView v3(gfx::Size(10, 10));
353   ColumnSet* c1 = layout.AddColumnSet(0);
354   c1->AddColumn(GridLayout::FILL, GridLayout::LEADING,
355                 1, GridLayout::USE_PREF, 0, 0);
356   c1->AddColumn(GridLayout::FILL, GridLayout::LEADING,
357                 1, GridLayout::USE_PREF, 0, 0);
358   c1->AddColumn(GridLayout::TRAILING, GridLayout::LEADING,
359                 0, GridLayout::USE_PREF, 0, 0);
360   layout.StartRow(0, 0);
361   layout.AddView(&v1);
362   layout.AddView(&v2);
363   layout.AddView(&v3);
364
365   host.SetBounds(0, 0, 31, 10);
366   layout.Layout(&host);
367   ExpectViewBoundsEquals(0, 0, 10, 10, &v1);
368   ExpectViewBoundsEquals(10, 0, 11, 10, &v2);
369   ExpectViewBoundsEquals(21, 0, 10, 10, &v3);
370
371   RemoveAll();
372 }
373
374 TEST_F(GridLayoutTest, TestVerticalResize1) {
375   SettableSizeView v1(gfx::Size(50, 20));
376   SettableSizeView v2(gfx::Size(10, 10));
377   ColumnSet* c1 = layout.AddColumnSet(0);
378   c1->AddColumn(GridLayout::FILL, GridLayout::FILL,
379                 1, GridLayout::USE_PREF, 0, 0);
380   layout.StartRow(1, 0);
381   layout.AddView(&v1);
382   layout.StartRow(0, 0);
383   layout.AddView(&v2);
384
385   GetPreferredSize();
386   EXPECT_EQ(gfx::Size(50, 30), pref);
387
388   host.SetBounds(0, 0, 50, 100);
389   layout.Layout(&host);
390   ExpectViewBoundsEquals(0, 0, 50, 90, &v1);
391   ExpectViewBoundsEquals(0, 90, 50, 10, &v2);
392
393   RemoveAll();
394 }
395
396 TEST_F(GridLayoutTest, Insets) {
397   SettableSizeView v1(gfx::Size(10, 20));
398   ColumnSet* c1 = layout.AddColumnSet(0);
399   layout.SetInsets(1, 2, 3, 4);
400   c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
401                 0, GridLayout::USE_PREF, 0, 0);
402   layout.StartRow(0, 0);
403   layout.AddView(&v1);
404
405   GetPreferredSize();
406   EXPECT_EQ(gfx::Size(16, 24), pref);
407
408   host.SetBounds(0, 0, pref.width(), pref.height());
409   layout.Layout(&host);
410   ExpectViewBoundsEquals(2, 1, 10, 20, &v1);
411
412   RemoveAll();
413 }
414
415 TEST_F(GridLayoutTest, FixedSize) {
416   layout.SetInsets(2, 2, 2, 2);
417
418   ColumnSet* set = layout.AddColumnSet(0);
419
420   int column_count = 4;
421   int title_width = 100;
422   int row_count = 2;
423   int pref_width = 10;
424   int pref_height = 20;
425
426   for (int i = 0; i < column_count; ++i) {
427     set->AddColumn(GridLayout::CENTER,
428                    GridLayout::CENTER,
429                    0,
430                    GridLayout::FIXED,
431                    title_width,
432                    title_width);
433   }
434
435   for (int row = 0; row < row_count; ++row) {
436     layout.StartRow(0, 0);
437     for (int col = 0; col < column_count; ++col) {
438       layout.AddView(new SettableSizeView(gfx::Size(pref_width, pref_height)));
439     }
440   }
441
442   layout.Layout(&host);
443
444   for (int i = 0; i < column_count; ++i) {
445     for (int row = 0; row < row_count; ++row) {
446       View* view = host.child_at(row * column_count + i);
447       ExpectViewBoundsEquals(
448           2 + title_width * i + (title_width - pref_width) / 2,
449           2 + pref_height * row,
450           pref_width,
451           pref_height, view);
452     }
453   }
454
455   GetPreferredSize();
456   EXPECT_EQ(gfx::Size(column_count * title_width + 4,
457                       row_count * pref_height + 4), pref);
458 }
459
460 TEST_F(GridLayoutTest, RowSpanWithPaddingRow) {
461   ColumnSet* set = layout.AddColumnSet(0);
462
463   set->AddColumn(GridLayout::CENTER,
464                  GridLayout::CENTER,
465                  0,
466                  GridLayout::FIXED,
467                  10,
468                  10);
469
470   layout.StartRow(0, 0);
471   layout.AddView(new SettableSizeView(gfx::Size(10, 10)), 1, 2);
472   layout.AddPaddingRow(0, 10);
473 }
474
475 TEST_F(GridLayoutTest, RowSpan) {
476   ColumnSet* set = layout.AddColumnSet(0);
477
478   set->AddColumn(GridLayout::LEADING,
479                  GridLayout::LEADING,
480                  0,
481                  GridLayout::USE_PREF,
482                  0,
483                  0);
484   set->AddColumn(GridLayout::LEADING,
485                  GridLayout::LEADING,
486                  0,
487                  GridLayout::USE_PREF,
488                  0,
489                  0);
490
491   layout.StartRow(0, 0);
492   layout.AddView(new SettableSizeView(gfx::Size(20, 10)));
493   layout.AddView(new SettableSizeView(gfx::Size(20, 40)), 1, 2);
494   layout.StartRow(1, 0);
495   View* s3 = new SettableSizeView(gfx::Size(20, 10));
496   layout.AddView(s3);
497
498   GetPreferredSize();
499   EXPECT_EQ(gfx::Size(40, 40), pref);
500
501   host.SetBounds(0, 0, pref.width(), pref.height());
502   layout.Layout(&host);
503   ExpectViewBoundsEquals(0, 10, 20, 10, s3);
504 }
505
506 TEST_F(GridLayoutTest, RowSpan2) {
507   ColumnSet* set = layout.AddColumnSet(0);
508
509   set->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
510                  0, GridLayout::USE_PREF, 0, 0);
511   set->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
512                  0,GridLayout::USE_PREF, 0, 0);
513
514   layout.StartRow(0, 0);
515   layout.AddView(new SettableSizeView(gfx::Size(20, 20)));
516   View* s3 = new SettableSizeView(gfx::Size(64, 64));
517   layout.AddView(s3, 1, 3);
518
519   layout.AddPaddingRow(0, 10);
520
521   layout.StartRow(0, 0);
522   layout.AddView(new SettableSizeView(gfx::Size(10, 20)));
523
524   GetPreferredSize();
525   EXPECT_EQ(gfx::Size(84, 64), pref);
526
527   host.SetBounds(0, 0, pref.width(), pref.height());
528   layout.Layout(&host);
529   ExpectViewBoundsEquals(20, 0, 64, 64, s3);
530 }
531
532 TEST_F(GridLayoutTest, FixedViewWidth) {
533   ColumnSet* set = layout.AddColumnSet(0);
534
535   set->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
536                  0, GridLayout::USE_PREF, 0, 0);
537   set->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
538                  0,GridLayout::USE_PREF, 0, 0);
539
540   layout.StartRow(0, 0);
541   View* view = new SettableSizeView(gfx::Size(30, 40));
542   layout.AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 10, 0);
543
544   GetPreferredSize();
545   EXPECT_EQ(10, pref.width());
546   EXPECT_EQ(40, pref.height());
547
548   host.SetBounds(0, 0, pref.width(), pref.height());
549   layout.Layout(&host);
550   ExpectViewBoundsEquals(0, 0, 10, 40, view);
551 }
552
553 TEST_F(GridLayoutTest, FixedViewHeight) {
554   ColumnSet* set = layout.AddColumnSet(0);
555
556   set->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
557                  0, GridLayout::USE_PREF, 0, 0);
558   set->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
559                  0,GridLayout::USE_PREF, 0, 0);
560
561   layout.StartRow(0, 0);
562   View* view = new SettableSizeView(gfx::Size(30, 40));
563   layout.AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 0, 10);
564
565   GetPreferredSize();
566   EXPECT_EQ(30, pref.width());
567   EXPECT_EQ(10, pref.height());
568
569   host.SetBounds(0, 0, pref.width(), pref.height());
570   layout.Layout(&host);
571   ExpectViewBoundsEquals(0, 0, 30, 10, view);
572 }
573
574 // Make sure that for views that span columns the underlying columns are resized
575 // based on the resize percent of the column.
576 TEST_F(GridLayoutTest, ColumnSpanResizing) {
577   ColumnSet* set = layout.AddColumnSet(0);
578
579   set->AddColumn(GridLayout::FILL, GridLayout::CENTER,
580                  2, GridLayout::USE_PREF, 0, 0);
581   set->AddColumn(GridLayout::FILL, GridLayout::CENTER,
582                  4, GridLayout::USE_PREF, 0, 0);
583
584   layout.StartRow(0, 0);
585   // span_view spans two columns and is twice as big the views added below.
586   View* span_view = new SettableSizeView(gfx::Size(12, 40));
587   layout.AddView(span_view, 2, 1, GridLayout::LEADING, GridLayout::LEADING);
588
589   layout.StartRow(0, 0);
590   View* view1 = new SettableSizeView(gfx::Size(2, 40));
591   View* view2 = new SettableSizeView(gfx::Size(4, 40));
592   layout.AddView(view1);
593   layout.AddView(view2);
594
595   host.SetBounds(0, 0, 12, 80);
596   layout.Layout(&host);
597
598   ExpectViewBoundsEquals(0, 0, 12, 40, span_view);
599
600   // view1 should be 4 pixels wide
601   // column_pref + (remaining_width * column_resize / total_column_resize) =
602   // 2 + (6 * 2 / 6).
603   ExpectViewBoundsEquals(0, 40, 4, 40, view1);
604
605   // And view2 should be 8 pixels wide:
606   // 4 + (6 * 4 / 6).
607   ExpectViewBoundsEquals(4, 40, 8, 40, view2);
608 }
609
610 // Check that GetPreferredSize() takes resizing of columns into account when
611 // there is additional space in the case we have column sets of different
612 // preferred sizes.
613 TEST_F(GridLayoutTest, ColumnResizingOnGetPreferredSize) {
614   ColumnSet* set = layout.AddColumnSet(0);
615   set->AddColumn(GridLayout::FILL, GridLayout::CENTER,
616                  1, GridLayout::USE_PREF, 0, 0);
617
618   set = layout.AddColumnSet(1);
619   set->AddColumn(GridLayout::FILL, GridLayout::CENTER,
620                  1, GridLayout::USE_PREF, 0, 0);
621
622   set = layout.AddColumnSet(2);
623   set->AddColumn(GridLayout::FILL, GridLayout::CENTER,
624                  1, GridLayout::USE_PREF, 0, 0);
625
626   // Make a row containing a flexible view that trades width for height.
627   layout.StartRow(0, 0);
628   View* view1 = new FlexibleView(100);
629   layout.AddView(view1, 1, 1, GridLayout::FILL, GridLayout::LEADING);
630
631   // The second row contains a view of fixed size that will enforce a column
632   // width of 20 pixels.
633   layout.StartRow(0, 1);
634   View* view2 = new SettableSizeView(gfx::Size(20, 20));
635   layout.AddView(view2, 1, 1, GridLayout::FILL, GridLayout::LEADING);
636
637   // Add another flexible view in row three in order to ensure column set
638   // ordering doesn't influence sizing behaviour.
639   layout.StartRow(0, 2);
640   View* view3 = new FlexibleView(40);
641   layout.AddView(view3, 1, 1, GridLayout::FILL, GridLayout::LEADING);
642
643   // We expect a height of 50: 30 from the variable width view in the first row
644   // plus 20 from the statically sized view in the second row. The flexible
645   // view in the third row should contribute no height.
646   EXPECT_EQ(gfx::Size(20, 50), layout.GetPreferredSize(&host));
647 }
648
649 TEST_F(GridLayoutTest, MinimumPreferredSize) {
650   SettableSizeView v1(gfx::Size(10, 20));
651   ColumnSet* set = layout.AddColumnSet(0);
652   set->AddColumn(GridLayout::FILL, GridLayout::FILL,
653                  0, GridLayout::USE_PREF, 0, 0);
654   layout.StartRow(0, 0);
655   layout.AddView(&v1);
656
657   GetPreferredSize();
658   EXPECT_EQ(gfx::Size(10, 20), pref);
659
660   layout.set_minimum_size(gfx::Size(40, 40));
661   GetPreferredSize();
662   EXPECT_EQ(gfx::Size(40, 40), pref);
663
664   RemoveAll();
665 }
666
667 }  // namespace views