1 // Copyright 2014 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_single_thread_task_runner.h"
7 #include "base/logging.h"
8 #include "base/time/tick_clock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
15 FakeSingleThreadTaskRunner::FakeSingleThreadTaskRunner(
16 base::SimpleTestTickClock
* clock
)
19 FakeSingleThreadTaskRunner::~FakeSingleThreadTaskRunner() {}
21 bool FakeSingleThreadTaskRunner::PostDelayedTask(
22 const tracked_objects::Location
& from_here
,
23 const base::Closure
& task
,
24 base::TimeDelta delay
) {
25 EXPECT_GE(delay
, base::TimeDelta());
26 PostedTask
posed_task(from_here
,
30 base::TestPendingTask::NESTABLE
);
32 tasks_
.insert(std::make_pair(posed_task
.GetTimeToRun(), posed_task
));
36 bool FakeSingleThreadTaskRunner::RunsTasksOnCurrentThread() const {
40 void FakeSingleThreadTaskRunner::RunTasks() {
42 // Run all tasks equal or older than current time.
43 std::multimap
<base::TimeTicks
, PostedTask
>::iterator it
= tasks_
.begin();
44 if (it
== tasks_
.end())
45 return; // No more tasks.
47 PostedTask task
= it
->second
;
48 if (clock_
->NowTicks() < task
.GetTimeToRun())
56 bool FakeSingleThreadTaskRunner::PostNonNestableDelayedTask(
57 const tracked_objects::Location
& from_here
,
58 const base::Closure
& task
,
59 base::TimeDelta delay
) {