| 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/scoped_ptr.h" | 7 #include "base/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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 new PluginInstance(delegate(), module(), |
| 145 static_cast<const PPP_Instance*>( | 145 static_cast<const PPP_Instance*>( |
| 146 GetMockInterface(PPP_INSTANCE_INTERFACE)))); | 146 GetMockInterface(PPP_INSTANCE_INTERFACE)), |
| 147 PluginInstance::PLUGIN_OWNS_INTERFACE)); |
| 147 PP_Instance pp_instance2 = instance2->pp_instance(); | 148 PP_Instance pp_instance2 = instance2->pp_instance(); |
| 148 | 149 |
| 149 // Make two resources and take refs on behalf of the "plugin" for each. | 150 // Make two resources and take refs on behalf of the "plugin" for each. |
| 150 scoped_refptr<TrackedMockResource> resource1( | 151 scoped_refptr<TrackedMockResource> resource1( |
| 151 new TrackedMockResource(instance2)); | 152 new TrackedMockResource(instance2)); |
| 152 resource1->GetReference(); | 153 resource1->GetReference(); |
| 153 scoped_refptr<TrackedMockResource> resource2( | 154 scoped_refptr<TrackedMockResource> resource2( |
| 154 new TrackedMockResource(instance2)); | 155 new TrackedMockResource(instance2)); |
| 155 resource2->GetReference(); | 156 resource2->GetReference(); |
| 156 | 157 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 171 ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); | 172 ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); |
| 172 resource1 = NULL; | 173 resource1 = NULL; |
| 173 ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); | 174 ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); |
| 174 } | 175 } |
| 175 | 176 |
| 176 TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { | 177 TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { |
| 177 // Make a second instance (the test harness already creates & manages one). | 178 // Make a second instance (the test harness already creates & manages one). |
| 178 scoped_refptr<PluginInstance> instance2( | 179 scoped_refptr<PluginInstance> instance2( |
| 179 new PluginInstance(delegate(), module(), | 180 new PluginInstance(delegate(), module(), |
| 180 static_cast<const PPP_Instance*>( | 181 static_cast<const PPP_Instance*>( |
| 181 GetMockInterface(PPP_INSTANCE_INTERFACE)))); | 182 GetMockInterface(PPP_INSTANCE_INTERFACE)), |
| 183 PluginInstance::PLUGIN_OWNS_INTERFACE)); |
| 182 PP_Instance pp_instance2 = instance2->pp_instance(); | 184 PP_Instance pp_instance2 = instance2->pp_instance(); |
| 183 | 185 |
| 184 // Make an object var. | 186 // Make an object var. |
| 185 scoped_ptr<NPObject> npobject(NewTrackedNPObject()); | 187 scoped_ptr<NPObject> npobject(NewTrackedNPObject()); |
| 186 ObjectVar::NPObjectToPPVar(instance2.get(), npobject.get()); | 188 ObjectVar::NPObjectToPPVar(instance2.get(), npobject.get()); |
| 187 | 189 |
| 188 EXPECT_EQ(1, g_npobjects_alive); | 190 EXPECT_EQ(1, g_npobjects_alive); |
| 189 EXPECT_EQ(1u, tracker().GetLiveObjectsForInstance(pp_instance2)); | 191 EXPECT_EQ(1u, tracker().GetLiveObjectsForInstance(pp_instance2)); |
| 190 | 192 |
| 191 // Free the instance, this should release the ObjectVar. | 193 // Free the instance, this should release the ObjectVar. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 220 | 222 |
| 221 // Releasing the resource should free the internal ref, and so making a new | 223 // Releasing the resource should free the internal ref, and so making a new |
| 222 // one now should generate a new ID. | 224 // one now should generate a new ID. |
| 223 PP_Var pp_object3 = ObjectVar::NPObjectToPPVar(instance(), npobject.get()); | 225 PP_Var pp_object3 = ObjectVar::NPObjectToPPVar(instance(), npobject.get()); |
| 224 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id); | 226 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id); |
| 225 tracker().UnrefVar(static_cast<int32_t>(pp_object3.value.as_id)); | 227 tracker().UnrefVar(static_cast<int32_t>(pp_object3.value.as_id)); |
| 226 } | 228 } |
| 227 | 229 |
| 228 } // namespace ppapi | 230 } // namespace ppapi |
| 229 } // namespace webkit | 231 } // namespace webkit |
| OLD | NEW |