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

Unified Diff: ui/views/layout/anchor_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_unittest.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/anchor_layout_state_unittest.cc
diff --git a/ui/views/layout/anchor_layout_unittest.cc b/ui/views/layout/anchor_layout_state_unittest.cc
similarity index 67%
copy from ui/views/layout/anchor_layout_unittest.cc
copy to ui/views/layout/anchor_layout_state_unittest.cc
index 4b0a3e91b86896866f7a1989dbf78b01aa8a4f04..2162968799f62bc1ca716dcb611e298a755a7c68 100644
--- a/ui/views/layout/anchor_layout_unittest.cc
+++ b/ui/views/layout/anchor_layout_state_unittest.cc
@@ -7,7 +7,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/align_attribute.h"
#include "ui/views/anchor_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 AnchorLayoutTest : public testing::Test {
+class AnchorLayoutStateTest : public testing::Test {
public:
void SetUp() override {
host_.reset(new View);
@@ -27,20 +27,19 @@ class AnchorLayoutTest : public testing::Test {
} // namespace
-TEST_F(AnchorLayoutTest, Empty) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, Empty) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
EXPECT_EQ(gfx::Size(0, 0), layout->GetPreferredSize(host_.get()));
}
-TEST_F(AnchorLayoutTest, AnchorLeftTop) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorLeftTop) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(
- base::WrapUnique(new AnchorAttribute({Anchor::Left, Anchor::Top})));
+ layout->AnchorView(v1, {Anchor::Left, Anchor::Top});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -50,13 +49,13 @@ TEST_F(AnchorLayoutTest, AnchorLeftTop) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorTop) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorTop) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AnchorAttribute({Anchor::Top})));
+ layout->AnchorView(v1, {Anchor::Top});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -66,13 +65,13 @@ TEST_F(AnchorLayoutTest, AnchorTop) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorLeft) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorLeft) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AnchorAttribute({Anchor::Left})));
+ layout->AnchorView(v1, {Anchor::Left});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -82,14 +81,13 @@ TEST_F(AnchorLayoutTest, AnchorLeft) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorRightTop) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorRightTop) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(
- base::WrapUnique(new AnchorAttribute({Anchor::Right, Anchor::Top})));
+ layout->AnchorView(v1, {Anchor::Right, Anchor::Top});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -99,14 +97,13 @@ TEST_F(AnchorLayoutTest, AnchorRightTop) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorLeftTopRight) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorLeftTopRight) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(
- new AnchorAttribute({Anchor::Left, Anchor::Top, Anchor::Right})));
+ layout->AnchorView(v1, {Anchor::Left, Anchor::Top, Anchor::Right});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -116,14 +113,13 @@ TEST_F(AnchorLayoutTest, AnchorLeftTopRight) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorLeftTopBottom) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorLeftTopBottom) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(
- new AnchorAttribute({Anchor::Left, Anchor::Top, Anchor::Bottom})));
+ layout->AnchorView(v1, {Anchor::Left, Anchor::Top, Anchor::Bottom});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -133,14 +129,13 @@ TEST_F(AnchorLayoutTest, AnchorLeftTopBottom) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorLeftRight) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorLeftRight) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(
- new AnchorAttribute({Anchor::Left, Anchor::Right})));
+ layout->AnchorView(v1, {Anchor::Left, Anchor::Right});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -150,14 +145,13 @@ TEST_F(AnchorLayoutTest, AnchorLeftRight) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorTopBottom) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorTopBottom) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(
- new AnchorAttribute({Anchor::Top, Anchor::Bottom})));
+ layout->AnchorView(v1, {Anchor::Top, Anchor::Bottom});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -167,13 +161,13 @@ TEST_F(AnchorLayoutTest, AnchorTopBottom) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorNone) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorNone) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AnchorAttribute(Anchors())));
+ layout->AnchorView(v1, Anchors());
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -183,14 +177,13 @@ TEST_F(AnchorLayoutTest, AnchorNone) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorRightBottom) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorRightBottom) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(
- new AnchorAttribute({Anchor::Right, Anchor::Bottom})));
+ layout->AnchorView(v1, {Anchor::Right, Anchor::Bottom});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -200,13 +193,13 @@ TEST_F(AnchorLayoutTest, AnchorRightBottom) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorRight) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorRight) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AnchorAttribute({Anchor::Right})));
+ layout->AnchorView(v1, {Anchor::Right});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -216,13 +209,13 @@ TEST_F(AnchorLayoutTest, AnchorRight) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorBottom) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorBottom) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AnchorAttribute({Anchor::Bottom})));
+ layout->AnchorView(v1, {Anchor::Bottom});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -232,14 +225,13 @@ TEST_F(AnchorLayoutTest, AnchorBottom) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorTopRightBottom) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorTopRightBottom) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(
- new AnchorAttribute({Anchor::Top, Anchor::Right, Anchor::Bottom})));
+ layout->AnchorView(v1, {Anchor::Top, Anchor::Right, Anchor::Bottom});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -249,14 +241,14 @@ TEST_F(AnchorLayoutTest, AnchorTopRightBottom) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AnchorLeftTopRightBottom) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AnchorLeftTopRightBottom) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AnchorAttribute(
- {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom})));
+ layout->AnchorView(v1,
+ {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom});
gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2);
- v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10);
+ layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10);
host_->AddChildView(v1);
EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds());
@@ -266,14 +258,14 @@ TEST_F(AnchorLayoutTest, AnchorLeftTopRightBottom) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AlignTopAnchorAll) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AlignTopAnchorAll) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top)));
- v1->attributes().Add(base::WrapUnique(new AnchorAttribute(
- {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom})));
- v1->SetBounds(0, 0, 10, 10);
+ layout->AlignView(v1, Align::Top);
+ layout->AnchorView(v1,
+ {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom});
+ layout->SetViewBounds(v1, 0, 0, 10, 10);
host_->AddChildView(v1);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 0, 100, 10), v1->bounds());
@@ -284,14 +276,14 @@ TEST_F(AnchorLayoutTest, AlignTopAnchorAll) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AlignBottomAnchorAll) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AlignBottomAnchorAll) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom)));
- v1->attributes().Add(base::WrapUnique(new AnchorAttribute(
- {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom})));
- v1->SetBounds(0, 0, 10, 10);
+ layout->AlignView(v1, Align::Bottom);
+ layout->AnchorView(v1,
+ {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom});
+ layout->SetViewBounds(v1, 0, 0, 10, 10);
host_->AddChildView(v1);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 90, 100, 10), v1->bounds());
@@ -302,14 +294,14 @@ TEST_F(AnchorLayoutTest, AlignBottomAnchorAll) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AlignLeftAnchorAll) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AlignLeftAnchorAll) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left)));
- v1->attributes().Add(base::WrapUnique(new AnchorAttribute(
- {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom})));
- v1->SetBounds(0, 0, 10, 10);
+ layout->AlignView(v1, Align::Left);
+ layout->AnchorView(v1,
+ {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom});
+ layout->SetViewBounds(v1, 0, 0, 10, 10);
host_->AddChildView(v1);
host_->Layout();
EXPECT_EQ(gfx::Rect(0, 0, 10, 100), v1->bounds());
@@ -320,14 +312,14 @@ TEST_F(AnchorLayoutTest, AlignLeftAnchorAll) {
EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds());
}
-TEST_F(AnchorLayoutTest, AlignRightAnchorAll) {
- AlignLayout* layout = new AlignLayout();
+TEST_F(AnchorLayoutStateTest, AlignRightAnchorAll) {
+ AlignLayoutState* layout = new AlignLayoutState();
host_->SetLayoutManager(layout);
View* v1 = new View();
- v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right)));
- v1->attributes().Add(base::WrapUnique(new AnchorAttribute(
- {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom})));
- v1->SetBounds(0, 0, 10, 10);
+ layout->AlignView(v1, Align::Right);
+ layout->AnchorView(v1,
+ {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom});
+ layout->SetViewBounds(v1, 0, 0, 10, 10);
host_->AddChildView(v1);
host_->Layout();
EXPECT_EQ(gfx::Rect(90, 0, 10, 100), v1->bounds());
« no previous file with comments | « ui/views/layout/align_layout_state_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698