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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_constraint_space_test.cc

Issue 2438313003: [LayoutNG] Remove derived constraint spaces from opportunity iterator. (Closed)
Patch Set: address comments? Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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_layout_opportunity_iterator.h" 7 #include "core/layout/ng/ng_layout_opportunity_iterator.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace blink { 10 namespace blink {
(...skipping 26 matching lines...) Expand all
37 EXPECT_TRUE(horz_space->FixedInlineSize()); 37 EXPECT_TRUE(horz_space->FixedInlineSize());
38 EXPECT_TRUE(vert_space->FixedBlockSize()); 38 EXPECT_TRUE(vert_space->FixedBlockSize());
39 39
40 EXPECT_FALSE(horz_space->FixedBlockSize()); 40 EXPECT_FALSE(horz_space->FixedBlockSize());
41 EXPECT_FALSE(vert_space->FixedInlineSize()); 41 EXPECT_FALSE(vert_space->FixedInlineSize());
42 42
43 EXPECT_EQ(FragmentColumn, horz_space->BlockFragmentationType()); 43 EXPECT_EQ(FragmentColumn, horz_space->BlockFragmentationType());
44 EXPECT_EQ(FragmentNone, vert_space->BlockFragmentationType()); 44 EXPECT_EQ(FragmentNone, vert_space->BlockFragmentationType());
45 } 45 }
46 46
47 static String OpportunityToString(const NGConstraintSpace* opportunity) { 47 static String OpportunityToString(const NGLayoutOpportunity& opportunity) {
48 return opportunity ? opportunity->ToString() : String("(null)"); 48 return !opportunity.IsEmpty() ? opportunity.ToString() : String("(empty)");
Gleb Lanbin 2016/10/21 22:13:01 .nit please try to use positive booleans statement
ikilpatrick 2016/10/24 17:09:19 Done.
49 } 49 }
50 50
51 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) { 51 TEST(NGConstraintSpaceTest, LayoutOpportunitiesNoExclusions) {
52 NGPhysicalSize physical_size; 52 NGPhysicalSize physical_size;
53 physical_size.width = LayoutUnit(600); 53 physical_size.width = LayoutUnit(600);
54 physical_size.height = LayoutUnit(400); 54 physical_size.height = LayoutUnit(400);
55 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); 55 auto* physical_space = new NGPhysicalConstraintSpace(physical_size);
56 auto* space = 56 auto* space =
57 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); 57 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space);
58 58
59 bool for_inline_or_bfc = true; 59 bool for_inline_or_bfc = true;
60 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); 60 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc);
61 61
62 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next())); 62 EXPECT_EQ("0,0 600x400", OpportunityToString(iterator->Next()));
63 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); 63 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next()));
64 } 64 }
65 65
66 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) { 66 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopRightExclusion) {
67 NGPhysicalSize physical_size; 67 NGPhysicalSize physical_size;
68 physical_size.width = LayoutUnit(600); 68 physical_size.width = LayoutUnit(600);
69 physical_size.height = LayoutUnit(400); 69 physical_size.height = LayoutUnit(400);
70 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); 70 auto* physical_space = new NGPhysicalConstraintSpace(physical_size);
71 71
72 // Add a 100x100 exclusion in the top right corner. 72 // Add a 100x100 exclusion in the top right corner.
73 physical_space->AddExclusion(new NGExclusion( 73 physical_space->AddExclusion(new NGExclusion(
74 LayoutUnit(0), LayoutUnit(600), LayoutUnit(100), LayoutUnit(500))); 74 LayoutUnit(0), LayoutUnit(600), LayoutUnit(100), LayoutUnit(500)));
75 75
76 auto* space = 76 auto* space =
77 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); 77 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space);
78 bool for_inline_or_bfc = true; 78 bool for_inline_or_bfc = true;
79 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); 79 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc);
80 80
81 // First opportunity should be to the left of the exclusion. 81 // First opportunity should be to the left of the exclusion.
82 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next())); 82 EXPECT_EQ("0,0 500x400", OpportunityToString(iterator->Next()));
83 83
84 // Second opportunity should be below the exclusion. 84 // Second opportunity should be below the exclusion.
85 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); 85 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next()));
86 86
87 // There should be no third opportunity. 87 // There should be no third opportunity.
88 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); 88 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next()));
89 } 89 }
90 90
91 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) { 91 TEST(NGConstraintSpaceTest, LayoutOpportunitiesTopLeftExclusion) {
92 NGPhysicalSize physical_size; 92 NGPhysicalSize physical_size;
93 physical_size.width = LayoutUnit(600); 93 physical_size.width = LayoutUnit(600);
94 physical_size.height = LayoutUnit(400); 94 physical_size.height = LayoutUnit(400);
95 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); 95 auto* physical_space = new NGPhysicalConstraintSpace(physical_size);
96 96
97 // Add a 100x100 exclusion in the top left corner. 97 // Add a 100x100 exclusion in the top left corner.
98 physical_space->AddExclusion(new NGExclusion(LayoutUnit(0), LayoutUnit(100), 98 physical_space->AddExclusion(new NGExclusion(LayoutUnit(0), LayoutUnit(100),
99 LayoutUnit(100), LayoutUnit(0))); 99 LayoutUnit(100), LayoutUnit(0)));
100 100
101 auto* space = 101 auto* space =
102 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); 102 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space);
103 bool for_inline_or_bfc = true; 103 bool for_inline_or_bfc = true;
104 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); 104 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc);
105 105
106 // First opportunity should be to the right of the exclusion. 106 // First opportunity should be to the right of the exclusion.
107 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next())); 107 EXPECT_EQ("100,0 500x400", OpportunityToString(iterator->Next()));
108 108
109 // Second opportunity should be below the exclusion. 109 // Second opportunity should be below the exclusion.
110 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next())); 110 EXPECT_EQ("0,100 600x300", OpportunityToString(iterator->Next()));
111 111
112 // There should be no third opportunity. 112 // There should be no third opportunity.
113 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); 113 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next()));
114 } 114 }
115 115
116 // Verifies that Layout Opportunity iterator produces 7 layout opportunities 116 // Verifies that Layout Opportunity iterator produces 7 layout opportunities
117 // from 4 start points created by 2 CSS exclusions positioned in the middle of 117 // from 4 start points created by 2 CSS exclusions positioned in the middle of
118 // the main constraint space. 118 // the main constraint space.
119 // 119 //
120 // Test case visual representation: 120 // Test case visual representation:
121 // 121 //
122 // 100 200 300 400 500 122 // 100 200 300 400 500
123 // (1)--|----|----|-(2)|----|-(3)+ 123 // (1)--|----|----|-(2)|----|-(3)+
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 EXPECT_EQ("250,0 250x400", OpportunityToString(iterator->Next())); 162 EXPECT_EQ("250,0 250x400", OpportunityToString(iterator->Next()));
163 163
164 // 3rd Start point 164 // 3rd Start point
165 EXPECT_EQ("550,0 50x400", OpportunityToString(iterator->Next())); 165 EXPECT_EQ("550,0 50x400", OpportunityToString(iterator->Next()));
166 166
167 // 4th Start point 167 // 4th Start point
168 EXPECT_EQ("0,300 600x50", OpportunityToString(iterator->Next())); 168 EXPECT_EQ("0,300 600x50", OpportunityToString(iterator->Next()));
169 EXPECT_EQ("0,300 500x100", OpportunityToString(iterator->Next())); 169 EXPECT_EQ("0,300 500x100", OpportunityToString(iterator->Next()));
170 170
171 // Iterator is exhausted. 171 // Iterator is exhausted.
172 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); 172 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next()));
173 } 173 }
174 174
175 // Verifies that Layout Opportunity iterator ignores the exclusion that is not 175 // Verifies that Layout Opportunity iterator ignores the exclusion that is not
176 // within constraint space. 176 // within constraint space.
177 // 177 //
178 // Test case visual representation: 178 // Test case visual representation:
179 // 179 //
180 // 100 200 300 400 500 180 // 100 200 300 400 500
181 // +----|----|----|----|----|----+ 181 // +----|----|----|----|----|----+
182 // 50 | | 182 // 50 | |
(...skipping 12 matching lines...) Expand all
195 auto* physical_space = new NGPhysicalConstraintSpace(physical_size); 195 auto* physical_space = new NGPhysicalConstraintSpace(physical_size);
196 physical_space->AddExclusion(new NGExclusion(LayoutUnit(150), LayoutUnit(100), 196 physical_space->AddExclusion(new NGExclusion(LayoutUnit(150), LayoutUnit(100),
197 LayoutUnit(200), LayoutUnit(0))); 197 LayoutUnit(200), LayoutUnit(0)));
198 auto* space = 198 auto* space =
199 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space); 199 new NGConstraintSpace(HorizontalTopBottom, LeftToRight, physical_space);
200 200
201 bool for_inline_or_bfc = true; 201 bool for_inline_or_bfc = true;
202 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc); 202 auto* iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc);
203 203
204 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next())); 204 EXPECT_EQ("0,0 600x100", OpportunityToString(iterator->Next()));
205 EXPECT_EQ("(null)", OpportunityToString(iterator->Next())); 205 EXPECT_EQ("(empty)", OpportunityToString(iterator->Next()));
206 } 206 }
207 207
208 } // namespace 208 } // namespace
209 } // namespace blink 209 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698