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

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

Issue 2583063004: [layoutng] Add a function to compute the min- and max-content contribution (Closed)
Patch Set: include margins Created 4 years 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_length_utils_test.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_length_utils_test.cc b/third_party/WebKit/Source/core/layout/ng/ng_length_utils_test.cc
index d4bfe6956b45fd1ed99b78f346d868c530cbc9b4..29bd7c4134fd6bdcd81ef6068e80c616cbaae619 100644
--- a/third_party/WebKit/Source/core/layout/ng/ng_length_utils_test.cc
+++ b/third_party/WebKit/Source/core/layout/ng/ng_length_utils_test.cc
@@ -122,6 +122,77 @@ TEST_F(NGLengthUtilsTest, testResolveBlockLength) {
LengthResolveType::kContentSize));
}
+TEST_F(NGLengthUtilsTest, testComputeContentContribution) {
+ MinAndMaxContentSizes sizes;
+ sizes.min_content = LayoutUnit(30);
+ sizes.max_content = LayoutUnit(40);
+
+ MinAndMaxContentSizes expected{LayoutUnit(), LayoutUnit()};
+ style_->setLogicalWidth(Length(30, Percent));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+
+ style_->setLogicalWidth(Length(FillAvailable));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+
+ expected = MinAndMaxContentSizes{LayoutUnit(150), LayoutUnit(150)};
+ style_->setLogicalWidth(Length(150, Fixed));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+
+ expected = sizes;
+ style_->setLogicalWidth(Length(Auto));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+
+ expected = MinAndMaxContentSizes{LayoutUnit(430), LayoutUnit(440)};
+ style_->setPaddingLeft(Length(400, Fixed));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+
+ expected = MinAndMaxContentSizes{LayoutUnit(100), LayoutUnit(100)};
+ style_->setPaddingLeft(Length(0, Fixed));
+ style_->setLogicalWidth(Length(CalculationValue::create(
+ PixelsAndPercent(100, -10), ValueRangeNonNegative)));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+
+ expected = MinAndMaxContentSizes{LayoutUnit(30), LayoutUnit(35)};
+ style_->setLogicalWidth(Length(Auto));
+ style_->setMaxWidth(Length(35, Fixed));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+
+ expected = MinAndMaxContentSizes{LayoutUnit(80), LayoutUnit(80)};
+ style_->setLogicalWidth(Length(50, Fixed));
+ style_->setMinWidth(Length(80, Fixed));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+
+ expected = MinAndMaxContentSizes{LayoutUnit(150), LayoutUnit(150)};
+ style_ = ComputedStyle::create();
+ style_->setLogicalWidth(Length(100, Fixed));
+ style_->setPaddingLeft(Length(50, Fixed));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+
+ expected = MinAndMaxContentSizes{LayoutUnit(100), LayoutUnit(100)};
+ style_->setBoxSizing(BoxSizingBorderBox);
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+
+ // Content size should never be below zero, even with box-sizing: border-box
+ // and a large padding...
+ expected = MinAndMaxContentSizes{LayoutUnit(400), LayoutUnit(400)};
+ style_->setPaddingLeft(Length(400, Fixed));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+
+ expected.min_content = expected.max_content =
+ sizes.min_content + LayoutUnit(400);
+ style_->setLogicalWidth(Length(MinContent));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+ style_->setLogicalWidth(Length(100, Fixed));
+ style_->setMaxWidth(Length(MaxContent));
+ // Due to padding and box-sizing, width computes to 400px and max-width to
+ // 440px, so the result is 400.
+ expected = MinAndMaxContentSizes{LayoutUnit(400), LayoutUnit(400)};
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+ expected = MinAndMaxContentSizes{LayoutUnit(40), LayoutUnit(40)};
+ style_->setPaddingLeft(Length(0, Fixed));
+ EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
+}
+
TEST_F(NGLengthUtilsTest, testComputeInlineSizeForFragment) {
MinAndMaxContentSizes sizes;
sizes.min_content = LayoutUnit(30);
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_length_utils.cc ('k') | third_party/WebKit/Source/core/layout/ng/ng_units.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698