OLD | NEW |
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 TEST_F(PluginVarTrackerTest, PluginObjectInstanceDeleted) { | 186 TEST_F(PluginVarTrackerTest, PluginObjectInstanceDeleted) { |
187 PP_Var host_object = MakeObject(12345); | 187 PP_Var host_object = MakeObject(12345); |
188 PP_Instance pp_instance = 0x12345; | 188 PP_Instance pp_instance = 0x12345; |
189 | 189 |
190 int deallocate_called = 0; | 190 int deallocate_called = 0; |
191 void* user_data = &deallocate_called; | 191 void* user_data = &deallocate_called; |
192 | 192 |
193 // Make a var with one reference. | 193 // Make a var with one reference. |
194 scoped_refptr<ProxyObjectVar> object( | 194 scoped_refptr<ProxyObjectVar> object( |
195 new ProxyObjectVar(plugin_dispatcher(), host_object.value.as_id)); | 195 new ProxyObjectVar(plugin_dispatcher(), host_object.value.as_id)); |
196 PP_Var plugin_var = MakeObject(var_tracker().AddVar(object)); | 196 PP_Var plugin_var = MakeObject(var_tracker().AddVar(object.get())); |
197 var_tracker().PluginImplementedObjectCreated(pp_instance, | 197 var_tracker().PluginImplementedObjectCreated(pp_instance, |
198 plugin_var, | 198 plugin_var, |
199 &mark_on_deallocate_class, | 199 &mark_on_deallocate_class, |
200 user_data); | 200 user_data); |
201 | 201 |
202 // Release the plugin ref to the var. WebKit hasn't called destroy so | 202 // Release the plugin ref to the var. WebKit hasn't called destroy so |
203 // we won't get a destroy call. | 203 // we won't get a destroy call. |
204 object = NULL; | 204 object = NULL; |
205 var_tracker().ReleaseVar(plugin_var); | 205 var_tracker().ReleaseVar(plugin_var); |
206 EXPECT_EQ(0, deallocate_called); | 206 EXPECT_EQ(0, deallocate_called); |
207 | 207 |
208 // Synthesize an instance destuction, this should call Deallocate. | 208 // Synthesize an instance destuction, this should call Deallocate. |
209 var_tracker().DidDeleteInstance(pp_instance); | 209 var_tracker().DidDeleteInstance(pp_instance); |
210 EXPECT_EQ(1, deallocate_called); | 210 EXPECT_EQ(1, deallocate_called); |
211 } | 211 } |
212 | 212 |
213 // Tests what happens when a plugin keeps a ref to a plugin-implemented | 213 // Tests what happens when a plugin keeps a ref to a plugin-implemented |
214 // object var longer than the instance. We should not call the destructor until | 214 // object var longer than the instance. We should not call the destructor until |
215 // the plugin releases its last ref. | 215 // the plugin releases its last ref. |
216 TEST_F(PluginVarTrackerTest, PluginObjectLeaked) { | 216 TEST_F(PluginVarTrackerTest, PluginObjectLeaked) { |
217 PP_Var host_object = MakeObject(12345); | 217 PP_Var host_object = MakeObject(12345); |
218 PP_Instance pp_instance = 0x12345; | 218 PP_Instance pp_instance = 0x12345; |
219 | 219 |
220 int deallocate_called = 0; | 220 int deallocate_called = 0; |
221 void* user_data = &deallocate_called; | 221 void* user_data = &deallocate_called; |
222 | 222 |
223 // Make a var with one reference. | 223 // Make a var with one reference. |
224 scoped_refptr<ProxyObjectVar> object( | 224 scoped_refptr<ProxyObjectVar> object( |
225 new ProxyObjectVar(plugin_dispatcher(), host_object.value.as_id)); | 225 new ProxyObjectVar(plugin_dispatcher(), host_object.value.as_id)); |
226 PP_Var plugin_var = MakeObject(var_tracker().AddVar(object)); | 226 PP_Var plugin_var = MakeObject(var_tracker().AddVar(object.get())); |
227 var_tracker().PluginImplementedObjectCreated(pp_instance, | 227 var_tracker().PluginImplementedObjectCreated(pp_instance, |
228 plugin_var, | 228 plugin_var, |
229 &mark_on_deallocate_class, | 229 &mark_on_deallocate_class, |
230 user_data); | 230 user_data); |
231 | 231 |
232 // Destroy the instance. This should not call deallocate since the plugin | 232 // Destroy the instance. This should not call deallocate since the plugin |
233 // still has a ref. | 233 // still has a ref. |
234 var_tracker().DidDeleteInstance(pp_instance); | 234 var_tracker().DidDeleteInstance(pp_instance); |
235 EXPECT_EQ(0, deallocate_called); | 235 EXPECT_EQ(0, deallocate_called); |
236 | 236 |
237 // Release the plugin ref to the var. Since the instance is gone this should | 237 // Release the plugin ref to the var. Since the instance is gone this should |
238 // call deallocate. | 238 // call deallocate. |
239 object = NULL; | 239 object = NULL; |
240 var_tracker().ReleaseVar(plugin_var); | 240 var_tracker().ReleaseVar(plugin_var); |
241 EXPECT_EQ(1, deallocate_called); | 241 EXPECT_EQ(1, deallocate_called); |
242 } | 242 } |
243 | 243 |
244 } // namespace proxy | 244 } // namespace proxy |
245 } // namespace ppapi | 245 } // namespace ppapi |
OLD | NEW |