| Index: base/task_scheduler/task_scheduler_impl_unittest.cc
|
| diff --git a/base/task_scheduler/task_scheduler_impl_unittest.cc b/base/task_scheduler/task_scheduler_impl_unittest.cc
|
| index 50e0caeb1c7059f467376c2ac7311a3eb01e841f..e2fc882fccf10631eee660ae5c4023c3be797ffd 100644
|
| --- a/base/task_scheduler/task_scheduler_impl_unittest.cc
|
| +++ b/base/task_scheduler/task_scheduler_impl_unittest.cc
|
| @@ -38,13 +38,58 @@ struct TraitsExecutionModePair {
|
| ExecutionMode execution_mode;
|
| };
|
|
|
| +class TestTaskSchedulerImplDelegate : public TaskSchedulerImpl::Delegate {
|
| + public:
|
| + using ThreadPoolCreationArgs =
|
| + TaskSchedulerImpl::Delegate::ThreadPoolCreationArgs;
|
| +
|
| + TestTaskSchedulerImplDelegate() = default;
|
| + ~TestTaskSchedulerImplDelegate() = default;
|
| +
|
| + size_t GetNumThreadPools() override { return 4; }
|
| +
|
| + ThreadPoolCreationArgs GetCreationArgsForThreadPool(size_t pool_index) {
|
| + switch (pool_index) {
|
| + case 0:
|
| + return ThreadPoolCreationArgs{
|
| + std::string("Background"), ThreadPriority::BACKGROUND,
|
| + SchedulerThreadPoolImpl::IORestriction::DISALLOWED, 1U};
|
| + case 1:
|
| + return ThreadPoolCreationArgs{
|
| + "BackgroundFileIO", ThreadPriority::BACKGROUND,
|
| + SchedulerThreadPoolImpl::IORestriction::ALLOWED, 3U};
|
| + case 2:
|
| + return ThreadPoolCreationArgs{
|
| + "Foreground", ThreadPriority::NORMAL,
|
| + SchedulerThreadPoolImpl::IORestriction::DISALLOWED, 4U};
|
| + case 3:
|
| + return ThreadPoolCreationArgs{
|
| + "ForegroundFileIO", ThreadPriority::NORMAL,
|
| + SchedulerThreadPoolImpl::IORestriction::ALLOWED, 12U};
|
| + default:
|
| + ADD_FAILURE() << "Requested creation args for invalid pool index.";
|
| + return ThreadPoolCreationArgs{};
|
| + }
|
| + }
|
| +
|
| + size_t GetThreadPoolIndexForTraits(const TaskTraits& traits) override {
|
| + if (traits.with_file_io())
|
| + return traits.priority() == TaskPriority::BACKGROUND ? 1U : 3U;
|
| + return traits.priority() == TaskPriority::BACKGROUND ? 0U : 2U;
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(TestTaskSchedulerImplDelegate);
|
| +};
|
| +
|
| class TaskSchedulerImplTest
|
| : public testing::TestWithParam<TraitsExecutionModePair> {
|
| protected:
|
| TaskSchedulerImplTest() = default;
|
|
|
| void SetUp() override {
|
| - scheduler_ = TaskSchedulerImpl::Create();
|
| + scheduler_ = TaskSchedulerImpl::Create(
|
| + WrapUnique(new TestTaskSchedulerImplDelegate));
|
| EXPECT_TRUE(scheduler_);
|
| }
|
| void TearDown() override { scheduler_->JoinForTesting(); }
|
| @@ -195,7 +240,8 @@ INSTANTIATE_TEST_CASE_P(OneTraitsExecutionModePair,
|
| // the expected priority and I/O restrictions and respects the characteristics
|
| // of its ExecutionMode.
|
| TEST(TaskSchedulerImplTest, MultipleTraitsExecutionModePairs) {
|
| - std::unique_ptr<TaskSchedulerImpl> scheduler = TaskSchedulerImpl::Create();
|
| + std::unique_ptr<TaskSchedulerImpl> scheduler =
|
| + TaskSchedulerImpl::Create(WrapUnique(new TestTaskSchedulerImplDelegate));
|
|
|
| std::vector<std::unique_ptr<ThreadPostingTasks>> threads_posting_tasks;
|
| for (const auto& traits_execution_mode_pair : GetTraitsExecutionModePairs()) {
|
|
|