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

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

Issue 2836313002: BoxLayout now suports per-view margins. (Closed)
Patch Set: Fixed BoxLayout for unit tests Created 3 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
« no previous file with comments | « ui/views/layout/box_layout.cc ('k') | ui/views/view.h » ('j') | 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 d2d073e5cb78d3cbae27b80b204e13adab569fce..66fe886258cb334de4ab7854ceb0b52bc24add53 100644
--- a/ui/views/layout/box_layout_unittest.cc
+++ b/ui/views/layout/box_layout_unittest.cc
@@ -9,6 +9,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/test/test_views.h"
#include "ui/views/view.h"
+#include "ui/views/view_properties.h"
namespace views {
@@ -629,4 +630,72 @@ TEST_F(BoxLayoutTest, MinimumCrossAxisHorizontal) {
EXPECT_EQ(gfx::Size(20, 30), layout->GetPreferredSize(host_.get()));
}
+TEST_F(BoxLayoutTest, MarginsUncollapsedHorizontal) {
+ BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal, 0, 0, 0, false);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(58, 22), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 6, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(34, 6, 20, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, MarginsCollapsedHorizontal) {
+ BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal, 0, 0, 0, true);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(54, 22), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 6, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(30, 6, 20, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, MarginsUncollapsedVertical) {
+ BoxLayout* layout = new BoxLayout(BoxLayout::kVertical, 0, 0, 0, false);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(30, 42), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 5, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(5, 26, 20, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, MarginsCollapsedVertical) {
+ BoxLayout* layout = new BoxLayout(BoxLayout::kVertical, 0, 0, 0, true);
+ host_->SetLayoutManager(layout);
+ View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5));
+ host_->AddChildView(v1);
+ View* v2 = new StaticSizedView(gfx::Size(20, 10));
+ v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4));
+ host_->AddChildView(v2);
+
+ EXPECT_EQ(gfx::Size(30, 37), layout->GetPreferredSize(host_.get()));
+ host_->SizeToPreferredSize();
+ layout->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(5, 5, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(5, 21, 20, 10), v2->bounds());
+}
+
} // namespace views
« no previous file with comments | « ui/views/layout/box_layout.cc ('k') | ui/views/view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698