1 // Copyright 2012 The Chromium Authors 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/test/task_runner_test_template.h" 6 7 namespace base { 8 9 namespace test { 10 TaskTracker()11TaskTracker::TaskTracker() : task_runs_(0), task_runs_cv_(&lock_) {} 12 13 TaskTracker::~TaskTracker() = default; 14 WrapTask(RepeatingClosure task,int i)15RepeatingClosure TaskTracker::WrapTask(RepeatingClosure task, int i) { 16 return BindRepeating(&TaskTracker::RunTask, this, std::move(task), i); 17 } 18 RunTask(RepeatingClosure task,int i)19void TaskTracker::RunTask(RepeatingClosure task, int i) { 20 AutoLock lock(lock_); 21 if (!task.is_null()) { 22 task.Run(); 23 } 24 ++task_run_counts_[i]; 25 ++task_runs_; 26 task_runs_cv_.Signal(); 27 } 28 GetTaskRunCounts() const29std::map<int, int> TaskTracker::GetTaskRunCounts() const { 30 AutoLock lock(lock_); 31 return task_run_counts_; 32 } 33 WaitForCompletedTasks(int count)34void TaskTracker::WaitForCompletedTasks(int count) { 35 AutoLock lock(lock_); 36 while (task_runs_ < count) 37 task_runs_cv_.Wait(); 38 } 39 40 } // namespace test 41 42 // This suite is instantiated in binaries that use //base:test_support. 43 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TaskRunnerTest); 44 45 } // namespace base 46