QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / base / test / task_runner_test_template.cc
blobb756203c44d751bc16f954544ac06960b41fba4b
1 // Copyright (c) 2012 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.
5 #include "base/test/task_runner_test_template.h"
7 namespace base {
9 namespace internal {
11 TaskTracker::TaskTracker() : task_runs_(0), task_runs_cv_(&lock_) {}
13 TaskTracker::~TaskTracker() {}
15 Closure TaskTracker::WrapTask(const Closure& task, int i) {
16 return Bind(&TaskTracker::RunTask, this, task, i);
19 void TaskTracker::RunTask(const Closure& task, int i) {
20 AutoLock lock(lock_);
21 if (!task.is_null()) {
22 task.Run();
24 ++task_run_counts_[i];
25 ++task_runs_;
26 task_runs_cv_.Signal();
29 std::map<int, int> TaskTracker::GetTaskRunCounts() const {
30 AutoLock lock(lock_);
31 return task_run_counts_;
34 void TaskTracker::WaitForCompletedTasks(int count) {
35 AutoLock lock(lock_);
36 while (task_runs_ < count)
37 task_runs_cv_.Wait();
40 void ExpectRunsTasksOnCurrentThread(
41 bool expected_value,
42 const scoped_refptr<TaskRunner>& task_runner) {
43 EXPECT_EQ(expected_value, task_runner->RunsTasksOnCurrentThread());
46 } // namespace internal
48 } // namespace base