Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/ng/ng_length_utils_test.cc |
| diff --git a/third_party/WebKit/Source/core/layout/ng/ng_length_utils_test.cc b/third_party/WebKit/Source/core/layout/ng/ng_length_utils_test.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8491e3121bbbbb546d036ca73d622ca2ee8e53b5 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/layout/ng/ng_length_utils_test.cc |
| @@ -0,0 +1,147 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/layout/ng/ng_length_utils.h" |
| + |
| +#include "core/layout/ng/ng_constraint_space.h" |
| +#include "core/style/ComputedStyle.h" |
| +#include "platform/CalculationValue.h" |
| +#include "platform/LayoutUnit.h" |
| +#include "platform/Length.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "wtf/RefPtr.h" |
| + |
| +namespace blink { |
| +namespace { |
| + |
| +class NGLengthUtilsTest : public ::testing::Test { |
| + protected: |
| + void SetUp() override { style_ = ComputedStyle::create(); } |
| + |
| + LayoutUnit resolveInlineLength( |
| + const Length& length, |
| + 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.
|
| + NGConstraintSpace constraintSpace(LayoutUnit(100), LayoutUnit(100)); |
| + return ::blink::resolveInlineLength(constraintSpace, length, type); |
| + } |
| + |
| + LayoutUnit resolveBlockLength( |
| + const Length& length, |
| + LengthResolveType type = LengthResolveType::MinSize, |
|
cbiesinger
2016/08/11 20:41:57
(and here)
ikilpatrick
2016/08/11 21:38:37
Done.
|
| + LayoutUnit contentSize = LayoutUnit()) { |
| + 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.
|
| + return ::blink::resolveBlockLength(constraintSpace, length, contentSize, |
| + type); |
| + } |
| + |
| + LayoutUnit computeInlineSizeForFragment( |
| + const NGConstraintSpace& constraintSpace = |
| + NGConstraintSpace(LayoutUnit(100), LayoutUnit(100))) { |
| + return ::blink::computeInlineSizeForFragment(constraintSpace, |
| + *style_.get()); |
|
cbiesinger
2016/08/11 20:41:57
*style_ does not work? :(
ikilpatrick
2016/08/11 21:38:37
Done.
|
| + } |
| + |
| + LayoutUnit computeBlockSizeForFragment( |
| + const NGConstraintSpace& constraintSpace = |
| + NGConstraintSpace(LayoutUnit(100), LayoutUnit(100))) { |
| + return ::blink::computeBlockSizeForFragment(constraintSpace, *style_.get(), |
| + 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.
|
| + } |
| + |
| + RefPtr<ComputedStyle> style_; |
| +}; |
| + |
| +TEST_F(NGLengthUtilsTest, testResolveInlineLength) { |
| + EXPECT_EQ(LayoutUnit(30), resolveInlineLength(Length(30, Percent))); |
| + EXPECT_EQ(LayoutUnit(150), resolveInlineLength(Length(150, Fixed))); |
| + EXPECT_EQ(LayoutUnit(0), resolveInlineLength(Length(Auto))); |
| + EXPECT_EQ(LayoutUnit(100), resolveInlineLength(Length(FillAvailable))); |
| + |
| + EXPECT_EQ(LayoutUnit(100), |
| + resolveInlineLength(Length(Auto), LengthResolveType::MaxSize)); |
| + EXPECT_EQ(LayoutUnit(100), resolveInlineLength(Length(FillAvailable), |
| + LengthResolveType::MaxSize)); |
| +} |
| + |
| +TEST_F(NGLengthUtilsTest, testResolveBlockLength) { |
| + EXPECT_EQ(LayoutUnit(30), resolveBlockLength(Length(30, Percent))); |
| + EXPECT_EQ(LayoutUnit(150), resolveBlockLength(Length(150, Fixed))); |
| + EXPECT_EQ(LayoutUnit(0), resolveBlockLength(Length(Auto))); |
| + EXPECT_EQ(LayoutUnit(100), resolveBlockLength(Length(FillAvailable))); |
| + |
| + EXPECT_EQ(LayoutUnit(0), |
| + resolveBlockLength(Length(Auto), LengthResolveType::ContentSize)); |
| + EXPECT_EQ(LayoutUnit(100), |
| + resolveBlockLength(Length(FillAvailable), |
| + LengthResolveType::ContentSize)); |
| +} |
| + |
| +TEST_F(NGLengthUtilsTest, testComputeInlineSizeForFragment) { |
| + style_->setLogicalWidth(Length(30, Percent)); |
| + EXPECT_EQ(LayoutUnit(30), computeInlineSizeForFragment()); |
| + |
| + style_->setLogicalWidth(Length(150, Fixed)); |
| + EXPECT_EQ(LayoutUnit(150), computeInlineSizeForFragment()); |
| + |
| + style_->setLogicalWidth(Length(Auto)); |
| + EXPECT_EQ(LayoutUnit(100), computeInlineSizeForFragment()); |
| + |
| + style_->setLogicalWidth(Length(FillAvailable)); |
| + EXPECT_EQ(LayoutUnit(100), computeInlineSizeForFragment()); |
| + |
| + style_->setLogicalWidth(Length(CalculationValue::create( |
| + PixelsAndPercent(100, -10), ValueRangeNonNegative))); |
| + EXPECT_EQ(LayoutUnit(90), computeInlineSizeForFragment()); |
| + |
| + NGConstraintSpace constraintSpace(LayoutUnit(200), LayoutUnit(200)); |
| + constraintSpace.setFixedSize(true, true); |
| + style_->setLogicalWidth(Length(150, Fixed)); |
| + EXPECT_EQ(LayoutUnit(200), computeInlineSizeForFragment(constraintSpace)); |
| + |
| + style_->setLogicalWidth(Length(100, Fixed)); |
| + style_->setMaxWidth(Length(80, Percent)); |
| + EXPECT_EQ(LayoutUnit(80), computeInlineSizeForFragment()); |
| + |
| + style_->setLogicalWidth(Length(60, Fixed)); |
| + style_->setMinWidth(Length(80, Percent)); |
| + EXPECT_EQ(LayoutUnit(80), computeInlineSizeForFragment()); |
| + |
| + // TODO(layout-ng): test {min,max}-content on max-width. |
| +} |
| + |
| +TEST_F(NGLengthUtilsTest, testComputeBlockSizeForFragment) { |
| + style_->setLogicalHeight(Length(30, Percent)); |
| + EXPECT_EQ(LayoutUnit(30), computeBlockSizeForFragment()); |
| + |
| + style_->setLogicalHeight(Length(150, Fixed)); |
| + EXPECT_EQ(LayoutUnit(150), computeBlockSizeForFragment()); |
| + |
| + style_->setLogicalHeight(Length(Auto)); |
| + EXPECT_EQ(LayoutUnit(0), computeBlockSizeForFragment()); |
| + |
| + style_->setLogicalHeight(Length(FillAvailable)); |
| + EXPECT_EQ(LayoutUnit(100), computeBlockSizeForFragment()); |
| + |
| + style_->setLogicalHeight(Length(CalculationValue::create( |
| + PixelsAndPercent(100, -10), ValueRangeNonNegative))); |
| + EXPECT_EQ(LayoutUnit(90), computeBlockSizeForFragment()); |
| + |
| + NGConstraintSpace constraintSpace(LayoutUnit(200), LayoutUnit(200)); |
| + constraintSpace.setFixedSize(true, true); |
| + style_->setLogicalHeight(Length(150, Fixed)); |
| + EXPECT_EQ(LayoutUnit(200), computeBlockSizeForFragment(constraintSpace)); |
| + |
| + style_->setLogicalHeight(Length(100, Fixed)); |
| + style_->setMaxHeight(Length(80, Percent)); |
| + EXPECT_EQ(LayoutUnit(80), computeBlockSizeForFragment()); |
| + |
| + style_->setLogicalHeight(Length(60, Fixed)); |
| + style_->setMinHeight(Length(80, Percent)); |
| + EXPECT_EQ(LayoutUnit(80), computeBlockSizeForFragment()); |
| + |
| + // TODO(layout-ng): test {min,max}-content on max-height. |
| +} |
| + |
| +} // namespace |
| +} // namespace blink |