Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Unified Diff: net/test/fake_time_system.h

Issue 15733008: Multicast DNS implementation (initial) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mdns_implementation2
Patch Set: Renamed files from "listener" to "client" Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..30e1135c6c16957b63c26857fa713ed8da2ee0fd
--- /dev/null
+++ b/net/test/fake_time_system.h
@@ -0,0 +1,63 @@
+// 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 {
+
+// This class implements both base::Clock and base::TaskRunner, and can
+// be used to simulate actual time in unit test for classes that both query
+// for the current time and shedule future tasks using a TaskRunner.
+
+class FakeTimeSystem : public base::Clock, public base::TaskRunner {
+ 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_
« net/dns/mdns_client_impl.cc ('K') | « net/net.gyp ('k') | net/test/fake_time_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698