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

Unified Diff: ui/gfx/skrect_conversion_unittest.cc

Issue 2231243002: Use CheckedNumeric when converting SkIRect to gfx::Rect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: handle the negative case; add more comments and unit tests Created 4 years, 4 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 | « ui/gfx/skia_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/skrect_conversion_unittest.cc
diff --git a/ui/gfx/skrect_conversion_unittest.cc b/ui/gfx/skrect_conversion_unittest.cc
index 7fe0c835cfe644ed97e8c992d21459d556e91c7e..f9c05c04589fb1506e3d8be70f3253105c73790e 100644
--- a/ui/gfx/skrect_conversion_unittest.cc
+++ b/ui/gfx/skrect_conversion_unittest.cc
@@ -22,4 +22,27 @@ TEST(RectTest, SkiaRectConversions) {
EXPECT_EQ(fsrc.ToString(), SkRectToRectF(skrect).ToString());
}
+TEST(RectTest, SkIRectToRectClamping) {
+ // This clamping only makes sense if SkIRect and gfx::Rect have the same size.
+ // Otherwise, either other overflows can occur that we don't handle, or no
+ // overflows can ocur.
+ if (sizeof(int) != sizeof(int32_t))
+ return;
+ using Limits = std::numeric_limits<int>;
+
+ // right-left and bottom-top would overflow.
+ // These should be mapped to max width/height, which is as close as gfx::Rect
+ // can represent.
+ EXPECT_EQ(
+ gfx::Rect(Limits::min(), Limits::min(), Limits::max(), Limits::max()),
+ SkIRectToRect(SkIRect::MakeLTRB(Limits::min(), Limits::min(),
+ Limits::max(), Limits::max())));
+
+ // right-left and bottom-top would underflow.
+ // These should be mapped to zero, like all negative values.
+ EXPECT_EQ(gfx::Rect(Limits::max(), Limits::max(), 0, 0),
+ SkIRectToRect(SkIRect::MakeLTRB(Limits::max(), Limits::max(),
+ Limits::min(), Limits::min())));
+}
+
} // namespace gfx
« no previous file with comments | « ui/gfx/skia_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698