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

Side by Side Diff: ppapi/proxy/plugin_var_tracker_unittest.cc

Issue 15806016: Update ppapi/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
« no previous file with comments | « ppapi/proxy/plugin_var_tracker.cc ('k') | ppapi/proxy/ppb_instance_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ipc/ipc_test_sink.h" 5 #include "ipc/ipc_test_sink.h"
6 #include "ppapi/c/dev/ppp_class_deprecated.h" 6 #include "ppapi/c/dev/ppp_class_deprecated.h"
7 #include "ppapi/proxy/plugin_var_tracker.h" 7 #include "ppapi/proxy/plugin_var_tracker.h"
8 #include "ppapi/proxy/ppapi_messages.h" 8 #include "ppapi/proxy/ppapi_messages.h"
9 #include "ppapi/proxy/ppapi_proxy_test.h" 9 #include "ppapi/proxy/ppapi_proxy_test.h"
10 #include "ppapi/proxy/proxy_object_var.h" 10 #include "ppapi/proxy/proxy_object_var.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 ProxyAutoLock lock; 192 ProxyAutoLock lock;
193 PP_Var host_object = MakeObject(12345); 193 PP_Var host_object = MakeObject(12345);
194 PP_Instance pp_instance = 0x12345; 194 PP_Instance pp_instance = 0x12345;
195 195
196 int deallocate_called = 0; 196 int deallocate_called = 0;
197 void* user_data = &deallocate_called; 197 void* user_data = &deallocate_called;
198 198
199 // Make a var with one reference. 199 // Make a var with one reference.
200 scoped_refptr<ProxyObjectVar> object( 200 scoped_refptr<ProxyObjectVar> object(
201 new ProxyObjectVar(plugin_dispatcher(), host_object.value.as_id)); 201 new ProxyObjectVar(plugin_dispatcher(), host_object.value.as_id));
202 PP_Var plugin_var = MakeObject(var_tracker().AddVar(object)); 202 PP_Var plugin_var = MakeObject(var_tracker().AddVar(object.get()));
203 var_tracker().PluginImplementedObjectCreated(pp_instance, 203 var_tracker().PluginImplementedObjectCreated(
204 plugin_var, 204 pp_instance, plugin_var, &mark_on_deallocate_class, user_data);
205 &mark_on_deallocate_class,
206 user_data);
207 205
208 // Release the plugin ref to the var. WebKit hasn't called destroy so 206 // Release the plugin ref to the var. WebKit hasn't called destroy so
209 // we won't get a destroy call. 207 // we won't get a destroy call.
210 object = NULL; 208 object = NULL;
211 var_tracker().ReleaseVar(plugin_var); 209 var_tracker().ReleaseVar(plugin_var);
212 EXPECT_EQ(0, deallocate_called); 210 EXPECT_EQ(0, deallocate_called);
213 211
214 // Synthesize an instance destuction, this should call Deallocate. 212 // Synthesize an instance destuction, this should call Deallocate.
215 var_tracker().DidDeleteInstance(pp_instance); 213 var_tracker().DidDeleteInstance(pp_instance);
216 EXPECT_EQ(1, deallocate_called); 214 EXPECT_EQ(1, deallocate_called);
217 } 215 }
218 216
219 // Tests what happens when a plugin keeps a ref to a plugin-implemented 217 // Tests what happens when a plugin keeps a ref to a plugin-implemented
220 // object var longer than the instance. We should not call the destructor until 218 // object var longer than the instance. We should not call the destructor until
221 // the plugin releases its last ref. 219 // the plugin releases its last ref.
222 TEST_F(PluginVarTrackerTest, PluginObjectLeaked) { 220 TEST_F(PluginVarTrackerTest, PluginObjectLeaked) {
223 ProxyAutoLock lock; 221 ProxyAutoLock lock;
224 PP_Var host_object = MakeObject(12345); 222 PP_Var host_object = MakeObject(12345);
225 PP_Instance pp_instance = 0x12345; 223 PP_Instance pp_instance = 0x12345;
226 224
227 int deallocate_called = 0; 225 int deallocate_called = 0;
228 void* user_data = &deallocate_called; 226 void* user_data = &deallocate_called;
229 227
230 // Make a var with one reference. 228 // Make a var with one reference.
231 scoped_refptr<ProxyObjectVar> object( 229 scoped_refptr<ProxyObjectVar> object(
232 new ProxyObjectVar(plugin_dispatcher(), host_object.value.as_id)); 230 new ProxyObjectVar(plugin_dispatcher(), host_object.value.as_id));
233 PP_Var plugin_var = MakeObject(var_tracker().AddVar(object)); 231 PP_Var plugin_var = MakeObject(var_tracker().AddVar(object.get()));
234 var_tracker().PluginImplementedObjectCreated(pp_instance, 232 var_tracker().PluginImplementedObjectCreated(
235 plugin_var, 233 pp_instance, plugin_var, &mark_on_deallocate_class, user_data);
236 &mark_on_deallocate_class,
237 user_data);
238 234
239 // Destroy the instance. This should not call deallocate since the plugin 235 // Destroy the instance. This should not call deallocate since the plugin
240 // still has a ref. 236 // still has a ref.
241 var_tracker().DidDeleteInstance(pp_instance); 237 var_tracker().DidDeleteInstance(pp_instance);
242 EXPECT_EQ(0, deallocate_called); 238 EXPECT_EQ(0, deallocate_called);
243 239
244 // Release the plugin ref to the var. Since the instance is gone this should 240 // Release the plugin ref to the var. Since the instance is gone this should
245 // call deallocate. 241 // call deallocate.
246 object = NULL; 242 object = NULL;
247 var_tracker().ReleaseVar(plugin_var); 243 var_tracker().ReleaseVar(plugin_var);
248 EXPECT_EQ(1, deallocate_called); 244 EXPECT_EQ(1, deallocate_called);
249 } 245 }
250 246
251 } // namespace proxy 247 } // namespace proxy
252 } // namespace ppapi 248 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/plugin_var_tracker.cc ('k') | ppapi/proxy/ppb_instance_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698