OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/layout/ng/ng_constraint_space.h" | 5 #include "core/layout/ng/ng_constraint_space.h" |
6 | 6 |
7 #include "core/layout/ng/ng_constraint_space.h" | 7 #include "core/layout/ng/ng_constraint_space.h" |
8 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | 8 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 // There should be no third opportunity. | 110 // There should be no third opportunity. |
111 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 111 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
112 } | 112 } |
113 | 113 |
114 // Verifies that Layout Opportunity iterator produces 7 layout opportunities | 114 // Verifies that Layout Opportunity iterator produces 7 layout opportunities |
115 // from 4 start points created by 2 CSS exclusions positioned in the middle of | 115 // from 4 start points created by 2 CSS exclusions positioned in the middle of |
116 // the main constraint space. | 116 // the main constraint space. |
117 // | 117 // |
118 // Test case visual representation: | 118 // Test case visual representation: |
119 // | 119 // |
120 // 100 200 300 400 500 | 120 // 100 200 300 400 500 |
121 // (1)--|----|----|-(2)|----|-(3)+ | 121 // (1)--|----|-(2)-|----|----|-(3)-+ |
122 // 50 | | | 122 // 50 | | |
123 // 100 | | | 123 // 100 | | |
124 // 150 | | | 124 // 150 | | |
125 // 200 | ********** | | 125 // 200 | ****** | |
126 // 250 | ********** | | 126 // 250 | ****** | |
127 // 300 (4) | | 127 // 300 (4) | |
128 // 350 | *** | | 128 // 350 | *** | |
129 // +-----------------------------+ | 129 // +-------------------------------+ |
130 // | 130 // |
131 // Expected: | 131 // Expected: |
132 // Layout opportunity iterator generates the next opportunities: | 132 // Layout opportunity iterator generates the next opportunities: |
133 // - 1st Start Point: 0,0 600x200; 0,0 150x400 | 133 // - 1st Start Point: 0,0 600x200; 0,0 150x400 |
134 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 | 134 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 |
135 // - 3rd Start Point: 550,0 50x400 | 135 // - 3rd Start Point: 550,0 50x400 |
136 // - 4th Start Point: 0,300 600x50; 0,300 500x100 | 136 // - 4th Start Point: 0,300 600x50; 0,300 500x100 |
137 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { | 137 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { |
138 NGPhysicalSize physical_size; | 138 NGPhysicalSize physical_size; |
139 physical_size.width = LayoutUnit(600); | 139 physical_size.width = LayoutUnit(600); |
(...skipping 22 matching lines...) Expand all Loading... | |
162 EXPECT_EQ("550,0 50x400", OpportunityToString(iterator->Next())); | 162 EXPECT_EQ("550,0 50x400", OpportunityToString(iterator->Next())); |
163 | 163 |
164 // 4th Start point | 164 // 4th Start point |
165 EXPECT_EQ("0,300 600x50", OpportunityToString(iterator->Next())); | 165 EXPECT_EQ("0,300 600x50", OpportunityToString(iterator->Next())); |
166 EXPECT_EQ("0,300 500x100", OpportunityToString(iterator->Next())); | 166 EXPECT_EQ("0,300 500x100", OpportunityToString(iterator->Next())); |
167 | 167 |
168 // Iterator is exhausted. | 168 // Iterator is exhausted. |
169 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 169 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
170 } | 170 } |
171 | 171 |
172 // This test is the same as LayoutOpportunitiesTwoInMiddle with the only | |
173 // difference that NGLayoutOpportunityIterator takes the additional argument | |
174 // origin_point that changes the iterator to return Layout Opportunities that | |
175 // lay after the origin point. | |
176 // | |
177 // Expected: | |
178 // Layout opportunity iterator generates the next opportunities: | |
179 // - 1st Start Point (0, 200): 150x200 | |
180 // - 2nd Start Point (250, 200): 350x150, 250x200 | |
181 // - 3rd Start Point (550, 200): 50x200 | |
182 // - 4th Start Point (0, 300): 600x50, 500x100 | |
183 // All other opportunities that are located before the origin point should be | |
184 // filtered out. | |
185 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOrigin) { | |
ikilpatrick
2016/10/28 16:39:28
\o/
| |
186 NGPhysicalSize physical_size; | |
187 physical_size.width = LayoutUnit(600); | |
188 physical_size.height = LayoutUnit(400); | |
189 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); | |
190 | |
191 // Add exclusions | |
192 physical_space->AddExclusion(new NGExclusion( | |
193 LayoutUnit(200), LayoutUnit(250), LayoutUnit(300), LayoutUnit(150))); | |
194 physical_space->AddExclusion(new NGExclusion( | |
195 LayoutUnit(350), LayoutUnit(550), LayoutUnit(400), LayoutUnit(500))); | |
196 | |
197 auto* space = | |
198 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); | |
199 const NGLogicalOffset origin_point = {LayoutUnit(0), LayoutUnit(200)}; | |
200 auto* iterator = new NGLayoutOpportunityIterator(space, origin_point); | |
201 | |
202 // 1st Start Point | |
203 EXPECT_EQ("0,200 150x200", OpportunityToString(iterator->Next())); | |
204 | |
205 // 2nd Start Point | |
206 EXPECT_EQ("250,200 350x150", OpportunityToString(iterator->Next())); | |
207 EXPECT_EQ("250,200 250x200", OpportunityToString(iterator->Next())); | |
208 | |
209 // 3rd Start Point | |
210 EXPECT_EQ("550,200 50x200", OpportunityToString(iterator->Next())); | |
211 | |
212 // 4th Start Point | |
213 EXPECT_EQ("0,300 600x50", OpportunityToString(iterator->Next())); | |
214 EXPECT_EQ("0,300 500x100", OpportunityToString(iterator->Next())); | |
215 | |
216 // Iterator is exhausted. | |
217 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | |
218 } | |
219 | |
172 // Verifies that Layout Opportunity iterator ignores the exclusion that is not | 220 // Verifies that Layout Opportunity iterator ignores the exclusion that is not |
173 // within constraint space. | 221 // within constraint space. |
174 // | 222 // |
175 // Test case visual representation: | 223 // Test case visual representation: |
176 // | 224 // |
177 // 100 200 300 400 500 | 225 // 100 200 300 400 500 |
178 // +----|----|----|----|----|----+ | 226 // +----|----|----|----|----|----+ |
179 // 50 | | | 227 // 50 | | |
180 // 100 | | | 228 // 100 | | |
181 // +-----------------------------+ | 229 // +-----------------------------+ |
(...skipping 14 matching lines...) Expand all Loading... | |
196 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); | 244 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); |
197 | 245 |
198 auto* iterator = space->LayoutOpportunities(); | 246 auto* iterator = space->LayoutOpportunities(); |
199 | 247 |
200 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); | 248 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); |
201 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 249 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
202 } | 250 } |
203 | 251 |
204 } // namespace | 252 } // namespace |
205 } // namespace blink | 253 } // namespace blink |
OLD | NEW |