OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/metrics/variations/variations_request_scheduler_mobile.
h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_registry_simple.h" |
| 9 #include "base/prefs/testing_pref_service.h" |
| 10 #include "chrome/common/pref_names.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace chrome_variations { |
| 14 |
| 15 namespace { |
| 16 |
| 17 // Simple method used to verify a Callback has been triggered. |
| 18 void SetToOne(int *n) { |
| 19 *n = 1; |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
| 24 TEST(VariationsRequestSchedulerMobileTest, StartNoRun) { |
| 25 TestingPrefServiceSimple prefs; |
| 26 // Initialize to as if it was just fetched. |
| 27 prefs.registry()->RegisterInt64Pref( |
| 28 prefs::kVariationsLastFetchTime, base::Time::Now().ToInternalValue()); |
| 29 int executed = 0; |
| 30 const base::Closure task = base::Bind(&SetToOne, &executed); |
| 31 VariationsRequestSchedulerMobile scheduler(task, &prefs); |
| 32 scheduler.Start(); |
| 33 // We expect it the task to not have triggered. |
| 34 EXPECT_EQ(0, executed); |
| 35 } |
| 36 |
| 37 TEST(VariationsRequestSchedulerMobileTest, StartRun) { |
| 38 TestingPrefServiceSimple prefs; |
| 39 // Verify it doesn't take more than a day. |
| 40 base::Time old = base::Time::Now() - base::TimeDelta::FromHours(24); |
| 41 prefs.registry()->RegisterInt64Pref( |
| 42 prefs::kVariationsLastFetchTime, old.ToInternalValue()); |
| 43 int executed = 0; |
| 44 const base::Closure task = base::Bind(&SetToOne, &executed); |
| 45 VariationsRequestSchedulerMobile scheduler(task, &prefs); |
| 46 scheduler.Start(); |
| 47 // We expect the task to have triggered. |
| 48 EXPECT_EQ(1, executed); |
| 49 } |
| 50 |
| 51 } // namespace chrome_variations |
OLD | NEW |