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

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

Issue 2625083003: Implement Harmony-style consistent button widths for Collected Cookies. (Closed)
Patch Set: selfnits Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/layout/grid_layout.h" 5 #include "ui/views/layout/grid_layout.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/views/view.h" 9 #include "ui/views/view.h"
10 10
11 namespace views { 11 namespace views {
12 12
13 void ExpectViewBoundsEquals(int x, int y, int w, int h, 13 void ExpectViewBoundsEquals(int x, int y, int w, int h,
14 const View* view) { 14 const View* view) {
15 EXPECT_EQ(x, view->x()); 15 EXPECT_EQ(x, view->x());
16 EXPECT_EQ(y, view->y()); 16 EXPECT_EQ(y, view->y());
17 EXPECT_EQ(w, view->width()); 17 EXPECT_EQ(w, view->width());
18 EXPECT_EQ(h, view->height()); 18 EXPECT_EQ(h, view->height());
19 } 19 }
20 20
21 class SettableSizeView : public View { 21 class SettableSizeView : public View {
22 public: 22 public:
23 explicit SettableSizeView(const gfx::Size& pref) { 23 explicit SettableSizeView(const gfx::Size& pref) {
24 pref_ = pref; 24 pref_ = pref;
25 } 25 }
26 26
27 gfx::Size GetPreferredSize() const override { return pref_; } 27 gfx::Size GetPreferredSize() const override { return pref_; }
28 28
29 void set_pref(const gfx::Size& pref) { pref_ = pref; }
30
29 private: 31 private:
30 gfx::Size pref_; 32 gfx::Size pref_;
Peter Kasting 2017/03/07 02:50:37 Nit: While here: DISALLOW_COPY_AND_ASSIGN
tapted 2017/03/07 12:06:41 Done.
31 }; 33 };
32 34
33 // A view with fixed circumference that trades height for width. 35 // A view with fixed circumference that trades height for width.
34 class FlexibleView : public View { 36 class FlexibleView : public View {
35 public: 37 public:
36 explicit FlexibleView(int circumference) { 38 explicit FlexibleView(int circumference) {
37 circumference_ = circumference; 39 circumference_ = circumference;
38 } 40 }
39 41
40 gfx::Size GetPreferredSize() const override { 42 gfx::Size GetPreferredSize() const override {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 EXPECT_EQ(gfx::Size(30, 20), pref); 139 EXPECT_EQ(gfx::Size(30, 20), pref);
138 140
139 host.SetBounds(0, 0, pref.width(), pref.height()); 141 host.SetBounds(0, 0, pref.width(), pref.height());
140 layout.Layout(&host); 142 layout.Layout(&host);
141 ExpectViewBoundsEquals(0, 0, 10, 20, &v1); 143 ExpectViewBoundsEquals(0, 0, 10, 20, &v1);
142 ExpectViewBoundsEquals(10, 0, 20, 20, &v2); 144 ExpectViewBoundsEquals(10, 0, 20, 20, &v2);
143 145
144 RemoveAll(); 146 RemoveAll();
145 } 147 }
146 148
149 // Test linked column sizes, and the column size limit.
150 TEST_F(GridLayoutTest, TwoColumnsLinkedSizes) {
151 SettableSizeView v1(gfx::Size(10, 20));
152 SettableSizeView v2(gfx::Size(20, 20));
153 ColumnSet* c1 = layout.AddColumnSet(0);
154
155 // Fill widths.
156 c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0, GridLayout::USE_PREF,
157 0, 0);
158 c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0, GridLayout::USE_PREF,
159 0, 0);
160
161 layout.StartRow(0, 0);
162 layout.AddView(&v1);
163 layout.AddView(&v2);
164
165 c1->LinkColumnSizes(0, 1, -1);
166 GetPreferredSize();
167
168 // |v1| should obtain the same width as |v2|, since |v2| is larger.
169 EXPECT_EQ(gfx::Size(20 + 20, 20), pref);
170 host.SetBounds(0, 0, pref.width(), pref.height());
171 layout.Layout(&host);
172 ExpectViewBoundsEquals(0, 0, 20, 20, &v1);
173 ExpectViewBoundsEquals(20, 0, 20, 20, &v2);
174
175 // If the limit is zero, behaves as though the columns are not linked.
176 c1->set_linked_column_size_limit(0);
177 GetPreferredSize();
178 EXPECT_EQ(gfx::Size(10 + 20, 20), pref);
179 host.SetBounds(0, 0, pref.width(), pref.height());
180 layout.Layout(&host);
181 ExpectViewBoundsEquals(0, 0, 10, 20, &v1);
182 ExpectViewBoundsEquals(10, 0, 20, 20, &v2);
183
184 // Set a size limit.
185 c1->set_linked_column_size_limit(40);
186 v1.set_pref(gfx::Size(35, 20));
187 GetPreferredSize();
188
189 // |v1| now dominates, but it is still below the limit.
190 EXPECT_EQ(gfx::Size(35 + 35, 20), pref);
191 host.SetBounds(0, 0, pref.width(), pref.height());
192 layout.Layout(&host);
193 ExpectViewBoundsEquals(0, 0, 35, 20, &v1);
194 ExpectViewBoundsEquals(35, 0, 35, 20, &v2);
195
196 // Go over the limit. There should be no influence on the size of |v2| at all.
197 v1.set_pref(gfx::Size(45, 20));
198 GetPreferredSize();
199 EXPECT_EQ(gfx::Size(45 + 20, 20), pref);
200 host.SetBounds(0, 0, pref.width(), pref.height());
201 layout.Layout(&host);
202 ExpectViewBoundsEquals(0, 0, 45, 20, &v1);
203 ExpectViewBoundsEquals(45, 0, 20, 20, &v2);
204
Peter Kasting 2017/03/07 02:50:37 Should there be a test case that if you have 3 lin
tapted 2017/03/07 12:06:41 Done.
205 RemoveAll();
206 }
207
147 TEST_F(GridLayoutTest, ColSpan1) { 208 TEST_F(GridLayoutTest, ColSpan1) {
148 SettableSizeView v1(gfx::Size(100, 20)); 209 SettableSizeView v1(gfx::Size(100, 20));
149 SettableSizeView v2(gfx::Size(10, 40)); 210 SettableSizeView v2(gfx::Size(10, 40));
150 ColumnSet* c1 = layout.AddColumnSet(0); 211 ColumnSet* c1 = layout.AddColumnSet(0);
151 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 212 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
152 0, GridLayout::USE_PREF, 0, 0); 213 0, GridLayout::USE_PREF, 0, 0);
153 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 214 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING,
154 1, GridLayout::USE_PREF, 0, 0); 215 1, GridLayout::USE_PREF, 0, 0);
155 layout.StartRow(0, 0); 216 layout.StartRow(0, 0);
156 layout.AddView(&v1, 2, 1); 217 layout.AddView(&v1, 2, 1);
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 EXPECT_EQ(gfx::Size(10, 20), pref); 719 EXPECT_EQ(gfx::Size(10, 20), pref);
659 720
660 layout.set_minimum_size(gfx::Size(40, 40)); 721 layout.set_minimum_size(gfx::Size(40, 40));
661 GetPreferredSize(); 722 GetPreferredSize();
662 EXPECT_EQ(gfx::Size(40, 40), pref); 723 EXPECT_EQ(gfx::Size(40, 40), pref);
663 724
664 RemoveAll(); 725 RemoveAll();
665 } 726 }
666 727
667 } // namespace views 728 } // namespace views
OLDNEW
« ui/views/layout/grid_layout.cc ('K') | « ui/views/layout/grid_layout.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698