| Index: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc
|
| diff --git a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc
|
| index 195b4b0a4bce9376fedcffa2aa5d7709c6723dfe..5ed0d130ff7c38a6e20e9781832690e6c399b3e8 100644
|
| --- a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc
|
| +++ b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc
|
| @@ -4,6 +4,8 @@
|
|
|
| #include "core/layout/ng/ng_block_layout_algorithm.h"
|
|
|
| +#include "core/dom/NodeComputedStyle.h"
|
| +#include "core/layout/ng/layout_ng_block_flow.h"
|
| #include "core/layout/ng/ng_block_node.h"
|
| #include "core/layout/ng/ng_constraint_space.h"
|
| #include "core/layout/ng/ng_constraint_space_builder.h"
|
| @@ -12,7 +14,10 @@
|
| #include "core/layout/ng/ng_layout_coordinator.h"
|
| #include "core/layout/ng/ng_length_utils.h"
|
| #include "core/layout/ng/ng_units.h"
|
| +#include "core/layout/LayoutTestHelper.h"
|
| #include "core/style/ComputedStyle.h"
|
| +#include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
|
| +#include "platform/testing/UnitTestHelpers.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace blink {
|
| @@ -28,9 +33,31 @@ NGConstraintSpace* ConstructConstraintSpace(NGWritingMode writing_mode,
|
| .ToConstraintSpace();
|
| }
|
|
|
| -class NGBlockLayoutAlgorithmTest : public ::testing::Test {
|
| +typedef bool TestParamLayoutNG;
|
| +class NGBlockLayoutAlgorithmTest
|
| + : public ::testing::WithParamInterface<TestParamLayoutNG>,
|
| + private ScopedLayoutNGForTest,
|
| + public RenderingTest {
|
| + public:
|
| + NGBlockLayoutAlgorithmTest() : ScopedLayoutNGForTest(true) {}
|
| +
|
| + // TODO(glebl): Should be shared between other Layout NG tests.
|
| + void LoadTestData(const char* fileName) {
|
| + String fullPath = testing::blinkRootDir();
|
| + fullPath.append("/Source/core/layout/ng/test_data/");
|
| + fullPath.append(fileName);
|
| + RefPtr<SharedBuffer> inputBuffer = testing::readFromFile(fullPath);
|
| + setBodyInnerHTML(String(inputBuffer->data(), inputBuffer->size()));
|
| + }
|
| +
|
| protected:
|
| - void SetUp() override { style_ = ComputedStyle::create(); }
|
| + void SetUp() override {
|
| + style_ = ComputedStyle::create();
|
| + RenderingTest::SetUp();
|
| + enableCompositing();
|
| + }
|
| +
|
| + void TearDown() override { RenderingTest::TearDown(); }
|
|
|
| NGPhysicalFragment* RunBlockLayoutAlgorithm(NGConstraintSpace* space,
|
| NGBlockNode* first_child) {
|
| @@ -147,51 +174,27 @@ TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildrenWithWritingMode) {
|
|
|
| // Verifies the collapsing margins case for the next pair:
|
| // - top margin of a box and top margin of its first in-flow child.
|
| -//
|
| -// Test case's HTML representation:
|
| -// <div style="margin-top: 20px; height: 50px;"> <!-- DIV1 -->
|
| -// <div style="margin-top: 10px"></div> <!-- DIV2 -->
|
| -// </div>
|
| -//
|
| -// Expected:
|
| -// - Empty margin strut of the fragment that establishes new formatting context
|
| -// - Margins are collapsed resulting a single margin 20px = max(20px, 10px)
|
| -// - The top offset of DIV2 == 20px
|
| TEST_F(NGBlockLayoutAlgorithmTest, CollapsingMarginsCase1) {
|
| - const int kHeight = 50;
|
| - const int kDiv1MarginTop = 20;
|
| - const int kDiv2MarginTop = 10;
|
| -
|
| - // DIV1
|
| - RefPtr<ComputedStyle> div1_style = ComputedStyle::create();
|
| - div1_style->setHeight(Length(kHeight, Fixed));
|
| - div1_style->setMarginTop(Length(kDiv1MarginTop, Fixed));
|
| - NGBlockNode* div1 = new NGBlockNode(div1_style.get());
|
| -
|
| - // DIV2
|
| - RefPtr<ComputedStyle> div2_style = ComputedStyle::create();
|
| - div2_style->setMarginTop(Length(kDiv2MarginTop, Fixed));
|
| - NGBlockNode* div2 = new NGBlockNode(div2_style.get());
|
| -
|
| - div1->SetFirstChild(div2);
|
| -
|
| - auto* space =
|
| - NGConstraintSpaceBuilder(kHorizontalTopBottom)
|
| - .SetAvailableSize(NGLogicalSize(LayoutUnit(100), NGSizeIndefinite))
|
| - .SetPercentageResolutionSize(
|
| - NGLogicalSize(LayoutUnit(100), NGSizeIndefinite))
|
| - .SetTextDirection(LTR)
|
| - .SetIsNewFormattingContext(true)
|
| - .ToConstraintSpace();
|
| - NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(space, div1);
|
| -
|
| - EXPECT_TRUE(frag->MarginStrut().IsEmpty());
|
| - ASSERT_EQ(frag->Children().size(), 1UL);
|
| - const NGPhysicalFragment* div2_fragment =
|
| - static_cast<const NGPhysicalFragment*>(frag->Children()[0].get());
|
| - EXPECT_EQ(NGMarginStrut({LayoutUnit(kDiv2MarginTop)}),
|
| - div2_fragment->MarginStrut());
|
| - EXPECT_EQ(kDiv1MarginTop, div2_fragment->TopOffset());
|
| + LoadTestData("margins_collapse1.html");
|
| +
|
| + Element* container = document().getElementById("container");
|
| + auto* container_style = container->computedStyle();
|
| + Element* first_child = document().getElementById("firstChild");
|
| + auto* first_child_style = first_child->computedStyle();
|
| +
|
| + EXPECT_EQ(first_child->offsetTop(),
|
| + std::max(container_style->marginTop().intValue(),
|
| + first_child_style->marginTop().intValue()));
|
| +
|
| + // Test LayoutNG specific.
|
| + LayoutNGBlockFlow* block_flow =
|
| + toLayoutNGBlockFlow(container->layoutObject());
|
| + NGConstraintSpace* space =
|
| + NGConstraintSpace::CreateFromLayoutObject(*block_flow);
|
| +
|
| + NGPhysicalFragment* frag = RunBlockLayoutAlgorithm(
|
| + space, new NGBlockNode(container->layoutObject()->slowFirstChild()));
|
| + EXPECT_EQ(NGMarginStrut({LayoutUnit(20)}), frag->MarginStrut());
|
| }
|
|
|
| // Verifies the collapsing margins case for the next pair:
|
|
|