1 // Copyright 2013 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 "media/cast/test/fake_task_runner.h"
7 #include "base/time/tick_clock.h"
8 #include "testing/gtest/include/gtest/gtest.h"
14 FakeTaskRunner::FakeTaskRunner(base::SimpleTestTickClock
* clock
)
18 FakeTaskRunner::~FakeTaskRunner() {}
20 bool FakeTaskRunner::PostDelayedTask(const tracked_objects::Location
& from_here
,
21 const base::Closure
& task
,
22 base::TimeDelta delay
) {
23 EXPECT_GE(delay
, base::TimeDelta());
24 PostedTask
posed_task(from_here
, task
, clock_
->NowTicks(), delay
,
25 base::TestPendingTask::NESTABLE
);
27 tasks_
.insert(std::make_pair(posed_task
.GetTimeToRun(), posed_task
));
31 bool FakeTaskRunner::RunsTasksOnCurrentThread() const {
35 void FakeTaskRunner::RunTasks() {
37 // Run all tasks equal or older than current time.
38 std::multimap
<base::TimeTicks
, PostedTask
>::iterator it
= tasks_
.begin();
39 if (it
== tasks_
.end()) return; // No more tasks.
41 PostedTask task
= it
->second
;
42 if (clock_
->NowTicks() < task
.GetTimeToRun()) return;