Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/ng/ng_relative_utils_test.cc |
| diff --git a/third_party/WebKit/Source/core/layout/ng/ng_relative_utils_test.cc b/third_party/WebKit/Source/core/layout/ng/ng_relative_utils_test.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7ede179cd54e3df379579da83c9d5a345f252f01 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/layout/ng/ng_relative_utils_test.cc |
| @@ -0,0 +1,147 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
|
ikilpatrick
2017/03/16 19:08:36
2017
atotic
2017/03/20 17:31:45
done
|
| +// 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_relative_utils.h" |
| + |
| +#include "core/layout/ng/geometry/ng_logical_offset.h" |
| +#include "core/style/ComputedStyle.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blink { |
| +namespace { |
| + |
| +//#define NGAuto LayoutUnit(-1) |
| + |
| +class NGRelativeUtilsTest : public ::testing::Test { |
| + public: |
| + static const LayoutUnit kInlineSize; |
| + static const LayoutUnit kBlockSize; |
| + static const LayoutUnit kLeft; |
| + static const LayoutUnit kRight; |
| + static const LayoutUnit kTop; |
| + static const LayoutUnit kBottom; |
| + static const LayoutUnit kAuto; |
| + static const LayoutUnit kZero; |
| + |
| + protected: |
| + void SetUp() override { |
| + style_ = ComputedStyle::create(); |
| + container_size_ = NGLogicalSize{kInlineSize, kBlockSize}; |
| + } |
| + |
| + void SetTRBL(LayoutUnit top, |
| + LayoutUnit right, |
| + LayoutUnit bottom, |
| + LayoutUnit left) { |
| + style_->setTop(top == kAuto ? Length(LengthType::Auto) |
| + : Length(top.toInt(), LengthType::Fixed)); |
| + style_->setRight(right == kAuto ? Length(LengthType::Auto) |
| + : Length(right.toInt(), LengthType::Fixed)); |
| + style_->setBottom(bottom == kAuto |
| + ? Length(LengthType::Auto) |
| + : Length(bottom.toInt(), LengthType::Fixed)); |
| + style_->setLeft(left == kAuto ? Length(LengthType::Auto) |
| + : Length(left.toInt(), LengthType::Fixed)); |
| + } |
| + |
| + RefPtr<ComputedStyle> style_; |
| + NGLogicalSize container_size_; |
| +}; |
| + |
| +const LayoutUnit NGRelativeUtilsTest::kInlineSize{100}; |
| +const LayoutUnit NGRelativeUtilsTest::kBlockSize{200}; |
| +const LayoutUnit NGRelativeUtilsTest::kLeft{3}; |
| +const LayoutUnit NGRelativeUtilsTest::kRight{5}; |
| +const LayoutUnit NGRelativeUtilsTest::kTop{7}; |
| +const LayoutUnit NGRelativeUtilsTest::kBottom{9}; |
| +const LayoutUnit NGRelativeUtilsTest::kAuto{-1}; |
| +const LayoutUnit NGRelativeUtilsTest::kZero{0}; |
| + |
| +TEST_F(NGRelativeUtilsTest, HorizontalTB) { |
| + NGLogicalOffset offset; |
| + |
| + // Everything auto defaults to kZero,kZero |
| + SetTRBL(kAuto, kAuto, kAuto, kAuto); |
| + offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom, |
| + TextDirection::kLtr, container_size_); |
| + EXPECT_EQ(offset.inline_offset, kZero); |
| + EXPECT_EQ(offset.block_offset, kZero); |
| + |
| + // Set all sides |
| + SetTRBL(kTop, kRight, kBottom, kLeft); |
| + |
| + // kLtr |
| + offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom, |
| + TextDirection::kLtr, container_size_); |
| + EXPECT_EQ(offset.inline_offset, kLeft); |
| + EXPECT_EQ(offset.block_offset, kTop); |
| + |
| + // kRtl |
| + offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom, |
| + TextDirection::kRtl, container_size_); |
| + EXPECT_EQ(offset.inline_offset, kRight); |
| + EXPECT_EQ(offset.block_offset, kTop); |
| + |
| + // Set only non-default sides |
| + SetTRBL(kAuto, kRight, kBottom, kAuto); |
| + offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom, |
| + TextDirection::kLtr, container_size_); |
| + EXPECT_EQ(offset.inline_offset, -kRight); |
| + EXPECT_EQ(offset.block_offset, -kBottom); |
| +} |
| + |
| +TEST_F(NGRelativeUtilsTest, VerticalRightLeft) { |
| + NGLogicalOffset offset; |
| + |
| + // Set all sides |
| + SetTRBL(kTop, kRight, kBottom, kLeft); |
| + |
| + // kLtr |
| + offset = ComputeRelativeOffset(*style_, kVerticalRightLeft, |
| + TextDirection::kLtr, container_size_); |
| + EXPECT_EQ(offset.inline_offset, kTop); |
| + EXPECT_EQ(offset.block_offset, kRight); |
| + |
| + // kRtl |
| + offset = ComputeRelativeOffset(*style_, kVerticalRightLeft, |
| + TextDirection::kRtl, container_size_); |
| + EXPECT_EQ(offset.inline_offset, kBottom); |
| + EXPECT_EQ(offset.block_offset, kRight); |
| + |
| + // Set only non-default sides |
| + SetTRBL(kAuto, kAuto, kBottom, kLeft); |
| + offset = ComputeRelativeOffset(*style_, kVerticalRightLeft, |
| + TextDirection::kLtr, container_size_); |
| + EXPECT_EQ(offset.inline_offset, -kBottom); |
| + EXPECT_EQ(offset.block_offset, -kLeft); |
| +} |
| + |
| +TEST_F(NGRelativeUtilsTest, VerticalLeftRight) { |
| + NGLogicalOffset offset; |
| + |
| + // Set all sides |
| + SetTRBL(kTop, kRight, kBottom, kLeft); |
| + |
| + // kLtr |
| + offset = ComputeRelativeOffset(*style_, kVerticalLeftRight, |
| + TextDirection::kLtr, container_size_); |
| + EXPECT_EQ(offset.inline_offset, kTop); |
| + EXPECT_EQ(offset.block_offset, kLeft); |
| + |
| + // kRtl |
| + offset = ComputeRelativeOffset(*style_, kVerticalLeftRight, |
| + TextDirection::kRtl, container_size_); |
| + EXPECT_EQ(offset.inline_offset, kBottom); |
| + EXPECT_EQ(offset.block_offset, kLeft); |
| + |
| + // Set only non-default sides |
| + SetTRBL(kAuto, kRight, kBottom, kAuto); |
| + offset = ComputeRelativeOffset(*style_, kVerticalLeftRight, |
| + TextDirection::kLtr, container_size_); |
| + EXPECT_EQ(offset.inline_offset, -kBottom); |
| + EXPECT_EQ(offset.block_offset, -kRight); |
| +} |
| + |
| +} // namespace |
| +} // namespace blink |