| 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "ppapi/c/pp_completion_callback.h" | 7 #include "ppapi/c/pp_completion_callback.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/shared_impl/callback_tracker.h" | 9 #include "ppapi/shared_impl/callback_tracker.h" |
| 10 #include "ppapi/shared_impl/resource.h" | 10 #include "ppapi/shared_impl/resource.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 private: | 73 private: |
| 74 CallbackRunInfo info_did_run_; | 74 CallbackRunInfo info_did_run_; |
| 75 CallbackRunInfo info_did_abort_; | 75 CallbackRunInfo info_did_abort_; |
| 76 CallbackRunInfo info_didnt_run_; | 76 CallbackRunInfo info_didnt_run_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 } // namespace | 79 } // namespace |
| 80 | 80 |
| 81 // Tests that callbacks are properly aborted on module shutdown. | 81 // Tests that callbacks are properly aborted on module shutdown. |
| 82 TEST_F(CallbackShutdownTest, AbortOnShutdown) { | 82 TEST_F(CallbackShutdownTest, AbortOnShutdown) { |
| 83 scoped_refptr<Resource> resource(new Resource(pp_instance())); | 83 scoped_refptr<Resource> resource(new Resource(OBJECT_IS_IMPL, pp_instance())); |
| 84 | 84 |
| 85 // Set up case (1) (see above). | 85 // Set up case (1) (see above). |
| 86 EXPECT_EQ(0U, info_did_run().run_count); | 86 EXPECT_EQ(0U, info_did_run().run_count); |
| 87 scoped_refptr<TrackedCallback> callback_did_run = new TrackedCallback( | 87 scoped_refptr<TrackedCallback> callback_did_run = new TrackedCallback( |
| 88 resource.get(), | 88 resource.get(), |
| 89 PP_MakeCompletionCallback(&TestCallback, &info_did_run())); | 89 PP_MakeCompletionCallback(&TestCallback, &info_did_run())); |
| 90 EXPECT_EQ(0U, info_did_run().run_count); | 90 EXPECT_EQ(0U, info_did_run().run_count); |
| 91 callback_did_run->Run(PP_OK); | 91 callback_did_run->Run(PP_OK); |
| 92 EXPECT_EQ(1U, info_did_run().run_count); | 92 EXPECT_EQ(1U, info_did_run().run_count); |
| 93 EXPECT_EQ(PP_OK, info_did_run().result); | 93 EXPECT_EQ(PP_OK, info_did_run().result); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 namespace { | 127 namespace { |
| 128 | 128 |
| 129 class CallbackResourceTest : public TrackedCallbackTest { | 129 class CallbackResourceTest : public TrackedCallbackTest { |
| 130 public: | 130 public: |
| 131 CallbackResourceTest() {} | 131 CallbackResourceTest() {} |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 class CallbackMockResource : public Resource { | 134 class CallbackMockResource : public Resource { |
| 135 public: | 135 public: |
| 136 CallbackMockResource(PP_Instance instance) : Resource(instance) {} | 136 CallbackMockResource(PP_Instance instance) |
| 137 : Resource(OBJECT_IS_IMPL, instance) {} |
| 137 ~CallbackMockResource() {} | 138 ~CallbackMockResource() {} |
| 138 | 139 |
| 139 PP_Resource SetupForTest() { | 140 PP_Resource SetupForTest() { |
| 140 PP_Resource resource_id = GetReference(); | 141 PP_Resource resource_id = GetReference(); |
| 141 EXPECT_NE(0, resource_id); | 142 EXPECT_NE(0, resource_id); |
| 142 | 143 |
| 143 callback_did_run_ = new TrackedCallback( | 144 callback_did_run_ = new TrackedCallback( |
| 144 this, | 145 this, |
| 145 PP_MakeCompletionCallback(&TestCallback, &info_did_run_)); | 146 PP_MakeCompletionCallback(&TestCallback, &info_did_run_)); |
| 146 EXPECT_EQ(0U, info_did_run_.run_count); | 147 EXPECT_EQ(0U, info_did_run_.run_count); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // Unref it again and do the same. | 258 // Unref it again and do the same. |
| 258 resource_tracker->ReleaseResource(new_resource_id); | 259 resource_tracker->ReleaseResource(new_resource_id); |
| 259 MessageLoop::current()->RunAllPending(); | 260 MessageLoop::current()->RunAllPending(); |
| 260 resource->CheckFinalState(); | 261 resource->CheckFinalState(); |
| 261 | 262 |
| 262 // This shouldn't be needed, but make sure there are no stranded tasks. | 263 // This shouldn't be needed, but make sure there are no stranded tasks. |
| 263 MessageLoop::current()->RunAllPending(); | 264 MessageLoop::current()->RunAllPending(); |
| 264 } | 265 } |
| 265 | 266 |
| 266 } // namespace ppapi | 267 } // namespace ppapi |
| OLD | NEW |