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

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

Issue 284753002: Add main axis alignment for BoxLayout. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« ui/views/layout/box_layout.cc ('K') | « ui/views/layout/box_layout.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/box_layout.h" 5 #include "ui/views/layout/box_layout.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/views/test/test_views.h" 8 #include "ui/views/test/test_views.h"
9 #include "ui/views/view.h" 9 #include "ui/views/view.h"
10 10
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 EXPECT_EQ(v2->GetPreferredSize().width(), host_->bounds().width()) << i; 150 EXPECT_EQ(v2->GetPreferredSize().width(), host_->bounds().width()) << i;
151 EXPECT_EQ(v2->GetPreferredSize().height(), host_->bounds().height()) << i; 151 EXPECT_EQ(v2->GetPreferredSize().height(), host_->bounds().height()) << i;
152 EXPECT_EQ(v1->GetPreferredSize().width(), v1->bounds().width()) << i; 152 EXPECT_EQ(v1->GetPreferredSize().width(), v1->bounds().width()) << i;
153 EXPECT_EQ(v1->GetPreferredSize().height(), v1->bounds().height()) << i; 153 EXPECT_EQ(v1->GetPreferredSize().height(), v1->bounds().height()) << i;
154 EXPECT_EQ(v2->GetPreferredSize().width(), v2->bounds().width()) << i; 154 EXPECT_EQ(v2->GetPreferredSize().width(), v2->bounds().width()) << i;
155 EXPECT_EQ(v2->GetPreferredSize().height(), v2->bounds().height()) << i; 155 EXPECT_EQ(v2->GetPreferredSize().height(), v2->bounds().height()) << i;
156 } 156 }
157 } 157 }
158 158
159 TEST_F(BoxLayoutTest, BoxPackHorizontal) {
160 layout_.reset(new BoxLayout(BoxLayout::kHorizontal, 10, 10, 10));
161
162 View* v1 = new StaticSizedView(gfx::Size(20, 20));
163 host_->AddChildView(v1);
164 View* v2 = new StaticSizedView(gfx::Size(10, 10));
165 host_->AddChildView(v2);
166
167 host_->SetBounds(0, 0, 100, 40);
168
169 // Aligns children to the center horizontally.
benwells 2014/05/13 02:48:05 Before testing CENTER and END, add two more test c
benwells 2014/05/13 02:48:05 Also I think there should be some testing of when
calamity 2014/05/13 04:29:29 Done.
calamity 2014/05/13 04:29:29 Done.
170 layout_->set_box_pack(BoxLayout::BOX_PACK_CENTER);
171 layout_->Layout(host_.get());
172 EXPECT_EQ(gfx::Rect(30, 10, 20, 20).ToString(), v1->bounds().ToString());
173 EXPECT_EQ(gfx::Rect(60, 10, 10, 20).ToString(), v2->bounds().ToString());
174
175 // Aligns children to the end of the host horizontally, accounting for the
176 // inside border spacing.
177 layout_->set_box_pack(BoxLayout::BOX_PACK_END);
178 layout_->Layout(host_.get());
179 EXPECT_EQ(gfx::Rect(50, 10, 20, 20).ToString(), v1->bounds().ToString());
180 EXPECT_EQ(gfx::Rect(80, 10, 10, 20).ToString(), v2->bounds().ToString());
181 }
182
183 TEST_F(BoxLayoutTest, BoxPackVertical) {
184 layout_.reset(new BoxLayout(BoxLayout::kVertical, 10, 10, 10));
185
186 View* v1 = new StaticSizedView(gfx::Size(20, 20));
187 host_->AddChildView(v1);
188 View* v2 = new StaticSizedView(gfx::Size(10, 10));
189 host_->AddChildView(v2);
190
191 host_->SetBounds(0, 0, 40, 100);
192
193 // Aligns children to the center vertically.
194 layout_->set_box_pack(BoxLayout::BOX_PACK_CENTER);
195 layout_->Layout(host_.get());
196 EXPECT_EQ(gfx::Rect(10, 30, 20, 20).ToString(), v1->bounds().ToString());
197 EXPECT_EQ(gfx::Rect(10, 60, 20, 10).ToString(), v2->bounds().ToString());
198
199 // Aligns children to the end of the host vertically, accounting for the
200 // inside border spacing.
201 layout_->set_box_pack(BoxLayout::BOX_PACK_END);
202 layout_->Layout(host_.get());
203 EXPECT_EQ(gfx::Rect(10, 50, 20, 20).ToString(), v1->bounds().ToString());
204 EXPECT_EQ(gfx::Rect(10, 80, 20, 10).ToString(), v2->bounds().ToString());
205 }
206
159 } // namespace views 207 } // namespace views
OLDNEW
« ui/views/layout/box_layout.cc ('K') | « ui/views/layout/box_layout.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698