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" |
11 #include "webkit/plugins/ppapi/callbacks.h" | 11 #include "webkit/plugins/ppapi/callbacks.h" |
12 #include "webkit/plugins/ppapi/host_globals.h" | |
13 #include "webkit/plugins/ppapi/mock_resource.h" | 12 #include "webkit/plugins/ppapi/mock_resource.h" |
14 #include "webkit/plugins/ppapi/plugin_module.h" | 13 #include "webkit/plugins/ppapi/plugin_module.h" |
15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
16 #include "webkit/plugins/ppapi/resource_helper.h" | 15 #include "webkit/plugins/ppapi/resource_helper.h" |
17 #include "webkit/plugins/ppapi/resource_tracker.h" | 16 #include "webkit/plugins/ppapi/resource_tracker.h" |
18 | 17 |
19 namespace webkit { | 18 namespace webkit { |
20 namespace ppapi { | 19 namespace ppapi { |
21 | 20 |
22 struct CallbackRunInfo { | 21 struct CallbackRunInfo { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 177 |
179 } // namespace | 178 } // namespace |
180 | 179 |
181 class CallbackResourceTest : public PpapiUnittest { | 180 class CallbackResourceTest : public PpapiUnittest { |
182 public: | 181 public: |
183 CallbackResourceTest() {} | 182 CallbackResourceTest() {} |
184 }; | 183 }; |
185 | 184 |
186 // Test that callbacks get aborted on the last resource unref. | 185 // Test that callbacks get aborted on the last resource unref. |
187 TEST_F(CallbackResourceTest, AbortOnNoRef) { | 186 TEST_F(CallbackResourceTest, AbortOnNoRef) { |
188 ResourceTracker* resource_tracker = | 187 ResourceTracker* resource_tracker = ResourceTracker::Get(); |
189 HostGlobals::Get()->host_resource_tracker(); | |
190 | 188 |
191 // Test several things: Unref-ing a resource (to zero refs) with callbacks | 189 // Test several things: Unref-ing a resource (to zero refs) with callbacks |
192 // which (1) have been run, (2) have been aborted, (3) haven't been completed. | 190 // which (1) have been run, (2) have been aborted, (3) haven't been completed. |
193 // Check that the uncompleted one gets aborted, and that the others don't get | 191 // Check that the uncompleted one gets aborted, and that the others don't get |
194 // called again. | 192 // called again. |
195 scoped_refptr<CallbackMockResource> resource_1( | 193 scoped_refptr<CallbackMockResource> resource_1( |
196 new CallbackMockResource(instance()->pp_instance())); | 194 new CallbackMockResource(instance()->pp_instance())); |
197 PP_Resource resource_1_id = resource_1->SetupForTest(); | 195 PP_Resource resource_1_id = resource_1->SetupForTest(); |
198 | 196 |
199 // Also do the same for a second resource, and make sure that unref-ing the | 197 // Also do the same for a second resource, and make sure that unref-ing the |
(...skipping 18 matching lines...) Expand all Loading... |
218 resource_1->CheckFinalState(); | 216 resource_1->CheckFinalState(); |
219 resource_2->CheckFinalState(); | 217 resource_2->CheckFinalState(); |
220 | 218 |
221 // This shouldn't be needed, but make sure there are no stranded tasks. | 219 // This shouldn't be needed, but make sure there are no stranded tasks. |
222 MessageLoop::current()->RunAllPending(); | 220 MessageLoop::current()->RunAllPending(); |
223 } | 221 } |
224 | 222 |
225 // Test that "resurrecting" a resource (getting a new ID for a |Resource|) | 223 // Test that "resurrecting" a resource (getting a new ID for a |Resource|) |
226 // doesn't resurrect callbacks. | 224 // doesn't resurrect callbacks. |
227 TEST_F(CallbackResourceTest, Resurrection) { | 225 TEST_F(CallbackResourceTest, Resurrection) { |
228 ResourceTracker* resource_tracker = | 226 ResourceTracker* resource_tracker = ResourceTracker::Get(); |
229 HostGlobals::Get()->host_resource_tracker(); | |
230 | 227 |
231 scoped_refptr<CallbackMockResource> resource( | 228 scoped_refptr<CallbackMockResource> resource( |
232 new CallbackMockResource(instance()->pp_instance())); | 229 new CallbackMockResource(instance()->pp_instance())); |
233 PP_Resource resource_id = resource->SetupForTest(); | 230 PP_Resource resource_id = resource->SetupForTest(); |
234 | 231 |
235 // Unref it, spin the message loop to run posted calls, and check that things | 232 // Unref it, spin the message loop to run posted calls, and check that things |
236 // are in the expected states. | 233 // are in the expected states. |
237 resource_tracker->ReleaseResource(resource_id); | 234 resource_tracker->ReleaseResource(resource_id); |
238 MessageLoop::current()->RunAllPending(); | 235 MessageLoop::current()->RunAllPending(); |
239 resource->CheckFinalState(); | 236 resource->CheckFinalState(); |
240 | 237 |
241 // "Resurrect" it and check that the callbacks are still dead. | 238 // "Resurrect" it and check that the callbacks are still dead. |
242 PP_Resource new_resource_id = resource->GetReference(); | 239 PP_Resource new_resource_id = resource->GetReference(); |
243 MessageLoop::current()->RunAllPending(); | 240 MessageLoop::current()->RunAllPending(); |
244 resource->CheckFinalState(); | 241 resource->CheckFinalState(); |
245 | 242 |
246 // Unref it again and do the same. | 243 // Unref it again and do the same. |
247 resource_tracker->ReleaseResource(new_resource_id); | 244 resource_tracker->ReleaseResource(new_resource_id); |
248 MessageLoop::current()->RunAllPending(); | 245 MessageLoop::current()->RunAllPending(); |
249 resource->CheckFinalState(); | 246 resource->CheckFinalState(); |
250 | 247 |
251 // This shouldn't be needed, but make sure there are no stranded tasks. | 248 // This shouldn't be needed, but make sure there are no stranded tasks. |
252 MessageLoop::current()->RunAllPending(); | 249 MessageLoop::current()->RunAllPending(); |
253 } | 250 } |
254 | 251 |
255 } // namespace ppapi | 252 } // namespace ppapi |
256 } // namespace webkit | 253 } // namespace webkit |
OLD | NEW |