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

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

Issue 874703003: PPAPI: Release renderer Var refcount when returning to plugin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 5 years, 10 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
« no previous file with comments | « ppapi/proxy/host_var_serialization_rules.cc ('k') | no next file » | 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 "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
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
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
OLDNEW
« no previous file with comments | « ppapi/proxy/host_var_serialization_rules.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698