OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 #include "ui/views/align_attribute.h" | 9 #include "ui/views/align_attribute.h" |
10 #include "ui/views/layout/align_layout.h" | 10 #include "ui/views/layout/align_layout_state.h" |
11 #include "ui/views/test/test_views.h" | 11 #include "ui/views/test/test_views.h" |
12 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
13 | 13 |
14 namespace views { | 14 namespace views { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 class AlignLayoutTest : public testing::Test { | 18 class AlignLayoutStateTest : public testing::Test { |
19 public: | 19 public: |
20 void SetUp() override { host_.reset(new View); } | 20 void SetUp() override { host_.reset(new View); } |
21 | 21 |
22 std::unique_ptr<View> host_; | 22 std::unique_ptr<View> host_; |
23 }; | 23 }; |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 TEST_F(AlignLayoutTest, Empty) { | 27 TEST_F(AlignLayoutStateTest, Empty) { |
28 AlignLayout* layout = new AlignLayout(); | 28 AlignLayoutState* layout = new AlignLayoutState(); |
29 host_->SetLayoutManager(layout); | 29 host_->SetLayoutManager(layout); |
30 EXPECT_EQ(gfx::Size(0, 0), layout->GetPreferredSize(host_.get())); | 30 EXPECT_EQ(gfx::Size(0, 0), layout->GetPreferredSize(host_.get())); |
31 } | 31 } |
32 | 32 |
33 TEST_F(AlignLayoutTest, AlignTop) { | 33 TEST_F(AlignLayoutStateTest, AlignTop) { |
34 AlignLayout* layout = new AlignLayout(); | 34 AlignLayoutState* layout = new AlignLayoutState(); |
35 host_->SetLayoutManager(layout); | 35 host_->SetLayoutManager(layout); |
36 View* v1 = new View(); | 36 View* v1 = new View(); |
37 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top))); | 37 layout->AlignView(v1, Align::Top); |
38 v1->SetBounds(0, 0, 0, 10); | 38 layout->SetViewBounds(v1, 0, 0, 0, 10); |
39 host_->AddChildView(v1); | 39 host_->AddChildView(v1); |
40 host_->SetBounds(0, 0, 20, 20); | 40 host_->SetBounds(0, 0, 20, 20); |
41 host_->Layout(); | 41 host_->Layout(); |
42 EXPECT_EQ(gfx::Rect(0, 0, 20, 10), v1->bounds()); | 42 EXPECT_EQ(gfx::Rect(0, 0, 20, 10), v1->bounds()); |
43 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds()); | 43 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds()); |
44 host_->SetBounds(0, 0, 30, 20); | 44 host_->SetBounds(0, 0, 30, 20); |
45 host_->Layout(); | 45 host_->Layout(); |
46 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v1->bounds()); | 46 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v1->bounds()); |
47 EXPECT_EQ(gfx::Rect(0, 0, 30, 20), host_->bounds()); | 47 EXPECT_EQ(gfx::Rect(0, 0, 30, 20), host_->bounds()); |
48 } | 48 } |
49 | 49 |
50 TEST_F(AlignLayoutTest, AlignBottom) { | 50 TEST_F(AlignLayoutStateTest, AlignBottom) { |
51 AlignLayout* layout = new AlignLayout(); | 51 AlignLayoutState* layout = new AlignLayoutState(); |
52 host_->SetLayoutManager(layout); | 52 host_->SetLayoutManager(layout); |
53 View* v1 = new View(); | 53 View* v1 = new View(); |
54 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom))); | 54 layout->AlignView(v1, Align::Bottom); |
55 v1->SetBounds(0, 0, 0, 10); | 55 layout->SetViewBounds(v1, 0, 0, 0, 10); |
56 host_->AddChildView(v1); | 56 host_->AddChildView(v1); |
57 host_->SetBounds(0, 0, 20, 20); | 57 host_->SetBounds(0, 0, 20, 20); |
58 host_->Layout(); | 58 host_->Layout(); |
59 EXPECT_EQ(gfx::Rect(0, 10, 20, 10), v1->bounds()); | 59 EXPECT_EQ(gfx::Rect(0, 10, 20, 10), v1->bounds()); |
60 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds()); | 60 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds()); |
61 host_->SetBounds(0, 0, 30, 20); | 61 host_->SetBounds(0, 0, 30, 20); |
62 host_->Layout(); | 62 host_->Layout(); |
63 EXPECT_EQ(gfx::Rect(0, 10, 30, 10), v1->bounds()); | 63 EXPECT_EQ(gfx::Rect(0, 10, 30, 10), v1->bounds()); |
64 EXPECT_EQ(gfx::Rect(0, 0, 30, 20), host_->bounds()); | 64 EXPECT_EQ(gfx::Rect(0, 0, 30, 20), host_->bounds()); |
65 } | 65 } |
66 | 66 |
67 TEST_F(AlignLayoutTest, AlignLeft) { | 67 TEST_F(AlignLayoutStateTest, AlignLeft) { |
68 AlignLayout* layout = new AlignLayout(); | 68 AlignLayoutState* layout = new AlignLayoutState(); |
69 host_->SetLayoutManager(layout); | 69 host_->SetLayoutManager(layout); |
70 View* v1 = new View(); | 70 View* v1 = new View(); |
71 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left))); | 71 layout->AlignView(v1, Align::Left); |
72 v1->SetBounds(0, 0, 10, 0); | 72 layout->SetViewBounds(v1, 0, 0, 10, 0); |
73 host_->AddChildView(v1); | 73 host_->AddChildView(v1); |
74 host_->SetBounds(0, 0, 20, 20); | 74 host_->SetBounds(0, 0, 20, 20); |
75 host_->Layout(); | 75 host_->Layout(); |
76 EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds()); | 76 EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds()); |
77 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds()); | 77 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds()); |
78 host_->SetBounds(0, 0, 20, 30); | 78 host_->SetBounds(0, 0, 20, 30); |
79 host_->Layout(); | 79 host_->Layout(); |
80 EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds()); | 80 EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds()); |
81 EXPECT_EQ(gfx::Rect(0, 0, 20, 30), host_->bounds()); | 81 EXPECT_EQ(gfx::Rect(0, 0, 20, 30), host_->bounds()); |
82 } | 82 } |
83 | 83 |
84 TEST_F(AlignLayoutTest, AlignRight) { | 84 TEST_F(AlignLayoutStateTest, AlignRight) { |
85 AlignLayout* layout = new AlignLayout(); | 85 AlignLayoutState* layout = new AlignLayoutState(); |
86 host_->SetLayoutManager(layout); | 86 host_->SetLayoutManager(layout); |
87 View* v1 = new View(); | 87 View* v1 = new View(); |
88 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right))); | 88 layout->AlignView(v1, Align::Right); |
89 v1->SetBounds(0, 0, 10, 0); | 89 layout->SetViewBounds(v1, 0, 0, 10, 0); |
90 host_->AddChildView(v1); | 90 host_->AddChildView(v1); |
91 host_->SetBounds(0, 0, 20, 20); | 91 host_->SetBounds(0, 0, 20, 20); |
92 host_->Layout(); | 92 host_->Layout(); |
93 EXPECT_EQ(gfx::Rect(10, 0, 10, 20), v1->bounds()); | 93 EXPECT_EQ(gfx::Rect(10, 0, 10, 20), v1->bounds()); |
94 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds()); | 94 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds()); |
95 host_->SetBounds(0, 0, 20, 30); | 95 host_->SetBounds(0, 0, 20, 30); |
96 host_->Layout(); | 96 host_->Layout(); |
97 EXPECT_EQ(gfx::Rect(10, 0, 10, 30), v1->bounds()); | 97 EXPECT_EQ(gfx::Rect(10, 0, 10, 30), v1->bounds()); |
98 EXPECT_EQ(gfx::Rect(0, 0, 20, 30), host_->bounds()); | 98 EXPECT_EQ(gfx::Rect(0, 0, 20, 30), host_->bounds()); |
99 } | 99 } |
100 | 100 |
101 TEST_F(AlignLayoutTest, AlignContent) { | 101 TEST_F(AlignLayoutStateTest, AlignContent) { |
102 AlignLayout* layout = new AlignLayout(); | 102 AlignLayoutState* layout = new AlignLayoutState(); |
103 host_->SetLayoutManager(layout); | 103 host_->SetLayoutManager(layout); |
104 View* v1 = new View(); | 104 View* v1 = new View(); |
105 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Content))); | 105 layout->AlignView(v1, Align::Content); |
106 v1->SetBounds(0, 0, 0, 0); | 106 layout->SetViewBounds(v1, 0, 0, 0, 0); |
107 host_->AddChildView(v1); | 107 host_->AddChildView(v1); |
108 host_->SetBounds(0, 0, 20, 20); | 108 host_->SetBounds(0, 0, 20, 20); |
109 host_->Layout(); | 109 host_->Layout(); |
110 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), v1->bounds()); | 110 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), v1->bounds()); |
111 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds()); | 111 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), host_->bounds()); |
112 host_->SetBounds(0, 0, 30, 30); | 112 host_->SetBounds(0, 0, 30, 30); |
113 host_->Layout(); | 113 host_->Layout(); |
114 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), v1->bounds()); | 114 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), v1->bounds()); |
115 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); | 115 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); |
116 } | 116 } |
117 | 117 |
118 TEST_F(AlignLayoutTest, AlignLeftTop) { | 118 TEST_F(AlignLayoutStateTest, AlignLeftTop) { |
119 AlignLayout* layout = new AlignLayout(); | 119 AlignLayoutState* layout = new AlignLayoutState(); |
120 host_->SetLayoutManager(layout); | 120 host_->SetLayoutManager(layout); |
121 View* v1 = new View(); | 121 View* v1 = new View(); |
122 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left))); | 122 layout->AlignView(v1, Align::Left); |
123 v1->SetBounds(0, 0, 10, 0); | 123 layout->SetViewBounds(v1, 0, 0, 10, 0); |
124 host_->AddChildView(v1); | 124 host_->AddChildView(v1); |
125 View* v2 = new View(); | 125 View* v2 = new View(); |
126 v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top))); | 126 layout->AlignView(v2, Align::Top); |
127 v2->SetBounds(0, 0, 0, 10); | 127 layout->SetViewBounds(v2, 0, 0, 0, 10); |
128 host_->AddChildView(v2); | 128 host_->AddChildView(v2); |
129 host_->SetBounds(0, 0, 40, 40); | 129 host_->SetBounds(0, 0, 40, 40); |
130 host_->Layout(); | 130 host_->Layout(); |
131 EXPECT_EQ(gfx::Rect(0, 10, 10, 30), v1->bounds()); | 131 EXPECT_EQ(gfx::Rect(0, 10, 10, 30), v1->bounds()); |
132 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds()); | 132 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds()); |
133 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 133 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
134 host_->SetBounds(0, 0, 30, 30); | 134 host_->SetBounds(0, 0, 30, 30); |
135 host_->Layout(); | 135 host_->Layout(); |
136 EXPECT_EQ(gfx::Rect(0, 10, 10, 20), v1->bounds()); | 136 EXPECT_EQ(gfx::Rect(0, 10, 10, 20), v1->bounds()); |
137 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds()); | 137 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds()); |
138 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); | 138 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); |
139 } | 139 } |
140 | 140 |
141 TEST_F(AlignLayoutTest, AlignLeftTopRight) { | 141 TEST_F(AlignLayoutStateTest, AlignLeftTopRight) { |
142 AlignLayout* layout = new AlignLayout(); | 142 AlignLayoutState* layout = new AlignLayoutState(); |
143 host_->SetLayoutManager(layout); | 143 host_->SetLayoutManager(layout); |
144 View* v1 = new View(); | 144 View* v1 = new View(); |
145 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left))); | 145 layout->AlignView(v1, Align::Left); |
146 v1->SetBounds(0, 0, 10, 0); | 146 layout->SetViewBounds(v1, 0, 0, 10, 0); |
147 host_->AddChildView(v1); | 147 host_->AddChildView(v1); |
148 View* v2 = new View(); | 148 View* v2 = new View(); |
149 v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top))); | 149 layout->AlignView(v2, Align::Top); |
150 v2->SetBounds(0, 0, 0, 10); | 150 layout->SetViewBounds(v2, 0, 0, 0, 10); |
151 host_->AddChildView(v2); | 151 host_->AddChildView(v2); |
152 View* v3 = new View(); | 152 View* v3 = new View(); |
153 v3->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right))); | 153 layout->AlignView(v3, Align::Right); |
154 v3->SetBounds(0, 0, 10, 0); | 154 layout->SetViewBounds(v3, 0, 0, 10, 0); |
155 host_->AddChildView(v3); | 155 host_->AddChildView(v3); |
156 host_->SetBounds(0, 0, 40, 40); | 156 host_->SetBounds(0, 0, 40, 40); |
157 host_->Layout(); | 157 host_->Layout(); |
158 EXPECT_EQ(gfx::Rect(0, 10, 10, 30), v1->bounds()); | 158 EXPECT_EQ(gfx::Rect(0, 10, 10, 30), v1->bounds()); |
159 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds()); | 159 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds()); |
160 EXPECT_EQ(gfx::Rect(30, 10, 10, 30), v3->bounds()); | 160 EXPECT_EQ(gfx::Rect(30, 10, 10, 30), v3->bounds()); |
161 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 161 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
162 host_->SetBounds(0, 0, 30, 30); | 162 host_->SetBounds(0, 0, 30, 30); |
163 host_->Layout(); | 163 host_->Layout(); |
164 EXPECT_EQ(gfx::Rect(0, 10, 10, 20), v1->bounds()); | 164 EXPECT_EQ(gfx::Rect(0, 10, 10, 20), v1->bounds()); |
165 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds()); | 165 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds()); |
166 EXPECT_EQ(gfx::Rect(20, 10, 10, 20), v3->bounds()); | 166 EXPECT_EQ(gfx::Rect(20, 10, 10, 20), v3->bounds()); |
167 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); | 167 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); |
168 } | 168 } |
169 | 169 |
170 TEST_F(AlignLayoutTest, AlignTopRight) { | 170 TEST_F(AlignLayoutStateTest, AlignTopRight) { |
171 AlignLayout* layout = new AlignLayout(); | 171 AlignLayoutState* layout = new AlignLayoutState(); |
172 host_->SetLayoutManager(layout); | 172 host_->SetLayoutManager(layout); |
173 View* v1 = new View(); | 173 View* v1 = new View(); |
174 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right))); | 174 layout->AlignView(v1, Align::Right); |
175 v1->SetBounds(0, 0, 10, 0); | 175 layout->SetViewBounds(v1, 0, 0, 10, 0); |
176 host_->AddChildView(v1); | 176 host_->AddChildView(v1); |
177 View* v2 = new View(); | 177 View* v2 = new View(); |
178 v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top))); | 178 layout->AlignView(v2, Align::Top); |
179 v2->SetBounds(0, 0, 0, 10); | 179 layout->SetViewBounds(v2, 0, 0, 0, 10); |
180 host_->AddChildView(v2); | 180 host_->AddChildView(v2); |
181 host_->SetBounds(0, 0, 40, 40); | 181 host_->SetBounds(0, 0, 40, 40); |
182 host_->Layout(); | 182 host_->Layout(); |
183 EXPECT_EQ(gfx::Rect(30, 10, 10, 30), v1->bounds()); | 183 EXPECT_EQ(gfx::Rect(30, 10, 10, 30), v1->bounds()); |
184 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds()); | 184 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v2->bounds()); |
185 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 185 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
186 host_->SetBounds(0, 0, 30, 30); | 186 host_->SetBounds(0, 0, 30, 30); |
187 host_->Layout(); | 187 host_->Layout(); |
188 EXPECT_EQ(gfx::Rect(20, 10, 10, 20), v1->bounds()); | 188 EXPECT_EQ(gfx::Rect(20, 10, 10, 20), v1->bounds()); |
189 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds()); | 189 EXPECT_EQ(gfx::Rect(0, 0, 30, 10), v2->bounds()); |
190 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); | 190 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); |
191 } | 191 } |
192 | 192 |
193 TEST_F(AlignLayoutTest, AlignLeftBottomRight) { | 193 TEST_F(AlignLayoutStateTest, AlignLeftBottomRight) { |
194 AlignLayout* layout = new AlignLayout(); | 194 AlignLayoutState* layout = new AlignLayoutState(); |
195 host_->SetLayoutManager(layout); | 195 host_->SetLayoutManager(layout); |
196 View* v1 = new View(); | 196 View* v1 = new View(); |
197 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left))); | 197 layout->AlignView(v1, Align::Left); |
198 v1->SetBounds(0, 0, 10, 0); | 198 layout->SetViewBounds(v1, 0, 0, 10, 0); |
199 host_->AddChildView(v1); | 199 host_->AddChildView(v1); |
200 View* v2 = new View(); | 200 View* v2 = new View(); |
201 v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom))); | 201 layout->AlignView(v2, Align::Bottom); |
202 v2->SetBounds(0, 0, 0, 10); | 202 layout->SetViewBounds(v2, 0, 0, 0, 10); |
203 host_->AddChildView(v2); | 203 host_->AddChildView(v2); |
204 View* v3 = new View(); | 204 View* v3 = new View(); |
205 v3->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right))); | 205 layout->AlignView(v3, Align::Right); |
206 v3->SetBounds(0, 0, 10, 0); | 206 layout->SetViewBounds(v3, 0, 0, 10, 0); |
207 host_->AddChildView(v3); | 207 host_->AddChildView(v3); |
208 host_->SetBounds(0, 0, 40, 40); | 208 host_->SetBounds(0, 0, 40, 40); |
209 host_->Layout(); | 209 host_->Layout(); |
210 EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds()); | 210 EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds()); |
211 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds()); | 211 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds()); |
212 EXPECT_EQ(gfx::Rect(30, 0, 10, 30), v3->bounds()); | 212 EXPECT_EQ(gfx::Rect(30, 0, 10, 30), v3->bounds()); |
213 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 213 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
214 host_->SetBounds(0, 0, 30, 30); | 214 host_->SetBounds(0, 0, 30, 30); |
215 host_->Layout(); | 215 host_->Layout(); |
216 EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds()); | 216 EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds()); |
217 EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds()); | 217 EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds()); |
218 EXPECT_EQ(gfx::Rect(20, 0, 10, 20), v3->bounds()); | 218 EXPECT_EQ(gfx::Rect(20, 0, 10, 20), v3->bounds()); |
219 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); | 219 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); |
220 } | 220 } |
221 | 221 |
222 TEST_F(AlignLayoutTest, AlignBottomRight) { | 222 TEST_F(AlignLayoutStateTest, AlignBottomRight) { |
223 AlignLayout* layout = new AlignLayout(); | 223 AlignLayoutState* layout = new AlignLayoutState(); |
224 host_->SetLayoutManager(layout); | 224 host_->SetLayoutManager(layout); |
225 View* v1 = new View(); | 225 View* v1 = new View(); |
226 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right))); | 226 layout->AlignView(v1, Align::Right); |
227 v1->SetBounds(0, 0, 10, 0); | 227 layout->SetViewBounds(v1, 0, 0, 10, 0); |
228 host_->AddChildView(v1); | 228 host_->AddChildView(v1); |
229 View* v2 = new View(); | 229 View* v2 = new View(); |
230 v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom))); | 230 layout->AlignView(v2, Align::Bottom); |
231 v2->SetBounds(0, 0, 0, 10); | 231 layout->SetViewBounds(v2, 0, 0, 0, 10); |
232 host_->AddChildView(v2); | 232 host_->AddChildView(v2); |
233 host_->SetBounds(0, 0, 40, 40); | 233 host_->SetBounds(0, 0, 40, 40); |
234 host_->Layout(); | 234 host_->Layout(); |
235 EXPECT_EQ(gfx::Rect(30, 0, 10, 30), v1->bounds()); | 235 EXPECT_EQ(gfx::Rect(30, 0, 10, 30), v1->bounds()); |
236 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds()); | 236 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds()); |
237 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 237 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
238 host_->SetBounds(0, 0, 30, 30); | 238 host_->SetBounds(0, 0, 30, 30); |
239 host_->Layout(); | 239 host_->Layout(); |
240 EXPECT_EQ(gfx::Rect(20, 0, 10, 20), v1->bounds()); | 240 EXPECT_EQ(gfx::Rect(20, 0, 10, 20), v1->bounds()); |
241 EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds()); | 241 EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds()); |
242 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); | 242 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); |
243 } | 243 } |
244 | 244 |
245 TEST_F(AlignLayoutTest, AlignLeftBottom) { | 245 TEST_F(AlignLayoutStateTest, AlignLeftBottom) { |
246 AlignLayout* layout = new AlignLayout(); | 246 AlignLayoutState* layout = new AlignLayoutState(); |
247 host_->SetLayoutManager(layout); | 247 host_->SetLayoutManager(layout); |
248 View* v1 = new View(); | 248 View* v1 = new View(); |
| 249 layout->AlignView(v1, Align::Left); |
249 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left))); | 250 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left))); |
250 v1->SetBounds(0, 0, 10, 0); | 251 layout->SetViewBounds(v1, 0, 0, 10, 0); |
251 host_->AddChildView(v1); | 252 host_->AddChildView(v1); |
252 View* v2 = new View(); | 253 View* v2 = new View(); |
253 v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom))); | 254 layout->AlignView(v2, Align::Bottom); |
254 v2->SetBounds(0, 0, 0, 10); | 255 layout->SetViewBounds(v2, 0, 0, 0, 10); |
255 host_->AddChildView(v2); | 256 host_->AddChildView(v2); |
256 host_->SetBounds(0, 0, 40, 40); | 257 host_->SetBounds(0, 0, 40, 40); |
257 host_->Layout(); | 258 host_->Layout(); |
258 EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds()); | 259 EXPECT_EQ(gfx::Rect(0, 0, 10, 30), v1->bounds()); |
259 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds()); | 260 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v2->bounds()); |
260 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 261 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
261 host_->SetBounds(0, 0, 30, 30); | 262 host_->SetBounds(0, 0, 30, 30); |
262 host_->Layout(); | 263 host_->Layout(); |
263 EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds()); | 264 EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds()); |
264 EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds()); | 265 EXPECT_EQ(gfx::Rect(0, 20, 30, 10), v2->bounds()); |
265 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); | 266 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), host_->bounds()); |
266 } | 267 } |
267 | 268 |
268 TEST_F(AlignLayoutTest, AlignLeftTopRightBottomContent) { | 269 TEST_F(AlignLayoutStateTest, AlignLeftTopRightBottomContent) { |
269 AlignLayout* layout = new AlignLayout(); | 270 AlignLayoutState* layout = new AlignLayoutState(); |
270 host_->SetLayoutManager(layout); | 271 host_->SetLayoutManager(layout); |
271 View* vc = new View(); | 272 View* vc = new View(); |
272 vc->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Content))); | 273 layout->AlignView(vc, Align::Content); |
273 vc->SetBounds(0, 0, 0, 0); | 274 vc->SetBounds(0, 0, 0, 0); |
274 host_->AddChildView(vc); | 275 host_->AddChildView(vc); |
275 host_->SetBounds(0, 0, 60, 60); | 276 host_->SetBounds(0, 0, 60, 60); |
276 host_->Layout(); | 277 host_->Layout(); |
277 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), vc->bounds()); | 278 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), vc->bounds()); |
278 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds()); | 279 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds()); |
279 View* vl = new View(); | 280 View* vl = new View(); |
280 vl->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left))); | 281 layout->AlignView(vl, Align::Left); |
281 vl->SetBounds(0, 0, 10, 0); | 282 layout->SetViewBounds(vl, 0, 0, 10, 0); |
282 host_->AddChildView(vl); | 283 host_->AddChildView(vl); |
283 host_->Layout(); | 284 host_->Layout(); |
284 EXPECT_EQ(gfx::Rect(0, 0, 10, 60), vl->bounds()); | 285 EXPECT_EQ(gfx::Rect(0, 0, 10, 60), vl->bounds()); |
285 EXPECT_EQ(gfx::Rect(10, 0, 50, 60), vc->bounds()); | 286 EXPECT_EQ(gfx::Rect(10, 0, 50, 60), vc->bounds()); |
286 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds()); | 287 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds()); |
287 View* vr = new View(); | 288 View* vr = new View(); |
| 289 layout->AlignView(vr, Align::Right); |
288 vr->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right))); | 290 vr->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right))); |
289 vr->SetBounds(0, 0, 10, 0); | 291 layout->SetViewBounds(vr, 0, 0, 10, 0); |
290 host_->AddChildView(vr); | 292 host_->AddChildView(vr); |
291 host_->Layout(); | 293 host_->Layout(); |
292 EXPECT_EQ(gfx::Rect(0, 0, 10, 60), vl->bounds()); | 294 EXPECT_EQ(gfx::Rect(0, 0, 10, 60), vl->bounds()); |
293 EXPECT_EQ(gfx::Rect(50, 0, 10, 60), vr->bounds()); | 295 EXPECT_EQ(gfx::Rect(50, 0, 10, 60), vr->bounds()); |
294 EXPECT_EQ(gfx::Rect(10, 0, 40, 60), vc->bounds()); | 296 EXPECT_EQ(gfx::Rect(10, 0, 40, 60), vc->bounds()); |
295 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds()); | 297 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds()); |
296 View* vt = new View(); | 298 View* vt = new View(); |
297 vt->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top))); | 299 layout->AlignView(vt, Align::Top); |
298 vt->SetBounds(0, 0, 0, 10); | 300 layout->SetViewBounds(vt, 0, 0, 0, 10); |
299 host_->AddChildView(vt); | 301 host_->AddChildView(vt); |
300 host_->Layout(); | 302 host_->Layout(); |
301 EXPECT_EQ(gfx::Rect(0, 10, 10, 50), vl->bounds()); | 303 EXPECT_EQ(gfx::Rect(0, 10, 10, 50), vl->bounds()); |
302 EXPECT_EQ(gfx::Rect(50, 10, 10, 50), vr->bounds()); | 304 EXPECT_EQ(gfx::Rect(50, 10, 10, 50), vr->bounds()); |
303 EXPECT_EQ(gfx::Rect(0, 0, 60, 10), vt->bounds()); | 305 EXPECT_EQ(gfx::Rect(0, 0, 60, 10), vt->bounds()); |
304 EXPECT_EQ(gfx::Rect(10, 10, 40, 50), vc->bounds()); | 306 EXPECT_EQ(gfx::Rect(10, 10, 40, 50), vc->bounds()); |
305 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds()); | 307 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds()); |
306 View* vb = new View(); | 308 View* vb = new View(); |
307 vb->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom))); | 309 layout->AlignView(vb, Align::Bottom); |
308 vb->SetBounds(0, 0, 0, 10); | 310 layout->SetViewBounds(vb, 0, 0, 0, 10); |
309 host_->AddChildView(vb); | 311 host_->AddChildView(vb); |
310 host_->Layout(); | 312 host_->Layout(); |
311 EXPECT_EQ(gfx::Rect(0, 10, 10, 40), vl->bounds()); | 313 EXPECT_EQ(gfx::Rect(0, 10, 10, 40), vl->bounds()); |
312 EXPECT_EQ(gfx::Rect(50, 10, 10, 40), vr->bounds()); | 314 EXPECT_EQ(gfx::Rect(50, 10, 10, 40), vr->bounds()); |
313 EXPECT_EQ(gfx::Rect(0, 0, 60, 10), vt->bounds()); | 315 EXPECT_EQ(gfx::Rect(0, 0, 60, 10), vt->bounds()); |
314 EXPECT_EQ(gfx::Rect(0, 50, 60, 10), vb->bounds()); | 316 EXPECT_EQ(gfx::Rect(0, 50, 60, 10), vb->bounds()); |
315 EXPECT_EQ(gfx::Rect(10, 10, 40, 40), vc->bounds()); | 317 EXPECT_EQ(gfx::Rect(10, 10, 40, 40), vc->bounds()); |
316 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds()); | 318 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), host_->bounds()); |
317 } | 319 } |
318 | 320 |
319 TEST_F(AlignLayoutTest, AlignStackedTop) { | 321 TEST_F(AlignLayoutStateTest, AlignStackedTop) { |
320 AlignLayout* layout = new AlignLayout(); | 322 AlignLayoutState* layout = new AlignLayoutState(); |
321 host_->SetLayoutManager(layout); | 323 host_->SetLayoutManager(layout); |
322 View* v1 = new View(); | 324 View* v1 = new View(); |
323 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top))); | 325 layout->AlignView(v1, Align::Top); |
324 v1->SetBounds(0, 0, 0, 10); | 326 layout->SetViewBounds(v1, 0, 0, 0, 10); |
325 host_->AddChildView(v1); | 327 host_->AddChildView(v1); |
326 host_->SetBounds(0, 0, 40, 40); | 328 host_->SetBounds(0, 0, 40, 40); |
327 host_->Layout(); | 329 host_->Layout(); |
328 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v1->bounds()); | 330 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v1->bounds()); |
329 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 331 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
330 View* v2 = new View(); | 332 View* v2 = new View(); |
331 v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top))); | 333 layout->AlignView(v2, Align::Top); |
332 v2->SetBounds(0, 0, 0, 10); | 334 layout->SetViewBounds(v2, 0, 0, 0, 10); |
333 host_->AddChildView(v2); | 335 host_->AddChildView(v2); |
334 host_->Layout(); | 336 host_->Layout(); |
335 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v1->bounds()); | 337 EXPECT_EQ(gfx::Rect(0, 0, 40, 10), v1->bounds()); |
336 EXPECT_EQ(gfx::Rect(0, 10, 40, 10), v2->bounds()); | 338 EXPECT_EQ(gfx::Rect(0, 10, 40, 10), v2->bounds()); |
337 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 339 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
338 } | 340 } |
339 | 341 |
340 TEST_F(AlignLayoutTest, AlignStackedBottom) { | 342 TEST_F(AlignLayoutStateTest, AlignStackedBottom) { |
341 AlignLayout* layout = new AlignLayout(); | 343 AlignLayoutState* layout = new AlignLayoutState(); |
342 host_->SetLayoutManager(layout); | 344 host_->SetLayoutManager(layout); |
343 View* v1 = new View(); | 345 View* v1 = new View(); |
344 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom))); | 346 layout->AlignView(v1, Align::Bottom); |
345 v1->SetBounds(0, 0, 0, 10); | 347 layout->SetViewBounds(v1, 0, 0, 0, 10); |
346 host_->AddChildView(v1); | 348 host_->AddChildView(v1); |
347 host_->SetBounds(0, 0, 40, 40); | 349 host_->SetBounds(0, 0, 40, 40); |
348 host_->Layout(); | 350 host_->Layout(); |
349 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v1->bounds()); | 351 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v1->bounds()); |
350 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 352 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
351 View* v2 = new View(); | 353 View* v2 = new View(); |
352 v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom))); | 354 layout->AlignView(v2, Align::Bottom); |
353 v2->SetBounds(0, 0, 0, 10); | 355 layout->SetViewBounds(v2, 0, 0, 0, 10); |
354 host_->AddChildView(v2); | 356 host_->AddChildView(v2); |
355 host_->Layout(); | 357 host_->Layout(); |
356 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v1->bounds()); | 358 EXPECT_EQ(gfx::Rect(0, 30, 40, 10), v1->bounds()); |
357 EXPECT_EQ(gfx::Rect(0, 20, 40, 10), v2->bounds()); | 359 EXPECT_EQ(gfx::Rect(0, 20, 40, 10), v2->bounds()); |
358 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 360 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
359 } | 361 } |
360 | 362 |
361 TEST_F(AlignLayoutTest, AlignStackedLeft) { | 363 TEST_F(AlignLayoutStateTest, AlignStackedLeft) { |
362 AlignLayout* layout = new AlignLayout(); | 364 AlignLayoutState* layout = new AlignLayoutState(); |
363 host_->SetLayoutManager(layout); | 365 host_->SetLayoutManager(layout); |
364 View* v1 = new View(); | 366 View* v1 = new View(); |
365 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left))); | 367 layout->AlignView(v1, Align::Left); |
366 v1->SetBounds(0, 0, 10, 0); | 368 layout->SetViewBounds(v1, 0, 0, 10, 0); |
367 host_->AddChildView(v1); | 369 host_->AddChildView(v1); |
368 host_->SetBounds(0, 0, 40, 40); | 370 host_->SetBounds(0, 0, 40, 40); |
369 host_->Layout(); | 371 host_->Layout(); |
370 EXPECT_EQ(gfx::Rect(0, 0, 10, 40), v1->bounds()); | 372 EXPECT_EQ(gfx::Rect(0, 0, 10, 40), v1->bounds()); |
371 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 373 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
372 View* v2 = new View(); | 374 View* v2 = new View(); |
373 v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left))); | 375 layout->AlignView(v2, Align::Left); |
374 v2->SetBounds(0, 0, 10, 0); | 376 layout->SetViewBounds(v2, 0, 0, 10, 0); |
375 host_->AddChildView(v2); | 377 host_->AddChildView(v2); |
376 host_->Layout(); | 378 host_->Layout(); |
377 EXPECT_EQ(gfx::Rect(0, 0, 10, 40), v1->bounds()); | 379 EXPECT_EQ(gfx::Rect(0, 0, 10, 40), v1->bounds()); |
378 EXPECT_EQ(gfx::Rect(10, 0, 10, 40), v2->bounds()); | 380 EXPECT_EQ(gfx::Rect(10, 0, 10, 40), v2->bounds()); |
379 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 381 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
380 } | 382 } |
381 | 383 |
382 TEST_F(AlignLayoutTest, AlignStackedRight) { | 384 TEST_F(AlignLayoutStateTest, AlignStackedRight) { |
383 AlignLayout* layout = new AlignLayout(); | 385 AlignLayoutState* layout = new AlignLayoutState(); |
384 host_->SetLayoutManager(layout); | 386 host_->SetLayoutManager(layout); |
385 View* v1 = new View(); | 387 View* v1 = new View(); |
386 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right))); | 388 layout->AlignView(v1, Align::Right); |
387 v1->SetBounds(0, 0, 10, 0); | 389 layout->SetViewBounds(v1, 0, 0, 10, 0); |
388 host_->AddChildView(v1); | 390 host_->AddChildView(v1); |
389 host_->SetBounds(0, 0, 40, 40); | 391 host_->SetBounds(0, 0, 40, 40); |
390 host_->Layout(); | 392 host_->Layout(); |
391 EXPECT_EQ(gfx::Rect(30, 0, 10, 40), v1->bounds()); | 393 EXPECT_EQ(gfx::Rect(30, 0, 10, 40), v1->bounds()); |
392 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 394 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
393 View* v2 = new View(); | 395 View* v2 = new View(); |
394 v2->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right))); | 396 layout->AlignView(v2, Align::Right); |
395 v2->SetBounds(0, 0, 10, 0); | 397 layout->SetViewBounds(v2, 0, 0, 10, 0); |
396 host_->AddChildView(v2); | 398 host_->AddChildView(v2); |
397 host_->Layout(); | 399 host_->Layout(); |
398 EXPECT_EQ(gfx::Rect(30, 0, 10, 40), v1->bounds()); | 400 EXPECT_EQ(gfx::Rect(30, 0, 10, 40), v1->bounds()); |
399 EXPECT_EQ(gfx::Rect(20, 0, 10, 40), v2->bounds()); | 401 EXPECT_EQ(gfx::Rect(20, 0, 10, 40), v2->bounds()); |
400 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); | 402 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), host_->bounds()); |
401 } | 403 } |
402 | 404 |
403 } // namespace views | 405 } // namespace views |
OLD | NEW |