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

Unified Diff: ui/views/layout/box_layout_unittest.cc

Issue 12575005: make BoxLayout use and respect GetHeightForWidth(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: BoxLayout::GetPreferredHeightForWidth Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « 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 017120d492e25cc68dbedd6652982f6163cc30ee..130e14d9a1408e057ff5f89db965d87446b29122 100644
--- a/ui/views/layout/box_layout_unittest.cc
+++ b/ui/views/layout/box_layout_unittest.cc
@@ -16,13 +16,33 @@ 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_;
}
private:
gfx::Size size_;
+
+ DISALLOW_COPY_AND_ASSIGN(StaticSizedView);
+};
+
+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_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProportionallySizedView);
};
class BoxLayoutTest : public testing::Test {
@@ -131,4 +151,20 @@ 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());
+
+ EXPECT_EQ(110, layout_->GetPreferredHeightForWidth(host_.get(), 50));
+}
+
} // namespace views
« no previous file with comments | « ui/views/layout/box_layout.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698