Index: webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc |
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d0a46efc7e0c8009f515dab994f76fbb10cbf4b8 |
--- /dev/null |
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc |
@@ -0,0 +1,46 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/basictypes.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/gfx/rect.h" |
+#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
+ |
+TEST(PpapiGraphics2DImplTest, ScaleRectBounds) { |
+ static const struct { |
+ int x1; |
+ int y1; |
+ int w1; |
+ int h1; |
+ int x2; |
+ int y2; |
+ int w2; |
+ int h2; |
+ float scale; |
+ } tests[] = { |
+ { 0, 0, 0, 0, 0, 0, 0, 0, 1.0 }, |
+ { 0, 0, 0, 0, 0, 0, 0, 0, 2.0 }, |
+ { 0, 0, 4, 4, 0, 0, 2, 2, 0.5 }, |
+ { 1, 1, 4, 4, 0, 0, 3, 3, 0.5 }, |
+ { 53, 75, 100, 100, 53, 75, 100, 100, 1.0 }, |
+ { 53, 75, 100, 100, 106, 150, 200, 200, 2.0 }, |
+ { 53, 75, 100, 100, 26, 37, 51, 51, 0.5 }, |
+ { 53, 74, 100, 100, 26, 37, 51, 50, 0.5 }, |
+ { -1, -1, 100, 100, -1, -1, 51, 51, 0.5 }, |
+ { -2, -2, 100, 100, -1, -1, 50, 50, 0.5 }, |
+ { -101, -100, 50, 50, -51, -50, 26, 25, 0.5 } |
+ }; |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
+ gfx::Rect orig(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
+ gfx::Rect expected(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
+ gfx::Rect scaled = webkit::ppapi::PPB_Graphics2D_Impl::ScaleRectBounds( |
+ orig, tests[i].scale); |
+ EXPECT_TRUE(scaled.Equals(expected)); |
+ // Reverse the scale and ensure all the original pixels are still inside |
+ // the result. |
+ gfx::Rect unscaled = webkit::ppapi::PPB_Graphics2D_Impl::ScaleRectBounds( |
+ scaled, 1.0f / tests[i].scale); |
+ EXPECT_TRUE(unscaled.Contains(orig)); |
+ } |
+} |