| 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..659f39e66e458cbdd2671b9100ebd4003c770e26 100644
|
| --- a/ui/views/layout/box_layout_unittest.cc
|
| +++ b/ui/views/layout/box_layout_unittest.cc
|
| @@ -75,6 +75,25 @@ TEST_F(BoxLayoutTest, Overflow) {
|
| View* v2 = new StaticSizedView(gfx::Size(10, 20));
|
| host_->AddChildView(v2);
|
| host_->SetBounds(0, 0, 10, 10);
|
| +
|
| + // Overflows by positioning views at the start and truncating anything that
|
| + // doesn't fit.
|
| + layout_->Layout(host_.get());
|
| + EXPECT_EQ(gfx::Rect(0, 0, 10, 10), v1->bounds());
|
| + EXPECT_EQ(gfx::Rect(0, 0, 0, 0), v2->bounds());
|
| +
|
| + // All values of main axis alignment should overflow in the same manner.
|
| + layout_->set_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_START);
|
| + layout_->Layout(host_.get());
|
| + EXPECT_EQ(gfx::Rect(0, 0, 10, 10), v1->bounds());
|
| + EXPECT_EQ(gfx::Rect(0, 0, 0, 0), v2->bounds());
|
| +
|
| + layout_->set_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
|
| + layout_->Layout(host_.get());
|
| + EXPECT_EQ(gfx::Rect(0, 0, 10, 10), v1->bounds());
|
| + EXPECT_EQ(gfx::Rect(0, 0, 0, 0), v2->bounds());
|
| +
|
| + layout_->set_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_END);
|
| layout_->Layout(host_.get());
|
| EXPECT_EQ(gfx::Rect(0, 0, 10, 10), v1->bounds());
|
| EXPECT_EQ(gfx::Rect(0, 0, 0, 0), v2->bounds());
|
| @@ -102,9 +121,9 @@ TEST_F(BoxLayoutTest, InvisibleChild) {
|
| EXPECT_EQ(gfx::Rect(10, 10, 10, 10), v2->bounds());
|
| }
|
|
|
| -TEST_F(BoxLayoutTest, DistributeEmptySpace) {
|
| +TEST_F(BoxLayoutTest, MainAxisAlignmentFill) {
|
| layout_.reset(new BoxLayout(BoxLayout::kHorizontal, 10, 10, 10));
|
| - layout_->set_spread_blank_space(true);
|
| + layout_->set_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_FILL);
|
|
|
| View* v1 = new StaticSizedView(gfx::Size(20, 20));
|
| host_->AddChildView(v1);
|
| @@ -156,4 +175,74 @@ TEST_F(BoxLayoutTest, EmptyPreferredSize) {
|
| }
|
| }
|
|
|
| +TEST_F(BoxLayoutTest, MainAxisAlignmentHorizontal) {
|
| + 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);
|
| +
|
| + // Align children to the horizontal start by default.
|
| + layout_->Layout(host_.get());
|
| + EXPECT_EQ(gfx::Rect(10, 10, 20, 20).ToString(), v1->bounds().ToString());
|
| + EXPECT_EQ(gfx::Rect(40, 10, 10, 20).ToString(), v2->bounds().ToString());
|
| +
|
| + // Ensure same results for MAIN_AXIS_ALIGNMENT_START.
|
| + layout_->set_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_START);
|
| + layout_->Layout(host_.get());
|
| + EXPECT_EQ(gfx::Rect(10, 10, 20, 20).ToString(), v1->bounds().ToString());
|
| + EXPECT_EQ(gfx::Rect(40, 10, 10, 20).ToString(), v2->bounds().ToString());
|
| +
|
| + // Aligns children to the center horizontally.
|
| + layout_->set_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_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_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_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, MainAxisAlignmentVertical) {
|
| + 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);
|
| +
|
| + // Align children to the vertical start by default.
|
| + layout_->Layout(host_.get());
|
| + EXPECT_EQ(gfx::Rect(10, 10, 20, 20).ToString(), v1->bounds().ToString());
|
| + EXPECT_EQ(gfx::Rect(10, 40, 20, 10).ToString(), v2->bounds().ToString());
|
| +
|
| + // Ensure same results for MAIN_AXIS_ALIGNMENT_START.
|
| + layout_->set_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_START);
|
| + layout_->Layout(host_.get());
|
| + EXPECT_EQ(gfx::Rect(10, 10, 20, 20).ToString(), v1->bounds().ToString());
|
| + EXPECT_EQ(gfx::Rect(10, 40, 20, 10).ToString(), v2->bounds().ToString());
|
| +
|
| + // Aligns children to the center vertically.
|
| + layout_->set_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_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_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_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
|
|
|