Disable content detection tests on Android
[chromium-blink-merge.git] / webkit / plugins / ppapi / ppb_graphics_2d_impl_unittest.cc
blob644b8c0ec0919674cc892f463995abc627cd26a6
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.
5 #include "base/basictypes.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/gfx/point.h"
8 #include "ui/gfx/rect.h"
9 #include "ui/gfx/safe_integer_conversions.h"
10 #include "webkit/plugins/ppapi/ppapi_unittest.h"
11 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
12 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
14 namespace webkit {
15 namespace ppapi {
17 typedef PpapiUnittest PpapiGraphics2DImplTest;
19 TEST_F(PpapiGraphics2DImplTest, ConvertToLogicalPixels) {
20 static const struct {
21 int x1;
22 int y1;
23 int w1;
24 int h1;
25 int x2;
26 int y2;
27 int w2;
28 int h2;
29 int dx1;
30 int dy1;
31 int dx2;
32 int dy2;
33 float scale;
34 bool result;
35 } tests[] = {
36 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, true },
37 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.0, true },
38 { 0, 0, 4, 4, 0, 0, 2, 2, 0, 0, 0, 0, 0.5, true },
39 { 1, 1, 4, 4, 0, 0, 3, 3, 0, 0, 0, 0, 0.5, false },
40 { 53, 75, 100, 100, 53, 75, 100, 100, 0, 0, 0, 0, 1.0, true },
41 { 53, 75, 100, 100, 106, 150, 200, 200, 0, 0, 0, 0, 2.0, true },
42 { 53, 75, 100, 100, 26, 37, 51, 51, 0, 0, 0, 0, 0.5, false },
43 { 53, 74, 100, 100, 26, 37, 51, 50, 0, 0, 0, 0, 0.5, false },
44 { -1, -1, 100, 100, -1, -1, 51, 51, 0, 0, 0, 0, 0.5, false },
45 { -2, -2, 100, 100, -1, -1, 50, 50, 4, -4, 2, -2, 0.5, true },
46 { -101, -100, 50, 50, -51, -50, 26, 25, 0, 0, 0, 0, 0.5, false },
47 { 10, 10, 20, 20, 5, 5, 10, 10, 0, 0, 0, 0, 0.5, true },
48 // Cannot scroll due to partial coverage on sides
49 { 11, 10, 20, 20, 5, 5, 11, 10, 0, 0, 0, 0, 0.5, false },
50 // Can scroll since backing store is actually smaller/scaling up
51 { 11, 20, 100, 100, 22, 40, 200, 200, 7, 3, 14, 6, 2.0, true },
52 // Can scroll due to delta and bounds being aligned
53 { 10, 10, 20, 20, 5, 5, 10, 10, 6, 4, 3, 2, 0.5, true },
54 // Cannot scroll due to dx
55 { 10, 10, 20, 20, 5, 5, 10, 10, 5, 4, 2, 2, 0.5, false },
56 // Cannot scroll due to dy
57 { 10, 10, 20, 20, 5, 5, 10, 10, 6, 3, 3, 1, 0.5, false },
58 // Cannot scroll due to top
59 { 10, 11, 20, 20, 5, 5, 10, 11, 6, 4, 3, 2, 0.5, false },
60 // Cannot scroll due to left
61 { 7, 10, 20, 20, 3, 5, 11, 10, 6, 4, 3, 2, 0.5, false },
62 // Cannot scroll due to width
63 { 10, 10, 21, 20, 5, 5, 11, 10, 6, 4, 3, 2, 0.5, false },
64 // Cannot scroll due to height
65 { 10, 10, 20, 51, 5, 5, 10, 26, 6, 4, 3, 2, 0.5, false },
66 // Check negative scroll deltas
67 { 10, 10, 20, 20, 5, 5, 10, 10, -6, -4, -3, -2, 0.5, true },
68 { 10, 10, 20, 20, 5, 5, 10, 10, -6, -3, -3, -1, 0.5, false },
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 gfx::Point delta(tests[i].dx1, tests[i].dy1);
75 bool res = webkit::ppapi::PPB_Graphics2D_Impl::ConvertToLogicalPixels(
76 tests[i].scale, &r1, &delta);
77 EXPECT_EQ(r2.ToString(), r1.ToString());
78 EXPECT_EQ(res, tests[i].result);
79 if (res) {
80 EXPECT_EQ(delta, gfx::Point(tests[i].dx2, tests[i].dy2));
82 // Reverse the scale and ensure all the original pixels are still inside
83 // the result.
84 webkit::ppapi::PPB_Graphics2D_Impl::ConvertToLogicalPixels(
85 1.0f / tests[i].scale, &r1, NULL);
86 EXPECT_TRUE(r1.Contains(orig));
91 Disabled because this doesn't run with the new proxy design.
92 TODO(brettw) Rewrite this test to use the new design.
94 #if !defined(USE_AURA) && (defined(OS_WIN) || defined(OS_LINUX))
95 // Windows and Linux don't support scaled optimized plugin paints ATM.
96 #define MAYBE_GetBitmap2xScale DISABLED_GetBitmap2xScale
97 #else
98 #define MAYBE_GetBitmap2xScale GetBitmap2xScale
99 #endif
101 // Test that GetBitmapForOptimizedPluginPaint doesn't return a bitmap rect
102 // that's bigger than the actual backing store bitmap.
103 TEST_F(PpapiGraphics2DImplTest, GetBitmap2xScale) {
104 PP_Size size;
105 size.width = 3;
106 size.height = 3;
107 PP_Resource resource =
108 PPB_Graphics2D_Impl::Create(instance()->pp_instance(), size, PP_TRUE);
109 EXPECT_TRUE(resource);
110 EXPECT_TRUE(instance()->BindGraphics(instance()->pp_instance(), resource));
111 instance()->set_always_on_top(true);
112 float scale = 2.0;
113 SetViewSize(size.width, size.height, 1.0 / scale);
115 gfx::Rect bounds(0, 0, 1, 1);
116 gfx::Rect location;
117 gfx::Rect clip;
118 float bitmap_scale = 0;
119 TransportDIB* dib = NULL;
120 EXPECT_TRUE(instance()->GetBitmapForOptimizedPluginPaint(
121 bounds, &dib, &location, &clip, &bitmap_scale));
123 EXPECT_EQ(0, location.x());
124 EXPECT_EQ(0, location.y());
125 EXPECT_EQ(gfx::ToFlooredInt(size.width / scale), location.width());
126 EXPECT_EQ(gfx::ToFlooredInt(size.height / scale), location.height());
127 EXPECT_EQ(0, clip.x());
128 EXPECT_EQ(0, clip.y());
129 EXPECT_EQ(size.width, clip.width());
130 EXPECT_EQ(size.height, clip.height());
131 EXPECT_EQ(scale, bitmap_scale);
135 } // namespace ppapi
136 } // namespace webkit