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

Unified 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 side-by-side diff with in-line comments
Download patch
« ui/views/layout/box_layout.cc ('K') | « ui/views/layout/box_layout.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/layout/box_layout_unittest.cc
diff --git a/ui/views/layout/box_layout_unittest.cc b/ui/views/layout/box_layout_unittest.cc
index 2c12090685eb4f4d7af95a26fc7702de82e6a9f5..c1744f91d4f2578b7a2e31e128ecf544fe41e991 100644
--- a/ui/views/layout/box_layout_unittest.cc
+++ b/ui/views/layout/box_layout_unittest.cc
@@ -156,4 +156,52 @@ TEST_F(BoxLayoutTest, EmptyPreferredSize) {
}
}
+TEST_F(BoxLayoutTest, BoxPackHorizontal) {
+ layout_.reset(new BoxLayout(BoxLayout::kHorizontal, 10, 10, 10));
+
+ View* v1 = new StaticSizedView(gfx::Size(20, 20));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(10, 10));
+ host_->AddChildView(v2);
+
+ host_->SetBounds(0, 0, 100, 40);
+
+ // 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.
+ layout_->set_box_pack(BoxLayout::BOX_PACK_CENTER);
+ layout_->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(30, 10, 20, 20).ToString(), v1->bounds().ToString());
+ EXPECT_EQ(gfx::Rect(60, 10, 10, 20).ToString(), v2->bounds().ToString());
+
+ // Aligns children to the end of the host horizontally, accounting for the
+ // inside border spacing.
+ layout_->set_box_pack(BoxLayout::BOX_PACK_END);
+ layout_->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(50, 10, 20, 20).ToString(), v1->bounds().ToString());
+ EXPECT_EQ(gfx::Rect(80, 10, 10, 20).ToString(), v2->bounds().ToString());
+}
+
+TEST_F(BoxLayoutTest, BoxPackVertical) {
+ layout_.reset(new BoxLayout(BoxLayout::kVertical, 10, 10, 10));
+
+ View* v1 = new StaticSizedView(gfx::Size(20, 20));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(10, 10));
+ host_->AddChildView(v2);
+
+ host_->SetBounds(0, 0, 40, 100);
+
+ // Aligns children to the center vertically.
+ layout_->set_box_pack(BoxLayout::BOX_PACK_CENTER);
+ layout_->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(10, 30, 20, 20).ToString(), v1->bounds().ToString());
+ EXPECT_EQ(gfx::Rect(10, 60, 20, 10).ToString(), v2->bounds().ToString());
+
+ // Aligns children to the end of the host vertically, accounting for the
+ // inside border spacing.
+ layout_->set_box_pack(BoxLayout::BOX_PACK_END);
+ layout_->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(10, 50, 20, 20).ToString(), v1->bounds().ToString());
+ EXPECT_EQ(gfx::Rect(10, 80, 20, 10).ToString(), v2->bounds().ToString());
+}
+
} // namespace views
« 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