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