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

Side by Side Diff: content/renderer/pepper/pepper_webplugin_impl_browsertest.cc

Issue 1141793002: Reland: Fix WebViewPlugin::scheduleAnimation crash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: filepath windows issue Created 5 years, 7 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "content/public/common/content_client.h"
6 #include "content/public/common/content_constants.h"
7 #include "content/public/common/pepper_plugin_info.h"
8 #include "content/public/renderer/content_renderer_client.h"
9 #include "content/public/test/render_view_test.h"
10 #include "content/renderer/pepper/pepper_webplugin_impl.h"
11 #include "content/renderer/pepper/plugin_instance_throttler_impl.h"
12 #include "content/renderer/pepper/plugin_module.h"
13 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
14 #include "content/renderer/render_frame_impl.h"
15 #include "content/test/test_content_client.h"
16 #include "ppapi/c/pp_errors.h"
17 #include "ppapi/c/ppb_core.h"
18 #include "ppapi/c/ppb_graphics_2d.h"
19 #include "ppapi/c/ppb_image_data.h"
20 #include "ppapi/c/ppb_instance.h"
21 #include "ppapi/c/ppp_instance.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/WebKit/public/web/WebLocalFrame.h"
24
25 namespace content {
26 namespace {
27
28 class PepperWebPluginImplBrowserTest
29 : public RenderViewTest,
30 public PluginInstanceThrottler::Observer {
31 public:
32 PepperWebPluginImplBrowserTest()
33 : throttler_(nullptr),
34 throttle_engaged_(false),
35 pp_module_(0),
36 pp_instance_(0),
37 graphics2d_(0) {}
38
39 void SetUp() override {
40 current_test_ = this;
41 RenderViewTest::SetUp();
42 }
43 void TearDown() override {
44 RenderViewTest::TearDown();
45 current_test_ = nullptr;
46 }
47 ContentClient* CreateContentClient() override {
48 return new MockContentClient;
49 }
50 ContentRendererClient* CreateContentRendererClient() override {
51 return new MockContentRendererClient;
52 }
53
54 // PluginInstanceThrottler::Observer implementation
55 void OnThrottleStateChange() override {
56 if (throttler_->IsThrottled())
57 throttle_engaged_ = true;
58 }
59
60 protected:
61 // PPP implementation
62 static const void* GetInterface(const char* name) {
63 static PPP_Instance ppp_instance = {
64 &PepperWebPluginImplBrowserTest::DidCreate,
65 &PepperWebPluginImplBrowserTest::DidDestroy,
66 &PepperWebPluginImplBrowserTest::DidChangeView,
67 &PepperWebPluginImplBrowserTest::DidChangeFocus,
68 &PepperWebPluginImplBrowserTest::HandleDocumentLoad};
69 if (!strcmp(name, PPP_INSTANCE_INTERFACE))
70 return &ppp_instance;
71 return nullptr;
72 }
73 static int InitializeModule(PP_Module module,
74 PPB_GetInterface get_interface) {
75 EXPECT_EQ(0, current_test_->pp_module_);
76 current_test_->pp_module_ = module;
77 ppb_core_ = static_cast<const PPB_Core*>(get_interface(PPB_CORE_INTERFACE));
78 ppb_graphics2d_ = static_cast<const PPB_Graphics2D*>(
79 get_interface(PPB_GRAPHICS_2D_INTERFACE));
80 ppb_image_data_ = static_cast<const PPB_ImageData*>(
81 get_interface(PPB_IMAGEDATA_INTERFACE));
82 ppb_instance_ =
83 static_cast<const PPB_Instance*>(get_interface(PPB_INSTANCE_INTERFACE));
84 return PP_OK;
85 }
86 static void ShutdownModule() {
87 EXPECT_NE(0, current_test_->pp_module_);
88 current_test_->pp_module_ = 0;
89 }
90
91 static void DummyCallback(void*, int32_t) {}
raymes 2015/05/18 04:39:06 nit: newline below
92 void PaintSomething() {
93 PP_Size size = {2, 1};
94 PP_Resource image = ppb_image_data_->Create(
95 pp_instance_, ppb_image_data_->GetNativeImageDataFormat(), &size,
96 PP_TRUE);
97 int32_t* pixels = static_cast<int32_t*>(ppb_image_data_->Map(image));
98 pixels[0] = 0xff000000;
99 pixels[1] = 0xffffffff;
100 ppb_image_data_->Unmap(image);
101 ppb_graphics2d_->ReplaceContents(graphics2d_, image);
102 PP_CompletionCallback callback = {
103 &PepperWebPluginImplBrowserTest::DummyCallback, nullptr, 0};
104 ppb_graphics2d_->Flush(graphics2d_, callback);
105 ppb_core_->ReleaseResource(image);
106 }
107
108 // PPP_Instance implementation
109 static PP_Bool DidCreate(PP_Instance instance,
110 uint32_t,
111 const char* [],
112 const char* []) {
113 EXPECT_EQ(0, current_test_->pp_instance_);
114 current_test_->pp_instance_ = instance;
115 PP_Size size = {2, 1};
116 current_test_->graphics2d_ =
117 ppb_graphics2d_->Create(instance, &size, PP_TRUE);
118 ppb_instance_->BindGraphics(instance, current_test_->graphics2d_);
119 return PP_TRUE;
120 }
121 static void DidDestroy(PP_Instance instance) {
122 EXPECT_NE(0, current_test_->pp_instance_);
123 current_test_->PaintSomething();
124 ppb_core_->ReleaseResource(current_test_->graphics2d_);
125 current_test_->pp_instance_ = 0;
126 }
127 static void DidChangeView(PP_Instance, PP_Resource) {}
128 static void DidChangeFocus(PP_Instance, PP_Bool) {}
129 static PP_Bool HandleDocumentLoad(PP_Instance, PP_Resource) {
130 return PP_FALSE;
131 }
132
133 static PepperPluginInfo GetPluginInfo() {
134 PepperPluginInfo info;
135 info.is_internal = true;
136 info.path = base::FilePath(FILE_PATH_LITERAL("internal-always-throttle"));
137 info.name = kAlwaysThrottleTestPluginName;
138 info.mime_types.push_back(
139 WebPluginMimeType("test/always-throttle", "", ""));
140 info.internal_entry_points.get_interface =
141 &PepperWebPluginImplBrowserTest::GetInterface;
142 info.internal_entry_points.initialize_module =
143 &PepperWebPluginImplBrowserTest::InitializeModule;
144 info.internal_entry_points.shutdown_module =
145 &PepperWebPluginImplBrowserTest::ShutdownModule;
146 return info;
147 }
148
149 class MockContentClient : public TestContentClient {
150 public:
151 void AddPepperPlugins(std::vector<PepperPluginInfo>* plugins) override {
152 plugins->push_back(GetPluginInfo());
153 }
154 };
155 class MockContentRendererClient : public ContentRendererClient {
156 public:
157 bool OverrideCreatePlugin(RenderFrame* render_frame,
158 blink::WebLocalFrame* frame,
159 const blink::WebPluginParams& params,
160 blink::WebPlugin** plugin) override {
161 current_test_->throttler_ = new PluginInstanceThrottlerImpl;
162 current_test_->throttler_->AddObserver(current_test_);
163 *plugin = render_frame->CreatePlugin(frame,
164 GetPluginInfo().ToWebPluginInfo(), params,
165 make_scoped_ptr(current_test_->throttler_));
166 return *plugin;
167 }
168 };
169
170 PluginInstanceThrottlerImpl* throttler_;
171 bool throttle_engaged_;
172 PP_Module pp_module_;
173 PP_Instance pp_instance_;
174 PP_Resource graphics2d_;
175 static PepperWebPluginImplBrowserTest* current_test_;
176 static const PPB_Core* ppb_core_;
177 static const PPB_Graphics2D* ppb_graphics2d_;
178 static const PPB_ImageData* ppb_image_data_;
179 static const PPB_Instance* ppb_instance_;
180 };
181 PepperWebPluginImplBrowserTest* PepperWebPluginImplBrowserTest::current_test_;
182 const PPB_Core* PepperWebPluginImplBrowserTest::ppb_core_;
183 const PPB_Graphics2D* PepperWebPluginImplBrowserTest::ppb_graphics2d_;
184 const PPB_ImageData* PepperWebPluginImplBrowserTest::ppb_image_data_;
185 const PPB_Instance* PepperWebPluginImplBrowserTest::ppb_instance_;
186
187 TEST_F(PepperWebPluginImplBrowserTest, NotEngageThrottleDuringDestroy) {
raymes 2015/05/18 04:39:06 nit: perhaps add a comment saying what this does w
188 LoadHTML("<!DOCTYPE html><object type='test/always-throttle'></object>");
189 EXPECT_NE(0, pp_instance_);
190 LoadHTML("");
191 EXPECT_EQ(0, pp_instance_);
192 EXPECT_FALSE(throttle_engaged_);
193 }
194
195 } // unnamed namespace
196
197 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698