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

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance_unittest.cc

Issue 20165002: Move webkit/plugins/ppapi to content/renderer/pepper. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: more more clang fun Created 7 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 "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h"
6
7 #include "base/basictypes.h"
8 #include "base/memory/ref_counted.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gfx/rect.h"
11 #include "ui/gfx/safe_integer_conversions.h"
12 #include "webkit/plugins/ppapi/plugin_delegate.h"
13 #include "webkit/plugins/ppapi/ppapi_unittest.h"
14 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
15
16 namespace webkit {
17 namespace ppapi {
18
19 namespace {
20
21 // A mock graphics object to bind. We only have to implement enough so that
22 // GetBitmapForOptimizedPluginPaint runs.
23 //
24 // If this is eventually all moved to content, we can simplify this. The
25 // point here is that we need to just have a bound graphics 2d resource host
26 // with the right properties.
27 class MockPlatformGraphics2D : public PluginDelegate::PlatformGraphics2D {
28 public:
29 // The image data pointer must outlive this class.
30 MockPlatformGraphics2D(PPB_ImageData_Impl* image_data, float scale)
31 : image_data_(image_data),
32 scale_(scale),
33 bound_instance_(NULL) {
34 }
35 virtual ~MockPlatformGraphics2D() {
36 if (bound_instance_)
37 bound_instance_->SetBoundGraphics2DForTest(NULL);
38 }
39
40 virtual bool ReadImageData(PP_Resource image,
41 const PP_Point* top_left) OVERRIDE {
42 return false;
43 }
44 virtual bool BindToInstance(PluginInstanceImpl* new_instance) OVERRIDE {
45 bound_instance_ = new_instance;
46 return true;
47 }
48 virtual void Paint(WebKit::WebCanvas* canvas,
49 const gfx::Rect& plugin_rect,
50 const gfx::Rect& paint_rect) OVERRIDE {}
51 virtual void ViewWillInitiatePaint() OVERRIDE {}
52 virtual void ViewInitiatedPaint() OVERRIDE {}
53 virtual void ViewFlushedPaint() OVERRIDE {}
54
55 virtual bool IsAlwaysOpaque() const OVERRIDE { return true; }
56 virtual void SetScale(float scale) OVERRIDE {}
57 virtual float GetScale() const OVERRIDE { return scale_; }
58 virtual PPB_ImageData_Impl* ImageData() OVERRIDE {
59 return image_data_;
60 }
61
62 private:
63 PPB_ImageData_Impl* image_data_;
64 float scale_;
65 PluginInstanceImpl* bound_instance_;
66
67 DISALLOW_COPY_AND_ASSIGN(MockPlatformGraphics2D);
68 };
69
70 } // namespace
71
72 // This class is forward-declared as a friend so can't be in the anonymous
73 // namespace.
74 class PpapiPluginInstanceTest : public PpapiUnittest {
75 public:
76 bool GetBitmapForOptimizedPluginPaint(const gfx::Rect& paint_bounds,
77 TransportDIB** dib,
78 gfx::Rect* location,
79 gfx::Rect* clip,
80 float* scale_factor) {
81 return !!instance()->GetBitmapForOptimizedPluginPaint(
82 paint_bounds, dib, location, clip, scale_factor);
83 }
84 };
85
86
87 // Test that GetBitmapForOptimizedPluginPaint doesn't return a bitmap rect
88 // that's bigger than the actual backing store bitmap.
89 TEST_F(PpapiPluginInstanceTest, GetBitmap2xScale) {
90 PP_Size size;
91 size.width = 3;
92 size.height = 3;
93
94 scoped_refptr<PPB_ImageData_Impl> image_data = new PPB_ImageData_Impl(
95 instance()->pp_instance(), PPB_ImageData_Impl::PLATFORM);
96 image_data->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(),
97 size.width, size.height, true);
98 ASSERT_TRUE(image_data->Map() != NULL);
99
100 float scale = 2.0;
101 MockPlatformGraphics2D mock_graphics_2d(image_data.get(), 1.0 / scale);
102 instance()->SetBoundGraphics2DForTest(&mock_graphics_2d);
103
104 instance()->SetAlwaysOnTop(true);
105 SetViewSize(size.width, size.height);
106
107 gfx::Rect bounds(0, 0, 1, 1);
108 gfx::Rect location;
109 gfx::Rect clip;
110 float bitmap_scale = 0;
111 TransportDIB* dib = NULL;
112 EXPECT_TRUE(GetBitmapForOptimizedPluginPaint(
113 bounds, &dib, &location, &clip, &bitmap_scale));
114
115 EXPECT_EQ(0, location.x());
116 EXPECT_EQ(0, location.y());
117 EXPECT_EQ(gfx::ToFlooredInt(size.width / scale), location.width());
118 EXPECT_EQ(gfx::ToFlooredInt(size.height / scale), location.height());
119 EXPECT_EQ(0, clip.x());
120 EXPECT_EQ(0, clip.y());
121 EXPECT_EQ(size.width, clip.width());
122 EXPECT_EQ(size.height, clip.height());
123 EXPECT_EQ(scale, bitmap_scale);
124 }
125
126 } // namespace ppapi
127 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance_impl.cc ('k') | webkit/plugins/ppapi/ppapi_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698