| 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 PluginInstance::Create0_5(delegate(), module(), | 144 PluginInstance::Create1_0(delegate(), module(), |
| 145 GetMockInterface(PPP_INSTANCE_INTERFACE_0_5))); | 145 GetMockInterface(PPP_INSTANCE_INTERFACE_1_0))); |
| 146 PP_Instance pp_instance2 = instance2->pp_instance(); | 146 PP_Instance pp_instance2 = instance2->pp_instance(); |
| 147 | 147 |
| 148 // 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. |
| 149 scoped_refptr<TrackedMockResource> resource1( | 149 scoped_refptr<TrackedMockResource> resource1( |
| 150 new TrackedMockResource(instance2)); | 150 new TrackedMockResource(instance2)); |
| 151 resource1->GetReference(); | 151 resource1->GetReference(); |
| 152 scoped_refptr<TrackedMockResource> resource2( | 152 scoped_refptr<TrackedMockResource> resource2( |
| 153 new TrackedMockResource(instance2)); | 153 new TrackedMockResource(instance2)); |
| 154 resource2->GetReference(); | 154 resource2->GetReference(); |
| 155 | 155 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 168 // should have a NULL instance. | 168 // should have a NULL instance. |
| 169 ASSERT_FALSE(resource1->instance()); | 169 ASSERT_FALSE(resource1->instance()); |
| 170 ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); | 170 ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); |
| 171 resource1 = NULL; | 171 resource1 = NULL; |
| 172 ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); | 172 ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); |
| 173 } | 173 } |
| 174 | 174 |
| 175 TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { | 175 TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { |
| 176 // Make a second instance (the test harness already creates & manages one). | 176 // Make a second instance (the test harness already creates & manages one). |
| 177 scoped_refptr<PluginInstance> instance2( | 177 scoped_refptr<PluginInstance> instance2( |
| 178 PluginInstance::Create0_5(delegate(), module(), | 178 PluginInstance::Create1_0(delegate(), module(), |
| 179 GetMockInterface(PPP_INSTANCE_INTERFACE_0_5))); | 179 GetMockInterface(PPP_INSTANCE_INTERFACE_1_0))); |
| 180 PP_Instance pp_instance2 = instance2->pp_instance(); | 180 PP_Instance pp_instance2 = instance2->pp_instance(); |
| 181 | 181 |
| 182 // Make an object var. | 182 // Make an object var. |
| 183 scoped_ptr<NPObject> npobject(NewTrackedNPObject()); | 183 scoped_ptr<NPObject> npobject(NewTrackedNPObject()); |
| 184 ObjectVar::NPObjectToPPVar(instance2.get(), npobject.get()); | 184 ObjectVar::NPObjectToPPVar(instance2.get(), npobject.get()); |
| 185 | 185 |
| 186 EXPECT_EQ(1, g_npobjects_alive); | 186 EXPECT_EQ(1, g_npobjects_alive); |
| 187 EXPECT_EQ(1u, tracker().GetLiveObjectsForInstance(pp_instance2)); | 187 EXPECT_EQ(1u, tracker().GetLiveObjectsForInstance(pp_instance2)); |
| 188 | 188 |
| 189 // Free the instance, this should release the ObjectVar. | 189 // Free the instance, this should release the ObjectVar. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 218 | 218 |
| 219 // 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 |
| 220 // one now should generate a new ID. | 220 // one now should generate a new ID. |
| 221 PP_Var pp_object3 = ObjectVar::NPObjectToPPVar(instance(), npobject.get()); | 221 PP_Var pp_object3 = ObjectVar::NPObjectToPPVar(instance(), npobject.get()); |
| 222 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); |
| 223 tracker().UnrefVar(static_cast<int32_t>(pp_object3.value.as_id)); | 223 tracker().UnrefVar(static_cast<int32_t>(pp_object3.value.as_id)); |
| 224 } | 224 } |
| 225 | 225 |
| 226 } // namespace ppapi | 226 } // namespace ppapi |
| 227 } // namespace webkit | 227 } // namespace webkit |
| OLD | NEW |