| 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/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "ppapi/c/pp_completion_callback.h" | 9 #include "ppapi/c/pp_completion_callback.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // first resource doesn't much up the second resource. | 195 // first resource doesn't much up the second resource. |
| 196 scoped_refptr<CallbackMockResource> resource_2( | 196 scoped_refptr<CallbackMockResource> resource_2( |
| 197 new CallbackMockResource(instance())); | 197 new CallbackMockResource(instance())); |
| 198 PP_Resource resource_2_id = resource_2->SetupForTest(); | 198 PP_Resource resource_2_id = resource_2->SetupForTest(); |
| 199 | 199 |
| 200 // Double-check that resource #1 is still okay. | 200 // Double-check that resource #1 is still okay. |
| 201 resource_1->CheckIntermediateState(); | 201 resource_1->CheckIntermediateState(); |
| 202 | 202 |
| 203 // Kill resource #1, spin the message loop to run posted calls, and check that | 203 // Kill resource #1, spin the message loop to run posted calls, and check that |
| 204 // things are in the expected states. | 204 // things are in the expected states. |
| 205 resource_tracker->UnrefResource(resource_1_id); | 205 resource_tracker->ReleaseResource(resource_1_id); |
| 206 MessageLoop::current()->RunAllPending(); | 206 MessageLoop::current()->RunAllPending(); |
| 207 resource_1->CheckFinalState(); | 207 resource_1->CheckFinalState(); |
| 208 resource_2->CheckIntermediateState(); | 208 resource_2->CheckIntermediateState(); |
| 209 | 209 |
| 210 // Kill resource #2. | 210 // Kill resource #2. |
| 211 resource_tracker->UnrefResource(resource_2_id); | 211 resource_tracker->ReleaseResource(resource_2_id); |
| 212 MessageLoop::current()->RunAllPending(); | 212 MessageLoop::current()->RunAllPending(); |
| 213 resource_1->CheckFinalState(); | 213 resource_1->CheckFinalState(); |
| 214 resource_2->CheckFinalState(); | 214 resource_2->CheckFinalState(); |
| 215 | 215 |
| 216 // This shouldn't be needed, but make sure there are no stranded tasks. | 216 // This shouldn't be needed, but make sure there are no stranded tasks. |
| 217 MessageLoop::current()->RunAllPending(); | 217 MessageLoop::current()->RunAllPending(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 // Test that "resurrecting" a resource (getting a new ID for a |Resource|) | 220 // Test that "resurrecting" a resource (getting a new ID for a |Resource|) |
| 221 // doesn't resurrect callbacks. | 221 // doesn't resurrect callbacks. |
| 222 TEST_F(CallbackResourceTest, Resurrection) { | 222 TEST_F(CallbackResourceTest, Resurrection) { |
| 223 ResourceTracker* resource_tracker = ResourceTracker::Get(); | 223 ResourceTracker* resource_tracker = ResourceTracker::Get(); |
| 224 | 224 |
| 225 scoped_refptr<CallbackMockResource> resource( | 225 scoped_refptr<CallbackMockResource> resource( |
| 226 new CallbackMockResource(instance())); | 226 new CallbackMockResource(instance())); |
| 227 PP_Resource resource_id = resource->SetupForTest(); | 227 PP_Resource resource_id = resource->SetupForTest(); |
| 228 | 228 |
| 229 // Unref it, spin the message loop to run posted calls, and check that things | 229 // Unref it, spin the message loop to run posted calls, and check that things |
| 230 // are in the expected states. | 230 // are in the expected states. |
| 231 resource_tracker->UnrefResource(resource_id); | 231 resource_tracker->ReleaseResource(resource_id); |
| 232 MessageLoop::current()->RunAllPending(); | 232 MessageLoop::current()->RunAllPending(); |
| 233 resource->CheckFinalState(); | 233 resource->CheckFinalState(); |
| 234 | 234 |
| 235 // "Resurrect" it and check that the callbacks are still dead. | 235 // "Resurrect" it and check that the callbacks are still dead. |
| 236 PP_Resource new_resource_id = resource->GetReference(); | 236 PP_Resource new_resource_id = resource->GetReference(); |
| 237 MessageLoop::current()->RunAllPending(); | 237 MessageLoop::current()->RunAllPending(); |
| 238 resource->CheckFinalState(); | 238 resource->CheckFinalState(); |
| 239 | 239 |
| 240 // Unref it again and do the same. | 240 // Unref it again and do the same. |
| 241 resource_tracker->UnrefResource(new_resource_id); | 241 resource_tracker->ReleaseResource(new_resource_id); |
| 242 MessageLoop::current()->RunAllPending(); | 242 MessageLoop::current()->RunAllPending(); |
| 243 resource->CheckFinalState(); | 243 resource->CheckFinalState(); |
| 244 | 244 |
| 245 // This shouldn't be needed, but make sure there are no stranded tasks. | 245 // This shouldn't be needed, but make sure there are no stranded tasks. |
| 246 MessageLoop::current()->RunAllPending(); | 246 MessageLoop::current()->RunAllPending(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 } // namespace ppapi | 249 } // namespace ppapi |
| 250 } // namespace webkit | 250 } // namespace webkit |
| OLD | NEW |