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

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

Issue 2291273002: [layoutng] Allow testing NGBox without a LayoutObject (Closed)
Patch Set: fix bad merge -- private: was duplicated Created 4 years, 4 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_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 f239f14719b25fa815b681e07e8f88faa541f101..7b21fa5f0e42c366d8d8beceffe805e7682c87fa 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
@@ -35,5 +35,48 @@ TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) {
EXPECT_EQ(frag->Height(), LayoutUnit(40));
}
+// Verifies that two children are laid out with the correct size and position.
+TEST_F(NGBlockLayoutAlgorithmTest, LayoutBlockChildren) {
+ const int kWidth = 30;
+ const int kHeight1 = 20;
+ const int kHeight2 = 30;
+ const int kMarginTop = 5;
+ const int kMarginBottom = 20;
+ style_->setWidth(Length(kWidth, Fixed));
+
+ NGConstraintSpace* space = new NGConstraintSpace(
+ HorizontalTopBottom, NGLogicalSize(LayoutUnit(100), NGSizeIndefinite));
+
+ RefPtr<ComputedStyle> first_style = ComputedStyle::create();
+ first_style->setHeight(Length(kHeight1, Fixed));
+ NGBox* first_child = new NGBox(first_style.get());
+
+ RefPtr<ComputedStyle> second_style = ComputedStyle::create();
+ second_style->setHeight(Length(kHeight2, Fixed));
+ second_style->setMarginTop(Length(kMarginTop, Fixed));
+ second_style->setMarginBottom(Length(kMarginBottom, Fixed));
+ NGBox* second_child = new NGBox(second_style.get());
+
+ first_child->SetNextSibling(second_child);
+
+ NGBlockLayoutAlgorithm algorithm(style_, first_child);
+ NGPhysicalFragment* frag;
+ while (!algorithm.Layout(space, &frag))
+ ;
+ EXPECT_EQ(frag->Width(), LayoutUnit(kWidth));
+ EXPECT_EQ(frag->Height(),
+ LayoutUnit(kHeight1 + kHeight2 + kMarginTop + kMarginBottom));
+ EXPECT_EQ(frag->Type(), NGPhysicalFragmentBase::FragmentBox);
+ ASSERT_EQ(frag->Children().size(), 2UL);
+
+ const NGPhysicalFragmentBase* child = frag->Children()[0];
+ EXPECT_EQ(child->Height(), kHeight1);
+ EXPECT_EQ(child->TopOffset(), 0);
+
+ child = frag->Children()[1];
+ EXPECT_EQ(child->Height(), kHeight2);
+ EXPECT_EQ(child->TopOffset(), kHeight1 + kMarginTop);
+}
+
} // namespace
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698