OLD | NEW |
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_absolute_utils.h" | 5 #include "core/layout/ng/ng_absolute_utils.h" |
6 | 6 |
7 #include "core/layout/ng/ng_constraint_space_builder.h" | 7 #include "core/layout/ng/ng_constraint_space_builder.h" |
8 #include "core/layout/ng/ng_length_utils.h" | 8 #include "core/layout/ng/ng_length_utils.h" |
9 #include "core/style/ComputedStyle.h" | 9 #include "core/style/ComputedStyle.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 | 416 |
417 // Rule 6: height is unknown. | 417 // Rule 6: height is unknown. |
418 SetVerticalStyle(top, margin_top, NGAuto, margin_bottom, bottom); | 418 SetVerticalStyle(top, margin_top, NGAuto, margin_bottom, bottom); |
419 EXPECT_EQ(AbsoluteNeedsChildBlockSize(*style_), false); | 419 EXPECT_EQ(AbsoluteNeedsChildBlockSize(*style_), false); |
420 auto_height.reset(); | 420 auto_height.reset(); |
421 ComputeFullAbsoluteWithChildBlockSize(*ltr_space_, *style_, static_position, | 421 ComputeFullAbsoluteWithChildBlockSize(*ltr_space_, *style_, static_position, |
422 auto_height, &p); | 422 auto_height, &p); |
423 EXPECT_EQ(height, p.size.height); | 423 EXPECT_EQ(height, p.size.height); |
424 } | 424 } |
425 | 425 |
| 426 TEST_F(NGAbsoluteUtilsTest, MinMax) { |
| 427 LayoutUnit min{50}; |
| 428 LayoutUnit max{150}; |
| 429 |
| 430 style_->setMinWidth(Length(min.toInt(), LengthType::Fixed)); |
| 431 style_->setMaxWidth(Length(max.toInt(), LengthType::Fixed)); |
| 432 style_->setMinHeight(Length(min.toInt(), LengthType::Fixed)); |
| 433 style_->setMaxHeight(Length(max.toInt(), LengthType::Fixed)); |
| 434 |
| 435 NGStaticPosition static_position{NGStaticPosition::kTopLeft, |
| 436 {LayoutUnit(), LayoutUnit()}}; |
| 437 MinAndMaxContentSizes estimated_inline{LayoutUnit(20), LayoutUnit(20)}; |
| 438 NGAbsolutePhysicalPosition p; |
| 439 |
| 440 // WIDTH TESTS |
| 441 |
| 442 // width < min gets set to min. |
| 443 SetHorizontalStyle(NGAuto, NGAuto, LayoutUnit(5), NGAuto, NGAuto); |
| 444 p = ComputePartialAbsoluteWithChildInlineSize( |
| 445 *ltr_space_, *style_, static_position, estimated_inline); |
| 446 EXPECT_EQ(min, p.size.width); |
| 447 |
| 448 // width > max gets set to max. |
| 449 SetHorizontalStyle(NGAuto, NGAuto, LayoutUnit(200), NGAuto, NGAuto); |
| 450 p = ComputePartialAbsoluteWithChildInlineSize( |
| 451 *ltr_space_, *style_, static_position, estimated_inline); |
| 452 EXPECT_EQ(max, p.size.width); |
| 453 |
| 454 // Unspecified width becomes minmax, gets clamped to min. |
| 455 SetHorizontalStyle(NGAuto, NGAuto, NGAuto, NGAuto, NGAuto); |
| 456 p = ComputePartialAbsoluteWithChildInlineSize( |
| 457 *ltr_space_, *style_, static_position, estimated_inline); |
| 458 EXPECT_EQ(min, p.size.width); |
| 459 |
| 460 // HEIGHT TESTS |
| 461 |
| 462 Optional<LayoutUnit> auto_height; |
| 463 |
| 464 // height < min gets set to min. |
| 465 SetVerticalStyle(NGAuto, NGAuto, LayoutUnit(5), NGAuto, NGAuto); |
| 466 ComputeFullAbsoluteWithChildBlockSize(*ltr_space_, *style_, static_position, |
| 467 auto_height, &p); |
| 468 EXPECT_EQ(min, p.size.height); |
| 469 |
| 470 // height > max gets set to max. |
| 471 SetVerticalStyle(NGAuto, NGAuto, LayoutUnit(200), NGAuto, NGAuto); |
| 472 ComputeFullAbsoluteWithChildBlockSize(*ltr_space_, *style_, static_position, |
| 473 auto_height, &p); |
| 474 EXPECT_EQ(max, p.size.height); |
| 475 |
| 476 // // Unspecified height becomes estimated, gets clamped to min. |
| 477 SetVerticalStyle(NGAuto, NGAuto, NGAuto, NGAuto, NGAuto); |
| 478 auto_height = LayoutUnit(20); |
| 479 ComputeFullAbsoluteWithChildBlockSize(*ltr_space_, *style_, static_position, |
| 480 auto_height, &p); |
| 481 EXPECT_EQ(min, p.size.width); |
| 482 } |
| 483 |
426 } // namespace | 484 } // namespace |
427 } // namespace blink | 485 } // namespace blink |
OLD | NEW |