mapRect should not fiddle with nonfinite values.

Docs-Preview: https://skia.org/?cl=128682
Bug: skia:7967
Change-Id: Ic43387b7705ee8385b8df2430886484ff856077c
Reviewed-on: https://skia-review.googlesource.com/128682
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/tests/RectTest.cpp b/tests/RectTest.cpp
index d34214d..7d2601a 100644
--- a/tests/RectTest.cpp
+++ b/tests/RectTest.cpp
@@ -113,3 +113,29 @@
     REPORTER_ASSERT(reporter,  SkRectPriv::MakeLargestInverted().isEmpty());
 }
 
+/*
+ *  Test the setBounds always handles non-finite values correctly:
+ *  - setBoundsCheck should return false, and set the rect to all zeros
+ *  - setBoundsNoCheck should ensure that rect.isFinite() is false (definitely NOT all zeros)
+ */
+DEF_TEST(Rect_setbounds, reporter) {
+    const SkPoint p0[] = { { SK_ScalarInfinity, 0 }, { 1, 1 }, { 2, 2 }, { 3, 3 } };
+    const SkPoint p1[] = { { 0, SK_ScalarInfinity }, { 1, 1 }, { 2, 2 }, { 3, 3 } };
+    const SkPoint p2[] = { { SK_ScalarNaN, 0 }, { 1, 1 }, { 2, 2 }, { 3, 3 } };
+    const SkPoint p3[] = { { 0, SK_ScalarNaN }, { 1, 1 }, { 2, 2 }, { 3, 3 } };
+
+    SkRect r;
+    const SkRect zeror = { 0, 0, 0, 0 };
+    for (const SkPoint* pts : { p0, p1, p2, p3 }) {
+        for (int n = 1; n <= 4; ++n) {
+            bool isfinite = r.setBoundsCheck(pts, n);
+            REPORTER_ASSERT(reporter, !isfinite);
+            REPORTER_ASSERT(reporter, r == zeror);
+
+            r.setBoundsNoCheck(pts, n);
+            if (r.isFinite())
+                r.setBoundsNoCheck(pts, n);
+            REPORTER_ASSERT(reporter, !r.isFinite());
+        }
+    }
+}