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

Side by Side Diff: chrome/common/cancelable_task_tracker_unittest.cc

Issue 15836003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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) 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 "chrome/common/cancelable_task_tracker.h" 5 #include "chrome/common/cancelable_task_tracker.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 223 }
224 224
225 // With the task tracker, post a task, a task with a reply, get a new 225 // With the task tracker, post a task, a task with a reply, get a new
226 // task id, and then cancel all of them. None of the tasks nor the 226 // task id, and then cancel all of them. None of the tasks nor the
227 // reply should run and the "is canceled" callback should return 227 // reply should run and the "is canceled" callback should return
228 // true. 228 // true.
229 TEST_F(CancelableTaskTrackerTest, CancelAll) { 229 TEST_F(CancelableTaskTrackerTest, CancelAll) {
230 scoped_refptr<base::TestSimpleTaskRunner> test_task_runner( 230 scoped_refptr<base::TestSimpleTaskRunner> test_task_runner(
231 new base::TestSimpleTaskRunner()); 231 new base::TestSimpleTaskRunner());
232 232
233 ignore_result( 233 ignore_result(task_tracker_.PostTask(
234 task_tracker_.PostTask( 234 test_task_runner.get(), FROM_HERE, MakeExpectedNotRunClosure(FROM_HERE)));
235 test_task_runner,
236 FROM_HERE,
237 MakeExpectedNotRunClosure(FROM_HERE)));
238 235
239 ignore_result( 236 ignore_result(
240 task_tracker_.PostTaskAndReply( 237 task_tracker_.PostTaskAndReply(test_task_runner.get(),
241 test_task_runner, 238 FROM_HERE,
242 FROM_HERE, 239 MakeExpectedNotRunClosure(FROM_HERE),
243 MakeExpectedNotRunClosure(FROM_HERE), 240 MakeExpectedNotRunClosure(FROM_HERE)));
244 MakeExpectedNotRunClosure(FROM_HERE)));
245 241
246 CancelableTaskTracker::IsCanceledCallback is_canceled; 242 CancelableTaskTracker::IsCanceledCallback is_canceled;
247 ignore_result(task_tracker_.NewTrackedTaskId(&is_canceled)); 243 ignore_result(task_tracker_.NewTrackedTaskId(&is_canceled));
248 244
249 task_tracker_.TryCancelAll(); 245 task_tracker_.TryCancelAll();
250 246
251 test_task_runner->RunUntilIdle(); 247 test_task_runner->RunUntilIdle();
252 248
253 RunCurrentLoopUntilIdle(); 249 RunCurrentLoopUntilIdle();
254 250
255 EXPECT_TRUE(is_canceled.Run()); 251 EXPECT_TRUE(is_canceled.Run());
256 } 252 }
257 253
258 // With the task tracker, post a task, a task with a reply, get a new 254 // With the task tracker, post a task, a task with a reply, get a new
259 // task id, and then cancel all of them. None of the tasks nor the 255 // task id, and then cancel all of them. None of the tasks nor the
260 // reply should run and the "is canceled" callback should return 256 // reply should run and the "is canceled" callback should return
261 // true. 257 // true.
262 TEST_F(CancelableTaskTrackerTest, DestructionCancelsAll) { 258 TEST_F(CancelableTaskTrackerTest, DestructionCancelsAll) {
263 scoped_refptr<base::TestSimpleTaskRunner> test_task_runner( 259 scoped_refptr<base::TestSimpleTaskRunner> test_task_runner(
264 new base::TestSimpleTaskRunner()); 260 new base::TestSimpleTaskRunner());
265 261
266 CancelableTaskTracker::IsCanceledCallback is_canceled; 262 CancelableTaskTracker::IsCanceledCallback is_canceled;
267 263
268 { 264 {
269 // Create another task tracker with a smaller scope. 265 // Create another task tracker with a smaller scope.
270 CancelableTaskTracker task_tracker; 266 CancelableTaskTracker task_tracker;
271 267
272 ignore_result( 268 ignore_result(task_tracker.PostTask(test_task_runner.get(),
273 task_tracker.PostTask( 269 FROM_HERE,
274 test_task_runner, 270 MakeExpectedNotRunClosure(FROM_HERE)));
275 FROM_HERE,
276 MakeExpectedNotRunClosure(FROM_HERE)));
277 271
278 ignore_result( 272 ignore_result(
279 task_tracker.PostTaskAndReply( 273 task_tracker.PostTaskAndReply(test_task_runner.get(),
280 test_task_runner, 274 FROM_HERE,
281 FROM_HERE, 275 MakeExpectedNotRunClosure(FROM_HERE),
282 MakeExpectedNotRunClosure(FROM_HERE), 276 MakeExpectedNotRunClosure(FROM_HERE)));
283 MakeExpectedNotRunClosure(FROM_HERE)));
284 277
285 ignore_result(task_tracker_.NewTrackedTaskId(&is_canceled)); 278 ignore_result(task_tracker_.NewTrackedTaskId(&is_canceled));
286 } 279 }
287 280
288 test_task_runner->RunUntilIdle(); 281 test_task_runner->RunUntilIdle();
289 282
290 RunCurrentLoopUntilIdle(); 283 RunCurrentLoopUntilIdle();
291 284
292 EXPECT_FALSE(is_canceled.Run()); 285 EXPECT_FALSE(is_canceled.Run());
293 } 286 }
294 287
295 // Post a task and cancel it. HasTrackedTasks() should return true 288 // Post a task and cancel it. HasTrackedTasks() should return true
296 // from when the task is posted until the (do-nothing) reply task is 289 // from when the task is posted until the (do-nothing) reply task is
297 // flushed. 290 // flushed.
298 TEST_F(CancelableTaskTrackerTest, HasTrackedTasksPost) { 291 TEST_F(CancelableTaskTrackerTest, HasTrackedTasksPost) {
299 scoped_refptr<base::TestSimpleTaskRunner> test_task_runner( 292 scoped_refptr<base::TestSimpleTaskRunner> test_task_runner(
300 new base::TestSimpleTaskRunner()); 293 new base::TestSimpleTaskRunner());
301 294
302 EXPECT_FALSE(task_tracker_.HasTrackedTasks()); 295 EXPECT_FALSE(task_tracker_.HasTrackedTasks());
303 296
304 ignore_result( 297 ignore_result(task_tracker_.PostTask(
305 task_tracker_.PostTask( 298 test_task_runner.get(), FROM_HERE, MakeExpectedNotRunClosure(FROM_HERE)));
306 test_task_runner,
307 FROM_HERE,
308 MakeExpectedNotRunClosure(FROM_HERE)));
309 299
310 task_tracker_.TryCancelAll(); 300 task_tracker_.TryCancelAll();
311 301
312 test_task_runner->RunUntilIdle(); 302 test_task_runner->RunUntilIdle();
313 303
314 EXPECT_TRUE(task_tracker_.HasTrackedTasks()); 304 EXPECT_TRUE(task_tracker_.HasTrackedTasks());
315 305
316 RunCurrentLoopUntilIdle(); 306 RunCurrentLoopUntilIdle();
317 307
318 EXPECT_FALSE(task_tracker_.HasTrackedTasks()); 308 EXPECT_FALSE(task_tracker_.HasTrackedTasks());
319 } 309 }
320 310
321 // Post a task with a reply and cancel it. HasTrackedTasks() should 311 // Post a task with a reply and cancel it. HasTrackedTasks() should
322 // return true from when the task is posted until it is canceled. 312 // return true from when the task is posted until it is canceled.
323 TEST_F(CancelableTaskTrackerTest, HasTrackedTasksPostWithReply) { 313 TEST_F(CancelableTaskTrackerTest, HasTrackedTasksPostWithReply) {
324 scoped_refptr<base::TestSimpleTaskRunner> test_task_runner( 314 scoped_refptr<base::TestSimpleTaskRunner> test_task_runner(
325 new base::TestSimpleTaskRunner()); 315 new base::TestSimpleTaskRunner());
326 316
327 EXPECT_FALSE(task_tracker_.HasTrackedTasks()); 317 EXPECT_FALSE(task_tracker_.HasTrackedTasks());
328 318
329 ignore_result( 319 ignore_result(
330 task_tracker_.PostTaskAndReply( 320 task_tracker_.PostTaskAndReply(test_task_runner.get(),
331 test_task_runner, 321 FROM_HERE,
332 FROM_HERE, 322 MakeExpectedNotRunClosure(FROM_HERE),
333 MakeExpectedNotRunClosure(FROM_HERE), 323 MakeExpectedNotRunClosure(FROM_HERE)));
334 MakeExpectedNotRunClosure(FROM_HERE)));
335 324
336 task_tracker_.TryCancelAll(); 325 task_tracker_.TryCancelAll();
337 326
338 test_task_runner->RunUntilIdle(); 327 test_task_runner->RunUntilIdle();
339 328
340 EXPECT_TRUE(task_tracker_.HasTrackedTasks()); 329 EXPECT_TRUE(task_tracker_.HasTrackedTasks());
341 330
342 RunCurrentLoopUntilIdle(); 331 RunCurrentLoopUntilIdle();
343 332
344 EXPECT_FALSE(task_tracker_.HasTrackedTasks()); 333 EXPECT_FALSE(task_tracker_.HasTrackedTasks());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 bad_thread.message_loop_proxy()->PostTask( 447 bad_thread.message_loop_proxy()->PostTask(
459 FROM_HERE, 448 FROM_HERE,
460 base::Bind(&MaybeRunDeadlyTaskTrackerMemberFunction, 449 base::Bind(&MaybeRunDeadlyTaskTrackerMemberFunction,
461 base::Unretained(&task_tracker_), 450 base::Unretained(&task_tracker_),
462 base::Bind(&CancelableTaskTracker::TryCancelAll))); 451 base::Bind(&CancelableTaskTracker::TryCancelAll)));
463 452
464 test_task_runner->RunUntilIdle(); 453 test_task_runner->RunUntilIdle();
465 } 454 }
466 455
467 } // namespace 456 } // namespace
OLDNEW
« no previous file with comments | « chrome/common/automation_messages.cc ('k') | chrome/common/extensions/api/commands/commands_manifest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698