Chromium Code Reviews| Index: chrome/browser/metrics/variations/variations_request_scheduler_mobile_unittest.cc |
| diff --git a/chrome/browser/metrics/variations/variations_request_scheduler_mobile_unittest.cc b/chrome/browser/metrics/variations/variations_request_scheduler_mobile_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f595ccecb147ad79d6a9f6254ffaf6792679e433 |
| --- /dev/null |
| +++ b/chrome/browser/metrics/variations/variations_request_scheduler_mobile_unittest.cc |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
|
Alexei Svitkine (slow)
2014/02/12 21:17:44
Nit: 2014
rkaplow
2014/02/12 22:51:52
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/metrics/variations/variations_request_scheduler_mobile.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/prefs/pref_registry_simple.h" |
| +#include "base/prefs/testing_pref_service.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace chrome_variations { |
| + |
| +namespace { |
| + |
| +// Simple method used to verify a Callback has been triggered. |
| +void SetToOne(int *n) { |
|
Alexei Svitkine (slow)
2014/02/12 21:17:44
I'd actually change this instead to be Increment()
rkaplow
2014/02/12 22:51:52
Done.
|
| + *n = 1; |
| +} |
| + |
| +} // namespace |
| + |
| +TEST(VariationsRequestSchedulerMobileTest, StartNoRun) { |
|
Alexei Svitkine (slow)
2014/02/12 21:17:44
Sweet, thanks for adding tests for this!
Can you
rkaplow
2014/02/12 22:51:52
Done.
|
| + TestingPrefServiceSimple prefs; |
| + // Initialize to as if it was just fetched. |
| + prefs.registry()->RegisterInt64Pref( |
| + prefs::kVariationsLastFetchTime, base::Time::Now().ToInternalValue()); |
|
Alexei Svitkine (slow)
2014/02/12 21:17:44
Nit: Wrap like this instead:
prefs.registry()->R
rkaplow
2014/02/12 22:51:52
Done.
|
| + int executed = 0; |
| + const base::Closure task = base::Bind(&SetToOne, &executed); |
| + VariationsRequestSchedulerMobile scheduler(task, &prefs); |
| + scheduler.Start(); |
| + // We expect it the task to not have triggered. |
| + EXPECT_EQ(0, executed); |
| +} |
| + |
| +TEST(VariationsRequestSchedulerMobileTest, StartRun) { |
| + TestingPrefServiceSimple prefs; |
| + // Verify it doesn't take more than a day. |
| + base::Time old = base::Time::Now() - base::TimeDelta::FromHours(24); |
| + prefs.registry()->RegisterInt64Pref( |
| + prefs::kVariationsLastFetchTime, old.ToInternalValue()); |
|
Alexei Svitkine (slow)
2014/02/12 21:17:44
Ditto.
rkaplow
2014/02/12 22:51:52
Done.
|
| + int executed = 0; |
| + const base::Closure task = base::Bind(&SetToOne, &executed); |
| + VariationsRequestSchedulerMobile scheduler(task, &prefs); |
| + scheduler.Start(); |
| + // We expect the task to have triggered. |
| + EXPECT_EQ(1, executed); |
| +} |
| + |
| +} // namespace chrome_variations |