| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/metrics/daily_event.h" | 5 #include "components/metrics/daily_event.h" |
| 6 | 6 |
| 7 #include "base/prefs/testing_pref_service.h" | 7 #include "base/prefs/testing_pref_service.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace metrics { | 10 namespace metrics { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 const char kTestPrefName[] = "TestPref"; | 14 const char kTestPrefName[] = "TestPref"; |
| 15 const char kTestMetricName[] = "TestMetric"; | 15 const char kTestMetricName[] = "TestMetric"; |
| 16 | 16 |
| 17 class TestDailyObserver : public DailyEvent::Observer { | 17 class TestDailyObserver : public DailyEvent::Observer { |
| 18 public: | 18 public: |
| 19 TestDailyObserver() : fired_(false) {} | 19 TestDailyObserver() : fired_(false) {} |
| 20 | 20 |
| 21 bool fired() const { return fired_; } | 21 bool fired() const { return fired_; } |
| 22 | 22 |
| 23 virtual void OnDailyEvent() OVERRIDE { | 23 virtual void OnDailyEvent() override { |
| 24 fired_ = true; | 24 fired_ = true; |
| 25 } | 25 } |
| 26 | 26 |
| 27 void Reset() { | 27 void Reset() { |
| 28 fired_ = false; | 28 fired_ = false; |
| 29 } | 29 } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 // True if this event has been observed. | 32 // True if this event has been observed. |
| 33 bool fired_; | 33 bool fired_; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 // The event should not fire if the preference is less than a day in the future. | 88 // The event should not fire if the preference is less than a day in the future. |
| 89 TEST_F(DailyEventTest, TestSoonNotFired) { | 89 TEST_F(DailyEventTest, TestSoonNotFired) { |
| 90 base::Time last_time = base::Time::Now() + base::TimeDelta::FromMinutes(2); | 90 base::Time last_time = base::Time::Now() + base::TimeDelta::FromMinutes(2); |
| 91 prefs_.SetInt64(kTestPrefName, last_time.ToInternalValue()); | 91 prefs_.SetInt64(kTestPrefName, last_time.ToInternalValue()); |
| 92 event_.CheckInterval(); | 92 event_.CheckInterval(); |
| 93 EXPECT_FALSE(observer_->fired()); | 93 EXPECT_FALSE(observer_->fired()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace metrics | 96 } // namespace metrics |
| OLD | NEW |