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

Side by Side 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: Move ScaleBounds back out of gfx::Rect 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 static const int kSentinel = -500;
11
12 TEST(PpapiGraphics2DImplTest, ScaleMetrics) {
13 static const struct {
14 int x1;
15 int y1;
16 int w1;
17 int h1;
18 int x2;
19 int y2;
20 int w2;
21 int h2;
22 int dx1;
23 int dy1;
24 int dx2;
25 int dy2;
26 float scale;
27 bool result;
28 } tests[] = {
29 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, true },
30 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.0, true },
31 { 0, 0, 4, 4, 0, 0, 2, 2, 0, 0, 0, 0, 0.5, true },
32 { 1, 1, 4, 4, 0, 0, 3, 3, 0, 0, 0, 0, 0.5, false },
33 { 53, 75, 100, 100, 53, 75, 100, 100, 0, 0, 0, 0, 1.0, true },
34 { 53, 75, 100, 100, 106, 150, 200, 200, 0, 0, 0, 0, 2.0, true },
35 { 53, 75, 100, 100, 26, 37, 51, 51, 0, 0, 0, 0, 0.5, false },
36 { 53, 74, 100, 100, 26, 37, 51, 50, 0, 0, 0, 0, 0.5, false },
37 { -1, -1, 100, 100, -1, -1, 51, 51, 0, 0, 0, 0, 0.5, false },
38 { -2, -2, 100, 100, -1, -1, 50, 50, 4, -4, 2, -2, 0.5, true },
39 { -101, -100, 50, 50, -51, -50, 26, 25, 0, 0, 0, 0, 0.5, false },
40
41 { 10, 10, 20, 20, 5, 5, 10, 10, 0, 0, 0, 0, 0.5, true },
42 // Cannot scroll due to partial coverage on sides
43 { 11, 10, 20, 20, 5, 5, 11, 10, 0, 0, 0, 0, 0.5, false },
44 // Can scroll since backing store is actually smaller/scaling up
45 { 11, 20, 100, 100, 22, 40, 200, 200, 7, 3, 14, 6, 2.0, true },
46 // Can scroll due to delta and bounds being aligned
47 { 10, 10, 20, 20, 5, 5, 10, 10, 6, 4, 3, 2, 0.5, true },
48 // Cannot scroll due to dx
49 { 10, 10, 20, 20, 5, 5, 10, 10, 5, 4, 2, 2, 0.5, false },
50 // Cannot scroll due to dy
51 { 10, 10, 20, 20, 5, 5, 10, 10, 6, 3, 3, 1, 0.5, false },
52 // Cannot scroll due to top
53 { 10, 11, 20, 20, 5, 5, 10, 11, 6, 4, 3, 2, 0.5, false },
54 // Cannot scroll due to left
55 { 7, 10, 20, 20, 3, 5, 11, 10, 6, 4, 3, 2, 0.5, false },
56 // Cannot scroll due to width
57 { 10, 10, 21, 20, 5, 5, 11, 10, 6, 4, 3, 2, 0.5, false },
58 // Cannot scroll due to height
59 { 10, 10, 20, 51, 5, 5, 10, 26, 6, 4, 3, 2, 0.5, false },
60 // Not checking scrolling
61 { 20, 20, 100, 100, 10, 10, 50, 50, kSentinel, kSentinel, kSentinel,
62 kSentinel, 0.5, true },
63 { 20, 21, 100, 100, 10, 10, 50, 51, kSentinel, kSentinel, kSentinel,
64 kSentinel, 0.5, true },
65 // Check negative scroll deltas
66 { 10, 10, 20, 20, 5, 5, 10, 10, -6, -4, -3, -2, 0.5, true },
67 { 10, 10, 20, 20, 5, 5, 10, 10, -6, -3, -3, -1, 0.5, false },
68
69 };
70 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
71 gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
72 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
73 gfx::Rect orig = r1;
74 int dx = tests[i].dx1;
75 int dy = tests[i].dy1;
76 bool res = webkit::ppapi::PPB_Graphics2D_Impl::ScaleMetrics(
77 tests[i].scale,
78 r1,
79 dx != kSentinel ? &dx : NULL,
80 dy != kSentinel ? &dy : NULL);
81 EXPECT_TRUE(r1.Equals(r2));
82 EXPECT_EQ(res, tests[i].result);
83 if (res) {
84 EXPECT_EQ(dx, tests[i].dx2);
85 EXPECT_EQ(dy, tests[i].dy2);
86 }
87 // Reverse the scale and ensure all the original pixels are still inside
88 // the result.
89 webkit::ppapi::PPB_Graphics2D_Impl::ScaleMetrics(
90 1.0f / tests[i].scale, r1, NULL, NULL);
91 EXPECT_TRUE(r1.Contains(orig));
92 }
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698