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

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: unit test 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
« 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 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
« 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