| 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.
|
| +// 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) {
|
| + *n = 1;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +TEST(VariationsRequestSchedulerMobileTest, StartNoRun) {
|
| + TestingPrefServiceSimple prefs;
|
| + // Initialize to as if it was just fetched.
|
| + prefs.registry()->RegisterInt64Pref(
|
| + prefs::kVariationsLastFetchTime, base::Time::Now().ToInternalValue());
|
| + 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());
|
| + 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
|
|
|