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

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

Issue 9348092: Revert 121901 - PPAPI: Add unlocking for PPP calls and callbacks. Add more locking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppp_video_decoder_proxy.cc ('k') | ppapi/shared_impl/ppp_instance_combined.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 "ppapi/proxy/ppapi_proxy_test.h" 5 #include "ppapi/proxy/ppapi_proxy_test.h"
6 6
7 #include "ppapi/proxy/serialized_var.h" 7 #include "ppapi/proxy/serialized_var.h"
8 #include "ppapi/shared_impl/proxy_lock.h"
9 8
10 namespace ppapi { 9 namespace ppapi {
11 namespace proxy { 10 namespace proxy {
12 11
13 namespace { 12 namespace {
14 13
15 PP_Var MakeObjectVar(int64_t object_id) { 14 PP_Var MakeObjectVar(int64_t object_id) {
16 PP_Var ret; 15 PP_Var ret;
17 ret.type = PP_VARTYPE_OBJECT; 16 ret.type = PP_VARTYPE_OBJECT;
18 ret.value.as_id = object_id; 17 ret.value.as_id = object_id;
19 return ret; 18 return ret;
20 } 19 }
21 20
22 class SerializedVarTest : public PluginProxyTest { 21 class SerializedVarTest : public PluginProxyTest {
23 public: 22 public:
24 SerializedVarTest() {} 23 SerializedVarTest() {}
25 }; 24 };
26 25
27 } // namespace 26 } // namespace
28 27
29 // Tests output arguments in the plugin. This is when the host calls into the 28 // Tests output arguments in the plugin. This is when the host calls into the
30 // plugin and the plugin returns something via an out param, like an exception. 29 // plugin and the plugin returns something via an out param, like an exception.
31 TEST_F(SerializedVarTest, PluginSerializedVarInOutParam) { 30 TEST_F(SerializedVarTest, PluginSerializedVarInOutParam) {
32 ProxyAutoLock lock;
33 PP_Var host_object = MakeObjectVar(0x31337); 31 PP_Var host_object = MakeObjectVar(0x31337);
34 32
35 PP_Var plugin_object; 33 PP_Var plugin_object;
36 { 34 {
37 // Receive the object param, we should be tracking it with no refcount, and 35 // Receive the object param, we should be tracking it with no refcount, and
38 // no messages sent. 36 // no messages sent.
39 SerializedVarTestConstructor input(host_object); 37 SerializedVarTestConstructor input(host_object);
40 SerializedVarReceiveInput receive_input(input); 38 SerializedVarReceiveInput receive_input(input);
41 plugin_object = receive_input.Get(plugin_dispatcher()); 39 plugin_object = receive_input.Get(plugin_dispatcher());
42 EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object)); 40 EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object));
(...skipping 29 matching lines...) Expand all
72 // back to the host, so the object should no longer be in the tracker. The 70 // back to the host, so the object should no longer be in the tracker. The
73 // reference we added has been removed, so another message should be sent to 71 // reference we added has been removed, so another message should be sent to
74 // the host to tell it we're done with the object. 72 // the host to tell it we're done with the object.
75 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); 73 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object));
76 EXPECT_EQ(2u, sink().message_count()); 74 EXPECT_EQ(2u, sink().message_count());
77 } 75 }
78 76
79 // Tests output strings in the plugin. This is when the host calls into the 77 // Tests output strings in the plugin. This is when the host calls into the
80 // plugin with a string and the plugin returns it via an out param. 78 // plugin with a string and the plugin returns it via an out param.
81 TEST_F(SerializedVarTest, PluginSerializedStringVarInOutParam) { 79 TEST_F(SerializedVarTest, PluginSerializedStringVarInOutParam) {
82 ProxyAutoLock lock;
83 PP_Var plugin_string; 80 PP_Var plugin_string;
84 const std::string kTestString("elite"); 81 const std::string kTestString("elite");
85 { 82 {
86 // Receive the string param. We should track it with 1 refcount. 83 // Receive the string param. We should track it with 1 refcount.
87 SerializedVarTestConstructor input(kTestString); 84 SerializedVarTestConstructor input(kTestString);
88 SerializedVarReceiveInput receive_input(input); 85 SerializedVarReceiveInput receive_input(input);
89 plugin_string = receive_input.Get(plugin_dispatcher()); 86 plugin_string = receive_input.Get(plugin_dispatcher());
90 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_string)); 87 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_string));
91 EXPECT_EQ(0u, sink().message_count()); 88 EXPECT_EQ(0u, sink().message_count());
92 89
(...skipping 21 matching lines...) Expand all
114 } 111 }
115 // The reference the string had initially should be gone, and the reference we 112 // The reference the string had initially should be gone, and the reference we
116 // passed to the host should also be gone, so the string should be removed. 113 // passed to the host should also be gone, so the string should be removed.
117 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_string)); 114 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_string));
118 EXPECT_EQ(0u, sink().message_count()); 115 EXPECT_EQ(0u, sink().message_count());
119 } 116 }
120 117
121 // Tests receiving an argument and passing it back to the browser as an output 118 // Tests receiving an argument and passing it back to the browser as an output
122 // parameter. 119 // parameter.
123 TEST_F(SerializedVarTest, PluginSerializedVarOutParam) { 120 TEST_F(SerializedVarTest, PluginSerializedVarOutParam) {
124 ProxyAutoLock lock;
125 PP_Var host_object = MakeObjectVar(0x31337); 121 PP_Var host_object = MakeObjectVar(0x31337);
126 122
127 // Start tracking this object in the plugin. 123 // Start tracking this object in the plugin.
128 PP_Var plugin_object = var_tracker().ReceiveObjectPassRef( 124 PP_Var plugin_object = var_tracker().ReceiveObjectPassRef(
129 host_object, plugin_dispatcher()); 125 host_object, plugin_dispatcher());
130 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object)); 126 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
131 127
132 { 128 {
133 SerializedVar sv; 129 SerializedVar sv;
134 { 130 {
(...skipping 19 matching lines...) Expand all
154 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); 150 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object));
155 EXPECT_EQ(1u, sink().message_count()); 151 EXPECT_EQ(1u, sink().message_count());
156 152
157 // We don't bother validating that message since it's nontrivial and the 153 // We don't bother validating that message since it's nontrivial and the
158 // PluginVarTracker test has cases that cover that this message is correct. 154 // PluginVarTracker test has cases that cover that this message is correct.
159 } 155 }
160 156
161 // Tests the case that the plugin receives the same var twice as an input 157 // Tests the case that the plugin receives the same var twice as an input
162 // parameter (not passing ownership). 158 // parameter (not passing ownership).
163 TEST_F(SerializedVarTest, PluginReceiveInput) { 159 TEST_F(SerializedVarTest, PluginReceiveInput) {
164 ProxyAutoLock lock;
165 PP_Var host_object = MakeObjectVar(0x31337); 160 PP_Var host_object = MakeObjectVar(0x31337);
166 161
167 PP_Var plugin_object; 162 PP_Var plugin_object;
168 { 163 {
169 // Receive the first param, we should be tracking it with no refcount, and 164 // Receive the first param, we should be tracking it with no refcount, and
170 // no messages sent. 165 // no messages sent.
171 SerializedVarTestConstructor input1(host_object); 166 SerializedVarTestConstructor input1(host_object);
172 SerializedVarReceiveInput receive_input(input1); 167 SerializedVarReceiveInput receive_input(input1);
173 plugin_object = receive_input.Get(plugin_dispatcher()); 168 plugin_object = receive_input.Get(plugin_dispatcher());
174 EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object)); 169 EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object));
(...skipping 20 matching lines...) Expand all
195 } 190 }
196 191
197 // Since we didn't keep any refs to the objects, it should have freed the 192 // Since we didn't keep any refs to the objects, it should have freed the
198 // object. 193 // object.
199 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); 194 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object));
200 } 195 }
201 196
202 // Tests the case that the plugin receives the same vars twice as an input 197 // Tests the case that the plugin receives the same vars twice as an input
203 // parameter (not passing ownership) within a vector. 198 // parameter (not passing ownership) within a vector.
204 TEST_F(SerializedVarTest, PluginVectorReceiveInput) { 199 TEST_F(SerializedVarTest, PluginVectorReceiveInput) {
205 ProxyAutoLock lock;
206 PP_Var host_object = MakeObjectVar(0x31337); 200 PP_Var host_object = MakeObjectVar(0x31337);
207 201
208 PP_Var* plugin_objects; 202 PP_Var* plugin_objects;
209 PP_Var* plugin_objects2; 203 PP_Var* plugin_objects2;
210 { 204 {
211 // Receive the params. The object should be tracked with no refcount and 205 // Receive the params. The object should be tracked with no refcount and
212 // no messages sent. The string should is plugin-side only and should have 206 // no messages sent. The string should is plugin-side only and should have
213 // a reference-count of 1. 207 // a reference-count of 1.
214 std::vector<SerializedVar> input1; 208 std::vector<SerializedVar> input1;
215 input1.push_back(SerializedVarTestConstructor(host_object)); 209 input1.push_back(SerializedVarTestConstructor(host_object));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // Since we didn't keep any refs to the objects or strings, so they should 256 // Since we didn't keep any refs to the objects or strings, so they should
263 // have been freed. 257 // have been freed.
264 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects[0])); 258 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects[0]));
265 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects[1])); 259 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects[1]));
266 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects2[1])); 260 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects2[1]));
267 } 261 }
268 262
269 // Tests the plugin receiving a var as a return value from the browser 263 // Tests the plugin receiving a var as a return value from the browser
270 // two different times (passing ownership). 264 // two different times (passing ownership).
271 TEST_F(SerializedVarTest, PluginReceiveReturn) { 265 TEST_F(SerializedVarTest, PluginReceiveReturn) {
272 ProxyAutoLock lock;
273 PP_Var host_object = MakeObjectVar(0x31337); 266 PP_Var host_object = MakeObjectVar(0x31337);
274 267
275 PP_Var plugin_object; 268 PP_Var plugin_object;
276 { 269 {
277 // Receive the first param, we should be tracking it with a refcount of 1. 270 // Receive the first param, we should be tracking it with a refcount of 1.
278 SerializedVarTestConstructor input1(host_object); 271 SerializedVarTestConstructor input1(host_object);
279 ReceiveSerializedVarReturnValue receive_input(input1); 272 ReceiveSerializedVarReturnValue receive_input(input1);
280 plugin_object = receive_input.Return(plugin_dispatcher()); 273 plugin_object = receive_input.Return(plugin_dispatcher());
281 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object)); 274 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
282 EXPECT_EQ(0u, sink().message_count()); 275 EXPECT_EQ(0u, sink().message_count());
(...skipping 23 matching lines...) Expand all
306 // Manually release the last refcount, it should have freed it and sent a 299 // Manually release the last refcount, it should have freed it and sent a
307 // release message to the browser. 300 // release message to the browser.
308 var_tracker().ReleaseVar(plugin_object); 301 var_tracker().ReleaseVar(plugin_object);
309 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); 302 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object));
310 EXPECT_EQ(2u, sink().message_count()); 303 EXPECT_EQ(2u, sink().message_count());
311 } 304 }
312 305
313 // Returns a value from the browser to the plugin, then return that one ref 306 // Returns a value from the browser to the plugin, then return that one ref
314 // back to the browser. 307 // back to the browser.
315 TEST_F(SerializedVarTest, PluginReturnValue) { 308 TEST_F(SerializedVarTest, PluginReturnValue) {
316 ProxyAutoLock lock;
317 PP_Var host_object = MakeObjectVar(0x31337); 309 PP_Var host_object = MakeObjectVar(0x31337);
318 310
319 PP_Var plugin_object; 311 PP_Var plugin_object;
320 { 312 {
321 // Receive the param in the plugin. 313 // Receive the param in the plugin.
322 SerializedVarTestConstructor input1(host_object); 314 SerializedVarTestConstructor input1(host_object);
323 ReceiveSerializedVarReturnValue receive_input(input1); 315 ReceiveSerializedVarReturnValue receive_input(input1);
324 plugin_object = receive_input.Return(plugin_dispatcher()); 316 plugin_object = receive_input.Return(plugin_dispatcher());
325 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object)); 317 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
326 EXPECT_EQ(0u, sink().message_count()); 318 EXPECT_EQ(0u, sink().message_count());
(...skipping 12 matching lines...) Expand all
339 } 331 }
340 332
341 // When the ReturnValue object goes out of scope, it should have sent a 333 // When the ReturnValue object goes out of scope, it should have sent a
342 // release message to the browser. 334 // release message to the browser.
343 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); 335 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object));
344 EXPECT_EQ(1u, sink().message_count()); 336 EXPECT_EQ(1u, sink().message_count());
345 } 337 }
346 338
347 } // namespace proxy 339 } // namespace proxy
348 } // namespace ppapi 340 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppp_video_decoder_proxy.cc ('k') | ppapi/shared_impl/ppp_instance_combined.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698