[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ppapi/proxy/ppapi_proxy_test.h" |
| 6 | |
| 7 | #include "ppapi/proxy/serialized_var.h" |
| 8 | |
| 9 | namespace pp { |
| 10 | namespace proxy { |
| 11 | |
| 12 | namespace { |
| 13 | |
| 14 | PP_Var MakeStringVar(int64_t string_id) { |
| 15 | PP_Var ret; |
| 16 | ret.type = PP_VARTYPE_STRING; |
| 17 | ret.value.as_id = string_id; |
| 18 | return ret; |
| 19 | } |
| 20 | |
| 21 | PP_Var MakeObjectVar(int64_t object_id) { |
| 22 | PP_Var ret; |
| 23 | ret.type = PP_VARTYPE_OBJECT; |
| 24 | ret.value.as_id = object_id; |
| 25 | return ret; |
| 26 | } |
| 27 | |
| 28 | class SerializedVarTest : public PluginProxyTest { |
| 29 | public: |
| 30 | SerializedVarTest() {} |
| 31 | }; |
| 32 | |
| 33 | } // namespace |
| 34 | |
| 35 | // Tests output arguments. |
| 36 | TEST_F(SerializedVarTest, PluginSerializedVarOutParam) { |
| 37 | PP_Var host_object = MakeObjectVar(0x31337); |
| 38 | |
| 39 | // Start tracking this object in the plugin. |
| 40 | PP_Var plugin_object = var_tracker().ReceiveObjectPassRef( |
| 41 | host_object, plugin_dispatcher()); |
| 42 | EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object)); |
| 43 | |
| 44 | { |
| 45 | SerializedVar sv; |
| 46 | { |
| 47 | // The "OutParam" does its work in its destructor, it will write the |
| 48 | // information to the SerializedVar we passed in the constructor. |
| 49 | SerializedVarOutParam out_param(&sv); |
| 50 | *out_param.OutParam(plugin_dispatcher()) = plugin_object; |
| 51 | } |
| 52 | |
| 53 | // The object should have transformed the plugin object back to the host |
| 54 | // object ID. Nothing in the var tracker should have changed yet, and no |
| 55 | // messages should have been sent. |
| 56 | SerializedVarTestReader reader(sv); |
| 57 | EXPECT_EQ(host_object.value.as_id, reader.GetIncompleteVar().value.as_id); |
| 58 | EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object)); |
| 59 | EXPECT_EQ(0u, sink().message_count()); |
| 60 | } |
| 61 | |
| 62 | // The out param should have done an "end send pass ref" on the plugin |
| 63 | // var serialization rules, which should have in turn released the reference |
| 64 | // in the var tracker. Since we only had one reference, this should have sent |
| 65 | // a release to the browser. |
| 66 | EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); |
| 67 | EXPECT_EQ(1u, sink().message_count()); |
| 68 | |
| 69 | // We don't bother validating that message since it's nontrivial and the |
| 70 | // PluginVarTracker test has cases that cover that this message is correct. |
| 71 | } |
| 72 | |
| 73 | } // namespace proxy |
| 74 | } // namespace pp |