diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/core/layout/ng/ng_length_utils_test.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/core/layout/ng/ng_length_utils_test.cc | 104 |
1 files changed, 53 insertions, 51 deletions
diff --git a/chromium/third_party/blink/renderer/core/layout/ng/ng_length_utils_test.cc b/chromium/third_party/blink/renderer/core/layout/ng/ng_length_utils_test.cc index f374f55a0cb..1c88961a155 100644 --- a/chromium/third_party/blink/renderer/core/layout/ng/ng_length_utils_test.cc +++ b/chromium/third_party/blink/renderer/core/layout/ng/ng_length_utils_test.cc @@ -111,15 +111,16 @@ class NGLengthUtilsTestWithNode : public NGLayoutTest { LayoutUnit ComputeBlockSizeForFragment( NGConstraintSpace constraint_space = ConstructConstraintSpace(200, 300), - LayoutUnit content_size = LayoutUnit()) { + LayoutUnit content_size = LayoutUnit(), + base::Optional<LayoutUnit> inline_size = base::nullopt) { LayoutBox* body = ToLayoutBox(GetDocument().body()->GetLayoutObject()); body->SetStyle(style_); body->SetIntrinsicLogicalWidthsDirty(); NGBoxStrut border_padding = ComputeBordersForTest(*style_) + ComputePadding(constraint_space, *style_); - return ::blink::ComputeBlockSizeForFragment(constraint_space, *style_, - border_padding, content_size); + return ::blink::ComputeBlockSizeForFragment( + constraint_space, *style_, border_padding, content_size, inline_size); } scoped_refptr<ComputedStyle> style_; @@ -172,107 +173,87 @@ TEST_F(NGLengthUtilsTest, testComputeContentContribution) { sizes.min_size = LayoutUnit(30); sizes.max_size = LayoutUnit(40); - NGBoxStrut border_padding; - MinMaxSizes expected = sizes; style_->SetLogicalWidth(Length::Percent(30)); - EXPECT_EQ(expected, - ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding, sizes)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes)); style_->SetLogicalWidth(Length::FillAvailable()); - EXPECT_EQ(expected, - ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding, sizes)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes)); expected = MinMaxSizes{LayoutUnit(150), LayoutUnit(150)}; style_->SetLogicalWidth(Length::Fixed(150)); - EXPECT_EQ(expected, - ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding, sizes)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes)); expected = sizes; style_->SetLogicalWidth(Length::Auto()); - EXPECT_EQ(expected, - ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding, sizes)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes)); expected = MinMaxSizes{LayoutUnit(430), LayoutUnit(440)}; style_->SetPaddingLeft(Length::Fixed(400)); auto sizes_padding400 = sizes; sizes_padding400 += LayoutUnit(400); - NGBoxStrut border_padding400 = {LayoutUnit(400), LayoutUnit(), LayoutUnit(), - LayoutUnit()}; - EXPECT_EQ(expected, ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding400, - sizes_padding400)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes_padding400)); expected = MinMaxSizes{LayoutUnit(30), LayoutUnit(40)}; style_->SetPaddingLeft(Length::Fixed(0)); style_->SetLogicalWidth(Length(CalculationValue::Create( PixelsAndPercent(100, -10), kValueRangeNonNegative))); - EXPECT_EQ(expected, - ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding, sizes)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes)); expected = MinMaxSizes{LayoutUnit(30), LayoutUnit(35)}; style_->SetLogicalWidth(Length::Auto()); style_->SetMaxWidth(Length::Fixed(35)); - EXPECT_EQ(expected, - ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding, sizes)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes)); expected = MinMaxSizes{LayoutUnit(80), LayoutUnit(80)}; style_->SetLogicalWidth(Length::Fixed(50)); style_->SetMinWidth(Length::Fixed(80)); - EXPECT_EQ(expected, - ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding, sizes)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes)); expected = MinMaxSizes{LayoutUnit(150), LayoutUnit(150)}; style_ = ComputedStyle::Create(); style_->SetLogicalWidth(Length::Fixed(100)); style_->SetPaddingLeft(Length::Fixed(50)); auto sizes_padding50 = sizes; - NGBoxStrut border_padding50 = {LayoutUnit(50), LayoutUnit(), LayoutUnit(), - LayoutUnit()}; sizes_padding50 += LayoutUnit(50); - EXPECT_EQ(expected, ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding50, - sizes_padding50)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes_padding50)); expected = MinMaxSizes{LayoutUnit(100), LayoutUnit(100)}; style_->SetBoxSizing(EBoxSizing::kBorderBox); - EXPECT_EQ(expected, ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding50, - sizes_padding50)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes_padding50)); // Content size should never be below zero, even with box-sizing: border-box // and a large padding... expected = MinMaxSizes{LayoutUnit(400), LayoutUnit(400)}; style_->SetPaddingLeft(Length::Fixed(400)); - EXPECT_EQ(expected, ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding400, - sizes_padding400)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes_padding400)); expected.min_size = expected.max_size = sizes.min_size + LayoutUnit(400); style_->SetLogicalWidth(Length::MinContent()); - EXPECT_EQ(expected, ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding400, - sizes_padding400)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes_padding400)); style_->SetLogicalWidth(Length::Fixed(100)); 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 = MinMaxSizes{LayoutUnit(400), LayoutUnit(400)}; - EXPECT_EQ(expected, ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding400, - sizes_padding400)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes_padding400)); expected = MinMaxSizes{LayoutUnit(40), LayoutUnit(40)}; style_->SetPaddingLeft(Length::Fixed(0)); - EXPECT_EQ(expected, - ComputeMinAndMaxContentContribution( - style_->GetWritingMode(), *style_, border_padding, sizes)); + EXPECT_EQ(expected, ComputeMinAndMaxContentContributionForTest( + style_->GetWritingMode(), *style_, sizes)); } TEST_F(NGLengthUtilsTestWithNode, testComputeInlineSizeForFragment) { @@ -401,6 +382,27 @@ TEST_F(NGLengthUtilsTestWithNode, testComputeBlockSizeForFragment) { style_->SetLogicalHeight(Length::FillAvailable()); EXPECT_EQ(LayoutUnit(400), ComputeBlockSizeForFragment()); + // Now check aspect-ratio. + style_ = ComputedStyle::Create(); + style_->SetLogicalWidth(Length::Fixed(100)); + style_->SetAspectRatio(IntSize(2, 1)); + EXPECT_EQ(LayoutUnit(50), + ComputeBlockSizeForFragment(ConstructConstraintSpace(200, 300), + LayoutUnit(), LayoutUnit(100))); + + // Default box-sizing + style_->SetPaddingRight(Length::Fixed(10)); + style_->SetPaddingBottom(Length::Fixed(20)); + // Should be (100 - 10) / 2 + 20 = 65. + EXPECT_EQ(LayoutUnit(65), + ComputeBlockSizeForFragment(ConstructConstraintSpace(200, 300), + LayoutUnit(20), LayoutUnit(100))); + // With box-sizing: border-box, should be 50. + style_->SetBoxSizing(EBoxSizing::kBorderBox); + EXPECT_EQ(LayoutUnit(50), + ComputeBlockSizeForFragment(ConstructConstraintSpace(200, 300), + LayoutUnit(20), LayoutUnit(100))); + // TODO(layout-ng): test {min,max}-content on max-height. } |