OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 | 8 |
9 namespace pp { | 9 namespace pp { |
10 namespace proxy { | 10 namespace proxy { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 SerializedVarReceiveInput receive_input2(input2); | 92 SerializedVarReceiveInput receive_input2(input2); |
93 PP_Var plugin_object2 = receive_input2.Get(plugin_dispatcher()); | 93 PP_Var plugin_object2 = receive_input2.Get(plugin_dispatcher()); |
94 EXPECT_EQ(plugin_object.value.as_id, plugin_object2.value.as_id); | 94 EXPECT_EQ(plugin_object.value.as_id, plugin_object2.value.as_id); |
95 EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object)); | 95 EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object)); |
96 EXPECT_EQ(0u, sink().message_count()); | 96 EXPECT_EQ(0u, sink().message_count()); |
97 | 97 |
98 // Take a reference to the object, as if the plugin was using it, and then | 98 // Take a reference to the object, as if the plugin was using it, and then |
99 // release it, we should still be tracking the object since the | 99 // release it, we should still be tracking the object since the |
100 // ReceiveInputs keep the "track_with_no_reference_count" alive until | 100 // ReceiveInputs keep the "track_with_no_reference_count" alive until |
101 // they're destroyed. | 101 // they're destroyed. |
102 var_tracker().AddRef(plugin_object); | 102 var_tracker().AddRefVar(plugin_object); |
103 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object)); | 103 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object)); |
104 var_tracker().Release(plugin_object); | 104 var_tracker().ReleaseVar(plugin_object); |
105 EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object)); | 105 EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object)); |
106 EXPECT_EQ(2u, sink().message_count()); | 106 EXPECT_EQ(2u, sink().message_count()); |
107 } | 107 } |
108 | 108 |
109 // Since we didn't keep any refs to the objects, it should have freed the | 109 // Since we didn't keep any refs to the objects, it should have freed the |
110 // object. | 110 // object. |
111 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); | 111 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); |
112 } | 112 } |
113 | 113 |
114 // Tests the plugin receiving a var as a return value from the browser | 114 // Tests the plugin receiving a var as a return value from the browser |
(...skipping 21 matching lines...) Expand all Loading... |
136 EXPECT_EQ(2, var_tracker().GetRefCountForObject(plugin_object)); | 136 EXPECT_EQ(2, var_tracker().GetRefCountForObject(plugin_object)); |
137 EXPECT_EQ(1u, sink().message_count()); | 137 EXPECT_EQ(1u, sink().message_count()); |
138 } | 138 } |
139 | 139 |
140 // The ReceiveSerializedVarReturnValue destructor shouldn't have affected | 140 // The ReceiveSerializedVarReturnValue destructor shouldn't have affected |
141 // the refcount or sent any messages. | 141 // the refcount or sent any messages. |
142 EXPECT_EQ(2, var_tracker().GetRefCountForObject(plugin_object)); | 142 EXPECT_EQ(2, var_tracker().GetRefCountForObject(plugin_object)); |
143 EXPECT_EQ(1u, sink().message_count()); | 143 EXPECT_EQ(1u, sink().message_count()); |
144 | 144 |
145 // Manually release one refcount, it shouldn't have sent any more messages. | 145 // Manually release one refcount, it shouldn't have sent any more messages. |
146 var_tracker().Release(plugin_object); | 146 var_tracker().ReleaseVar(plugin_object); |
147 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object)); | 147 EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object)); |
148 EXPECT_EQ(1u, sink().message_count()); | 148 EXPECT_EQ(1u, sink().message_count()); |
149 | 149 |
150 // Manually release the last refcount, it should have freed it and sent a | 150 // Manually release the last refcount, it should have freed it and sent a |
151 // release message to the browser. | 151 // release message to the browser. |
152 var_tracker().Release(plugin_object); | 152 var_tracker().ReleaseVar(plugin_object); |
153 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); | 153 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); |
154 EXPECT_EQ(2u, sink().message_count()); | 154 EXPECT_EQ(2u, sink().message_count()); |
155 } | 155 } |
156 | 156 |
157 // Returns a value from the browser to the plugin, then return that one ref | 157 // Returns a value from the browser to the plugin, then return that one ref |
158 // back to the browser. | 158 // back to the browser. |
159 TEST_F(SerializedVarTest, PluginReturnValue) { | 159 TEST_F(SerializedVarTest, PluginReturnValue) { |
160 PP_Var host_object = MakeObjectVar(0x31337); | 160 PP_Var host_object = MakeObjectVar(0x31337); |
161 | 161 |
162 PP_Var plugin_object; | 162 PP_Var plugin_object; |
(...skipping 19 matching lines...) Expand all Loading... |
182 } | 182 } |
183 | 183 |
184 // When the ReturnValue object goes out of scope, it should have sent a | 184 // When the ReturnValue object goes out of scope, it should have sent a |
185 // release message to the browser. | 185 // release message to the browser. |
186 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); | 186 EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object)); |
187 EXPECT_EQ(1u, sink().message_count()); | 187 EXPECT_EQ(1u, sink().message_count()); |
188 } | 188 } |
189 | 189 |
190 } // namespace proxy | 190 } // namespace proxy |
191 } // namespace pp | 191 } // namespace pp |
OLD | NEW |