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 3 // found in the LICENSE file. 4 5 #ifndef BASE_TASK_SCHEDULER_TEST_UTILS_H_ 6 #define BASE_TASK_SCHEDULER_TEST_UTILS_H_ 7 8 #include "base/memory/ref_counted.h" 9 #include "base/task_runner.h" 10 #include "base/task_scheduler/scheduler_worker_observer.h" 11 #include "base/task_scheduler/sequence.h" 12 #include "testing/gmock/include/gmock/gmock.h" 13 14 namespace base { 15 namespace internal { 16 17 class SchedulerWorkerPool; 18 struct Task; 19 20 namespace test { 21 22 class MockSchedulerWorkerObserver : public SchedulerWorkerObserver { 23 public: 24 MockSchedulerWorkerObserver(); 25 ~MockSchedulerWorkerObserver(); 26 27 MOCK_METHOD0(OnSchedulerWorkerMainEntry, void()); 28 MOCK_METHOD0(OnSchedulerWorkerMainExit, void()); 29 30 private: 31 DISALLOW_COPY_AND_ASSIGN(MockSchedulerWorkerObserver); 32 }; 33 34 // An enumeration of possible task scheduler TaskRunner types. Used to 35 // parametrize relevant task_scheduler tests. 36 enum class ExecutionMode { PARALLEL, SEQUENCED, SINGLE_THREADED }; 37 38 // Creates a Sequence and pushes |task| to it. Returns that sequence. 39 scoped_refptr<Sequence> CreateSequenceWithTask(Task task); 40 41 // Creates a TaskRunner that posts tasks to |worker_pool| with the 42 // |execution_mode| execution mode and the WithBaseSyncPrimitives() trait. 43 // Caveat: this does not support ExecutionMode::SINGLE_THREADED. 44 scoped_refptr<TaskRunner> CreateTaskRunnerWithExecutionMode( 45 SchedulerWorkerPool* worker_pool, 46 test::ExecutionMode execution_mode); 47 48 } // namespace test 49 } // namespace internal 50 } // namespace base 51 52 #endif // BASE_TASK_SCHEDULER_TEST_UTILS_H_ 53