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 "ppapi/proxy/ppapi_proxy_test.h" | 5 #include "ppapi/proxy/ppapi_proxy_test.h" |
6 | 6 |
| 7 #include "ppapi/proxy/proxy_object_var.h" |
7 #include "ppapi/proxy/serialized_var.h" | 8 #include "ppapi/proxy/serialized_var.h" |
8 #include "ppapi/shared_impl/proxy_lock.h" | 9 #include "ppapi/shared_impl/proxy_lock.h" |
9 | 10 |
10 namespace ppapi { | 11 namespace ppapi { |
11 namespace proxy { | 12 namespace proxy { |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 PP_Var MakeObjectVar(int64_t object_id) { | 16 PP_Var MakeObjectVar(int64_t object_id) { |
16 PP_Var ret; | 17 PP_Var ret; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 EXPECT_EQ(old_message_count, sink().message_count()); | 266 EXPECT_EQ(old_message_count, sink().message_count()); |
266 } | 267 } |
267 | 268 |
268 // Since we didn't keep any refs to the objects or strings, so they should | 269 // Since we didn't keep any refs to the objects or strings, so they should |
269 // have been freed. | 270 // have been freed. |
270 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects[0])); | 271 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects[0])); |
271 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects[1])); | 272 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects[1])); |
272 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects2[1])); | 273 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects2[1])); |
273 } | 274 } |
274 | 275 |
| 276 // Tests the browser sending a String var as a return value to make sure we |
| 277 // ref-count the host side properly. |
| 278 typedef HostProxyTest HostSerializedVarTest; |
| 279 TEST_F(HostSerializedVarTest, PluginReceiveStringReturn) { |
| 280 { |
| 281 PP_Var string_var = StringVar::StringToPPVar("Hello"); |
| 282 EXPECT_EQ(1, var_tracker().GetRefCountForObject(string_var)); |
| 283 GetDispatcher()->serialization_rules()->BeginSendPassRef(string_var); |
| 284 GetDispatcher()->serialization_rules()->EndSendPassRef(string_var); |
| 285 // It should be gone, so we should get -1 to indicate that. |
| 286 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(string_var)); |
| 287 } |
| 288 |
| 289 { |
| 290 // Note this is as little weird; we're testing the behavior of the host- |
| 291 // side of the proxy, but we use ProxyObjectVar, because this unit test |
| 292 // doesn't have access to stuff in content/renderer/pepper. The ref-counting |
| 293 // behavior should be the same, however. All we're really testing |
| 294 // is the code in ppapi/proxy (HostVarSerializationRules). |
| 295 scoped_refptr<Var> obj_var = new ProxyObjectVar(NULL, 1234); |
| 296 PP_Var obj_pp_var = obj_var->GetPPVar(); |
| 297 EXPECT_EQ(1, var_tracker().GetRefCountForObject(obj_pp_var)); |
| 298 GetDispatcher()->serialization_rules()->BeginSendPassRef(obj_pp_var); |
| 299 GetDispatcher()->serialization_rules()->EndSendPassRef(obj_pp_var); |
| 300 // The host side for object vars always keeps 1 ref on behalf of the plugin. |
| 301 // See HostVarSerializationRules and PluginVarSerializationRules for an |
| 302 // explanation. |
| 303 EXPECT_EQ(1, var_tracker().GetRefCountForObject(obj_pp_var)); |
| 304 var_tracker().ReleaseVar(obj_pp_var); |
| 305 } |
| 306 } |
| 307 |
275 // Tests the plugin receiving a var as a return value from the browser | 308 // Tests the plugin receiving a var as a return value from the browser |
276 // two different times (passing ownership). | 309 // two different times (passing ownership). |
277 TEST_F(SerializedVarTest, PluginReceiveReturn) { | 310 TEST_F(SerializedVarTest, PluginReceiveReturn) { |
278 ProxyAutoLock lock; | 311 ProxyAutoLock lock; |
279 PP_Var host_object = MakeObjectVar(0x31337); | 312 PP_Var host_object = MakeObjectVar(0x31337); |
280 | 313 |
281 PP_Var plugin_object; | 314 PP_Var plugin_object; |
282 { | 315 { |
283 // Receive the first param, we should be tracking it with a refcount of 1. | 316 // Receive the first param, we should be tracking it with a refcount of 1. |
284 SerializedVarTestConstructor input1(host_object); | 317 SerializedVarTestConstructor input1(host_object); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 378 } |
346 | 379 |
347 // When the ReturnValue object goes out of scope, it should have sent a | 380 // When the ReturnValue object goes out of scope, it should have sent a |
348 // release message to the browser. | 381 // release message to the browser. |
349 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); | 382 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); |
350 EXPECT_EQ(1u, sink().message_count()); | 383 EXPECT_EQ(1u, sink().message_count()); |
351 } | 384 } |
352 | 385 |
353 } // namespace proxy | 386 } // namespace proxy |
354 } // namespace ppapi | 387 } // namespace ppapi |
OLD | NEW |