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

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

Issue 2445633003: Experimental alignment layout manager using state retained in the layout manager
Patch Set: Created 4 years, 2 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/align_layout_state.cc ('k') | ui/views/layout/anchor_layout_state_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/layout/align_layout_state_unittest.cc
diff --git a/ui/views/layout/align_layout_unittest.cc b/ui/views/layout/align_layout_state_unittest.cc
similarity index 67%
copy from ui/views/layout/align_layout_unittest.cc
copy to ui/views/layout/align_layout_state_unittest.cc
index 0da19d995f67e055cb1613f56639ff9b012d362e..47b903183bc7debec3d17ecac6226bf03fc5dd09 100644
--- a/ui/views/layout/align_layout_unittest.cc
+++ b/ui/views/layout/align_layout_state_unittest.cc
@@ -7,7 +7,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/align_attribute.h"
-#include "ui/views/layout/align_layout.h"
+#include "ui/views/layout/align_layout_state.h"
#include "ui/views/test/test_views.h"
#include "ui/views/view.h"
@@ -15,7 +15,7 @@ namespace views {
namespace {
-class AlignLayoutTest : public testing::Test {
+class AlignLayoutStateTest : public testing::Test {
public:
void SetUp() override { host_.reset(new View); }
@@ -24,18 +24,18 @@ class AlignLayoutTest : public testing::Test {
} // namespace
-TEST_F(AlignLayoutTest, Empty) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, Empty) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
EXPECT_EQ(gfx::Size(0, 0), layout->GetPreferredSize(host_.get()));
}
-TEST_F(AlignLayoutTest, AlignTop) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignTop) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top)));
- v1->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v1, Align::Top);
+ layout->SetViewBounds(v1, 0, 0, 0, 10);
host_->AddChildView(v1);
host_->SetBounds(0, 0, 20, 20);
host_->Layout();
@@ -47,12 +47,12 @@ TEST_F(AlignLayoutTest, AlignTop) {
EXPECT_EQ(gfx::Rect(0, 0, 30, 20), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignBottom) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignBottom) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom)));
- v1->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v1, Align::Bottom);
+ layout->SetViewBounds(v1, 0, 0, 0, 10);
host_->AddChildView(v1);
host_->SetBounds(0, 0, 20, 20);
host_->Layout();
@@ -64,12 +64,12 @@ TEST_F(AlignLayoutTest, AlignBottom) {
EXPECT_EQ(gfx::Rect(0, 0, 30, 20), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignLeft) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignLeft) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left)));
- v1->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v1, Align::Left);
+ layout->SetViewBounds(v1, 0, 0, 10, 0);
host_->AddChildView(v1);
host_->SetBounds(0, 0, 20, 20);
host_->Layout();
@@ -81,12 +81,12 @@ TEST_F(AlignLayoutTest, AlignLeft) {
EXPECT_EQ(gfx::Rect(0, 0, 20, 30), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignRight) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignRight) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right)));
- v1->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v1, Align::Right);
+ layout->SetViewBounds(v1, 0, 0, 10, 0);
host_->AddChildView(v1);
host_->SetBounds(0, 0, 20, 20);
host_->Layout();
@@ -98,12 +98,12 @@ TEST_F(AlignLayoutTest, AlignRight) {
EXPECT_EQ(gfx::Rect(0, 0, 20, 30), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignContent) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignContent) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Content)));
- v1->SetBounds(0, 0, 0, 0);
+ layout->AlignView(v1, Align::Content);
+ layout->SetViewBounds(v1, 0, 0, 0, 0);
host_->AddChildView(v1);
host_->SetBounds(0, 0, 20, 20);
host_->Layout();
@@ -115,16 +115,16 @@ TEST_F(AlignLayoutTest, AlignContent) {
EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignLeftTop) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignLeftTop) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left)));
- v1->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v1, Align::Left);
+ layout->SetViewBounds(v1, 0, 0, 10, 0);
host_->AddChildView(v1);
View* v2 = new View();
- v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top)));
- v2->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v2, Align::Top);
+ layout->SetViewBounds(v2, 0, 0, 0, 10);
host_->AddChildView(v2);
host_->SetBounds(0, 0, 40, 40);
host_->Layout();
@@ -138,20 +138,20 @@ TEST_F(AlignLayoutTest, AlignLeftTop) {
EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignLeftTopRight) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignLeftTopRight) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left)));
- v1->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v1, Align::Left);
+ layout->SetViewBounds(v1, 0, 0, 10, 0);
host_->AddChildView(v1);
View* v2 = new View();
- v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top)));
- v2->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v2, Align::Top);
+ layout->SetViewBounds(v2, 0, 0, 0, 10);
host_->AddChildView(v2);
View* v3 = new View();
- v3->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right)));
- v3->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v3, Align::Right);
+ layout->SetViewBounds(v3, 0, 0, 10, 0);
host_->AddChildView(v3);
host_->SetBounds(0, 0, 40, 40);
host_->Layout();
@@ -167,16 +167,16 @@ TEST_F(AlignLayoutTest, AlignLeftTopRight) {
EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignTopRight) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignTopRight) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right)));
- v1->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v1, Align::Right);
+ layout->SetViewBounds(v1, 0, 0, 10, 0);
host_->AddChildView(v1);
View* v2 = new View();
- v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top)));
- v2->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v2, Align::Top);
+ layout->SetViewBounds(v2, 0, 0, 0, 10);
host_->AddChildView(v2);
host_->SetBounds(0, 0, 40, 40);
host_->Layout();
@@ -190,20 +190,20 @@ TEST_F(AlignLayoutTest, AlignTopRight) {
EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignLeftBottomRight) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignLeftBottomRight) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left)));
- v1->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v1, Align::Left);
+ layout->SetViewBounds(v1, 0, 0, 10, 0);
host_->AddChildView(v1);
View* v2 = new View();
- v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom)));
- v2->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v2, Align::Bottom);
+ layout->SetViewBounds(v2, 0, 0, 0, 10);
host_->AddChildView(v2);
View* v3 = new View();
- v3->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right)));
- v3->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v3, Align::Right);
+ layout->SetViewBounds(v3, 0, 0, 10, 0);
host_->AddChildView(v3);
host_->SetBounds(0, 0, 40, 40);
host_->Layout();
@@ -219,16 +219,16 @@ TEST_F(AlignLayoutTest, AlignLeftBottomRight) {
EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignBottomRight) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignBottomRight) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right)));
- v1->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v1, Align::Right);
+ layout->SetViewBounds(v1, 0, 0, 10, 0);
host_->AddChildView(v1);
View* v2 = new View();
- v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom)));
- v2->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v2, Align::Bottom);
+ layout->SetViewBounds(v2, 0, 0, 0, 10);
host_->AddChildView(v2);
host_->SetBounds(0, 0, 40, 40);
host_->Layout();
@@ -242,16 +242,17 @@ TEST_F(AlignLayoutTest, AlignBottomRight) {
EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignLeftBottom) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignLeftBottom) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
+ layout->AlignView(v1, Align::Left);
v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left)));
- v1->SetBounds(0, 0, 10, 0);
+ layout->SetViewBounds(v1, 0, 0, 10, 0);
host_->AddChildView(v1);
View* v2 = new View();
- v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom)));
- v2->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v2, Align::Bottom);
+ layout->SetViewBounds(v2, 0, 0, 0, 10);
host_->AddChildView(v2);
host_->SetBounds(0, 0, 40, 40);
host_->Layout();
@@ -265,11 +266,11 @@ TEST_F(AlignLayoutTest, AlignLeftBottom) {
EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignLeftTopRightBottomContent) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignLeftTopRightBottomContent) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* vc = new View();
- vc->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Content)));
+ layout->AlignView(vc, Align::Content);
vc->SetBounds(0, 0, 0, 0);
host_->AddChildView(vc);
host_->SetBounds(0, 0, 60, 60);
@@ -277,16 +278,17 @@ TEST_F(AlignLayoutTest, AlignLeftTopRightBottomContent) {
EXPECT_EQ(gfx::Rect(0, 0, 60, 60), vc->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds());
View* vl = new View();
- vl->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left)));
- vl->SetBounds(0, 0, 10, 0);
+ layout->AlignView(vl, Align::Left);
+ layout->SetViewBounds(vl, 0, 0, 10, 0);
host_->AddChildView(vl);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 0, 10, 60), vl->bounds());
EXPECT_EQ(gfx::Rect(10, 0, 50, 60), vc->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds());
View* vr = new View();
+ layout->AlignView(vr, Align::Right);
vr->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right)));
- vr->SetBounds(0, 0, 10, 0);
+ layout->SetViewBounds(vr, 0, 0, 10, 0);
host_->AddChildView(vr);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 0, 10, 60), vl->bounds());
@@ -294,8 +296,8 @@ TEST_F(AlignLayoutTest, AlignLeftTopRightBottomContent) {
EXPECT_EQ(gfx::Rect(10, 0, 40, 60), vc->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds());
View* vt = new View();
- vt->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top)));
- vt->SetBounds(0, 0, 0, 10);
+ layout->AlignView(vt, Align::Top);
+ layout->SetViewBounds(vt, 0, 0, 0, 10);
host_->AddChildView(vt);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 10, 10, 50), vl->bounds());
@@ -304,8 +306,8 @@ TEST_F(AlignLayoutTest, AlignLeftTopRightBottomContent) {
EXPECT_EQ(gfx::Rect(10, 10, 40, 50), vc->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds());
View* vb = new View();
- vb->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom)));
- vb->SetBounds(0, 0, 0, 10);
+ layout->AlignView(vb, Align::Bottom);
+ layout->SetViewBounds(vb, 0, 0, 0, 10);
host_->AddChildView(vb);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 10, 10, 40), vl->bounds());
@@ -316,20 +318,20 @@ TEST_F(AlignLayoutTest, AlignLeftTopRightBottomContent) {
EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignStackedTop) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignStackedTop) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top)));
- v1->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v1, Align::Top);
+ layout->SetViewBounds(v1, 0, 0, 0, 10);
host_->AddChildView(v1);
host_->SetBounds(0, 0, 40, 40);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
View* v2 = new View();
- v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top)));
- v2->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v2, Align::Top);
+ layout->SetViewBounds(v2, 0, 0, 0, 10);
host_->AddChildView(v2);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v1->bounds());
@@ -337,20 +339,20 @@ TEST_F(AlignLayoutTest, AlignStackedTop) {
EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignStackedBottom) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignStackedBottom) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom)));
- v1->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v1, Align::Bottom);
+ layout->SetViewBounds(v1, 0, 0, 0, 10);
host_->AddChildView(v1);
host_->SetBounds(0, 0, 40, 40);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
View* v2 = new View();
- v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom)));
- v2->SetBounds(0, 0, 0, 10);
+ layout->AlignView(v2, Align::Bottom);
+ layout->SetViewBounds(v2, 0, 0, 0, 10);
host_->AddChildView(v2);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v1->bounds());
@@ -358,20 +360,20 @@ TEST_F(AlignLayoutTest, AlignStackedBottom) {
EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignStackedLeft) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignStackedLeft) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left)));
- v1->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v1, Align::Left);
+ layout->SetViewBounds(v1, 0, 0, 10, 0);
host_->AddChildView(v1);
host_->SetBounds(0, 0, 40, 40);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 0, 10, 40), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
View* v2 = new View();
- v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left)));
- v2->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v2, Align::Left);
+ layout->SetViewBounds(v2, 0, 0, 10, 0);
host_->AddChildView(v2);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 0, 10, 40), v1->bounds());
@@ -379,20 +381,20 @@ TEST_F(AlignLayoutTest, AlignStackedLeft) {
EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
}
-TEST_F(AlignLayoutTest, AlignStackedRight) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AlignLayoutStateTest, AlignStackedRight) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right)));
- v1->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v1, Align::Right);
+ layout->SetViewBounds(v1, 0, 0, 10, 0);
host_->AddChildView(v1);
host_->SetBounds(0, 0, 40, 40);
host_->Layout();
EXPECT_EQ(gfx::Rect(30, 0, 10, 40), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
View* v2 = new View();
- v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right)));
- v2->SetBounds(0, 0, 10, 0);
+ layout->AlignView(v2, Align::Right);
+ layout->SetViewBounds(v2, 0, 0, 10, 0);
host_->AddChildView(v2);
host_->Layout();
EXPECT_EQ(gfx::Rect(30, 0, 10, 40), v1->bounds());
« no previous file with comments | « ui/views/layout/align_layout_state.cc ('k') | ui/views/layout/anchor_layout_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698