Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/browser/policy/policy_statistics_collector_unittest.cc

Issue 27536003: Moved prefs::kUserPolicyRefreshRate to component/policy/policy_pref_names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/policy_statistics_collector.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cstring> 5 #include <cstring>
6 #include <string> 6 #include <string>
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 protected: 55 protected:
56 PolicyStatisticsCollectorTest() 56 PolicyStatisticsCollectorTest()
57 : update_delay_(base::TimeDelta::FromMilliseconds( 57 : update_delay_(base::TimeDelta::FromMilliseconds(
58 PolicyStatisticsCollector::kStatisticsUpdateRate)), 58 PolicyStatisticsCollector::kStatisticsUpdateRate)),
59 test_policy_id1_(-1), 59 test_policy_id1_(-1),
60 test_policy_id2_(-1), 60 test_policy_id2_(-1),
61 task_runner_(new base::TestSimpleTaskRunner()) { 61 task_runner_(new base::TestSimpleTaskRunner()) {
62 } 62 }
63 63
64 virtual void SetUp() OVERRIDE { 64 virtual void SetUp() OVERRIDE {
65 prefs_.registry()->RegisterInt64Pref(prefs::kLastPolicyStatisticsUpdate, 0); 65 prefs_.registry()->RegisterInt64Pref(
66 policy_prefs::kLastPolicyStatisticsUpdate, 0);
66 67
67 // Find ids for kTestPolicy1 and kTestPolicy2. 68 // Find ids for kTestPolicy1 and kTestPolicy2.
68 const policy::PolicyDefinitionList* policy_list = 69 const policy::PolicyDefinitionList* policy_list =
69 policy::GetChromePolicyDefinitionList(); 70 policy::GetChromePolicyDefinitionList();
70 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin; 71 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin;
71 policy != policy_list->end; ++policy) { 72 policy != policy_list->end; ++policy) {
72 if (strcmp(policy->name, kTestPolicy1) == 0) 73 if (strcmp(policy->name, kTestPolicy1) == 0)
73 test_policy_id1_ = policy->id; 74 test_policy_id1_ = policy->id;
74 else if (strcmp(policy->name, kTestPolicy2) == 0) 75 else if (strcmp(policy->name, kTestPolicy2) == 0)
75 test_policy_id2_ = policy->id; 76 test_policy_id2_ = policy->id;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 MockPolicyService policy_service_; 117 MockPolicyService policy_service_;
117 PolicyMap policy_map_; 118 PolicyMap policy_map_;
118 119
119 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 120 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
120 scoped_ptr<TestPolicyStatisticsCollector> policy_statistics_collector_; 121 scoped_ptr<TestPolicyStatisticsCollector> policy_statistics_collector_;
121 }; 122 };
122 123
123 TEST_F(PolicyStatisticsCollectorTest, CollectPending) { 124 TEST_F(PolicyStatisticsCollectorTest, CollectPending) {
124 SetPolicy(kTestPolicy1); 125 SetPolicy(kTestPolicy1);
125 126
126 prefs_.SetInt64(prefs::kLastPolicyStatisticsUpdate, 127 prefs_.SetInt64(policy_prefs::kLastPolicyStatisticsUpdate,
127 (base::Time::Now() - update_delay_).ToInternalValue()); 128 (base::Time::Now() - update_delay_).ToInternalValue());
128 129
129 EXPECT_CALL(*policy_statistics_collector_.get(), 130 EXPECT_CALL(*policy_statistics_collector_.get(),
130 RecordPolicyUse(test_policy_id1_)); 131 RecordPolicyUse(test_policy_id1_));
131 132
132 policy_statistics_collector_->Initialize(); 133 policy_statistics_collector_->Initialize();
133 EXPECT_EQ(1u, task_runner_->GetPendingTasks().size()); 134 EXPECT_EQ(1u, task_runner_->GetPendingTasks().size());
134 EXPECT_EQ(update_delay_, GetFirstDelay()); 135 EXPECT_EQ(update_delay_, GetFirstDelay());
135 } 136 }
136 137
137 TEST_F(PolicyStatisticsCollectorTest, CollectPendingVeryOld) { 138 TEST_F(PolicyStatisticsCollectorTest, CollectPendingVeryOld) {
138 SetPolicy(kTestPolicy1); 139 SetPolicy(kTestPolicy1);
139 140
140 // Must not be 0.0 (read comment for Time::FromDoubleT). 141 // Must not be 0.0 (read comment for Time::FromDoubleT).
141 prefs_.SetInt64(prefs::kLastPolicyStatisticsUpdate, 142 prefs_.SetInt64(policy_prefs::kLastPolicyStatisticsUpdate,
142 base::Time::FromDoubleT(1.0).ToInternalValue()); 143 base::Time::FromDoubleT(1.0).ToInternalValue());
143 144
144 EXPECT_CALL(*policy_statistics_collector_.get(), 145 EXPECT_CALL(*policy_statistics_collector_.get(),
145 RecordPolicyUse(test_policy_id1_)); 146 RecordPolicyUse(test_policy_id1_));
146 147
147 policy_statistics_collector_->Initialize(); 148 policy_statistics_collector_->Initialize();
148 EXPECT_EQ(1u, task_runner_->GetPendingTasks().size()); 149 EXPECT_EQ(1u, task_runner_->GetPendingTasks().size());
149 EXPECT_EQ(update_delay_, GetFirstDelay()); 150 EXPECT_EQ(update_delay_, GetFirstDelay());
150 } 151 }
151 152
152 TEST_F(PolicyStatisticsCollectorTest, CollectLater) { 153 TEST_F(PolicyStatisticsCollectorTest, CollectLater) {
153 SetPolicy(kTestPolicy1); 154 SetPolicy(kTestPolicy1);
154 155
155 prefs_.SetInt64(prefs::kLastPolicyStatisticsUpdate, 156 prefs_.SetInt64(policy_prefs::kLastPolicyStatisticsUpdate,
156 (base::Time::Now() - update_delay_ / 2).ToInternalValue()); 157 (base::Time::Now() - update_delay_ / 2).ToInternalValue());
157 158
158 policy_statistics_collector_->Initialize(); 159 policy_statistics_collector_->Initialize();
159 EXPECT_EQ(1u, task_runner_->GetPendingTasks().size()); 160 EXPECT_EQ(1u, task_runner_->GetPendingTasks().size());
160 EXPECT_LT(GetFirstDelay(), update_delay_); 161 EXPECT_LT(GetFirstDelay(), update_delay_);
161 } 162 }
162 163
163 TEST_F(PolicyStatisticsCollectorTest, MultiplePolicies) { 164 TEST_F(PolicyStatisticsCollectorTest, MultiplePolicies) {
164 SetPolicy(kTestPolicy1); 165 SetPolicy(kTestPolicy1);
165 SetPolicy(kTestPolicy2); 166 SetPolicy(kTestPolicy2);
166 167
167 prefs_.SetInt64(prefs::kLastPolicyStatisticsUpdate, 168 prefs_.SetInt64(policy_prefs::kLastPolicyStatisticsUpdate,
168 (base::Time::Now() - update_delay_).ToInternalValue()); 169 (base::Time::Now() - update_delay_).ToInternalValue());
169 170
170 EXPECT_CALL(*policy_statistics_collector_.get(), 171 EXPECT_CALL(*policy_statistics_collector_.get(),
171 RecordPolicyUse(test_policy_id1_)); 172 RecordPolicyUse(test_policy_id1_));
172 EXPECT_CALL(*policy_statistics_collector_.get(), 173 EXPECT_CALL(*policy_statistics_collector_.get(),
173 RecordPolicyUse(test_policy_id2_)); 174 RecordPolicyUse(test_policy_id2_));
174 175
175 policy_statistics_collector_->Initialize(); 176 policy_statistics_collector_->Initialize();
176 EXPECT_EQ(1u, task_runner_->GetPendingTasks().size()); 177 EXPECT_EQ(1u, task_runner_->GetPendingTasks().size());
177 } 178 }
178 179
179 } // namespace policy 180 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_statistics_collector.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698