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

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

Issue 2230913003: Experimental alignment layout manager using a property on the views Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed AlignAttribute and associated types to FillAttribute 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.cc ('k') | ui/views/layout/anchor_layout_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_unittest.cc
diff --git a/ui/views/layout/align_layout_unittest.cc b/ui/views/layout/align_layout_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b262dcc097df8a6b8b0eb666aac1e748ef986978
--- /dev/null
+++ b/ui/views/layout/align_layout_unittest.cc
@@ -0,0 +1,403 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stddef.h>
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "ui/views/fill_attribute.h"
+#include "ui/views/layout/align_layout.h"
+#include "ui/views/test/test_views.h"
+#include "ui/views/view.h"
+
+namespace views {
+
+namespace {
+
+class AlignLayoutTest : public testing::Test {
+ public:
+ void SetUp() override { host_.reset(new View); }
+
+ std::unique_ptr<View> host_;
+};
+
+} // namespace
+
+TEST_F(AlignLayoutTest, Empty) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ EXPECT_EQ(gfx::Size(0, 0), layout->GetPreferredSize(host_.get()));
+}
+
+TEST_F(AlignLayoutTest, FillTop) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
+ v1->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(v1);
+ host_->SetBounds(0, 0, 20, 20);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds());
+ host_->SetBounds(0, 0, 30, 20);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 20), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillBottom) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
+ v1->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(v1);
+ host_->SetBounds(0, 0, 20, 20);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 10, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds());
+ host_->SetBounds(0, 0, 30, 20);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 10, 30, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 20), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillLeft) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
+ v1->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v1);
+ host_->SetBounds(0, 0, 20, 20);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds());
+ host_->SetBounds(0, 0, 20, 30);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 20, 30), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillRight) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
+ v1->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v1);
+ host_->SetBounds(0, 0, 20, 20);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(10, 0, 10, 20), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds());
+ host_->SetBounds(0, 0, 20, 30);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(10, 0, 10, 30), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 20, 30), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillContent) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Content)));
+ v1->SetBounds(0, 0, 0, 0);
+ host_->AddChildView(v1);
+ host_->SetBounds(0, 0, 20, 20);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 20, 20), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds());
+ host_->SetBounds(0, 0, 30, 30);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 30), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillLeftTop) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
+ v1->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v1);
+ View* v2 = new View();
+ v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
+ v2->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(v2);
+ host_->SetBounds(0, 0, 40, 40);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 10, 10, 30), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
+ host_->SetBounds(0, 0, 30, 30);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 10, 10, 20), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillLeftTopRight) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
+ v1->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v1);
+ View* v2 = new View();
+ v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
+ v2->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(v2);
+ View* v3 = new View();
+ v3->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
+ v3->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v3);
+ host_->SetBounds(0, 0, 40, 40);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 10, 10, 30), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(30, 10, 10, 30), v3->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
+ host_->SetBounds(0, 0, 30, 30);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 10, 10, 20), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(20, 10, 10, 20), v3->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillTopRight) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
+ v1->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v1);
+ View* v2 = new View();
+ v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
+ v2->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(v2);
+ host_->SetBounds(0, 0, 40, 40);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(30, 10, 10, 30), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
+ host_->SetBounds(0, 0, 30, 30);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(20, 10, 10, 20), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillLeftBottomRight) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
+ v1->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v1);
+ View* v2 = new View();
+ v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
+ v2->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(v2);
+ View* v3 = new View();
+ v3->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
+ v3->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v3);
+ host_->SetBounds(0, 0, 40, 40);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(30, 0, 10, 30), v3->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
+ host_->SetBounds(0, 0, 30, 30);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(20, 0, 10, 20), v3->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillBottomRight) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
+ v1->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v1);
+ View* v2 = new View();
+ v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
+ v2->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(v2);
+ host_->SetBounds(0, 0, 40, 40);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(30, 0, 10, 30), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
+ host_->SetBounds(0, 0, 30, 30);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(20, 0, 10, 20), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillLeftBottom) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
+ v1->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v1);
+ View* v2 = new View();
+ v2->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
+ v2->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(v2);
+ host_->SetBounds(0, 0, 40, 40);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
+ host_->SetBounds(0, 0, 30, 30);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillLeftTopRightBottomContent) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* vc = new View();
+ vc->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Content)));
+ vc->SetBounds(0, 0, 0, 0);
+ host_->AddChildView(vc);
+ host_->SetBounds(0, 0, 60, 60);
+ host_->Layout();
+ 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 FillAttribute(Fill::Left)));
+ vl->SetBounds(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();
+ vr->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
+ vr->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(vr);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 10, 60), vl->bounds());
+ EXPECT_EQ(gfx::Rect(50, 0, 10, 60), vr->bounds());
+ 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 FillAttribute(Fill::Top)));
+ vt->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(vt);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 10, 10, 50), vl->bounds());
+ EXPECT_EQ(gfx::Rect(50, 10, 10, 50), vr->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 60, 10), vt->bounds());
+ 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 FillAttribute(Fill::Bottom)));
+ vb->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(vb);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 10, 10, 40), vl->bounds());
+ EXPECT_EQ(gfx::Rect(50, 10, 10, 40), vr->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 60, 10), vt->bounds());
+ EXPECT_EQ(gfx::Rect(0, 50, 60, 10), vb->bounds());
+ EXPECT_EQ(gfx::Rect(10, 10, 40, 40), vc->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillStackedTop) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Top)));
+ v1->SetBounds(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 FillAttribute(Fill::Top)));
+ v2->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(v2);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 10, 40, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillStackedBottom) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Bottom)));
+ v1->SetBounds(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 FillAttribute(Fill::Bottom)));
+ v2->SetBounds(0, 0, 0, 10);
+ host_->AddChildView(v2);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 20, 40, 10), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillStackedLeft) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Left)));
+ v1->SetBounds(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 FillAttribute(Fill::Left)));
+ v2->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v2);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(0, 0, 10, 40), v1->bounds());
+ EXPECT_EQ(gfx::Rect(10, 0, 10, 40), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
+}
+
+TEST_F(AlignLayoutTest, FillStackedRight) {
+ AlignLayout* layout = new AlignLayout();
+ host_->SetLayoutManager(layout);
+ View* v1 = new View();
+ v1->attributes().Add(base::WrapUnique(new FillAttribute(Fill::Right)));
+ v1->SetBounds(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 FillAttribute(Fill::Right)));
+ v2->SetBounds(0, 0, 10, 0);
+ host_->AddChildView(v2);
+ host_->Layout();
+ EXPECT_EQ(gfx::Rect(30, 0, 10, 40), v1->bounds());
+ EXPECT_EQ(gfx::Rect(20, 0, 10, 40), v2->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds());
+}
+
+} // namespace views
« no previous file with comments | « ui/views/layout/align_layout.cc ('k') | ui/views/layout/anchor_layout_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698