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