Chromium Code Reviews| Index: ui/gfx/geometry/size_unittest.cc |
| diff --git a/ui/gfx/geometry/size_unittest.cc b/ui/gfx/geometry/size_unittest.cc |
| index 16b1ddceaec9ed6b96e8bebc5c1173627edc7a7e..eb16d4aaa46bbf4b3538e99e6ec53fe219e3e8c6 100644 |
| --- a/ui/gfx/geometry/size_unittest.cc |
| +++ b/ui/gfx/geometry/size_unittest.cc |
| @@ -153,4 +153,84 @@ TEST(SizeTest, IntegerOverflow) { |
| EXPECT_EQ(test, min_size); |
| } |
| +// This checks that we set IsEmpty appropriately. |
| +TEST(SizeTest, TrivialDimensionTests) { |
| + // First, using the constructor. |
| + EXPECT_TRUE(SizeF(kTrivial / 2.f, 1.f).IsEmpty()); |
| + EXPECT_TRUE(SizeF(.01f, kTrivial / 2.f).IsEmpty()); |
| + EXPECT_TRUE(SizeF(0.f, 0.f).IsEmpty()); |
| + EXPECT_FALSE(SizeF(.01f, .01f).IsEmpty()); |
| + |
| + // Then use the setter. |
| + SizeF test(2.f, 1.f); |
| + EXPECT_FALSE(test.IsEmpty()); |
| + |
| + test.SetSize(kTrivial / 2.f, 1.f); |
| + EXPECT_TRUE(test.IsEmpty()); |
| + |
| + test.SetSize(.01f, kTrivial / 2.f); |
| + EXPECT_TRUE(test.IsEmpty()); |
| + |
| + test.SetSize(0.f, 0.f); |
| + EXPECT_TRUE(test.IsEmpty()); |
| + |
| + test.SetSize(.01f, .01f); |
| + EXPECT_FALSE(test.IsEmpty()); |
| + |
| + // Now just one dimension at a time. |
| + test.set_width(kTrivial / 2.f); |
| + EXPECT_TRUE(test.IsEmpty()); |
| + |
| + test.set_width(4e13f); |
| + test.set_height(kTrivial / 2.f); |
| + EXPECT_TRUE(test.IsEmpty()); |
| + |
| + test.set_width(kTrivial / 2.f); |
| + test.set_height(4e13f); |
| + EXPECT_TRUE(test.IsEmpty()); |
| + |
| + test.set_width(2.f); |
| + EXPECT_FALSE(test.IsEmpty()); |
| +} |
| + |
| +// These are the ramifications of the decision to keep the recorded size |
| +// at zero for trivial sizes. |
| +TEST(SizeTest, ClampsToZero) { |
| + SizeF test(kTrivial / 2.f, 1.f); |
| + |
| + EXPECT_EQ(test.width(), 0.f); |
| + EXPECT_EQ(test.height(), 1.f); |
| + |
| + test.SetSize(.01f, kTrivial / 2.f); |
| + |
| + EXPECT_EQ(test.width(), .01f); |
| + EXPECT_EQ(test.height(), 0.f); |
| + |
| + test.SetSize(kTrivial, kTrivial); |
| + test.Scale(0.5f); |
| + |
| + EXPECT_EQ(test.width(), 0.f); |
| + EXPECT_EQ(test.height(), 0.f); |
| + |
| + test.SetSize(0.f, 0.f); |
| + test.Enlarge(kTrivial / 2.f, kTrivial / 2.f); |
| + test.Enlarge(kTrivial / 2.f, kTrivial / 2.f); |
| + test.Enlarge(kTrivial / 2.f, kTrivial / 2.f); |
| + |
| + EXPECT_EQ(test, SizeF(0.f, 0.f)); |
| +} |
| + |
| +// These make sure the constructor and setter have the same effect on the |
| +// boundary case. This claims to know the boundary, but not which way it goes. |
| +TEST(SizeTest, ConsistentClamping) { |
| + SizeF left(kTrivial, 0.f); |
| + SizeF top(0.f, kTrivial); |
| + SizeF right, bottom; |
|
danakj
2017/03/23 20:12:06
Not sure that |right| and |bottom| express these,
Peter Mayo
2017/03/23 23:58:41
I have a better way I'll propose with the next edi
|
| + right.SetSize(kTrivial, 0.f); |
| + bottom.SetSize(0.f, kTrivial); |
| + |
| + EXPECT_EQ(left, right); |
| + EXPECT_EQ(top, bottom); |
| +} |
| + |
| } // namespace gfx |