• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/task_scheduler/test_utils.h"
6 
7 #include <utility>
8 
9 #include "base/task_scheduler/scheduler_worker_pool.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 
12 namespace base {
13 namespace internal {
14 namespace test {
15 
16 MockSchedulerWorkerObserver::MockSchedulerWorkerObserver() = default;
17 MockSchedulerWorkerObserver::~MockSchedulerWorkerObserver() = default;
18 
CreateSequenceWithTask(Task task)19 scoped_refptr<Sequence> CreateSequenceWithTask(Task task) {
20   scoped_refptr<Sequence> sequence = MakeRefCounted<Sequence>();
21   sequence->PushTask(std::move(task));
22   return sequence;
23 }
24 
CreateTaskRunnerWithExecutionMode(SchedulerWorkerPool * worker_pool,test::ExecutionMode execution_mode)25 scoped_refptr<TaskRunner> CreateTaskRunnerWithExecutionMode(
26     SchedulerWorkerPool* worker_pool,
27     test::ExecutionMode execution_mode) {
28   // Allow tasks posted to the returned TaskRunner to wait on a WaitableEvent.
29   const TaskTraits traits = {WithBaseSyncPrimitives()};
30   switch (execution_mode) {
31     case test::ExecutionMode::PARALLEL:
32       return worker_pool->CreateTaskRunnerWithTraits(traits);
33     case test::ExecutionMode::SEQUENCED:
34       return worker_pool->CreateSequencedTaskRunnerWithTraits(traits);
35     default:
36       // Fall through.
37       break;
38   }
39   ADD_FAILURE() << "Unexpected ExecutionMode";
40   return nullptr;
41 }
42 
43 }  // namespace test
44 }  // namespace internal
45 }  // namespace base
46