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 "webkit/plugins/ppapi/ppapi_unittest.h" | 5 #include "webkit/plugins/ppapi/ppapi_unittest.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
9 #include "ppapi/c/ppp_instance.h" | 9 #include "ppapi/c/ppp_instance.h" |
10 #include "third_party/npapi/bindings/npruntime.h" | 10 #include "third_party/npapi/bindings/npruntime.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // Now we have two refs, derefing twice should delete the object. | 134 // Now we have two refs, derefing twice should delete the object. |
135 tracker().UnrefResource(resource_id); | 135 tracker().UnrefResource(resource_id); |
136 ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); | 136 ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); |
137 tracker().UnrefResource(resource_id); | 137 tracker().UnrefResource(resource_id); |
138 ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); | 138 ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); |
139 } | 139 } |
140 | 140 |
141 TEST_F(ResourceTrackerTest, DeleteResourceWithInstance) { | 141 TEST_F(ResourceTrackerTest, DeleteResourceWithInstance) { |
142 // Make a second instance (the test harness already creates & manages one). | 142 // Make a second instance (the test harness already creates & manages one). |
143 scoped_refptr<PluginInstance> instance2( | 143 scoped_refptr<PluginInstance> instance2( |
144 new PluginInstance(delegate(), module(), | 144 PluginInstance::Create0_5(delegate(), module(), |
145 PluginInstance::new_instance_interface<PPP_Instance>( | 145 GetMockInterface(PPP_INSTANCE_INTERFACE_0_5))); |
146 GetMockInterface(PPP_INSTANCE_INTERFACE)))); | |
147 PP_Instance pp_instance2 = instance2->pp_instance(); | 146 PP_Instance pp_instance2 = instance2->pp_instance(); |
148 | 147 |
149 // Make two resources and take refs on behalf of the "plugin" for each. | 148 // Make two resources and take refs on behalf of the "plugin" for each. |
150 scoped_refptr<TrackedMockResource> resource1( | 149 scoped_refptr<TrackedMockResource> resource1( |
151 new TrackedMockResource(instance2)); | 150 new TrackedMockResource(instance2)); |
152 resource1->GetReference(); | 151 resource1->GetReference(); |
153 scoped_refptr<TrackedMockResource> resource2( | 152 scoped_refptr<TrackedMockResource> resource2( |
154 new TrackedMockResource(instance2)); | 153 new TrackedMockResource(instance2)); |
155 resource2->GetReference(); | 154 resource2->GetReference(); |
156 | 155 |
(...skipping 12 matching lines...) Expand all Loading... |
169 // should have a NULL instance. | 168 // should have a NULL instance. |
170 ASSERT_FALSE(resource1->instance()); | 169 ASSERT_FALSE(resource1->instance()); |
171 ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); | 170 ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); |
172 resource1 = NULL; | 171 resource1 = NULL; |
173 ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); | 172 ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); |
174 } | 173 } |
175 | 174 |
176 TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { | 175 TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { |
177 // Make a second instance (the test harness already creates & manages one). | 176 // Make a second instance (the test harness already creates & manages one). |
178 scoped_refptr<PluginInstance> instance2( | 177 scoped_refptr<PluginInstance> instance2( |
179 new PluginInstance(delegate(), module(), | 178 PluginInstance::Create0_5(delegate(), module(), |
180 PluginInstance::new_instance_interface<PPP_Instance>( | 179 GetMockInterface(PPP_INSTANCE_INTERFACE_0_5))); |
181 GetMockInterface(PPP_INSTANCE_INTERFACE)))); | |
182 PP_Instance pp_instance2 = instance2->pp_instance(); | 180 PP_Instance pp_instance2 = instance2->pp_instance(); |
183 | 181 |
184 // Make an object var. | 182 // Make an object var. |
185 scoped_ptr<NPObject> npobject(NewTrackedNPObject()); | 183 scoped_ptr<NPObject> npobject(NewTrackedNPObject()); |
186 ObjectVar::NPObjectToPPVar(instance2.get(), npobject.get()); | 184 ObjectVar::NPObjectToPPVar(instance2.get(), npobject.get()); |
187 | 185 |
188 EXPECT_EQ(1, g_npobjects_alive); | 186 EXPECT_EQ(1, g_npobjects_alive); |
189 EXPECT_EQ(1u, tracker().GetLiveObjectsForInstance(pp_instance2)); | 187 EXPECT_EQ(1u, tracker().GetLiveObjectsForInstance(pp_instance2)); |
190 | 188 |
191 // Free the instance, this should release the ObjectVar. | 189 // Free the instance, this should release the ObjectVar. |
(...skipping 28 matching lines...) Expand all Loading... |
220 | 218 |
221 // Releasing the resource should free the internal ref, and so making a new | 219 // Releasing the resource should free the internal ref, and so making a new |
222 // one now should generate a new ID. | 220 // one now should generate a new ID. |
223 PP_Var pp_object3 = ObjectVar::NPObjectToPPVar(instance(), npobject.get()); | 221 PP_Var pp_object3 = ObjectVar::NPObjectToPPVar(instance(), npobject.get()); |
224 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id); | 222 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id); |
225 tracker().UnrefVar(static_cast<int32_t>(pp_object3.value.as_id)); | 223 tracker().UnrefVar(static_cast<int32_t>(pp_object3.value.as_id)); |
226 } | 224 } |
227 | 225 |
228 } // namespace ppapi | 226 } // namespace ppapi |
229 } // namespace webkit | 227 } // namespace webkit |
OLD | NEW |