OLD | NEW |
---|---|
(Empty) | |
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 | |
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/message_loop/message_loop.h" | |
9 #include "base/prefs/pref_registry_simple.h" | |
10 #include "base/prefs/testing_pref_service.h" | |
11 #include "chrome/common/pref_names.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
Alexei Svitkine (slow)
2014/02/13 16:13:08
Nit: Remove extra blank line.
rkaplow
2014/02/13 16:55:59
Done.
| |
14 | |
15 namespace chrome_variations { | |
16 | |
17 namespace { | |
18 | |
19 // Simple method used to verify a Callback has been triggered. | |
20 void Increment(int *n) { | |
21 (*n)++; | |
22 } | |
23 | |
24 } // namespace | |
25 | |
26 TEST(VariationsRequestSchedulerMobileTest, StartNoRun) { | |
27 TestingPrefServiceSimple prefs; | |
28 // Initialize to as if it was just fetched. | |
29 prefs.registry()->RegisterInt64Pref(prefs::kVariationsLastFetchTime, | |
30 base::Time::Now().ToInternalValue()); | |
31 int executed = 0; | |
32 const base::Closure task = base::Bind(&Increment, &executed); | |
33 VariationsRequestSchedulerMobile scheduler(task, &prefs); | |
34 scheduler.Start(); | |
35 // We expect it the task to not have triggered. | |
36 EXPECT_EQ(0, executed); | |
37 } | |
38 | |
39 TEST(VariationsRequestSchedulerMobileTest, StartRun) { | |
40 TestingPrefServiceSimple prefs; | |
41 // Verify it doesn't take more than a day. | |
42 base::Time old = base::Time::Now() - base::TimeDelta::FromHours(24); | |
43 prefs.registry()->RegisterInt64Pref(prefs::kVariationsLastFetchTime, | |
44 old.ToInternalValue()); | |
45 int executed = 0; | |
46 const base::Closure task = base::Bind(&Increment, &executed); | |
47 VariationsRequestSchedulerMobile scheduler(task, &prefs); | |
48 scheduler.Start(); | |
49 // We expect the task to have triggered. | |
50 EXPECT_EQ(1, executed); | |
51 } | |
52 | |
53 TEST(VariationsRequestSchedulerMobileTest, ScheduleFetch) { | |
54 base::MessageLoopForUI message_loop_; | |
Alexei Svitkine (slow)
2014/02/13 16:13:08
Indent is wrong.
rkaplow
2014/02/13 16:55:59
Done.
| |
55 | |
56 TestingPrefServiceSimple prefs; | |
57 | |
58 base::Time old = base::Time::Now() - base::TimeDelta::FromHours(24); | |
59 prefs.registry()->RegisterInt64Pref(prefs::kVariationsLastFetchTime, | |
60 old.ToInternalValue()); | |
61 int executed = 0; | |
62 const base::Closure task = base::Bind(&Increment, &executed); | |
63 VariationsRequestSchedulerMobile scheduler(task, &prefs); | |
64 | |
65 // Verify timer not running. | |
66 EXPECT_FALSE(scheduler.schedule_fetch_timer_.IsRunning()); | |
67 scheduler.ScheduleFetch(); | |
68 | |
69 // Timer now running. | |
70 EXPECT_TRUE(scheduler.schedule_fetch_timer_.IsRunning()); | |
71 | |
72 // 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.
| |
73 scheduler.schedule_fetch_timer_.user_task().Run(); | |
74 | |
75 // We expect the input task to have triggered. | |
76 EXPECT_EQ(1, executed); | |
77 } | |
78 | |
Alexei Svitkine (slow)
2014/02/13 16:13:08
Nit: Remove extra line.
rkaplow
2014/02/13 16:55:59
Done.
| |
79 | |
80 } // namespace chrome_variations | |
OLD | NEW |