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

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

Powered by Google App Engine
This is Rietveld 408576698