| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_scheduler/task_tracker.h" | 5 #include "base/task_scheduler/task_tracker.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 424 |
| 425 // Running the task should fail iff the task isn't allowed to use singletons. | 425 // Running the task should fail iff the task isn't allowed to use singletons. |
| 426 if (can_use_singletons) { | 426 if (can_use_singletons) { |
| 427 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create())); | 427 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create())); |
| 428 } else { | 428 } else { |
| 429 EXPECT_DCHECK_DEATH( | 429 EXPECT_DCHECK_DEATH( |
| 430 { tracker.RunTask(std::move(task), SequenceToken::Create()); }); | 430 { tracker.RunTask(std::move(task), SequenceToken::Create()); }); |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 | 433 |
| 434 // Verify that AssertIOAllowed() succeeds only for a WithFileIO() task. |
| 435 TEST_P(TaskSchedulerTaskTrackerTest, IOAllowed) { |
| 436 TaskTracker tracker; |
| 437 |
| 438 // Unset the IO allowed bit. Expect TaskTracker to set it before running a |
| 439 // task with the WithFileIO() trait. |
| 440 ThreadRestrictions::SetIOAllowed(false); |
| 441 auto task_with_file_io = MakeUnique<Task>( |
| 442 FROM_HERE, Bind([]() { |
| 443 // Shouldn't fail. |
| 444 ThreadRestrictions::AssertIOAllowed(); |
| 445 }), |
| 446 TaskTraits().WithFileIO().WithShutdownBehavior(GetParam()), TimeDelta()); |
| 447 EXPECT_TRUE(tracker.WillPostTask(task_with_file_io.get())); |
| 448 tracker.RunTask(std::move(task_with_file_io), SequenceToken::Create()); |
| 449 |
| 450 // Set the IO allowed bit. Expect TaskTracker to unset it before running a |
| 451 // task without the WithFileIO() trait. |
| 452 ThreadRestrictions::SetIOAllowed(true); |
| 453 auto task_without_file_io = MakeUnique<Task>( |
| 454 FROM_HERE, Bind([]() { |
| 455 EXPECT_DCHECK_DEATH({ ThreadRestrictions::AssertIOAllowed(); }); |
| 456 }), |
| 457 TaskTraits().WithShutdownBehavior(GetParam()), TimeDelta()); |
| 458 EXPECT_TRUE(tracker.WillPostTask(task_without_file_io.get())); |
| 459 tracker.RunTask(std::move(task_without_file_io), SequenceToken::Create()); |
| 460 } |
| 461 |
| 434 static void RunTaskRunnerHandleVerificationTask( | 462 static void RunTaskRunnerHandleVerificationTask( |
| 435 TaskTracker* tracker, | 463 TaskTracker* tracker, |
| 436 std::unique_ptr<Task> verify_task) { | 464 std::unique_ptr<Task> verify_task) { |
| 437 // Pretend |verify_task| is posted to respect TaskTracker's contract. | 465 // Pretend |verify_task| is posted to respect TaskTracker's contract. |
| 438 EXPECT_TRUE(tracker->WillPostTask(verify_task.get())); | 466 EXPECT_TRUE(tracker->WillPostTask(verify_task.get())); |
| 439 | 467 |
| 440 // Confirm that the test conditions are right (no TaskRunnerHandles set | 468 // Confirm that the test conditions are right (no TaskRunnerHandles set |
| 441 // already). | 469 // already). |
| 442 EXPECT_FALSE(ThreadTaskRunnerHandle::IsSet()); | 470 EXPECT_FALSE(ThreadTaskRunnerHandle::IsSet()); |
| 443 EXPECT_FALSE(SequencedTaskRunnerHandle::IsSet()); | 471 EXPECT_FALSE(SequencedTaskRunnerHandle::IsSet()); |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 // Run the test on the separate thread since it is not possible to reset the | 876 // Run the test on the separate thread since it is not possible to reset the |
| 849 // "wait allowed" bit of a thread without being a friend of | 877 // "wait allowed" bit of a thread without being a friend of |
| 850 // ThreadRestrictions. | 878 // ThreadRestrictions. |
| 851 WaitAllowedTestThread wait_allowed_test_thread; | 879 WaitAllowedTestThread wait_allowed_test_thread; |
| 852 wait_allowed_test_thread.Start(); | 880 wait_allowed_test_thread.Start(); |
| 853 wait_allowed_test_thread.Join(); | 881 wait_allowed_test_thread.Join(); |
| 854 } | 882 } |
| 855 | 883 |
| 856 } // namespace internal | 884 } // namespace internal |
| 857 } // namespace base | 885 } // namespace base |
| OLD | NEW |