Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_relative_utils_test.cc

Issue 2755733003: Implement relative utilities (Closed)
Patch Set: CR fixes Created 3 years, 9 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
OLDNEW
(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 //#define NGAuto LayoutUnit(-1)
ikilpatrick 2017/03/21 17:51:17 ?
atotic 2017/03/21 19:13:54 gone
15
16 class NGRelativeUtilsTest : public ::testing::Test {
17 public:
18 static const LayoutUnit kInlineSize;
19 static const LayoutUnit kBlockSize;
20 static const LayoutUnit kLeft;
21 static const LayoutUnit kRight;
22 static const LayoutUnit kTop;
23 static const LayoutUnit kBottom;
24 static const LayoutUnit kAuto;
25 static const LayoutUnit kZero;
26
27 protected:
28 void SetUp() override {
29 style_ = ComputedStyle::create();
30 container_size_ = NGLogicalSize{kInlineSize, kBlockSize};
31 }
32
33 void SetTRBL(LayoutUnit top,
34 LayoutUnit right,
35 LayoutUnit bottom,
36 LayoutUnit left) {
37 style_->setTop(top == kAuto ? Length(LengthType::Auto)
38 : Length(top.toInt(), LengthType::Fixed));
39 style_->setRight(right == kAuto ? Length(LengthType::Auto)
40 : Length(right.toInt(), LengthType::Fixed));
41 style_->setBottom(bottom == kAuto
42 ? Length(LengthType::Auto)
43 : Length(bottom.toInt(), LengthType::Fixed));
44 style_->setLeft(left == kAuto ? Length(LengthType::Auto)
45 : Length(left.toInt(), LengthType::Fixed));
46 }
47
48 RefPtr<ComputedStyle> style_;
49 NGLogicalSize container_size_;
50 };
51
52 const LayoutUnit NGRelativeUtilsTest::kInlineSize{100};
53 const LayoutUnit NGRelativeUtilsTest::kBlockSize{200};
54 const LayoutUnit NGRelativeUtilsTest::kLeft{3};
55 const LayoutUnit NGRelativeUtilsTest::kRight{5};
56 const LayoutUnit NGRelativeUtilsTest::kTop{7};
57 const LayoutUnit NGRelativeUtilsTest::kBottom{9};
58 const LayoutUnit NGRelativeUtilsTest::kAuto{-1};
59 const LayoutUnit NGRelativeUtilsTest::kZero{0};
ikilpatrick 2017/03/21 17:51:17 these are all in the anon namespace? they can prob
atotic 2017/03/21 19:13:54 done I was worried that this might be prohibited
60
61 TEST_F(NGRelativeUtilsTest, HorizontalTB) {
62 NGLogicalOffset offset;
63
64 // Everything auto defaults to kZero,kZero
65 SetTRBL(kAuto, kAuto, kAuto, kAuto);
66 offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom,
67 TextDirection::kLtr, container_size_);
68 EXPECT_EQ(offset.inline_offset, kZero);
69 EXPECT_EQ(offset.block_offset, kZero);
70
71 // Set all sides
72 SetTRBL(kTop, kRight, kBottom, kLeft);
73
74 // kLtr
75 offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom,
76 TextDirection::kLtr, container_size_);
77 EXPECT_EQ(offset.inline_offset, kLeft);
78 EXPECT_EQ(offset.block_offset, kTop);
79
80 // kRtl
81 offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom,
82 TextDirection::kRtl, container_size_);
83 EXPECT_EQ(offset.inline_offset, kRight);
84 EXPECT_EQ(offset.block_offset, kTop);
85
86 // Set only non-default sides
87 SetTRBL(kAuto, kRight, kBottom, kAuto);
88 offset = ComputeRelativeOffset(*style_, kHorizontalTopBottom,
89 TextDirection::kLtr, container_size_);
90 EXPECT_EQ(offset.inline_offset, -kRight);
91 EXPECT_EQ(offset.block_offset, -kBottom);
92 }
93
94 TEST_F(NGRelativeUtilsTest, VerticalRightLeft) {
95 NGLogicalOffset offset;
96
97 // Set all sides
98 SetTRBL(kTop, kRight, kBottom, kLeft);
99
100 // kLtr
101 offset = ComputeRelativeOffset(*style_, kVerticalRightLeft,
102 TextDirection::kLtr, container_size_);
103 EXPECT_EQ(offset.inline_offset, kTop);
104 EXPECT_EQ(offset.block_offset, kRight);
105
106 // kRtl
107 offset = ComputeRelativeOffset(*style_, kVerticalRightLeft,
108 TextDirection::kRtl, container_size_);
109 EXPECT_EQ(offset.inline_offset, kBottom);
110 EXPECT_EQ(offset.block_offset, kRight);
111
112 // Set only non-default sides
113 SetTRBL(kAuto, kAuto, kBottom, kLeft);
114 offset = ComputeRelativeOffset(*style_, kVerticalRightLeft,
115 TextDirection::kLtr, container_size_);
116 EXPECT_EQ(offset.inline_offset, -kBottom);
117 EXPECT_EQ(offset.block_offset, -kLeft);
118 }
119
120 TEST_F(NGRelativeUtilsTest, VerticalLeftRight) {
121 NGLogicalOffset offset;
122
123 // Set all sides
124 SetTRBL(kTop, kRight, kBottom, kLeft);
125
126 // kLtr
127 offset = ComputeRelativeOffset(*style_, kVerticalLeftRight,
128 TextDirection::kLtr, container_size_);
129 EXPECT_EQ(offset.inline_offset, kTop);
130 EXPECT_EQ(offset.block_offset, kLeft);
131
132 // kRtl
133 offset = ComputeRelativeOffset(*style_, kVerticalLeftRight,
134 TextDirection::kRtl, container_size_);
135 EXPECT_EQ(offset.inline_offset, kBottom);
136 EXPECT_EQ(offset.block_offset, kLeft);
137
138 // Set only non-default sides
139 SetTRBL(kAuto, kRight, kBottom, kAuto);
140 offset = ComputeRelativeOffset(*style_, kVerticalLeftRight,
141 TextDirection::kLtr, container_size_);
142 EXPECT_EQ(offset.inline_offset, -kBottom);
143 EXPECT_EQ(offset.block_offset, -kRight);
144 }
145
146 } // namespace
147 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698