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

Unified Diff: webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc

Issue 10704198: Scale to DIPs in ppb_graphics2d_impl for proper invalidation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix shared_lib build, simplify based on feedback and fix nits Created 8 years, 5 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
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));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698