OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_relative_utils.h" |
| 6 |
| 7 #include "core/layout/ng/geometry/ng_logical_offset.h" |
| 8 #include "core/style/ComputedStyle.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace blink { |
| 12 namespace { |
| 13 |
| 14 const LayoutUnit kInlineSize{100}; |
| 15 const LayoutUnit kBlockSize{200}; |
| 16 const LayoutUnit kLeft{3}; |
| 17 const LayoutUnit kRight{5}; |
| 18 const LayoutUnit kTop{7}; |
| 19 const LayoutUnit kBottom{9}; |
| 20 const LayoutUnit kAuto{-1}; |
| 21 const LayoutUnit kZero{0}; |
| 22 |
| 23 class NGRelativeUtilsTest : public ::testing::Test { |
| 24 protected: |
| 25 void SetUp() override { |
| 26 style_ = ComputedStyle::create(); |
| 27 container_size_ = NGLogicalSize{kInlineSize, kBlockSize}; |
| 28 } |
| 29 |
| 30 void SetTRBL(LayoutUnit top, |
| 31 LayoutUnit right, |
| 32 LayoutUnit bottom, |
| 33 LayoutUnit left) { |
| 34 style_->setTop(top == kAuto ? Length(LengthType::Auto) |
| 35 : Length(top.toInt(), LengthType::Fixed)); |
| 36 style_->setRight(right == kAuto ? Length(LengthType::Auto) |
| 37 : Length(right.toInt(), LengthType::Fixed)); |
| 38 style_->setBottom(bottom == kAuto |
| 39 ? Length(LengthType::Auto) |
| 40 : Length(bottom.toInt(), LengthType::Fixed)); |
| 41 style_->setLeft(left == kAuto ? Length(LengthType::Auto) |
| 42 : Length(left.toInt(), LengthType::Fixed)); |
| 43 } |
| 44 |
| 45 RefPtr<ComputedStyle> style_; |
| 46 NGLogicalSize container_size_; |
| 47 }; |
| 48 |
| 49 TEST_F(NGRelativeUtilsTest, HorizontalTB) { |
| 50 NGLogicalOffset offset; |
| 51 |
| 52 // Everything auto defaults to kZero,kZero |
| 53 SetTRBL(kAuto, kAuto, kAuto, kAuto); |
| 54 offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom, |
| 55 TextDirection::kLtr, container_size_); |
| 56 EXPECT_EQ(offset.inline_offset, kZero); |
| 57 EXPECT_EQ(offset.block_offset, kZero); |
| 58 |
| 59 // Set all sides |
| 60 SetTRBL(kTop, kRight, kBottom, kLeft); |
| 61 |
| 62 // kLtr |
| 63 offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom, |
| 64 TextDirection::kLtr, container_size_); |
| 65 EXPECT_EQ(offset.inline_offset, kLeft); |
| 66 EXPECT_EQ(offset.block_offset, kTop); |
| 67 |
| 68 // kRtl |
| 69 offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom, |
| 70 TextDirection::kRtl, container_size_); |
| 71 EXPECT_EQ(offset.inline_offset, kRight); |
| 72 EXPECT_EQ(offset.block_offset, kTop); |
| 73 |
| 74 // Set only non-default sides |
| 75 SetTRBL(kAuto, kRight, kBottom, kAuto); |
| 76 offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom, |
| 77 TextDirection::kLtr, container_size_); |
| 78 EXPECT_EQ(offset.inline_offset, -kRight); |
| 79 EXPECT_EQ(offset.block_offset, -kBottom); |
| 80 } |
| 81 |
| 82 TEST_F(NGRelativeUtilsTest, VerticalRightLeft) { |
| 83 NGLogicalOffset offset; |
| 84 |
| 85 // Set all sides |
| 86 SetTRBL(kTop, kRight, kBottom, kLeft); |
| 87 |
| 88 // kLtr |
| 89 offset = ComputeRelativeOffset(*style_, kVerticalRightLeft, |
| 90 TextDirection::kLtr, container_size_); |
| 91 EXPECT_EQ(offset.inline_offset, kTop); |
| 92 EXPECT_EQ(offset.block_offset, kRight); |
| 93 |
| 94 // kRtl |
| 95 offset = ComputeRelativeOffset(*style_, kVerticalRightLeft, |
| 96 TextDirection::kRtl, container_size_); |
| 97 EXPECT_EQ(offset.inline_offset, kBottom); |
| 98 EXPECT_EQ(offset.block_offset, kRight); |
| 99 |
| 100 // Set only non-default sides |
| 101 SetTRBL(kAuto, kAuto, kBottom, kLeft); |
| 102 offset = ComputeRelativeOffset(*style_, kVerticalRightLeft, |
| 103 TextDirection::kLtr, container_size_); |
| 104 EXPECT_EQ(offset.inline_offset, -kBottom); |
| 105 EXPECT_EQ(offset.block_offset, -kLeft); |
| 106 } |
| 107 |
| 108 TEST_F(NGRelativeUtilsTest, VerticalLeftRight) { |
| 109 NGLogicalOffset offset; |
| 110 |
| 111 // Set all sides |
| 112 SetTRBL(kTop, kRight, kBottom, kLeft); |
| 113 |
| 114 // kLtr |
| 115 offset = ComputeRelativeOffset(*style_, kVerticalLeftRight, |
| 116 TextDirection::kLtr, container_size_); |
| 117 EXPECT_EQ(offset.inline_offset, kTop); |
| 118 EXPECT_EQ(offset.block_offset, kLeft); |
| 119 |
| 120 // kRtl |
| 121 offset = ComputeRelativeOffset(*style_, kVerticalLeftRight, |
| 122 TextDirection::kRtl, container_size_); |
| 123 EXPECT_EQ(offset.inline_offset, kBottom); |
| 124 EXPECT_EQ(offset.block_offset, kLeft); |
| 125 |
| 126 // Set only non-default sides |
| 127 SetTRBL(kAuto, kRight, kBottom, kAuto); |
| 128 offset = ComputeRelativeOffset(*style_, kVerticalLeftRight, |
| 129 TextDirection::kLtr, container_size_); |
| 130 EXPECT_EQ(offset.inline_offset, -kBottom); |
| 131 EXPECT_EQ(offset.block_offset, -kRight); |
| 132 } |
| 133 |
| 134 } // namespace |
| 135 } // namespace blink |
OLD | NEW |