We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / net / quic / test_tools / test_task_runner.cc
blob385fd5dfa82fe13fc4d77fe96718267fe264edcc
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 "net/quic/test_tools/test_task_runner.h"
7 #include <algorithm>
9 #include "net/quic/test_tools/mock_clock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace net {
13 namespace test {
15 TestTaskRunner::TestTaskRunner(MockClock* clock)
16 : clock_(clock) {
19 TestTaskRunner::~TestTaskRunner() {
22 bool TestTaskRunner::PostDelayedTask(const tracked_objects::Location& from_here,
23 const base::Closure& task,
24 base::TimeDelta delay) {
25 EXPECT_GE(delay, base::TimeDelta());
26 tasks_.push_back(
27 PostedTask(from_here, task, clock_->NowInTicks(), delay,
28 base::TestPendingTask::NESTABLE));
29 return false;
32 bool TestTaskRunner::RunsTasksOnCurrentThread() const {
33 return true;
36 const std::vector<PostedTask>& TestTaskRunner::GetPostedTasks() const {
37 return tasks_;
40 void TestTaskRunner::RunNextTask() {
41 // Find the next task to run, advance the time to the correct time
42 // and then run the task.
43 std::vector<PostedTask>::iterator next = FindNextTask();
44 DCHECK(next != tasks_.end());
45 clock_->AdvanceTime(QuicTime::Delta::FromMicroseconds(
46 (next->GetTimeToRun() - clock_->NowInTicks()).InMicroseconds()));
47 PostedTask task = *next;
48 tasks_.erase(next);
49 task.task.Run();
52 namespace {
54 struct ShouldRunBeforeLessThan {
55 bool operator()(const PostedTask& task1, const PostedTask& task2) const {
56 return task1.ShouldRunBefore(task2);
60 } // namespace
62 std::vector<PostedTask>::iterator TestTaskRunner::FindNextTask() {
63 return std::min_element(
64 tasks_.begin(), tasks_.end(), ShouldRunBeforeLessThan());
67 } // namespace test
68 } // namespace net