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

Unified Diff: components/autofill/core/browser/test_autofill_clock.cc

Issue 2639403002: [Autofill] Remove direct use of base::Time::Now() in Autofill (Closed)
Patch Set: Added DCHECK Created 3 years, 11 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: components/autofill/core/browser/test_autofill_clock.cc
diff --git a/components/autofill/core/browser/test_autofill_clock.cc b/components/autofill/core/browser/test_autofill_clock.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4d5829b8a26ef60307c4308760b1af7f0a527c2a
--- /dev/null
+++ b/components/autofill/core/browser/test_autofill_clock.cc
@@ -0,0 +1,33 @@
+// Copyright 2017 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 "components/autofill/core/browser/test_autofill_clock.h"
+
+#include <utility>
+
+#include "base/test/simple_test_clock.h"
+#include "components/autofill/core/common/autofill_clock.h"
+
+namespace autofill {
+
+TestAutofillClock::TestAutofillClock() {
+ // Create a new test clock and set it as the AutofillClock clock and keep a
+ // pointer to manipulate the time it returns.
+ std::unique_ptr<base::SimpleTestClock> unique_test_clock(
+ new base::SimpleTestClock());
+ // Keep a pointer to the clock to be able to use its SetNow() function.
+ test_clock_ = unique_test_clock.get();
+ AutofillClock::SetTestClock(std::move(unique_test_clock));
+}
+
+TestAutofillClock::~TestAutofillClock() {
+ // Destroys the test clock and resets a normal clock.
+ AutofillClock::SetClock();
+}
+
+void TestAutofillClock::SetNow(base::Time now) {
+ test_clock_->SetNow(now);
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698