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..c613a308d713a3755a3e75fb1d7ff4c72467c55d |
--- /dev/null |
+++ b/chrome/browser/metrics/variations/variations_request_scheduler_mobile_unittest.cc |
@@ -0,0 +1,80 @@ |
+// Copyright 2014 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/message_loop/message_loop.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" |
+ |
Alexei Svitkine (slow)
2014/02/13 16:13:08
Nit: Remove extra blank line.
rkaplow
2014/02/13 16:55:59
Done.
|
+ |
+namespace chrome_variations { |
+ |
+namespace { |
+ |
+// Simple method used to verify a Callback has been triggered. |
+void Increment(int *n) { |
+ (*n)++; |
+} |
+ |
+} // 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(&Increment, &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(&Increment, &executed); |
+ VariationsRequestSchedulerMobile scheduler(task, &prefs); |
+ scheduler.Start(); |
+ // We expect the task to have triggered. |
+ EXPECT_EQ(1, executed); |
+} |
+ |
+TEST(VariationsRequestSchedulerMobileTest, ScheduleFetch) { |
+ base::MessageLoopForUI message_loop_; |
Alexei Svitkine (slow)
2014/02/13 16:13:08
Indent is wrong.
rkaplow
2014/02/13 16:55:59
Done.
|
+ |
+ TestingPrefServiceSimple prefs; |
+ |
+ 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(&Increment, &executed); |
+ VariationsRequestSchedulerMobile scheduler(task, &prefs); |
+ |
+ // Verify timer not running. |
+ EXPECT_FALSE(scheduler.schedule_fetch_timer_.IsRunning()); |
+ scheduler.ScheduleFetch(); |
+ |
+ // Timer now running. |
+ EXPECT_TRUE(scheduler.schedule_fetch_timer_.IsRunning()); |
+ |
+ // Force execution of the task on this timer. |
Alexei Svitkine (slow)
2014/02/13 16:13:08
I'd expand the comment to say that this is verifyi
rkaplow
2014/02/13 16:55:59
I didn't see a way to simulate time passing for a
Alexei Svitkine (slow)
2014/02/13 17:36:22
Right. I was just saying that you should expand th
rkaplow
2014/02/13 18:54:47
Done.
|
+ scheduler.schedule_fetch_timer_.user_task().Run(); |
+ |
+ // We expect the input task to have triggered. |
+ EXPECT_EQ(1, executed); |
+} |
+ |
Alexei Svitkine (slow)
2014/02/13 16:13:08
Nit: Remove extra line.
rkaplow
2014/02/13 16:55:59
Done.
|
+ |
+} // namespace chrome_variations |