Chromium Code Reviews| 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 017120d492e25cc68dbedd6652982f6163cc30ee..f917eb68720f9d55d7675709544c9268f3f9aa0a 100644 |
| --- a/ui/views/layout/box_layout_unittest.cc |
| +++ b/ui/views/layout/box_layout_unittest.cc |
| @@ -16,8 +16,9 @@ class StaticSizedView : public View { |
| explicit StaticSizedView(const gfx::Size& size) |
| : size_(size) { |
| } |
| + virtual ~StaticSizedView() {} |
| - virtual gfx::Size GetPreferredSize() OVERRIDE{ |
| + virtual gfx::Size GetPreferredSize() OVERRIDE { |
| return size_; |
| } |
| @@ -25,6 +26,21 @@ class StaticSizedView : public View { |
| gfx::Size size_; |
| }; |
| +class ProportionallySizedView : public View { |
| + public: |
| + explicit ProportionallySizedView(int factor) : factor_(factor) {} |
| + virtual ~ProportionallySizedView() {} |
| + |
| + virtual int GetHeightForWidth(int w) OVERRIDE { |
| + return w * factor_; |
| + } |
| + |
| + private: |
| + // The multiplicative factor between width and height, i.e. |
| + // height = width * factor_. |
| + int factor_; |
| +}; |
|
sky
2013/03/13 14:03:03
DISALLOW_...
Evan Stade
2013/03/13 23:49:56
Done.
|
| + |
| class BoxLayoutTest : public testing::Test { |
| public: |
| virtual void SetUp() OVERRIDE { |
| @@ -131,4 +147,18 @@ TEST_F(BoxLayoutTest, DistributeEmptySpace) { |
| EXPECT_EQ(gfx::Rect(60, 10, 30, 20).ToString(), v2->bounds().ToString()); |
| } |
| +TEST_F(BoxLayoutTest, UseHeightForWidth) { |
| + layout_.reset(new BoxLayout(BoxLayout::kVertical, 0, 0, 0)); |
| + View* v1 = new StaticSizedView(gfx::Size(20, 10)); |
| + host_->AddChildView(v1); |
| + View* v2 = new ProportionallySizedView(2); |
| + host_->AddChildView(v2); |
| + EXPECT_EQ(gfx::Size(20, 50), layout_->GetPreferredSize(host_.get())); |
| + |
| + host_->SetBounds(0, 0, 20, 50); |
| + layout_->Layout(host_.get()); |
| + EXPECT_EQ(gfx::Rect(0, 0, 20, 10), v1->bounds()); |
| + EXPECT_EQ(gfx::Rect(0, 10, 20, 40), v2->bounds()); |
| +} |
| + |
| } // namespace views |