Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: ppapi/shared_impl/tracked_callback_unittest.cc

Issue 19492014: PPAPI: Purposely leak ProxyLock, fix shutdown race (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test cleanup Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/message_loop.h" 6 #include "base/message_loop/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/proxy_lock.h"
10 #include "ppapi/shared_impl/resource.h" 11 #include "ppapi/shared_impl/resource.h"
11 #include "ppapi/shared_impl/resource_tracker.h" 12 #include "ppapi/shared_impl/resource_tracker.h"
12 #include "ppapi/shared_impl/test_globals.h" 13 #include "ppapi/shared_impl/test_globals.h"
13 #include "ppapi/shared_impl/tracked_callback.h" 14 #include "ppapi/shared_impl/tracked_callback.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace ppapi { 17 namespace ppapi {
17 18
18 namespace { 19 namespace {
19 20
20 class TrackedCallbackTest : public testing::Test { 21 class TrackedCallbackTest : public testing::Test {
21 public: 22 public:
22 TrackedCallbackTest() 23 TrackedCallbackTest()
23 : message_loop_(base::MessageLoop::TYPE_DEFAULT), pp_instance_(1234) {} 24 : message_loop_(base::MessageLoop::TYPE_DEFAULT), pp_instance_(1234) {}
24 25
25 PP_Instance pp_instance() const { return pp_instance_; } 26 PP_Instance pp_instance() const { return pp_instance_; }
26 27
27 virtual void SetUp() OVERRIDE { 28 virtual void SetUp() OVERRIDE {
29 ProxyLock::EnableLockingOnThreadForTest();
30 ProxyAutoLock lock;
28 globals_.GetResourceTracker()->DidCreateInstance(pp_instance_); 31 globals_.GetResourceTracker()->DidCreateInstance(pp_instance_);
29 } 32 }
30 virtual void TearDown() OVERRIDE { 33 virtual void TearDown() OVERRIDE {
34 ProxyAutoLock lock;
31 globals_.GetResourceTracker()->DidDeleteInstance(pp_instance_); 35 globals_.GetResourceTracker()->DidDeleteInstance(pp_instance_);
32 } 36 }
33 37
34 private: 38 private:
35 base::MessageLoop message_loop_; 39 base::MessageLoop message_loop_;
36 TestGlobals globals_; 40 TestGlobals globals_;
37 PP_Instance pp_instance_; 41 PP_Instance pp_instance_;
38 }; 42 };
39 43
40 struct CallbackRunInfo { 44 struct CallbackRunInfo {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 private: 76 private:
73 CallbackRunInfo info_did_run_; 77 CallbackRunInfo info_did_run_;
74 CallbackRunInfo info_did_abort_; 78 CallbackRunInfo info_did_abort_;
75 CallbackRunInfo info_didnt_run_; 79 CallbackRunInfo info_didnt_run_;
76 }; 80 };
77 81
78 } // namespace 82 } // namespace
79 83
80 // Tests that callbacks are properly aborted on module shutdown. 84 // Tests that callbacks are properly aborted on module shutdown.
81 TEST_F(CallbackShutdownTest, AbortOnShutdown) { 85 TEST_F(CallbackShutdownTest, AbortOnShutdown) {
86 ProxyAutoLock lock;
82 scoped_refptr<Resource> resource(new Resource(OBJECT_IS_IMPL, pp_instance())); 87 scoped_refptr<Resource> resource(new Resource(OBJECT_IS_IMPL, pp_instance()));
83 88
84 // Set up case (1) (see above). 89 // Set up case (1) (see above).
85 EXPECT_EQ(0U, info_did_run().run_count); 90 EXPECT_EQ(0U, info_did_run().run_count);
86 scoped_refptr<TrackedCallback> callback_did_run = new TrackedCallback( 91 scoped_refptr<TrackedCallback> callback_did_run = new TrackedCallback(
87 resource.get(), 92 resource.get(),
88 PP_MakeCompletionCallback(&TestCallback, &info_did_run())); 93 PP_MakeCompletionCallback(&TestCallback, &info_did_run()));
89 EXPECT_EQ(0U, info_did_run().run_count); 94 EXPECT_EQ(0U, info_did_run().run_count);
90 callback_did_run->Run(PP_OK); 95 callback_did_run->Run(PP_OK);
91 EXPECT_EQ(1U, info_did_run().run_count); 96 EXPECT_EQ(1U, info_did_run().run_count);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 CallbackRunInfo info_did_abort_; 194 CallbackRunInfo info_did_abort_;
190 195
191 scoped_refptr<TrackedCallback> callback_didnt_run_; 196 scoped_refptr<TrackedCallback> callback_didnt_run_;
192 CallbackRunInfo info_didnt_run_; 197 CallbackRunInfo info_didnt_run_;
193 }; 198 };
194 199
195 } // namespace 200 } // namespace
196 201
197 // Test that callbacks get aborted on the last resource unref. 202 // Test that callbacks get aborted on the last resource unref.
198 TEST_F(CallbackResourceTest, AbortOnNoRef) { 203 TEST_F(CallbackResourceTest, AbortOnNoRef) {
204 ProxyAutoLock lock;
199 ResourceTracker* resource_tracker = 205 ResourceTracker* resource_tracker =
200 PpapiGlobals::Get()->GetResourceTracker(); 206 PpapiGlobals::Get()->GetResourceTracker();
201 207
202 // Test several things: Unref-ing a resource (to zero refs) with callbacks 208 // Test several things: Unref-ing a resource (to zero refs) with callbacks
203 // which (1) have been run, (2) have been aborted, (3) haven't been completed. 209 // which (1) have been run, (2) have been aborted, (3) haven't been completed.
204 // Check that the uncompleted one gets aborted, and that the others don't get 210 // Check that the uncompleted one gets aborted, and that the others don't get
205 // called again. 211 // called again.
206 scoped_refptr<CallbackMockResource> resource_1( 212 scoped_refptr<CallbackMockResource> resource_1(
207 new CallbackMockResource(pp_instance())); 213 new CallbackMockResource(pp_instance()));
208 PP_Resource resource_1_id = resource_1->SetupForTest(); 214 PP_Resource resource_1_id = resource_1->SetupForTest();
209 215
210 // Also do the same for a second resource, and make sure that unref-ing the 216 // Also do the same for a second resource, and make sure that unref-ing the
211 // first resource doesn't much up the second resource. 217 // first resource doesn't much up the second resource.
212 scoped_refptr<CallbackMockResource> resource_2( 218 scoped_refptr<CallbackMockResource> resource_2(
213 new CallbackMockResource(pp_instance())); 219 new CallbackMockResource(pp_instance()));
214 PP_Resource resource_2_id = resource_2->SetupForTest(); 220 PP_Resource resource_2_id = resource_2->SetupForTest();
215 221
216 // Double-check that resource #1 is still okay. 222 // Double-check that resource #1 is still okay.
217 resource_1->CheckIntermediateState(); 223 resource_1->CheckIntermediateState();
218 224
219 // Kill resource #1, spin the message loop to run posted calls, and check that 225 // Kill resource #1, spin the message loop to run posted calls, and check that
220 // things are in the expected states. 226 // things are in the expected states.
221 resource_tracker->ReleaseResource(resource_1_id); 227 resource_tracker->ReleaseResource(resource_1_id);
222 base::MessageLoop::current()->RunUntilIdle(); 228 {
229 ProxyAutoUnlock unlock;
230 base::MessageLoop::current()->RunUntilIdle();
231 }
223 resource_1->CheckFinalState(); 232 resource_1->CheckFinalState();
224 resource_2->CheckIntermediateState(); 233 resource_2->CheckIntermediateState();
225 234
226 // Kill resource #2. 235 // Kill resource #2.
227 resource_tracker->ReleaseResource(resource_2_id); 236 resource_tracker->ReleaseResource(resource_2_id);
228 base::MessageLoop::current()->RunUntilIdle(); 237 {
238 ProxyAutoUnlock unlock;
239 base::MessageLoop::current()->RunUntilIdle();
240 }
229 resource_1->CheckFinalState(); 241 resource_1->CheckFinalState();
230 resource_2->CheckFinalState(); 242 resource_2->CheckFinalState();
231 243
232 // This shouldn't be needed, but make sure there are no stranded tasks. 244 // This shouldn't be needed, but make sure there are no stranded tasks.
233 base::MessageLoop::current()->RunUntilIdle(); 245 {
246 ProxyAutoUnlock unlock;
247 base::MessageLoop::current()->RunUntilIdle();
248 }
234 } 249 }
235 250
236 // Test that "resurrecting" a resource (getting a new ID for a |Resource|) 251 // Test that "resurrecting" a resource (getting a new ID for a |Resource|)
237 // doesn't resurrect callbacks. 252 // doesn't resurrect callbacks.
238 TEST_F(CallbackResourceTest, Resurrection) { 253 TEST_F(CallbackResourceTest, Resurrection) {
254 ProxyAutoLock lock;
239 ResourceTracker* resource_tracker = 255 ResourceTracker* resource_tracker =
240 PpapiGlobals::Get()->GetResourceTracker(); 256 PpapiGlobals::Get()->GetResourceTracker();
241 257
242 scoped_refptr<CallbackMockResource> resource( 258 scoped_refptr<CallbackMockResource> resource(
243 new CallbackMockResource(pp_instance())); 259 new CallbackMockResource(pp_instance()));
244 PP_Resource resource_id = resource->SetupForTest(); 260 PP_Resource resource_id = resource->SetupForTest();
245 261
246 // Unref it, spin the message loop to run posted calls, and check that things 262 // Unref it, spin the message loop to run posted calls, and check that things
247 // are in the expected states. 263 // are in the expected states.
248 resource_tracker->ReleaseResource(resource_id); 264 resource_tracker->ReleaseResource(resource_id);
249 base::MessageLoop::current()->RunUntilIdle(); 265 {
266 ProxyAutoUnlock unlock;
267 base::MessageLoop::current()->RunUntilIdle();
268 }
250 resource->CheckFinalState(); 269 resource->CheckFinalState();
251 270
252 // "Resurrect" it and check that the callbacks are still dead. 271 // "Resurrect" it and check that the callbacks are still dead.
253 PP_Resource new_resource_id = resource->GetReference(); 272 PP_Resource new_resource_id = resource->GetReference();
254 base::MessageLoop::current()->RunUntilIdle(); 273 {
274 ProxyAutoUnlock unlock;
275 base::MessageLoop::current()->RunUntilIdle();
276 }
255 resource->CheckFinalState(); 277 resource->CheckFinalState();
256 278
257 // Unref it again and do the same. 279 // Unref it again and do the same.
258 resource_tracker->ReleaseResource(new_resource_id); 280 resource_tracker->ReleaseResource(new_resource_id);
259 base::MessageLoop::current()->RunUntilIdle(); 281 {
282 ProxyAutoUnlock unlock;
283 base::MessageLoop::current()->RunUntilIdle();
284 }
260 resource->CheckFinalState(); 285 resource->CheckFinalState();
261 286
262 // This shouldn't be needed, but make sure there are no stranded tasks. 287 // This shouldn't be needed, but make sure there are no stranded tasks.
263 base::MessageLoop::current()->RunUntilIdle(); 288 {
289 ProxyAutoUnlock unlock;
290 base::MessageLoop::current()->RunUntilIdle();
291 }
264 } 292 }
265 293
266 } // namespace ppapi 294 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698