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 17 matching lines...) Expand all Loading... |
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 = | 37 auto* space = |
38 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); | 38 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); |
39 auto* iterator = space->LayoutOpportunities(); | 39 auto* iterator = space->LayoutOpportunities(); |
40 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next())); | 40 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next())); |
41 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 41 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
42 } | 42 } |
43 | 43 |
44 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { | 44 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { |
45 NGLogicalSize size; | 45 NGLogicalSize size; |
46 size.inline_size = LayoutUnit(600); | 46 size.inline_size = LayoutUnit(600); |
47 size.block_size = LayoutUnit(400); | 47 size.block_size = LayoutUnit(400); |
48 // 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. |
49 auto* space = | 49 auto* space = |
50 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); | 50 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); |
51 NGExclusion exclusion; | 51 NGExclusion exclusion; |
52 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), | 52 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), |
53 /* block_size */ LayoutUnit(100)}; | 53 /* block_size */ LayoutUnit(100)}; |
54 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(500), | 54 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(500), |
55 /* block_offset */ LayoutUnit(0)}; | 55 /* block_offset */ LayoutUnit(0)}; |
56 space->AddExclusion(exclusion); | 56 space->AddExclusion(exclusion); |
57 auto* iterator = space->LayoutOpportunities(); | 57 auto* iterator = space->LayoutOpportunities(); |
58 // First opportunity should be to the left of the exclusion. | 58 // First opportunity should be to the left of the exclusion. |
59 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); | 59 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); |
60 // Second opportunity should be below the exclusion. | 60 // Second opportunity should be below the exclusion. |
61 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); | 61 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); |
62 // There should be no third opportunity. | 62 // There should be no third opportunity. |
63 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 63 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
64 } | 64 } |
65 | 65 |
66 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { | 66 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { |
67 NGLogicalSize size; | 67 NGLogicalSize size; |
68 size.inline_size = LayoutUnit(600); | 68 size.inline_size = LayoutUnit(600); |
69 size.block_size = LayoutUnit(400); | 69 size.block_size = LayoutUnit(400); |
70 // 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. |
71 auto* space = | 71 auto* space = |
72 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); | 72 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); |
73 NGExclusion exclusion; | 73 NGExclusion exclusion; |
74 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), | 74 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), |
75 /* block_size */ LayoutUnit(100)}; | 75 /* block_size */ LayoutUnit(100)}; |
76 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), | 76 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), |
77 /* block_offset */ LayoutUnit(0)}; | 77 /* block_offset */ LayoutUnit(0)}; |
78 space->AddExclusion(exclusion); | 78 space->AddExclusion(exclusion); |
79 auto* iterator = space->LayoutOpportunities(); | 79 auto* iterator = space->LayoutOpportunities(); |
80 // First opportunity should be to the right of the exclusion. | 80 // First opportunity should be to the right of the exclusion. |
81 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next())); | 81 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next())); |
82 // Second opportunity should be below the exclusion. | 82 // Second opportunity should be below the exclusion. |
(...skipping 23 matching lines...) Expand all Loading... |
106 // Layout opportunity iterator generates the next opportunities: | 106 // Layout opportunity iterator generates the next opportunities: |
107 // - 1st Start Point: 0,0 600x200; 0,0 150x400 | 107 // - 1st Start Point: 0,0 600x200; 0,0 150x400 |
108 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 | 108 // - 2nd Start Point: 250,0 350x350; 250,0 250x400 |
109 // - 3rd Start Point: 550,0 50x400 | 109 // - 3rd Start Point: 550,0 50x400 |
110 // - 4th Start Point: 0,300 600x50; 0,300 500x100 | 110 // - 4th Start Point: 0,300 600x50; 0,300 500x100 |
111 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { | 111 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddle) { |
112 NGLogicalSize size; | 112 NGLogicalSize size; |
113 size.inline_size = LayoutUnit(600); | 113 size.inline_size = LayoutUnit(600); |
114 size.block_size = LayoutUnit(400); | 114 size.block_size = LayoutUnit(400); |
115 auto* space = | 115 auto* space = |
116 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); | 116 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); |
117 // Add exclusions | 117 // Add exclusions |
118 NGExclusion exclusion1; | 118 NGExclusion exclusion1; |
119 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), | 119 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), |
120 /* block_size */ LayoutUnit(100)}; | 120 /* block_size */ LayoutUnit(100)}; |
121 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), | 121 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), |
122 /* block_offset */ LayoutUnit(200)}; | 122 /* block_offset */ LayoutUnit(200)}; |
123 space->AddExclusion(exclusion1); | 123 space->AddExclusion(exclusion1); |
124 NGExclusion exclusion2; | 124 NGExclusion exclusion2; |
125 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), | 125 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), |
126 /* block_size */ LayoutUnit(50)}; | 126 /* block_size */ LayoutUnit(50)}; |
(...skipping 27 matching lines...) Expand all Loading... |
154 // - 1st Start Point (0, 200): 350x150, 250x200 | 154 // - 1st Start Point (0, 200): 350x150, 250x200 |
155 // - 3rd Start Point (550, 200): 50x200 | 155 // - 3rd Start Point (550, 200): 50x200 |
156 // - 4th Start Point (0, 300): 600x50, 500x100 | 156 // - 4th Start Point (0, 300): 600x50, 500x100 |
157 // 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 |
158 // filtered out. | 158 // filtered out. |
159 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOriginAndLeader) { | 159 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTwoInMiddleWithOriginAndLeader) { |
160 NGLogicalSize size; | 160 NGLogicalSize size; |
161 size.inline_size = LayoutUnit(600); | 161 size.inline_size = LayoutUnit(600); |
162 size.block_size = LayoutUnit(400); | 162 size.block_size = LayoutUnit(400); |
163 auto* space = | 163 auto* space = |
164 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); | 164 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); |
165 // Add exclusions | 165 // Add exclusions |
166 NGExclusion exclusion1; | 166 NGExclusion exclusion1; |
167 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), | 167 exclusion1.rect.size = {/* inline_size */ LayoutUnit(100), |
168 /* block_size */ LayoutUnit(100)}; | 168 /* block_size */ LayoutUnit(100)}; |
169 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), | 169 exclusion1.rect.offset = {/* inline_offset */ LayoutUnit(150), |
170 /* block_offset */ LayoutUnit(200)}; | 170 /* block_offset */ LayoutUnit(200)}; |
171 space->AddExclusion(exclusion1); | 171 space->AddExclusion(exclusion1); |
172 NGExclusion exclusion2; | 172 NGExclusion exclusion2; |
173 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), | 173 exclusion2.rect.size = {/* inline_size */ LayoutUnit(50), |
174 /* block_size */ LayoutUnit(50)}; | 174 /* block_size */ LayoutUnit(50)}; |
(...skipping 28 matching lines...) Expand all Loading... |
203 // *** <- Exclusion | 203 // *** <- Exclusion |
204 // | 204 // |
205 // Expected: | 205 // Expected: |
206 // Layout opportunity iterator generates only one opportunity that equals to | 206 // Layout opportunity iterator generates only one opportunity that equals to |
207 // available constraint space, i.e. 0,0 600x200 | 207 // available constraint space, i.e. 0,0 600x200 |
208 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { | 208 TEST(NGConstraintSpaceTest, LayoutOpportunitiesWithOutOfBoundsExclusions) { |
209 NGLogicalSize size; | 209 NGLogicalSize size; |
210 size.inline_size = LayoutUnit(600); | 210 size.inline_size = LayoutUnit(600); |
211 size.block_size = LayoutUnit(100); | 211 size.block_size = LayoutUnit(100); |
212 auto* space = | 212 auto* space = |
213 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::Ltr, size); | 213 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, size); |
214 NGExclusion exclusion; | 214 NGExclusion exclusion; |
215 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), | 215 exclusion.rect.size = {/* inline_size */ LayoutUnit(100), |
216 /* block_size */ LayoutUnit(100)}; | 216 /* block_size */ LayoutUnit(100)}; |
217 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), | 217 exclusion.rect.offset = {/* inline_offset */ LayoutUnit(0), |
218 /* block_offset */ LayoutUnit(150)}; | 218 /* block_offset */ LayoutUnit(150)}; |
219 space->AddExclusion(exclusion); | 219 space->AddExclusion(exclusion); |
220 auto* iterator = space->LayoutOpportunities(); | 220 auto* iterator = space->LayoutOpportunities(); |
221 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); | 221 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); |
222 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); | 222 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next())); |
223 } | 223 } |
224 | 224 |
225 } // namespace | 225 } // namespace |
226 } // namespace blink | 226 } // namespace blink |
OLD | NEW |