Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/task/cancelable_task_tracker.h" | 5 #include "base/task/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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 | 309 |
| 310 test_task_runner->RunUntilIdle(); | 310 test_task_runner->RunUntilIdle(); |
| 311 | 311 |
| 312 EXPECT_TRUE(task_tracker_.HasTrackedTasks()); | 312 EXPECT_TRUE(task_tracker_.HasTrackedTasks()); |
| 313 | 313 |
| 314 RunCurrentLoopUntilIdle(); | 314 RunCurrentLoopUntilIdle(); |
| 315 | 315 |
| 316 EXPECT_FALSE(task_tracker_.HasTrackedTasks()); | 316 EXPECT_FALSE(task_tracker_.HasTrackedTasks()); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // Post a task with a delay and cancel it. HasTrackedTasks() should return true | |
| 320 // from when the task is posted until it is canceled. | |
| 321 TEST_F(CancelableTaskTrackerTest, HasTrackedTasksPostDelayed) { | |
|
Marc Treib
2017/02/02 10:52:21
I think there's a few more tests here that should
mastiz
2017/02/02 12:35:54
I added these but then rethought the whole approac
| |
| 322 scoped_refptr<TestSimpleTaskRunner> test_task_runner( | |
| 323 new TestSimpleTaskRunner()); | |
| 324 | |
| 325 EXPECT_FALSE(task_tracker_.HasTrackedTasks()); | |
| 326 | |
| 327 ignore_result(task_tracker_.PostDelayedTask( | |
| 328 test_task_runner.get(), FROM_HERE, MakeExpectedNotRunClosure(FROM_HERE), | |
| 329 base::TimeDelta::FromSeconds(1))); | |
| 330 | |
| 331 task_tracker_.TryCancelAll(); | |
| 332 | |
| 333 test_task_runner->RunUntilIdle(); | |
| 334 | |
| 335 EXPECT_TRUE(task_tracker_.HasTrackedTasks()); | |
| 336 | |
| 337 RunCurrentLoopUntilIdle(); | |
| 338 | |
| 339 EXPECT_FALSE(task_tracker_.HasTrackedTasks()); | |
| 340 } | |
| 341 | |
| 319 // Create a new tracked task ID. HasTrackedTasks() should return true | 342 // Create a new tracked task ID. HasTrackedTasks() should return true |
| 320 // until the IsCanceledCallback is destroyed. | 343 // until the IsCanceledCallback is destroyed. |
| 321 TEST_F(CancelableTaskTrackerTest, HasTrackedTasksIsCancelled) { | 344 TEST_F(CancelableTaskTrackerTest, HasTrackedTasksIsCancelled) { |
| 322 EXPECT_FALSE(task_tracker_.HasTrackedTasks()); | 345 EXPECT_FALSE(task_tracker_.HasTrackedTasks()); |
| 323 | 346 |
| 324 CancelableTaskTracker::IsCanceledCallback is_canceled; | 347 CancelableTaskTracker::IsCanceledCallback is_canceled; |
| 325 ignore_result(task_tracker_.NewTrackedTaskId(&is_canceled)); | 348 ignore_result(task_tracker_.NewTrackedTaskId(&is_canceled)); |
| 326 | 349 |
| 327 task_tracker_.TryCancelAll(); | 350 task_tracker_.TryCancelAll(); |
| 328 | 351 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 | 427 |
| 405 bad_thread.task_runner()->PostTask( | 428 bad_thread.task_runner()->PostTask( |
| 406 FROM_HERE, | 429 FROM_HERE, |
| 407 Bind(&MaybeRunDeadlyTaskTrackerMemberFunction, Unretained(&task_tracker_), | 430 Bind(&MaybeRunDeadlyTaskTrackerMemberFunction, Unretained(&task_tracker_), |
| 408 Bind(&CancelableTaskTracker::TryCancelAll))); | 431 Bind(&CancelableTaskTracker::TryCancelAll))); |
| 409 | 432 |
| 410 test_task_runner->RunUntilIdle(); | 433 test_task_runner->RunUntilIdle(); |
| 411 } | 434 } |
| 412 | 435 |
| 413 } // namespace base | 436 } // namespace base |
| OLD | NEW |