| 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 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 bool fired_; | 31 bool fired_; |
| 32 | 32 |
| 33 DISALLOW_COPY_AND_ASSIGN(TestDailyObserver); | 33 DISALLOW_COPY_AND_ASSIGN(TestDailyObserver); |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 class DailyEventTest : public testing::Test { | 36 class DailyEventTest : public testing::Test { |
| 37 public: | 37 public: |
| 38 DailyEventTest() : event_(&prefs_, kTestPrefName, kTestMetricName) { | 38 DailyEventTest() : event_(&prefs_, kTestPrefName, kTestMetricName) { |
| 39 DailyEvent::RegisterPref(prefs_.registry(), kTestPrefName); | 39 DailyEvent::RegisterPref(prefs_.registry(), kTestPrefName); |
| 40 observer_ = new TestDailyObserver(); | 40 observer_ = new TestDailyObserver(); |
| 41 scoped_ptr<metrics::DailyEvent::Observer> p(observer_); | 41 event_.AddObserver(make_scoped_ptr(observer_)); |
| 42 event_.AddObserver(p.Pass()); | |
| 43 } | 42 } |
| 44 | 43 |
| 45 protected: | 44 protected: |
| 46 TestingPrefServiceSimple prefs_; | 45 TestingPrefServiceSimple prefs_; |
| 47 TestDailyObserver* observer_; | 46 TestDailyObserver* observer_; |
| 48 DailyEvent event_; | 47 DailyEvent event_; |
| 49 | 48 |
| 50 private: | 49 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(DailyEventTest); | 50 DISALLOW_COPY_AND_ASSIGN(DailyEventTest); |
| 52 }; | 51 }; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 84 |
| 86 // The event should not fire if the preference is less than a day in the future. | 85 // The event should not fire if the preference is less than a day in the future. |
| 87 TEST_F(DailyEventTest, TestSoonNotFired) { | 86 TEST_F(DailyEventTest, TestSoonNotFired) { |
| 88 base::Time last_time = base::Time::Now() + base::TimeDelta::FromMinutes(2); | 87 base::Time last_time = base::Time::Now() + base::TimeDelta::FromMinutes(2); |
| 89 prefs_.SetInt64(kTestPrefName, last_time.ToInternalValue()); | 88 prefs_.SetInt64(kTestPrefName, last_time.ToInternalValue()); |
| 90 event_.CheckInterval(); | 89 event_.CheckInterval(); |
| 91 EXPECT_FALSE(observer_->fired()); | 90 EXPECT_FALSE(observer_->fired()); |
| 92 } | 91 } |
| 93 | 92 |
| 94 } // namespace metrics | 93 } // namespace metrics |
| OLD | NEW |