OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/layout/ng/ng_length_utils.h" | |
6 | |
7 #include "core/layout/ng/ng_constraint_space.h" | |
8 #include "core/style/ComputedStyle.h" | |
9 #include "platform/CalculationValue.h" | |
10 #include "platform/LayoutUnit.h" | |
11 #include "platform/Length.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "wtf/RefPtr.h" | |
14 | |
15 namespace blink { | |
16 namespace { | |
17 | |
18 class NGLengthUtilsTest : public ::testing::Test { | |
19 protected: | |
20 void SetUp() override { style_ = ComputedStyle::create(); } | |
21 | |
22 LayoutUnit resolveInlineLength( | |
23 const Length& length, | |
24 LengthResolveType type = LengthResolveType::MinSize) { | |
cbiesinger
2016/08/11 20:41:57
I feel like it makes more sense to default to Cont
ikilpatrick
2016/08/11 21:38:37
Done.
| |
25 NGConstraintSpace constraintSpace(LayoutUnit(100), LayoutUnit(100)); | |
26 return ::blink::resolveInlineLength(constraintSpace, length, type); | |
27 } | |
28 | |
29 LayoutUnit resolveBlockLength( | |
30 const Length& length, | |
31 LengthResolveType type = LengthResolveType::MinSize, | |
cbiesinger
2016/08/11 20:41:57
(and here)
ikilpatrick
2016/08/11 21:38:37
Done.
| |
32 LayoutUnit contentSize = LayoutUnit()) { | |
33 NGConstraintSpace constraintSpace(LayoutUnit(100), LayoutUnit(100)); | |
cbiesinger
2016/08/11 20:41:57
I'd almost prefer that you didn't use 100 here --
ikilpatrick
2016/08/11 21:38:37
Done.
| |
34 return ::blink::resolveBlockLength(constraintSpace, length, contentSize, | |
35 type); | |
36 } | |
37 | |
38 LayoutUnit computeInlineSizeForFragment( | |
39 const NGConstraintSpace& constraintSpace = | |
40 NGConstraintSpace(LayoutUnit(100), LayoutUnit(100))) { | |
41 return ::blink::computeInlineSizeForFragment(constraintSpace, | |
42 *style_.get()); | |
cbiesinger
2016/08/11 20:41:57
*style_ does not work? :(
ikilpatrick
2016/08/11 21:38:37
Done.
| |
43 } | |
44 | |
45 LayoutUnit computeBlockSizeForFragment( | |
46 const NGConstraintSpace& constraintSpace = | |
47 NGConstraintSpace(LayoutUnit(100), LayoutUnit(100))) { | |
48 return ::blink::computeBlockSizeForFragment(constraintSpace, *style_.get(), | |
49 LayoutUnit()); | |
cbiesinger
2016/08/11 20:41:57
Longer-term we'll want some tests where this is no
ikilpatrick
2016/08/11 21:38:37
Done.
| |
50 } | |
51 | |
52 RefPtr<ComputedStyle> style_; | |
53 }; | |
54 | |
55 TEST_F(NGLengthUtilsTest, testResolveInlineLength) { | |
56 EXPECT_EQ(LayoutUnit(30), resolveInlineLength(Length(30, Percent))); | |
57 EXPECT_EQ(LayoutUnit(150), resolveInlineLength(Length(150, Fixed))); | |
58 EXPECT_EQ(LayoutUnit(0), resolveInlineLength(Length(Auto))); | |
59 EXPECT_EQ(LayoutUnit(100), resolveInlineLength(Length(FillAvailable))); | |
60 | |
61 EXPECT_EQ(LayoutUnit(100), | |
62 resolveInlineLength(Length(Auto), LengthResolveType::MaxSize)); | |
63 EXPECT_EQ(LayoutUnit(100), resolveInlineLength(Length(FillAvailable), | |
64 LengthResolveType::MaxSize)); | |
65 } | |
66 | |
67 TEST_F(NGLengthUtilsTest, testResolveBlockLength) { | |
68 EXPECT_EQ(LayoutUnit(30), resolveBlockLength(Length(30, Percent))); | |
69 EXPECT_EQ(LayoutUnit(150), resolveBlockLength(Length(150, Fixed))); | |
70 EXPECT_EQ(LayoutUnit(0), resolveBlockLength(Length(Auto))); | |
71 EXPECT_EQ(LayoutUnit(100), resolveBlockLength(Length(FillAvailable))); | |
72 | |
73 EXPECT_EQ(LayoutUnit(0), | |
74 resolveBlockLength(Length(Auto), LengthResolveType::ContentSize)); | |
75 EXPECT_EQ(LayoutUnit(100), | |
76 resolveBlockLength(Length(FillAvailable), | |
77 LengthResolveType::ContentSize)); | |
78 } | |
79 | |
80 TEST_F(NGLengthUtilsTest, testComputeInlineSizeForFragment) { | |
81 style_->setLogicalWidth(Length(30, Percent)); | |
82 EXPECT_EQ(LayoutUnit(30), computeInlineSizeForFragment()); | |
83 | |
84 style_->setLogicalWidth(Length(150, Fixed)); | |
85 EXPECT_EQ(LayoutUnit(150), computeInlineSizeForFragment()); | |
86 | |
87 style_->setLogicalWidth(Length(Auto)); | |
88 EXPECT_EQ(LayoutUnit(100), computeInlineSizeForFragment()); | |
89 | |
90 style_->setLogicalWidth(Length(FillAvailable)); | |
91 EXPECT_EQ(LayoutUnit(100), computeInlineSizeForFragment()); | |
92 | |
93 style_->setLogicalWidth(Length(CalculationValue::create( | |
94 PixelsAndPercent(100, -10), ValueRangeNonNegative))); | |
95 EXPECT_EQ(LayoutUnit(90), computeInlineSizeForFragment()); | |
96 | |
97 NGConstraintSpace constraintSpace(LayoutUnit(200), LayoutUnit(200)); | |
98 constraintSpace.setFixedSize(true, true); | |
99 style_->setLogicalWidth(Length(150, Fixed)); | |
100 EXPECT_EQ(LayoutUnit(200), computeInlineSizeForFragment(constraintSpace)); | |
101 | |
102 style_->setLogicalWidth(Length(100, Fixed)); | |
103 style_->setMaxWidth(Length(80, Percent)); | |
104 EXPECT_EQ(LayoutUnit(80), computeInlineSizeForFragment()); | |
105 | |
106 style_->setLogicalWidth(Length(60, Fixed)); | |
107 style_->setMinWidth(Length(80, Percent)); | |
108 EXPECT_EQ(LayoutUnit(80), computeInlineSizeForFragment()); | |
109 | |
110 // TODO(layout-ng): test {min,max}-content on max-width. | |
111 } | |
112 | |
113 TEST_F(NGLengthUtilsTest, testComputeBlockSizeForFragment) { | |
114 style_->setLogicalHeight(Length(30, Percent)); | |
115 EXPECT_EQ(LayoutUnit(30), computeBlockSizeForFragment()); | |
116 | |
117 style_->setLogicalHeight(Length(150, Fixed)); | |
118 EXPECT_EQ(LayoutUnit(150), computeBlockSizeForFragment()); | |
119 | |
120 style_->setLogicalHeight(Length(Auto)); | |
121 EXPECT_EQ(LayoutUnit(0), computeBlockSizeForFragment()); | |
122 | |
123 style_->setLogicalHeight(Length(FillAvailable)); | |
124 EXPECT_EQ(LayoutUnit(100), computeBlockSizeForFragment()); | |
125 | |
126 style_->setLogicalHeight(Length(CalculationValue::create( | |
127 PixelsAndPercent(100, -10), ValueRangeNonNegative))); | |
128 EXPECT_EQ(LayoutUnit(90), computeBlockSizeForFragment()); | |
129 | |
130 NGConstraintSpace constraintSpace(LayoutUnit(200), LayoutUnit(200)); | |
131 constraintSpace.setFixedSize(true, true); | |
132 style_->setLogicalHeight(Length(150, Fixed)); | |
133 EXPECT_EQ(LayoutUnit(200), computeBlockSizeForFragment(constraintSpace)); | |
134 | |
135 style_->setLogicalHeight(Length(100, Fixed)); | |
136 style_->setMaxHeight(Length(80, Percent)); | |
137 EXPECT_EQ(LayoutUnit(80), computeBlockSizeForFragment()); | |
138 | |
139 style_->setLogicalHeight(Length(60, Fixed)); | |
140 style_->setMinHeight(Length(80, Percent)); | |
141 EXPECT_EQ(LayoutUnit(80), computeBlockSizeForFragment()); | |
142 | |
143 // TODO(layout-ng): test {min,max}-content on max-height. | |
144 } | |
145 | |
146 } // namespace | |
147 } // namespace blink | |
OLD | NEW |