Index: base/test/scoped_time_controller.h |
diff --git a/base/test/scoped_time_controller.h b/base/test/scoped_time_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..569a3c877229e75a8315adfcba0b5e44a1f9062b |
--- /dev/null |
+++ b/base/test/scoped_time_controller.h |
@@ -0,0 +1,43 @@ |
+// Copyright (c) 2011 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 BASE_TEST_SCOPED_TIME_CONTROLLER_H_ |
+#define BASE_TEST_SCOPED_TIME_CONTROLLER_H_ |
+ |
+#include "base/compiler_specific.h" |
+#include "base/time.h" |
+ |
+namespace base { |
+namespace test { |
+ |
+// TimeFactory that captures and freeses current time, and let to advance it |
+// manually. Sets itself as a TimeFactory instance on construction, and |
+// restores the previous one on destruction. |
+// Use it with care, as it might break assumed time monotonicity after deletion. |
+// The best way is to set it first in SetUp and remove it last at the |
+// TearDown method. |
+class ScopedTimeController : public base::TimeFactory { |
+ public: |
+ ScopedTimeController(); |
+ virtual ~ScopedTimeController(); |
+ |
+ // Advances inner time for |delta|. |Delta| have to be non-negative. |
+ void Advance(base::TimeDelta delta); |
+ |
+ // TimeFactory overrides |
+ virtual base::Time TimeNow() OVERRIDE; |
+ virtual base::TimeTicks TimeTicksNow() OVERRIDE; |
+ private: |
+ base::Time current_time_; |
+ base::TimeTicks current_timeticks_; |
+ |
+ base::TimeFactory* replaced_instance_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ScopedTimeController); |
+}; |
+ |
+} // namespace test |
+} // namespace base |
+ |
+#endif // BASE_TEST_SCOPED_TIME_CONTROLLER_H_ |