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

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

Issue 174213003: PPAPI: Use clang-format on ppapi/shared_impl (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: remove DEPS Created 6 years, 10 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
« no previous file with comments | « ppapi/shared_impl/tracked_callback.cc ('k') | ppapi/shared_impl/unittest_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "ppapi/c/pp_completion_callback.h" 8 #include "ppapi/c/pp_completion_callback.h"
9 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/shared_impl/callback_tracker.h" 10 #include "ppapi/shared_impl/callback_tracker.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 namespace { 71 namespace {
72 72
73 class CallbackShutdownTest : public TrackedCallbackTest { 73 class CallbackShutdownTest : public TrackedCallbackTest {
74 public: 74 public:
75 CallbackShutdownTest() {} 75 CallbackShutdownTest() {}
76 76
77 // Cases: 77 // Cases:
78 // (1) A callback which is run (so shouldn't be aborted on shutdown). 78 // (1) A callback which is run (so shouldn't be aborted on shutdown).
79 // (2) A callback which is aborted (so shouldn't be aborted on shutdown). 79 // (2) A callback which is aborted (so shouldn't be aborted on shutdown).
80 // (3) A callback which isn't run (so should be aborted on shutdown). 80 // (3) A callback which isn't run (so should be aborted on shutdown).
81 CallbackRunInfo& info_did_run() { return info_did_run_; } // (1) 81 CallbackRunInfo& info_did_run() { return info_did_run_; } // (1)
82 CallbackRunInfo& info_did_abort() { return info_did_abort_; } // (2) 82 CallbackRunInfo& info_did_abort() { return info_did_abort_; } // (2)
83 CallbackRunInfo& info_didnt_run() { return info_didnt_run_; } // (3) 83 CallbackRunInfo& info_didnt_run() { return info_didnt_run_; } // (3)
84 84
85 private: 85 private:
86 CallbackRunInfo info_did_run_; 86 CallbackRunInfo info_did_run_;
87 CallbackRunInfo info_did_abort_; 87 CallbackRunInfo info_did_abort_;
88 CallbackRunInfo info_didnt_run_; 88 CallbackRunInfo info_didnt_run_;
89 }; 89 };
90 90
91 } // namespace 91 } // namespace
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 public: 148 public:
149 CallbackMockResource(PP_Instance instance) 149 CallbackMockResource(PP_Instance instance)
150 : Resource(OBJECT_IS_IMPL, instance) {} 150 : Resource(OBJECT_IS_IMPL, instance) {}
151 ~CallbackMockResource() {} 151 ~CallbackMockResource() {}
152 152
153 PP_Resource SetupForTest() { 153 PP_Resource SetupForTest() {
154 PP_Resource resource_id = GetReference(); 154 PP_Resource resource_id = GetReference();
155 EXPECT_NE(0, resource_id); 155 EXPECT_NE(0, resource_id);
156 156
157 callback_did_run_ = new TrackedCallback( 157 callback_did_run_ = new TrackedCallback(
158 this, 158 this, PP_MakeCompletionCallback(&TestCallback, &info_did_run_));
159 PP_MakeCompletionCallback(&TestCallback, &info_did_run_));
160 EXPECT_EQ(0U, info_did_run_.run_count); 159 EXPECT_EQ(0U, info_did_run_.run_count);
161 EXPECT_EQ(0U, info_did_run_.completion_task_run_count); 160 EXPECT_EQ(0U, info_did_run_.completion_task_run_count);
162 161
163 // In order to test that the completion task can override the callback 162 // In order to test that the completion task can override the callback
164 // result, we need to test callbacks with and without a completion task. 163 // result, we need to test callbacks with and without a completion task.
165 callback_did_run_with_completion_task_ = new TrackedCallback( 164 callback_did_run_with_completion_task_ = new TrackedCallback(
166 this, 165 this,
167 PP_MakeCompletionCallback(&TestCallback, 166 PP_MakeCompletionCallback(&TestCallback,
168 &info_did_run_with_completion_task_)); 167 &info_did_run_with_completion_task_));
169 callback_did_run_with_completion_task_->set_completion_task( 168 callback_did_run_with_completion_task_->set_completion_task(
170 Bind(&CallbackMockResource::CompletionTask, this, 169 Bind(&CallbackMockResource::CompletionTask,
170 this,
171 &info_did_run_with_completion_task_)); 171 &info_did_run_with_completion_task_));
172 EXPECT_EQ(0U, info_did_run_with_completion_task_.run_count); 172 EXPECT_EQ(0U, info_did_run_with_completion_task_.run_count);
173 EXPECT_EQ(0U, info_did_run_with_completion_task_.completion_task_run_count); 173 EXPECT_EQ(0U, info_did_run_with_completion_task_.completion_task_run_count);
174 174
175 callback_did_abort_ = new TrackedCallback( 175 callback_did_abort_ = new TrackedCallback(
176 this, 176 this, PP_MakeCompletionCallback(&TestCallback, &info_did_abort_));
177 PP_MakeCompletionCallback(&TestCallback, &info_did_abort_));
178 callback_did_abort_->set_completion_task( 177 callback_did_abort_->set_completion_task(
179 Bind(&CallbackMockResource::CompletionTask, this, &info_did_abort_)); 178 Bind(&CallbackMockResource::CompletionTask, this, &info_did_abort_));
180 EXPECT_EQ(0U, info_did_abort_.run_count); 179 EXPECT_EQ(0U, info_did_abort_.run_count);
181 EXPECT_EQ(0U, info_did_abort_.completion_task_run_count); 180 EXPECT_EQ(0U, info_did_abort_.completion_task_run_count);
182 181
183 callback_didnt_run_ = new TrackedCallback( 182 callback_didnt_run_ = new TrackedCallback(
184 this, 183 this, PP_MakeCompletionCallback(&TestCallback, &info_didnt_run_));
185 PP_MakeCompletionCallback(&TestCallback, &info_didnt_run_));
186 callback_didnt_run_->set_completion_task( 184 callback_didnt_run_->set_completion_task(
187 Bind(&CallbackMockResource::CompletionTask, this, &info_didnt_run_)); 185 Bind(&CallbackMockResource::CompletionTask, this, &info_didnt_run_));
188 EXPECT_EQ(0U, info_didnt_run_.run_count); 186 EXPECT_EQ(0U, info_didnt_run_.run_count);
189 EXPECT_EQ(0U, info_didnt_run_.completion_task_run_count); 187 EXPECT_EQ(0U, info_didnt_run_.completion_task_run_count);
190 188
191 callback_did_run_->Run(PP_OK); 189 callback_did_run_->Run(PP_OK);
192 callback_did_run_with_completion_task_->Run(PP_OK); 190 callback_did_run_with_completion_task_->Run(PP_OK);
193 callback_did_abort_->Abort(); 191 callback_did_abort_->Abort();
194 192
195 CheckIntermediateState(); 193 CheckIntermediateState();
(...skipping 12 matching lines...) Expand all
208 206
209 void CheckIntermediateState() { 207 void CheckIntermediateState() {
210 EXPECT_EQ(1U, info_did_run_.run_count); 208 EXPECT_EQ(1U, info_did_run_.run_count);
211 EXPECT_EQ(PP_OK, info_did_run_.result); 209 EXPECT_EQ(PP_OK, info_did_run_.result);
212 EXPECT_EQ(0U, info_did_run_.completion_task_run_count); 210 EXPECT_EQ(0U, info_did_run_.completion_task_run_count);
213 211
214 EXPECT_EQ(1U, info_did_run_with_completion_task_.run_count); 212 EXPECT_EQ(1U, info_did_run_with_completion_task_.run_count);
215 // completion task should override the result. 213 // completion task should override the result.
216 EXPECT_EQ(kOverrideResultValue, info_did_run_with_completion_task_.result); 214 EXPECT_EQ(kOverrideResultValue, info_did_run_with_completion_task_.result);
217 EXPECT_EQ(1U, info_did_run_with_completion_task_.completion_task_run_count); 215 EXPECT_EQ(1U, info_did_run_with_completion_task_.completion_task_run_count);
218 EXPECT_EQ(PP_OK, 216 EXPECT_EQ(PP_OK, info_did_run_with_completion_task_.completion_task_result);
219 info_did_run_with_completion_task_.completion_task_result);
220 217
221 EXPECT_EQ(1U, info_did_abort_.run_count); 218 EXPECT_EQ(1U, info_did_abort_.run_count);
222 // completion task shouldn't override an abort. 219 // completion task shouldn't override an abort.
223 EXPECT_EQ(PP_ERROR_ABORTED, info_did_abort_.result); 220 EXPECT_EQ(PP_ERROR_ABORTED, info_did_abort_.result);
224 EXPECT_EQ(1U, info_did_abort_.completion_task_run_count); 221 EXPECT_EQ(1U, info_did_abort_.completion_task_run_count);
225 EXPECT_EQ(PP_ERROR_ABORTED, info_did_abort_.completion_task_result); 222 EXPECT_EQ(PP_ERROR_ABORTED, info_did_abort_.completion_task_result);
226 223
227 EXPECT_EQ(0U, info_didnt_run_.completion_task_run_count); 224 EXPECT_EQ(0U, info_didnt_run_.completion_task_run_count);
228 EXPECT_EQ(0U, info_didnt_run_.run_count); 225 EXPECT_EQ(0U, info_didnt_run_.run_count);
229 } 226 }
(...skipping 18 matching lines...) Expand all
248 245
249 scoped_refptr<TrackedCallback> callback_didnt_run_; 246 scoped_refptr<TrackedCallback> callback_didnt_run_;
250 CallbackRunInfo info_didnt_run_; 247 CallbackRunInfo info_didnt_run_;
251 }; 248 };
252 249
253 } // namespace 250 } // namespace
254 251
255 // Test that callbacks get aborted on the last resource unref. 252 // Test that callbacks get aborted on the last resource unref.
256 TEST_F(CallbackResourceTest, AbortOnNoRef) { 253 TEST_F(CallbackResourceTest, AbortOnNoRef) {
257 ProxyAutoLock lock; 254 ProxyAutoLock lock;
258 ResourceTracker* resource_tracker = 255 ResourceTracker* resource_tracker = PpapiGlobals::Get()->GetResourceTracker();
259 PpapiGlobals::Get()->GetResourceTracker();
260 256
261 // Test several things: Unref-ing a resource (to zero refs) with callbacks 257 // Test several things: Unref-ing a resource (to zero refs) with callbacks
262 // which (1) have been run, (2) have been aborted, (3) haven't been completed. 258 // which (1) have been run, (2) have been aborted, (3) haven't been completed.
263 // Check that the uncompleted one gets aborted, and that the others don't get 259 // Check that the uncompleted one gets aborted, and that the others don't get
264 // called again. 260 // called again.
265 scoped_refptr<CallbackMockResource> resource_1( 261 scoped_refptr<CallbackMockResource> resource_1(
266 new CallbackMockResource(pp_instance())); 262 new CallbackMockResource(pp_instance()));
267 PP_Resource resource_1_id = resource_1->SetupForTest(); 263 PP_Resource resource_1_id = resource_1->SetupForTest();
268 264
269 // Also do the same for a second resource, and make sure that unref-ing the 265 // Also do the same for a second resource, and make sure that unref-ing the
(...skipping 28 matching lines...) Expand all
298 { 294 {
299 ProxyAutoUnlock unlock; 295 ProxyAutoUnlock unlock;
300 base::MessageLoop::current()->RunUntilIdle(); 296 base::MessageLoop::current()->RunUntilIdle();
301 } 297 }
302 } 298 }
303 299
304 // Test that "resurrecting" a resource (getting a new ID for a |Resource|) 300 // Test that "resurrecting" a resource (getting a new ID for a |Resource|)
305 // doesn't resurrect callbacks. 301 // doesn't resurrect callbacks.
306 TEST_F(CallbackResourceTest, Resurrection) { 302 TEST_F(CallbackResourceTest, Resurrection) {
307 ProxyAutoLock lock; 303 ProxyAutoLock lock;
308 ResourceTracker* resource_tracker = 304 ResourceTracker* resource_tracker = PpapiGlobals::Get()->GetResourceTracker();
309 PpapiGlobals::Get()->GetResourceTracker();
310 305
311 scoped_refptr<CallbackMockResource> resource( 306 scoped_refptr<CallbackMockResource> resource(
312 new CallbackMockResource(pp_instance())); 307 new CallbackMockResource(pp_instance()));
313 PP_Resource resource_id = resource->SetupForTest(); 308 PP_Resource resource_id = resource->SetupForTest();
314 309
315 // Unref it, spin the message loop to run posted calls, and check that things 310 // Unref it, spin the message loop to run posted calls, and check that things
316 // are in the expected states. 311 // are in the expected states.
317 resource_tracker->ReleaseResource(resource_id); 312 resource_tracker->ReleaseResource(resource_id);
318 { 313 {
319 ProxyAutoUnlock unlock; 314 ProxyAutoUnlock unlock;
(...skipping 18 matching lines...) Expand all
338 resource->CheckFinalState(); 333 resource->CheckFinalState();
339 334
340 // This shouldn't be needed, but make sure there are no stranded tasks. 335 // This shouldn't be needed, but make sure there are no stranded tasks.
341 { 336 {
342 ProxyAutoUnlock unlock; 337 ProxyAutoUnlock unlock;
343 base::MessageLoop::current()->RunUntilIdle(); 338 base::MessageLoop::current()->RunUntilIdle();
344 } 339 }
345 } 340 }
346 341
347 } // namespace ppapi 342 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/tracked_callback.cc ('k') | ppapi/shared_impl/unittest_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698