OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/basictypes.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "ui/gfx/rect.h" |
| 8 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
| 9 |
| 10 TEST(PpapiGraphics2DImplTest, ScaleRectBounds) { |
| 11 static const struct { |
| 12 int x1; |
| 13 int y1; |
| 14 int w1; |
| 15 int h1; |
| 16 int x2; |
| 17 int y2; |
| 18 int w2; |
| 19 int h2; |
| 20 float scale; |
| 21 } tests[] = { |
| 22 { 0, 0, 0, 0, 0, 0, 0, 0, 1.0 }, |
| 23 { 0, 0, 0, 0, 0, 0, 0, 0, 2.0 }, |
| 24 { 0, 0, 4, 4, 0, 0, 2, 2, 0.5 }, |
| 25 { 1, 1, 4, 4, 0, 0, 3, 3, 0.5 }, |
| 26 { 53, 75, 100, 100, 53, 75, 100, 100, 1.0 }, |
| 27 { 53, 75, 100, 100, 106, 150, 200, 200, 2.0 }, |
| 28 { 53, 75, 100, 100, 26, 37, 51, 51, 0.5 }, |
| 29 { 53, 74, 100, 100, 26, 37, 51, 50, 0.5 }, |
| 30 { -1, -1, 100, 100, -1, -1, 51, 51, 0.5 }, |
| 31 { -2, -2, 100, 100, -1, -1, 50, 50, 0.5 }, |
| 32 { -101, -100, 50, 50, -51, -50, 26, 25, 0.5 } |
| 33 }; |
| 34 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 35 gfx::Rect orig(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
| 36 gfx::Rect expected(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
| 37 gfx::Rect scaled = webkit::ppapi::PPB_Graphics2D_Impl::ScaleRectBounds( |
| 38 orig, tests[i].scale); |
| 39 EXPECT_TRUE(scaled.Equals(expected)); |
| 40 // Reverse the scale and ensure all the original pixels are still inside |
| 41 // the result. |
| 42 gfx::Rect unscaled = webkit::ppapi::PPB_Graphics2D_Impl::ScaleRectBounds( |
| 43 scaled, 1.0f / tests[i].scale); |
| 44 EXPECT_TRUE(unscaled.Contains(orig)); |
| 45 } |
| 46 } |
OLD | NEW |