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

Unified Diff: ui/gfx/geometry/size_unittest.cc

Issue 2749513011: Stabilize empty rect handling in EnclosingRect. (Closed)
Patch Set: Move kTrivial inside the class Created 3 years, 9 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
« ui/gfx/geometry/size_f.h ('K') | « ui/gfx/geometry/size_f.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b55200a681f27f714c9633b8f408c8c6c90f2cfb 100644
--- a/ui/gfx/geometry/size_unittest.cc
+++ b/ui/gfx/geometry/size_unittest.cc
@@ -153,4 +153,97 @@ TEST(SizeTest, IntegerOverflow) {
EXPECT_EQ(test, min_size);
}
+float SizeFPrivateMatch() {
+ return SizeF::kTrivial;
+};
+
+static float myTrivial = SizeFPrivateMatch() / 2.f;
danakj 2017/03/28 18:00:20 these names are all (old) blink style not chromium
Peter Mayo 2017/03/28 20:11:21 Done.
+static float boundaryTrivial = SizeFPrivateMatch();
+static float nearlyTrivial = SizeFPrivateMatch() * 1.5f;
+
+// This checks that we set IsEmpty appropriately.
+TEST(SizeTest, TrivialDimensionTests) {
+ // First, using the constructor.
+ EXPECT_TRUE(SizeF(myTrivial, 1.f).IsEmpty());
+ EXPECT_TRUE(SizeF(.01f, myTrivial).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(myTrivial, 1.f);
+ EXPECT_TRUE(test.IsEmpty());
+
+ test.SetSize(.01f, myTrivial);
+ 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(myTrivial);
+ EXPECT_TRUE(test.IsEmpty());
+
+ test.set_width(4e13f);
+ test.set_height(myTrivial);
+ EXPECT_TRUE(test.IsEmpty());
+
+ test.set_width(myTrivial);
+ 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(myTrivial, 1.f);
+
+ EXPECT_FLOAT_EQ(0.f, test.width());
+ EXPECT_FLOAT_EQ(1.f, test.height());
+
+ test.SetSize(.01f, myTrivial);
+
+ EXPECT_FLOAT_EQ(.01f, test.width());
+ EXPECT_FLOAT_EQ(0.f, test.height());
+
+ test.SetSize(nearlyTrivial, nearlyTrivial);
Peter Mayo 2017/03/28 20:11:21 Added an expectation here that validates nearly_tr
+ test.Scale(0.5f);
+
+ EXPECT_FLOAT_EQ(0.f, test.width());
+ EXPECT_FLOAT_EQ(0.f, test.height());
+
+ test.SetSize(0.f, 0.f);
+ test.Enlarge(myTrivial, myTrivial);
+ test.Enlarge(myTrivial, myTrivial);
+ test.Enlarge(myTrivial, myTrivial);
+
+ EXPECT_EQ(SizeF(0.f, 0.f), test);
+}
+
+// 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 resized;
+
+ resized.SetSize(boundaryTrivial, 0.f);
+ EXPECT_EQ(SizeF(boundaryTrivial, 0.f), resized);
+
+ resized.SetSize(0.f, boundaryTrivial);
+ EXPECT_EQ(SizeF(0.f, boundaryTrivial), resized);
+}
+
+// Let's make sure we don't unexpectedly grow the struct by adding constants.
+// Also, if some platform packs floats inefficiently, it would be worth noting.
+TEST(SizeTest, StaysSmall) {
+ EXPECT_EQ(2 * sizeof(float), sizeof(SizeF));
+}
+
} // namespace gfx
« ui/gfx/geometry/size_f.h ('K') | « ui/gfx/geometry/size_f.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698