Index: net/test/fake_time_system.cc |
diff --git a/net/test/fake_time_system.cc b/net/test/fake_time_system.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..408ed074d2f4b7b870ec635f61b2c98aa6874f49 |
--- /dev/null |
+++ b/net/test/fake_time_system.cc |
@@ -0,0 +1,54 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/test/fake_time_system.h" |
+ |
+namespace net { |
+ |
+FakeTimeSystem::Task::Task(base::Time time, base::Closure task) |
+ : task_(task), time_(time) { |
+} |
+ |
+FakeTimeSystem::Task::~Task() { |
+} |
+ |
+bool FakeTimeSystem::Task::operator<(const FakeTimeSystem::Task& other) const { |
+ return time_ > other.time_; |
+} |
+ |
+base::Time FakeTimeSystem::Now() { |
+ return now_; |
+} |
+ |
+FakeTimeSystem::FakeTimeSystem() : now_(base::Time()) { |
+} |
+ |
+FakeTimeSystem::~FakeTimeSystem() { |
+} |
+ |
+void FakeTimeSystem::SetNow(base::Time now) { |
+ now_ = now; |
+} |
+ |
+bool FakeTimeSystem::RunsTasksOnCurrentThread() const { |
+ return true; |
+} |
+ |
+bool FakeTimeSystem::PostDelayedTask(const tracked_objects::Location& from_here, |
+ const base::Closure& task, |
+ base::TimeDelta delay) { |
+ base::Time time = now_ + delay; |
+ tasks_.push(Task(time, task)); |
+ return true; |
+} |
+ |
+void FakeTimeSystem::RunPendingTasks() { |
+ while (!tasks_.empty() && tasks_.top().time() <= now_) { |
+ base::Closure to_run = tasks_.top().closure(); |
+ tasks_.pop(); |
+ to_run.Run(); |
+ } |
+} |
+ |
+} // namespace net |