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_constraint_space_builder.h" | 8 #include "core/layout/ng/ng_constraint_space_builder.h" |
9 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | 9 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 static String OpportunityToString(const NGLayoutOpportunity& opportunity) { | 29 static String OpportunityToString(const NGLayoutOpportunity& opportunity) { |
30 return opportunity.IsEmpty() ? String("(empty)") : opportunity.ToString(); | 30 return opportunity.IsEmpty() ? String("(empty)") : opportunity.ToString(); |
31 } | 31 } |
32 | 32 |
33 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) { | 33 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) { |
34 NGLogicalSize size; | 34 NGLogicalSize size; |
35 size.inline_size = LayoutUnit(600); | 35 size.inline_size = LayoutUnit(600); |
36 size.block_size = LayoutUnit(400); | 36 size.block_size = LayoutUnit(400); |
37 auto* space = ConstructConstraintSpace(kHorizontalTopBottom, LTR, size); | 37 auto* space = |
| 38 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); |
38 auto* iterator = space->LayoutOpportunities(); | 39 auto* iterator = space->LayoutOpportunities(); |
39 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next())); | 40 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next())); |
40 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 41 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
41 } | 42 } |
42 | 43 |
43 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { | 44 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { |
44 NGLogicalSize size; | 45 NGLogicalSize size; |
45 size.inline_size = LayoutUnit(600); | 46 size.inline_size = LayoutUnit(600); |
46 size.block_size = LayoutUnit(400); | 47 size.block_size = LayoutUnit(400); |
47 // Create a space with a 100x100 exclusion in the top right corner. | 48 // Create a space with a 100x100 exclusion in the top right corner. |
48 auto* space = ConstructConstraintSpace(kHorizontalTopBottom, LTR, size); | 49 auto* space = |
| 50 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); |
49 NGExclusion exclusion; | 51 NGExclusion exclusion; |
50 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), | 52 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), |
51 /* block_size */ LayoutUnit(100)}; | 53 /* block_size */ LayoutUnit(100)}; |
52 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(500), | 54 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(500), |
53 /* block_offset */ LayoutUnit(0)}; | 55 /* block_offset */ LayoutUnit(0)}; |
54 space->AddExclusion(exclusion); | 56 space->AddExclusion(exclusion); |
55 auto* iterator = space->LayoutOpportunities(); | 57 auto* iterator = space->LayoutOpportunities(); |
56 // First opportunity should be to the left of the exclusion. | 58 // First opportunity should be to the left of the exclusion. |
57 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); | 59 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); |
58 // Second opportunity should be below the exclusion. | 60 // Second opportunity should be below the exclusion. |
59 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); | 61 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); |
60 // There should be no third opportunity. | 62 // There should be no third opportunity. |
61 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 63 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
62 } | 64 } |
63 | 65 |
64 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { | 66 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { |
65 NGLogicalSize size; | 67 NGLogicalSize size; |
66 size.inline_size = LayoutUnit(600); | 68 size.inline_size = LayoutUnit(600); |
67 size.block_size = LayoutUnit(400); | 69 size.block_size = LayoutUnit(400); |
68 // Create a space with a 100x100 exclusion in the top left corner. | 70 // Create a space with a 100x100 exclusion in the top left corner. |
69 auto* space = ConstructConstraintSpace(kHorizontalTopBottom, LTR, size); | 71 auto* space = |
| 72 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); |
70 NGExclusion exclusion; | 73 NGExclusion exclusion; |
71 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), | 74 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), |
72 /* block_size */ LayoutUnit(100)}; | 75 /* block_size */ LayoutUnit(100)}; |
73 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), | 76 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), |
74 /* block_offset */ LayoutUnit(0)}; | 77 /* block_offset */ LayoutUnit(0)}; |
75 space->AddExclusion(exclusion); | 78 space->AddExclusion(exclusion); |
76 auto* iterator = space->LayoutOpportunities(); | 79 auto* iterator = space->LayoutOpportunities(); |
77 // First opportunity should be to the right of the exclusion. | 80 // First opportunity should be to the right of the exclusion. |
78 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next())); | 81 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next())); |
79 // Second opportunity should be below the exclusion. | 82 // Second opportunity should be below the exclusion. |
(...skipping 22 matching lines...) Expand all Loading... |
102 // Expected: | 105 // Expected: |
103 // Layout opportunity iterator generates the next opportunities: | 106 // Layout opportunity iterator generates the next opportunities: |
104 // - 1st Start Point: 0,0 600x200; 0,0 150x400 | 107 // - 1st Start Point: 0,0 600x200; 0,0 150x400 |
105 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 | 108 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 |
106 // - 3rd Start Point: 550,0 50x400 | 109 // - 3rd Start Point: 550,0 50x400 |
107 // - 4th Start Point: 0,300 600x50; 0,300 500x100 | 110 // - 4th Start Point: 0,300 600x50; 0,300 500x100 |
108 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { | 111 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { |
109 NGLogicalSize size; | 112 NGLogicalSize size; |
110 size.inline_size = LayoutUnit(600); | 113 size.inline_size = LayoutUnit(600); |
111 size.block_size = LayoutUnit(400); | 114 size.block_size = LayoutUnit(400); |
112 auto* space = ConstructConstraintSpace(kHorizontalTopBottom, LTR, size); | 115 auto* space = |
| 116 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); |
113 // Add exclusions | 117 // Add exclusions |
114 NGExclusion exclusion1; | 118 NGExclusion exclusion1; |
115 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), | 119 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), |
116 /* block_size */ LayoutUnit(100)}; | 120 /* block_size */ LayoutUnit(100)}; |
117 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), | 121 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), |
118 /* block_offset */ LayoutUnit(200)}; | 122 /* block_offset */ LayoutUnit(200)}; |
119 space->AddExclusion(exclusion1); | 123 space->AddExclusion(exclusion1); |
120 NGExclusion exclusion2; | 124 NGExclusion exclusion2; |
121 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), | 125 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), |
122 /* block_size */ LayoutUnit(50)}; | 126 /* block_size */ LayoutUnit(50)}; |
(...skipping 26 matching lines...) Expand all Loading... |
149 // Layout opportunity iterator generates the next opportunities: | 153 // Layout opportunity iterator generates the next opportunities: |
150 // - 1st Start Point (0, 200): 350x150, 250x200 | 154 // - 1st Start Point (0, 200): 350x150, 250x200 |
151 // - 3rd Start Point (550, 200): 50x200 | 155 // - 3rd Start Point (550, 200): 50x200 |
152 // - 4th Start Point (0, 300): 600x50, 500x100 | 156 // - 4th Start Point (0, 300): 600x50, 500x100 |
153 // All other opportunities that are located before the origin point should be | 157 // All other opportunities that are located before the origin point should be |
154 // filtered out. | 158 // filtered out. |
155 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOriginAndLeader) { | 159 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOriginAndLeader) { |
156 NGLogicalSize size; | 160 NGLogicalSize size; |
157 size.inline_size = LayoutUnit(600); | 161 size.inline_size = LayoutUnit(600); |
158 size.block_size = LayoutUnit(400); | 162 size.block_size = LayoutUnit(400); |
159 auto* space = ConstructConstraintSpace(kHorizontalTopBottom, LTR, size); | 163 auto* space = |
| 164 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); |
160 // Add exclusions | 165 // Add exclusions |
161 NGExclusion exclusion1; | 166 NGExclusion exclusion1; |
162 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), | 167 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), |
163 /* block_size */ LayoutUnit(100)}; | 168 /* block_size */ LayoutUnit(100)}; |
164 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), | 169 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), |
165 /* block_offset */ LayoutUnit(200)}; | 170 /* block_offset */ LayoutUnit(200)}; |
166 space->AddExclusion(exclusion1); | 171 space->AddExclusion(exclusion1); |
167 NGExclusion exclusion2; | 172 NGExclusion exclusion2; |
168 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), | 173 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), |
169 /* block_size */ LayoutUnit(50)}; | 174 /* block_size */ LayoutUnit(50)}; |
(...skipping 27 matching lines...) Expand all Loading... |
197 // +-----------------------------+ | 202 // +-----------------------------+ |
198 // *** <- Exclusion | 203 // *** <- Exclusion |
199 // | 204 // |
200 // Expected: | 205 // Expected: |
201 // Layout opportunity iterator generates only one opportunity that equals to | 206 // Layout opportunity iterator generates only one opportunity that equals to |
202 // available constraint space, i.e. 0,0 600x200 | 207 // available constraint space, i.e. 0,0 600x200 |
203 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { | 208 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { |
204 NGLogicalSize size; | 209 NGLogicalSize size; |
205 size.inline_size = LayoutUnit(600); | 210 size.inline_size = LayoutUnit(600); |
206 size.block_size = LayoutUnit(100); | 211 size.block_size = LayoutUnit(100); |
207 auto* space = ConstructConstraintSpace(kHorizontalTopBottom, LTR, size); | 212 auto* space = |
| 213 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); |
208 NGExclusion exclusion; | 214 NGExclusion exclusion; |
209 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), | 215 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), |
210 /* block_size */ LayoutUnit(100)}; | 216 /* block_size */ LayoutUnit(100)}; |
211 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), | 217 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), |
212 /* block_offset */ LayoutUnit(150)}; | 218 /* block_offset */ LayoutUnit(150)}; |
213 space->AddExclusion(exclusion); | 219 space->AddExclusion(exclusion); |
214 auto* iterator = space->LayoutOpportunities(); | 220 auto* iterator = space->LayoutOpportunities(); |
215 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); | 221 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); |
216 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 222 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
217 } | 223 } |
218 | 224 |
219 } // namespace | 225 } // namespace |
220 } // namespace blink | 226 } // namespace blink |
OLD | NEW |