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_length_utils_test.cc

Issue 2243513003: [LayoutNG] Add tests for ng_length_utils. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: .. Created 4 years, 4 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_length_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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::ContentSize) {
25 NGConstraintSpace constraintSpace(LayoutUnit(200), LayoutUnit(300));
26 return ::blink::resolveInlineLength(constraintSpace, length, type);
27 }
28
29 LayoutUnit resolveBlockLength(
30 const Length& length,
31 LengthResolveType type = LengthResolveType::ContentSize,
32 LayoutUnit contentSize = LayoutUnit()) {
33 NGConstraintSpace constraintSpace(LayoutUnit(200), LayoutUnit(300));
34 return ::blink::resolveBlockLength(constraintSpace, length, contentSize,
35 type);
36 }
37
38 LayoutUnit computeInlineSizeForFragment(
39 const NGConstraintSpace& constraintSpace =
40 NGConstraintSpace(LayoutUnit(200), LayoutUnit(300))) {
41 return ::blink::computeInlineSizeForFragment(constraintSpace, *style_);
42 }
43
44 LayoutUnit computeBlockSizeForFragment(
45 const NGConstraintSpace& constraintSpace =
46 NGConstraintSpace(LayoutUnit(200), LayoutUnit(300)),
47 LayoutUnit contentSize = LayoutUnit()) {
48 return ::blink::computeBlockSizeForFragment(constraintSpace, *style_,
49 contentSize);
50 }
51
52 RefPtr<ComputedStyle> style_;
53 };
54
55 TEST_F(NGLengthUtilsTest, testResolveInlineLength) {
56 EXPECT_EQ(LayoutUnit(60), resolveInlineLength(Length(30, Percent)));
57 EXPECT_EQ(LayoutUnit(150), resolveInlineLength(Length(150, Fixed)));
58 EXPECT_EQ(LayoutUnit(0),
59 resolveInlineLength(Length(Auto), LengthResolveType::MinSize));
60 EXPECT_EQ(LayoutUnit(200), resolveInlineLength(Length(Auto)));
61 EXPECT_EQ(LayoutUnit(200), resolveInlineLength(Length(FillAvailable)));
62
63 EXPECT_EQ(LayoutUnit(200),
64 resolveInlineLength(Length(Auto), LengthResolveType::MaxSize));
65 EXPECT_EQ(LayoutUnit(200), resolveInlineLength(Length(FillAvailable),
66 LengthResolveType::MaxSize));
67 }
68
69 TEST_F(NGLengthUtilsTest, testResolveBlockLength) {
70 EXPECT_EQ(LayoutUnit(90), resolveBlockLength(Length(30, Percent)));
71 EXPECT_EQ(LayoutUnit(150), resolveBlockLength(Length(150, Fixed)));
72 EXPECT_EQ(LayoutUnit(0), resolveBlockLength(Length(Auto)));
73 EXPECT_EQ(LayoutUnit(300), resolveBlockLength(Length(FillAvailable)));
74
75 EXPECT_EQ(LayoutUnit(0),
76 resolveBlockLength(Length(Auto), LengthResolveType::ContentSize));
77 EXPECT_EQ(LayoutUnit(300),
78 resolveBlockLength(Length(FillAvailable),
79 LengthResolveType::ContentSize));
80 }
81
82 TEST_F(NGLengthUtilsTest, testComputeInlineSizeForFragment) {
83 style_->setLogicalWidth(Length(30, Percent));
84 EXPECT_EQ(LayoutUnit(60), computeInlineSizeForFragment());
85
86 style_->setLogicalWidth(Length(150, Fixed));
87 EXPECT_EQ(LayoutUnit(150), computeInlineSizeForFragment());
88
89 style_->setLogicalWidth(Length(Auto));
90 EXPECT_EQ(LayoutUnit(200), computeInlineSizeForFragment());
91
92 style_->setLogicalWidth(Length(FillAvailable));
93 EXPECT_EQ(LayoutUnit(200), computeInlineSizeForFragment());
94
95 style_->setLogicalWidth(Length(CalculationValue::create(
96 PixelsAndPercent(100, -10), ValueRangeNonNegative)));
97 EXPECT_EQ(LayoutUnit(80), computeInlineSizeForFragment());
98
99 NGConstraintSpace constraintSpace(LayoutUnit(120), LayoutUnit(120));
100 constraintSpace.setFixedSize(true, true);
101 style_->setLogicalWidth(Length(150, Fixed));
102 EXPECT_EQ(LayoutUnit(120), computeInlineSizeForFragment(constraintSpace));
103
104 style_->setLogicalWidth(Length(200, Fixed));
105 style_->setMaxWidth(Length(80, Percent));
106 EXPECT_EQ(LayoutUnit(160), computeInlineSizeForFragment());
107
108 style_->setLogicalWidth(Length(100, Fixed));
109 style_->setMinWidth(Length(80, Percent));
110 EXPECT_EQ(LayoutUnit(160), computeInlineSizeForFragment());
111
112 // TODO(layout-ng): test {min,max}-content on max-width.
113 }
114
115 TEST_F(NGLengthUtilsTest, testComputeBlockSizeForFragment) {
116 style_->setLogicalHeight(Length(30, Percent));
117 EXPECT_EQ(LayoutUnit(90), computeBlockSizeForFragment());
118
119 style_->setLogicalHeight(Length(150, Fixed));
120 EXPECT_EQ(LayoutUnit(150), computeBlockSizeForFragment());
121
122 style_->setLogicalHeight(Length(Auto));
123 EXPECT_EQ(LayoutUnit(0), computeBlockSizeForFragment());
124
125 style_->setLogicalHeight(Length(Auto));
126 EXPECT_EQ(LayoutUnit(120),
127 computeBlockSizeForFragment(
128 NGConstraintSpace(LayoutUnit(200), LayoutUnit(300)),
129 LayoutUnit(120)));
130
131 style_->setLogicalHeight(Length(FillAvailable));
132 EXPECT_EQ(LayoutUnit(300), computeBlockSizeForFragment());
133
134 style_->setLogicalHeight(Length(CalculationValue::create(
135 PixelsAndPercent(100, -10), ValueRangeNonNegative)));
136 EXPECT_EQ(LayoutUnit(70), computeBlockSizeForFragment());
137
138 NGConstraintSpace constraintSpace(LayoutUnit(200), LayoutUnit(200));
139 constraintSpace.setFixedSize(true, true);
140 style_->setLogicalHeight(Length(150, Fixed));
141 EXPECT_EQ(LayoutUnit(200), computeBlockSizeForFragment(constraintSpace));
142
143 style_->setLogicalHeight(Length(300, Fixed));
144 style_->setMaxHeight(Length(80, Percent));
145 EXPECT_EQ(LayoutUnit(240), computeBlockSizeForFragment());
146
147 style_->setLogicalHeight(Length(100, Fixed));
148 style_->setMinHeight(Length(80, Percent));
149 EXPECT_EQ(LayoutUnit(240), computeBlockSizeForFragment());
150
151 // TODO(layout-ng): test {min,max}-content on max-height.
152 }
153
154 } // namespace
155 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_length_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698