Index: ui/gfx/rect_unittest.cc |
diff --git a/ui/gfx/rect_unittest.cc b/ui/gfx/rect_unittest.cc |
index 4eefdd69f5622da8e6a058cfafd21e77eb37efd4..1328cae23095df7e6564706a020bad4aa0fee1c5 100644 |
--- a/ui/gfx/rect_unittest.cc |
+++ b/ui/gfx/rect_unittest.cc |
@@ -344,6 +344,45 @@ TEST(RectTest, SkRectToRect) { |
EXPECT_EQ(src, gfx::SkRectToRect(skrect)); |
} |
+TEST(RectTest, ScaleRect) { |
+ static const struct { |
+ int x1; // rect 1 |
+ int y1; |
+ int w1; |
+ int h1; |
+ int x2; // rect 2 |
+ 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 r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
+ gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
+ gfx::Rect orig(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
+ r1.ScaleBounds(tests[i].scale); |
+ EXPECT_TRUE(r1.Equals(r2)); |
+ r1.ScaleBounds(1.0 / tests[i].scale); |
+ EXPECT_TRUE(r1.x() <= orig.x()); |
+ EXPECT_TRUE(r1.y() <= orig.y()); |
+ EXPECT_TRUE(r1.x() + r1.width() >= orig.x() + orig.width()); |
+ EXPECT_TRUE(r1.y() + r1.height() >= orig.y() + orig.height()); |
+ } |
+ |
+} |
+ |
#if defined(OS_WIN) |
TEST(RectTest, ConstructAndAssign) { |
const RECT rect_1 = { 0, 0, 10, 10 }; |