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

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

Issue 2723023003: Revert of [LayoutNG] Move remaining ng_units structs to their own files (Closed)
Patch Set: 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/layout/ng/ng_block_layout_algorithm.h" 5 #include "core/layout/ng/ng_block_layout_algorithm.h"
6 6
7 #include "core/dom/NodeComputedStyle.h" 7 #include "core/dom/NodeComputedStyle.h"
8 #include "core/dom/TagCollection.h" 8 #include "core/dom/TagCollection.h"
9 #include "core/layout/LayoutTestHelper.h" 9 #include "core/layout/LayoutTestHelper.h"
10 #include "core/layout/ng/layout_ng_block_flow.h" 10 #include "core/layout/ng/layout_ng_block_flow.h"
11 #include "core/layout/ng/ng_block_break_token.h" 11 #include "core/layout/ng/ng_block_break_token.h"
12 #include "core/layout/ng/ng_block_node.h" 12 #include "core/layout/ng/ng_block_node.h"
13 #include "core/layout/ng/ng_constraint_space.h" 13 #include "core/layout/ng/ng_constraint_space.h"
14 #include "core/layout/ng/ng_constraint_space_builder.h" 14 #include "core/layout/ng/ng_constraint_space_builder.h"
15 #include "core/layout/ng/ng_floating_object.h" 15 #include "core/layout/ng/ng_floating_object.h"
16 #include "core/layout/ng/ng_length_utils.h" 16 #include "core/layout/ng/ng_length_utils.h"
17 #include "core/layout/ng/ng_physical_box_fragment.h" 17 #include "core/layout/ng/ng_physical_box_fragment.h"
18 #include "core/layout/ng/ng_physical_fragment.h" 18 #include "core/layout/ng/ng_physical_fragment.h"
19 #include "core/layout/ng/ng_units.h"
19 #include "core/style/ComputedStyle.h" 20 #include "core/style/ComputedStyle.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 namespace blink { 24 namespace blink {
24 namespace { 25 namespace {
25 26
26 using testing::ElementsAre; 27 using testing::ElementsAre;
27 using testing::Pointee; 28 using testing::Pointee;
28 29
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 NGBlockNode* node = new NGBlockNode(block_flow); 88 NGBlockNode* node = new NGBlockNode(block_flow);
88 NGConstraintSpace* space = 89 NGConstraintSpace* space =
89 NGConstraintSpace::CreateFromLayoutObject(*block_flow); 90 NGConstraintSpace::CreateFromLayoutObject(*block_flow);
90 91
91 RefPtr<NGLayoutResult> result = 92 RefPtr<NGLayoutResult> result =
92 NGBlockLayoutAlgorithm(node, space).Layout(); 93 NGBlockLayoutAlgorithm(node, space).Layout();
93 return std::make_pair( 94 return std::make_pair(
94 toNGPhysicalBoxFragment(result->PhysicalFragment().get()), space); 95 toNGPhysicalBoxFragment(result->PhysicalFragment().get()), space);
95 } 96 }
96 97
97 MinMaxContentSize RunComputeMinAndMax(NGBlockNode* first_child) { 98 MinAndMaxContentSizes RunComputeMinAndMax(NGBlockNode* first_child) {
98 // The constraint space is not used for min/max computation, but we need 99 // The constraint space is not used for min/max computation, but we need
99 // it to create the algorithm. 100 // it to create the algorithm.
100 NGConstraintSpace* space = 101 NGConstraintSpace* space =
101 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, 102 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr,
102 NGLogicalSize(LayoutUnit(), LayoutUnit())); 103 NGLogicalSize(LayoutUnit(), LayoutUnit()));
103 NGBlockNode* node = new NGBlockNode(style_.get()); 104 NGBlockNode* node = new NGBlockNode(style_.get());
104 node->SetFirstChild(first_child); 105 node->SetFirstChild(first_child);
105 106
106 NGBlockLayoutAlgorithm algorithm(node, space); 107 NGBlockLayoutAlgorithm algorithm(node, space);
107 EXPECT_TRUE(algorithm.ComputeMinMaxContentSize().has_value()); 108 EXPECT_TRUE(algorithm.ComputeMinAndMaxContentSizes().has_value());
108 return *algorithm.ComputeMinMaxContentSize(); 109 return *algorithm.ComputeMinAndMaxContentSizes();
109 } 110 }
110 111
111 RefPtr<ComputedStyle> style_; 112 RefPtr<ComputedStyle> style_;
112 }; 113 };
113 114
114 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { 115 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) {
115 style_->setWidth(Length(30, Fixed)); 116 style_->setWidth(Length(30, Fixed));
116 style_->setHeight(Length(40, Fixed)); 117 style_->setHeight(Length(40, Fixed));
117 118
118 auto* space = ConstructConstraintSpace( 119 auto* space = ConstructConstraintSpace(
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 1294 RefPtr<ComputedStyle> first_style = ComputedStyle::create();
1294 first_style->setWidth(Length(kWidthChild1, Fixed)); 1295 first_style->setWidth(Length(kWidthChild1, Fixed));
1295 NGBlockNode* first_child = new NGBlockNode(first_style.get()); 1296 NGBlockNode* first_child = new NGBlockNode(first_style.get());
1296 1297
1297 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); 1298 RefPtr<ComputedStyle> second_style = ComputedStyle::create();
1298 second_style->setWidth(Length(kWidthChild2, Fixed)); 1299 second_style->setWidth(Length(kWidthChild2, Fixed));
1299 NGBlockNode* second_child = new NGBlockNode(second_style.get()); 1300 NGBlockNode* second_child = new NGBlockNode(second_style.get());
1300 1301
1301 first_child->SetNextSibling(second_child); 1302 first_child->SetNextSibling(second_child);
1302 1303
1303 MinMaxContentSize sizes = RunComputeMinAndMax(first_child); 1304 MinAndMaxContentSizes sizes = RunComputeMinAndMax(first_child);
1304 EXPECT_EQ(kWidthChild2, sizes.min_content); 1305 EXPECT_EQ(kWidthChild2, sizes.min_content);
1305 EXPECT_EQ(kWidthChild2, sizes.max_content); 1306 EXPECT_EQ(kWidthChild2, sizes.max_content);
1306 } 1307 }
1307 1308
1308 // Tests that we correctly handle shrink-to-fit 1309 // Tests that we correctly handle shrink-to-fit
1309 TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFit) { 1310 TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFit) {
1310 const int kWidthChild1 = 20; 1311 const int kWidthChild1 = 20;
1311 const int kWidthChild2 = 30; 1312 const int kWidthChild2 = 30;
1312 1313
1313 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 1314 RefPtr<ComputedStyle> first_style = ComputedStyle::create();
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2474 2475
2475 child = iterator.NextChild(); 2476 child = iterator.NextChild();
2476 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); 2477 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size());
2477 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset()); 2478 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset());
2478 2479
2479 EXPECT_FALSE(iterator.NextChild()); 2480 EXPECT_FALSE(iterator.NextChild());
2480 } 2481 }
2481 2482
2482 } // namespace 2483 } // namespace
2483 } // namespace blink 2484 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698