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

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

Issue 2721613003: [LayoutNG] Move remaining ng_units structs to their own files (Closed)
Patch Set: Don't export NGBoxStrut for now 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"
20 #include "core/style/ComputedStyle.h" 19 #include "core/style/ComputedStyle.h"
21 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
23 22
24 namespace blink { 23 namespace blink {
25 namespace { 24 namespace {
26 25
27 using testing::ElementsAre; 26 using testing::ElementsAre;
28 using testing::Pointee; 27 using testing::Pointee;
29 28
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 NGBlockNode* node = new NGBlockNode(block_flow); 87 NGBlockNode* node = new NGBlockNode(block_flow);
89 NGConstraintSpace* space = 88 NGConstraintSpace* space =
90 NGConstraintSpace::CreateFromLayoutObject(*block_flow); 89 NGConstraintSpace::CreateFromLayoutObject(*block_flow);
91 90
92 RefPtr<NGLayoutResult> result = 91 RefPtr<NGLayoutResult> result =
93 NGBlockLayoutAlgorithm(node, space).Layout(); 92 NGBlockLayoutAlgorithm(node, space).Layout();
94 return std::make_pair( 93 return std::make_pair(
95 toNGPhysicalBoxFragment(result->PhysicalFragment().get()), space); 94 toNGPhysicalBoxFragment(result->PhysicalFragment().get()), space);
96 } 95 }
97 96
98 MinAndMaxContentSizes RunComputeMinAndMax(NGBlockNode* first_child) { 97 MinMaxContentSize RunComputeMinAndMax(NGBlockNode* first_child) {
99 // The constraint space is not used for min/max computation, but we need 98 // The constraint space is not used for min/max computation, but we need
100 // it to create the algorithm. 99 // it to create the algorithm.
101 NGConstraintSpace* space = 100 NGConstraintSpace* space =
102 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, 101 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr,
103 NGLogicalSize(LayoutUnit(), LayoutUnit())); 102 NGLogicalSize(LayoutUnit(), LayoutUnit()));
104 NGBlockNode* node = new NGBlockNode(style_.get()); 103 NGBlockNode* node = new NGBlockNode(style_.get());
105 node->SetFirstChild(first_child); 104 node->SetFirstChild(first_child);
106 105
107 NGBlockLayoutAlgorithm algorithm(node, space); 106 NGBlockLayoutAlgorithm algorithm(node, space);
108 EXPECT_TRUE(algorithm.ComputeMinAndMaxContentSizes().has_value()); 107 EXPECT_TRUE(algorithm.ComputeMinMaxContentSize().has_value());
109 return *algorithm.ComputeMinAndMaxContentSizes(); 108 return *algorithm.ComputeMinMaxContentSize();
110 } 109 }
111 110
112 RefPtr<ComputedStyle> style_; 111 RefPtr<ComputedStyle> style_;
113 }; 112 };
114 113
115 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { 114 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) {
116 style_->setWidth(Length(30, Fixed)); 115 style_->setWidth(Length(30, Fixed));
117 style_->setHeight(Length(40, Fixed)); 116 style_->setHeight(Length(40, Fixed));
118 117
119 auto* space = ConstructConstraintSpace( 118 auto* space = ConstructConstraintSpace(
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 1293 RefPtr<ComputedStyle> first_style = ComputedStyle::create();
1295 first_style->setWidth(Length(kWidthChild1, Fixed)); 1294 first_style->setWidth(Length(kWidthChild1, Fixed));
1296 NGBlockNode* first_child = new NGBlockNode(first_style.get()); 1295 NGBlockNode* first_child = new NGBlockNode(first_style.get());
1297 1296
1298 RefPtr<ComputedStyle> second_style = ComputedStyle::create(); 1297 RefPtr<ComputedStyle> second_style = ComputedStyle::create();
1299 second_style->setWidth(Length(kWidthChild2, Fixed)); 1298 second_style->setWidth(Length(kWidthChild2, Fixed));
1300 NGBlockNode* second_child = new NGBlockNode(second_style.get()); 1299 NGBlockNode* second_child = new NGBlockNode(second_style.get());
1301 1300
1302 first_child->SetNextSibling(second_child); 1301 first_child->SetNextSibling(second_child);
1303 1302
1304 MinAndMaxContentSizes sizes = RunComputeMinAndMax(first_child); 1303 MinMaxContentSize sizes = RunComputeMinAndMax(first_child);
1305 EXPECT_EQ(kWidthChild2, sizes.min_content); 1304 EXPECT_EQ(kWidthChild2, sizes.min_content);
1306 EXPECT_EQ(kWidthChild2, sizes.max_content); 1305 EXPECT_EQ(kWidthChild2, sizes.max_content);
1307 } 1306 }
1308 1307
1309 // Tests that we correctly handle shrink-to-fit 1308 // Tests that we correctly handle shrink-to-fit
1310 TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFit) { 1309 TEST_F(NGBlockLayoutAlgorithmTest, ShrinkToFit) {
1311 const int kWidthChild1 = 20; 1310 const int kWidthChild1 = 20;
1312 const int kWidthChild2 = 30; 1311 const int kWidthChild2 = 30;
1313 1312
1314 RefPtr<ComputedStyle> first_style = ComputedStyle::create(); 1313 RefPtr<ComputedStyle> first_style = ComputedStyle::create();
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 2474
2476 child = iterator.NextChild(); 2475 child = iterator.NextChild();
2477 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); 2476 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size());
2478 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset()); 2477 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset());
2479 2478
2480 EXPECT_FALSE(iterator.NextChild()); 2479 EXPECT_FALSE(iterator.NextChild());
2481 } 2480 }
2482 2481
2483 } // namespace 2482 } // namespace
2484 } // namespace blink 2483 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698