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

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

Issue 2755733003: Implement relative utilities (Closed)
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_relative_utils.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a618534f83da75886d3bd1f17dd4aa27bb793205
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/ng/ng_relative_utils_test.cc
@@ -0,0 +1,135 @@
+// Copyright 2017 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_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 {
+
+const LayoutUnit kInlineSize{100};
+const LayoutUnit kBlockSize{200};
+const LayoutUnit kLeft{3};
+const LayoutUnit kRight{5};
+const LayoutUnit kTop{7};
+const LayoutUnit kBottom{9};
+const LayoutUnit kAuto{-1};
+const LayoutUnit kZero{0};
+
+class NGRelativeUtilsTest : public ::testing::Test {
+ 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_;
+};
+
+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
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_relative_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698