Index: net/test/fake_time_system.h |
diff --git a/net/test/fake_time_system.h b/net/test/fake_time_system.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6a3997308b74f6630fb7510179ef9cdc8fe02b56 |
--- /dev/null |
+++ b/net/test/fake_time_system.h |
@@ -0,0 +1,60 @@ |
+// 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. |
+ |
+#ifndef NET_TEST_FAKE_TIME_SYSTEM_H_ |
+#define NET_TEST_FAKE_TIME_SYSTEM_H_ |
+ |
+#include <queue> |
+ |
+#include "base/callback.h" |
+#include "base/task_runner.h" |
+#include "base/time/clock.h" |
+ |
+namespace net { |
+ |
+class FakeTimeSystem : public base::Clock, public base::TaskRunner { |
szym
2013/05/24 15:32:22
Needs class-level comment. Not sure you need this.
Noam Samuel
2013/05/29 21:25:16
Done.
|
+ public: |
+ class Task { |
+ public: |
+ Task(base::Time time, base::Closure task); |
+ ~Task(); |
+ |
+ bool operator<(const Task &other) const; |
+ |
+ const base::Closure& closure() const { return task_; } |
+ const base::Time time() const { return time_; } |
+ |
+ private: |
+ base::Closure task_; |
+ base::Time time_; |
+ }; |
+ |
+ |
+ FakeTimeSystem(); |
+ |
+ void SetNow(base::Time now); |
+ |
+ // Runs pending tasks until the queue is empty. Runs only tasks |
+ // that are supposed to be run after |now_|. |
+ void RunPendingTasks(); |
+ |
+ virtual base::Time Now() OVERRIDE; |
+ |
+ virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
+ const base::Closure& task, |
+ base::TimeDelta delay) OVERRIDE; |
+ |
+ virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
+ |
+ private: |
+ virtual ~FakeTimeSystem(); |
+ |
+ base::Time now_; |
+ std::priority_queue<Task> tasks_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FakeTimeSystem); |
+}; |
+} |
+ |
+#endif // NET_TEST_FAKE_TIME_SYSTEM_H_ |