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

Unified 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 side-by-side diff with in-line comments
Download patch
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..f1141e6eddef1c64fa343ae7768625d4aaa479b5
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/ng/ng_relative_utils_test.cc
@@ -0,0 +1,147 @@
+// 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 {
+
+//#define NGAuto LayoutUnit(-1)
ikilpatrick 2017/03/21 17:51:17 ?
atotic 2017/03/21 19:13:54 gone
+
+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};
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
+
+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

Powered by Google App Engine
This is Rietveld 408576698