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

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

Issue 2399963002: [layoutng] margin: auto support (Closed)
Patch Set: one more test now passes! Created 4 years, 2 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_length_utils.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 41c576a89a94c6dbc49bf7de784b08b63f993a7a..568b7ffe75ec97a91303ae84cd93d4737a33d2de 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
@@ -5,6 +5,9 @@
#include "core/layout/ng/ng_length_utils.h"
#include "core/layout/ng/ng_constraint_space.h"
+#include "core/layout/ng/ng_fragment.h"
+#include "core/layout/ng/ng_fragment_builder.h"
+#include "core/layout/ng/ng_physical_fragment.h"
#include "core/layout/ng/ng_units.h"
#include "core/style/ComputedStyle.h"
#include "platform/CalculationValue.h"
@@ -273,5 +276,49 @@ TEST_F(NGLengthUtilsTest, testPadding) {
EXPECT_EQ(LayoutUnit(20), padding.inline_start);
}
+TEST_F(NGLengthUtilsTest, testAutoMargins) {
+ style_->setMarginRight(Length(Auto));
+ style_->setMarginLeft(Length(Auto));
+
+ NGFragmentBuilder builder(NGPhysicalFragmentBase::FragmentBox);
+ builder.SetInlineSize(LayoutUnit(150));
+ NGPhysicalFragment* physical_fragment = builder.ToFragment();
+ NGFragment* fragment =
+ new NGFragment(HorizontalTopBottom, LeftToRight, physical_fragment);
+
+ NGConstraintSpace* constraint_space(ConstructConstraintSpace(200, 300));
+
+ NGBoxStrut margins;
+ ApplyAutoMargins(*constraint_space, *style_, *fragment, margins);
+
+ EXPECT_EQ(LayoutUnit(), margins.block_start);
+ EXPECT_EQ(LayoutUnit(), margins.block_end);
+ EXPECT_EQ(LayoutUnit(25), margins.inline_start);
+ EXPECT_EQ(LayoutUnit(25), margins.inline_end);
+
+ style_->setMarginLeft(Length(0, Fixed));
+ margins = NGBoxStrut();
+ ApplyAutoMargins(*constraint_space, *style_, *fragment, margins);
+ EXPECT_EQ(LayoutUnit(0), margins.inline_start);
+ EXPECT_EQ(LayoutUnit(50), margins.inline_end);
+
+ style_->setMarginLeft(Length(Auto));
+ style_->setMarginRight(Length(0, Fixed));
+ margins = NGBoxStrut();
+ ApplyAutoMargins(*constraint_space, *style_, *fragment, margins);
+ EXPECT_EQ(LayoutUnit(50), margins.inline_start);
+ EXPECT_EQ(LayoutUnit(0), margins.inline_end);
+
+ // Test that we don't end up with negative "auto" margins when the box is too
+ // big.
+ style_->setMarginLeft(Length(Auto));
+ style_->setMarginRight(Length(5000, Fixed));
+ margins = NGBoxStrut();
+ margins.inline_end = LayoutUnit(5000);
+ ApplyAutoMargins(*constraint_space, *style_, *fragment, margins);
+ EXPECT_EQ(LayoutUnit(0), margins.inline_start);
+ EXPECT_EQ(LayoutUnit(5000), margins.inline_end);
+}
+
} // namespace
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_length_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698