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

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

Issue 2721613003: [LayoutNG] Move remaining ng_units structs to their own files (Closed)
Patch Set: Don't export NGBoxStrut for now Created 3 years, 9 months 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_length_utils.h" 5 #include "core/layout/ng/ng_length_utils.h"
6 6
7 #include "core/layout/ng/ng_box_fragment.h" 7 #include "core/layout/ng/ng_box_fragment.h"
8 #include "core/layout/ng/ng_constraint_space.h" 8 #include "core/layout/ng/ng_constraint_space.h"
9 #include "core/layout/ng/ng_constraint_space_builder.h" 9 #include "core/layout/ng/ng_constraint_space_builder.h"
10 #include "core/layout/ng/ng_fragment_builder.h" 10 #include "core/layout/ng/ng_fragment_builder.h"
11 #include "core/layout/ng/ng_physical_box_fragment.h" 11 #include "core/layout/ng/ng_physical_box_fragment.h"
12 #include "core/layout/ng/ng_units.h"
13 #include "core/style/ComputedStyle.h" 12 #include "core/style/ComputedStyle.h"
14 #include "platform/CalculationValue.h" 13 #include "platform/CalculationValue.h"
15 #include "platform/LayoutUnit.h" 14 #include "platform/LayoutUnit.h"
16 #include "platform/Length.h" 15 #include "platform/Length.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 #include "wtf/RefPtr.h" 17 #include "wtf/RefPtr.h"
19 18
20 namespace blink { 19 namespace blink {
21 namespace { 20 namespace {
22 21
(...skipping 11 matching lines...) Expand all
34 .SetPercentageResolutionSize( 33 .SetPercentageResolutionSize(
35 NGLogicalSize(LayoutUnit(inline_size), LayoutUnit(block_size))) 34 NGLogicalSize(LayoutUnit(inline_size), LayoutUnit(block_size)))
36 .SetIsFixedSizeInline(fixed_inline) 35 .SetIsFixedSizeInline(fixed_inline)
37 .SetIsFixedSizeBlock(fixed_block) 36 .SetIsFixedSizeBlock(fixed_block)
38 .ToConstraintSpace(kHorizontalTopBottom); 37 .ToConstraintSpace(kHorizontalTopBottom);
39 } 38 }
40 39
41 LayoutUnit ResolveInlineLength( 40 LayoutUnit ResolveInlineLength(
42 const Length& length, 41 const Length& length,
43 LengthResolveType type = LengthResolveType::kContentSize, 42 LengthResolveType type = LengthResolveType::kContentSize,
44 const WTF::Optional<MinAndMaxContentSizes>& sizes = WTF::nullopt) { 43 const WTF::Optional<MinMaxContentSize>& sizes = WTF::nullopt) {
45 NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 300); 44 NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 300);
46 return ::blink::ResolveInlineLength(*constraintSpace, *style_, sizes, 45 return ::blink::ResolveInlineLength(*constraintSpace, *style_, sizes,
47 length, type); 46 length, type);
48 } 47 }
49 48
50 LayoutUnit ResolveBlockLength( 49 LayoutUnit ResolveBlockLength(
51 const Length& length, 50 const Length& length,
52 LengthResolveType type = LengthResolveType::kContentSize, 51 LengthResolveType type = LengthResolveType::kContentSize,
53 LayoutUnit contentSize = LayoutUnit()) { 52 LayoutUnit contentSize = LayoutUnit()) {
54 NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 300); 53 NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 300);
55 return ::blink::ResolveBlockLength(*constraintSpace, *style_, length, 54 return ::blink::ResolveBlockLength(*constraintSpace, *style_, length,
56 contentSize, type); 55 contentSize, type);
57 } 56 }
58 57
59 LayoutUnit ComputeInlineSizeForFragment( 58 LayoutUnit ComputeInlineSizeForFragment(
60 const NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 59 const NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200,
61 300), 60 300),
62 const MinAndMaxContentSizes& sizes = MinAndMaxContentSizes()) { 61 const MinMaxContentSize& sizes = MinMaxContentSize()) {
63 return ::blink::ComputeInlineSizeForFragment(*constraintSpace, *style_, 62 return ::blink::ComputeInlineSizeForFragment(*constraintSpace, *style_,
64 sizes); 63 sizes);
65 } 64 }
66 65
67 LayoutUnit ComputeBlockSizeForFragment( 66 LayoutUnit ComputeBlockSizeForFragment(
68 const NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200, 67 const NGConstraintSpace* constraintSpace = ConstructConstraintSpace(200,
69 300), 68 300),
70 LayoutUnit contentSize = LayoutUnit()) { 69 LayoutUnit contentSize = LayoutUnit()) {
71 return ::blink::ComputeBlockSizeForFragment(*constraintSpace, *style_, 70 return ::blink::ComputeBlockSizeForFragment(*constraintSpace, *style_,
72 contentSize); 71 contentSize);
73 } 72 }
74 73
75 RefPtr<ComputedStyle> style_; 74 RefPtr<ComputedStyle> style_;
76 }; 75 };
77 76
78 TEST_F(NGLengthUtilsTest, testResolveInlineLength) { 77 TEST_F(NGLengthUtilsTest, testResolveInlineLength) {
79 EXPECT_EQ(LayoutUnit(60), ResolveInlineLength(Length(30, Percent))); 78 EXPECT_EQ(LayoutUnit(60), ResolveInlineLength(Length(30, Percent)));
80 EXPECT_EQ(LayoutUnit(150), ResolveInlineLength(Length(150, Fixed))); 79 EXPECT_EQ(LayoutUnit(150), ResolveInlineLength(Length(150, Fixed)));
81 EXPECT_EQ(LayoutUnit(0), 80 EXPECT_EQ(LayoutUnit(0),
82 ResolveInlineLength(Length(Auto), LengthResolveType::kMinSize)); 81 ResolveInlineLength(Length(Auto), LengthResolveType::kMinSize));
83 EXPECT_EQ(LayoutUnit(200), ResolveInlineLength(Length(Auto))); 82 EXPECT_EQ(LayoutUnit(200), ResolveInlineLength(Length(Auto)));
84 EXPECT_EQ(LayoutUnit(200), ResolveInlineLength(Length(FillAvailable))); 83 EXPECT_EQ(LayoutUnit(200), ResolveInlineLength(Length(FillAvailable)));
85 84
86 EXPECT_EQ(LayoutUnit(200), 85 EXPECT_EQ(LayoutUnit(200),
87 ResolveInlineLength(Length(Auto), LengthResolveType::kMaxSize)); 86 ResolveInlineLength(Length(Auto), LengthResolveType::kMaxSize));
88 EXPECT_EQ(LayoutUnit(200), ResolveInlineLength(Length(FillAvailable), 87 EXPECT_EQ(LayoutUnit(200), ResolveInlineLength(Length(FillAvailable),
89 LengthResolveType::kMaxSize)); 88 LengthResolveType::kMaxSize));
90 MinAndMaxContentSizes sizes; 89 MinMaxContentSize sizes;
91 sizes.min_content = LayoutUnit(30); 90 sizes.min_content = LayoutUnit(30);
92 sizes.max_content = LayoutUnit(40); 91 sizes.max_content = LayoutUnit(40);
93 EXPECT_EQ(LayoutUnit(30), 92 EXPECT_EQ(LayoutUnit(30),
94 ResolveInlineLength(Length(MinContent), 93 ResolveInlineLength(Length(MinContent),
95 LengthResolveType::kContentSize, sizes)); 94 LengthResolveType::kContentSize, sizes));
96 EXPECT_EQ(LayoutUnit(40), 95 EXPECT_EQ(LayoutUnit(40),
97 ResolveInlineLength(Length(MaxContent), 96 ResolveInlineLength(Length(MaxContent),
98 LengthResolveType::kContentSize, sizes)); 97 LengthResolveType::kContentSize, sizes));
99 EXPECT_EQ(LayoutUnit(40), 98 EXPECT_EQ(LayoutUnit(40),
100 ResolveInlineLength(Length(FitContent), 99 ResolveInlineLength(Length(FitContent),
(...skipping 15 matching lines...) Expand all
116 EXPECT_EQ(LayoutUnit(300), ResolveBlockLength(Length(FillAvailable))); 115 EXPECT_EQ(LayoutUnit(300), ResolveBlockLength(Length(FillAvailable)));
117 116
118 EXPECT_EQ(LayoutUnit(0), 117 EXPECT_EQ(LayoutUnit(0),
119 ResolveBlockLength(Length(Auto), LengthResolveType::kContentSize)); 118 ResolveBlockLength(Length(Auto), LengthResolveType::kContentSize));
120 EXPECT_EQ(LayoutUnit(300), 119 EXPECT_EQ(LayoutUnit(300),
121 ResolveBlockLength(Length(FillAvailable), 120 ResolveBlockLength(Length(FillAvailable),
122 LengthResolveType::kContentSize)); 121 LengthResolveType::kContentSize));
123 } 122 }
124 123
125 TEST_F(NGLengthUtilsTest, testComputeContentContribution) { 124 TEST_F(NGLengthUtilsTest, testComputeContentContribution) {
126 MinAndMaxContentSizes sizes; 125 MinMaxContentSize sizes;
127 sizes.min_content = LayoutUnit(30); 126 sizes.min_content = LayoutUnit(30);
128 sizes.max_content = LayoutUnit(40); 127 sizes.max_content = LayoutUnit(40);
129 128
130 MinAndMaxContentSizes expected{LayoutUnit(), LayoutUnit()}; 129 MinMaxContentSize expected{LayoutUnit(), LayoutUnit()};
131 style_->setLogicalWidth(Length(30, Percent)); 130 style_->setLogicalWidth(Length(30, Percent));
132 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 131 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
133 132
134 style_->setLogicalWidth(Length(FillAvailable)); 133 style_->setLogicalWidth(Length(FillAvailable));
135 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 134 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
136 135
137 expected = MinAndMaxContentSizes{LayoutUnit(150), LayoutUnit(150)}; 136 expected = MinMaxContentSize{LayoutUnit(150), LayoutUnit(150)};
138 style_->setLogicalWidth(Length(150, Fixed)); 137 style_->setLogicalWidth(Length(150, Fixed));
139 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 138 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
140 139
141 expected = sizes; 140 expected = sizes;
142 style_->setLogicalWidth(Length(Auto)); 141 style_->setLogicalWidth(Length(Auto));
143 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 142 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
144 143
145 expected = MinAndMaxContentSizes{LayoutUnit(430), LayoutUnit(440)}; 144 expected = MinMaxContentSize{LayoutUnit(430), LayoutUnit(440)};
146 style_->setPaddingLeft(Length(400, Fixed)); 145 style_->setPaddingLeft(Length(400, Fixed));
147 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 146 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
148 147
149 expected = MinAndMaxContentSizes{LayoutUnit(100), LayoutUnit(100)}; 148 expected = MinMaxContentSize{LayoutUnit(100), LayoutUnit(100)};
150 style_->setPaddingLeft(Length(0, Fixed)); 149 style_->setPaddingLeft(Length(0, Fixed));
151 style_->setLogicalWidth(Length(CalculationValue::create( 150 style_->setLogicalWidth(Length(CalculationValue::create(
152 PixelsAndPercent(100, -10), ValueRangeNonNegative))); 151 PixelsAndPercent(100, -10), ValueRangeNonNegative)));
153 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 152 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
154 153
155 expected = MinAndMaxContentSizes{LayoutUnit(30), LayoutUnit(35)}; 154 expected = MinMaxContentSize{LayoutUnit(30), LayoutUnit(35)};
156 style_->setLogicalWidth(Length(Auto)); 155 style_->setLogicalWidth(Length(Auto));
157 style_->setMaxWidth(Length(35, Fixed)); 156 style_->setMaxWidth(Length(35, Fixed));
158 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 157 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
159 158
160 expected = MinAndMaxContentSizes{LayoutUnit(80), LayoutUnit(80)}; 159 expected = MinMaxContentSize{LayoutUnit(80), LayoutUnit(80)};
161 style_->setLogicalWidth(Length(50, Fixed)); 160 style_->setLogicalWidth(Length(50, Fixed));
162 style_->setMinWidth(Length(80, Fixed)); 161 style_->setMinWidth(Length(80, Fixed));
163 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 162 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
164 163
165 expected = MinAndMaxContentSizes{LayoutUnit(150), LayoutUnit(150)}; 164 expected = MinMaxContentSize{LayoutUnit(150), LayoutUnit(150)};
166 style_ = ComputedStyle::create(); 165 style_ = ComputedStyle::create();
167 style_->setLogicalWidth(Length(100, Fixed)); 166 style_->setLogicalWidth(Length(100, Fixed));
168 style_->setPaddingLeft(Length(50, Fixed)); 167 style_->setPaddingLeft(Length(50, Fixed));
169 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 168 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
170 169
171 expected = MinAndMaxContentSizes{LayoutUnit(100), LayoutUnit(100)}; 170 expected = MinMaxContentSize{LayoutUnit(100), LayoutUnit(100)};
172 style_->setBoxSizing(EBoxSizing::kBorderBox); 171 style_->setBoxSizing(EBoxSizing::kBorderBox);
173 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 172 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
174 173
175 // Content size should never be below zero, even with box-sizing: border-box 174 // Content size should never be below zero, even with box-sizing: border-box
176 // and a large padding... 175 // and a large padding...
177 expected = MinAndMaxContentSizes{LayoutUnit(400), LayoutUnit(400)}; 176 expected = MinMaxContentSize{LayoutUnit(400), LayoutUnit(400)};
178 style_->setPaddingLeft(Length(400, Fixed)); 177 style_->setPaddingLeft(Length(400, Fixed));
179 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 178 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
180 179
181 expected.min_content = expected.max_content = 180 expected.min_content = expected.max_content =
182 sizes.min_content + LayoutUnit(400); 181 sizes.min_content + LayoutUnit(400);
183 style_->setLogicalWidth(Length(MinContent)); 182 style_->setLogicalWidth(Length(MinContent));
184 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 183 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
185 style_->setLogicalWidth(Length(100, Fixed)); 184 style_->setLogicalWidth(Length(100, Fixed));
186 style_->setMaxWidth(Length(MaxContent)); 185 style_->setMaxWidth(Length(MaxContent));
187 // Due to padding and box-sizing, width computes to 400px and max-width to 186 // Due to padding and box-sizing, width computes to 400px and max-width to
188 // 440px, so the result is 400. 187 // 440px, so the result is 400.
189 expected = MinAndMaxContentSizes{LayoutUnit(400), LayoutUnit(400)}; 188 expected = MinMaxContentSize{LayoutUnit(400), LayoutUnit(400)};
190 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 189 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
191 expected = MinAndMaxContentSizes{LayoutUnit(40), LayoutUnit(40)}; 190 expected = MinMaxContentSize{LayoutUnit(40), LayoutUnit(40)};
192 style_->setPaddingLeft(Length(0, Fixed)); 191 style_->setPaddingLeft(Length(0, Fixed));
193 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes)); 192 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
194 } 193 }
195 194
196 TEST_F(NGLengthUtilsTest, testComputeInlineSizeForFragment) { 195 TEST_F(NGLengthUtilsTest, testComputeInlineSizeForFragment) {
197 MinAndMaxContentSizes sizes; 196 MinMaxContentSize sizes;
198 sizes.min_content = LayoutUnit(30); 197 sizes.min_content = LayoutUnit(30);
199 sizes.max_content = LayoutUnit(40); 198 sizes.max_content = LayoutUnit(40);
200 199
201 style_->setLogicalWidth(Length(30, Percent)); 200 style_->setLogicalWidth(Length(30, Percent));
202 EXPECT_EQ(LayoutUnit(60), ComputeInlineSizeForFragment()); 201 EXPECT_EQ(LayoutUnit(60), ComputeInlineSizeForFragment());
203 202
204 style_->setLogicalWidth(Length(150, Fixed)); 203 style_->setLogicalWidth(Length(150, Fixed));
205 EXPECT_EQ(LayoutUnit(150), ComputeInlineSizeForFragment()); 204 EXPECT_EQ(LayoutUnit(150), ComputeInlineSizeForFragment());
206 205
207 style_->setLogicalWidth(Length(Auto)); 206 style_->setLogicalWidth(Length(Auto));
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 EXPECT_EQ(125, GetUsedColumnWidth(4, 100, 10, 530)); 489 EXPECT_EQ(125, GetUsedColumnWidth(4, 100, 10, 530));
491 EXPECT_EQ(4, GetUsedColumnCount(4, 100, 10, 530)); 490 EXPECT_EQ(4, GetUsedColumnCount(4, 100, 10, 530));
492 EXPECT_EQ(100, GetUsedColumnWidth(6, 100, 10, 540)); 491 EXPECT_EQ(100, GetUsedColumnWidth(6, 100, 10, 540));
493 EXPECT_EQ(5, GetUsedColumnCount(6, 100, 10, 540)); 492 EXPECT_EQ(5, GetUsedColumnCount(6, 100, 10, 540));
494 EXPECT_EQ(100, GetUsedColumnWidth(0, 100, 10, 540)); 493 EXPECT_EQ(100, GetUsedColumnWidth(0, 100, 10, 540));
495 EXPECT_EQ(5, GetUsedColumnCount(0, 100, 10, 540)); 494 EXPECT_EQ(5, GetUsedColumnCount(0, 100, 10, 540));
496 } 495 }
497 496
498 } // namespace 497 } // namespace
499 } // namespace blink 498 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698