Report errors from ChromiumEnv::GetChildren in Posix.
[chromium-blink-merge.git] / media / cast / test / fake_task_runner.cc
blobee4cc562098446c6cff1d4e00e75ba9df0ae76ca
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"
10 namespace media {
11 namespace cast {
12 namespace test {
14 FakeTaskRunner::FakeTaskRunner(base::SimpleTestTickClock* clock)
15 : clock_(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));
28 return false;
31 bool FakeTaskRunner::RunsTasksOnCurrentThread() const {
32 return true;
35 void FakeTaskRunner::RunTasks() {
36 for (;;) {
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;
44 tasks_.erase(it);
45 task.task.Run();
49 } // namespace test
50 } // namespace cast
51 } // namespace media