Add unit tests for duration metrics

As a side-effect, move utils::GetMonotonicTime() into the newly added
ClockInterface type.

BUG=None
TEST=Unit tests pass

Change-Id: I972a7e4ba37b63f96348fbeda901697b8ba2fc05
Reviewed-on: https://gerrit.chromium.org/gerrit/48814
Reviewed-by: Chris Sosa <[email protected]>
Tested-by: David Zeuthen <[email protected]>
Commit-Queue: David Zeuthen <[email protected]>
diff --git a/fake_clock.h b/fake_clock.h
new file mode 100644
index 0000000..105d664
--- /dev/null
+++ b/fake_clock.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2013 The Chromium OS 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 CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_CLOCK_H__
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_CLOCK_H__
+
+#include "update_engine/clock_interface.h"
+
+namespace chromeos_update_engine {
+
+// Implements a clock that can be made to tell any time you want.
+class FakeClock : public ClockInterface {
+ public:
+  FakeClock() {}
+
+  virtual base::Time GetWallclockTime() {
+    return wallclock_time_;
+  }
+
+  virtual base::Time GetMonotonicTime() {
+    return monotonic_time_;
+  }
+
+  void SetWallclockTime(const base::Time &time) {
+    wallclock_time_ = time;
+  }
+
+  void SetMonotonicTime(const base::Time &time) {
+    monotonic_time_ = time;
+  }
+
+ private:
+  base::Time wallclock_time_;
+  base::Time monotonic_time_;
+
+  DISALLOW_COPY_AND_ASSIGN(FakeClock);
+};
+
+}  // namespace chromeos_update_engine
+
+#endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_CLOCK_H__