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

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

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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
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 "base/callback.h" 5 #include "base/callback.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/policy/cloud_policy_refresh_scheduler.h" 10 #include "chrome/browser/policy/cloud_policy_refresh_scheduler.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // value back to get a millisecond-clamped time stamp for the checks below. 47 // value back to get a millisecond-clamped time stamp for the checks below.
48 store_.policy_.reset(new em::PolicyData()); 48 store_.policy_.reset(new em::PolicyData());
49 store_.policy_->set_timestamp( 49 store_.policy_->set_timestamp(
50 ((base::Time::NowFromSystemTime() - base::TimeDelta::FromMinutes(1)) - 50 ((base::Time::NowFromSystemTime() - base::TimeDelta::FromMinutes(1)) -
51 base::Time::UnixEpoch()).InMilliseconds()); 51 base::Time::UnixEpoch()).InMilliseconds());
52 last_refresh_ = 52 last_refresh_ =
53 base::Time::UnixEpoch() + 53 base::Time::UnixEpoch() +
54 base::TimeDelta::FromMilliseconds(store_.policy_->timestamp()); 54 base::TimeDelta::FromMilliseconds(store_.policy_->timestamp());
55 55
56 // Keep track of when the last task was posted. 56 // Keep track of when the last task was posted.
57 EXPECT_CALL(*task_runner_, PostDelayedTask(_, _, _)) 57 EXPECT_CALL(*task_runner_.get(), PostDelayedTask(_, _, _))
58 .WillRepeatedly(DoAll(SaveArg<1>(&last_callback_), 58 .WillRepeatedly(DoAll(SaveArg<1>(&last_callback_),
59 SaveArg<2>(&last_delay_), 59 SaveArg<2>(&last_delay_),
60 Return(true))); 60 Return(true)));
61 } 61 }
62 62
63 CloudPolicyRefreshScheduler* CreateRefreshScheduler() { 63 CloudPolicyRefreshScheduler* CreateRefreshScheduler() {
64 return new CloudPolicyRefreshScheduler(&client_, &store_, &prefs_, 64 return new CloudPolicyRefreshScheduler(&client_, &store_, &prefs_,
65 prefs::kUserPolicyRefreshRate, 65 prefs::kUserPolicyRefreshRate,
66 task_runner_); 66 task_runner_);
67 } 67 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 client_.SetPolicy(em::PolicyFetchResponse()); 124 client_.SetPolicy(em::PolicyFetchResponse());
125 scoped_ptr<CloudPolicyRefreshScheduler> scheduler(CreateRefreshScheduler()); 125 scoped_ptr<CloudPolicyRefreshScheduler> scheduler(CreateRefreshScheduler());
126 CheckTiming(kPolicyRefreshRate); 126 CheckTiming(kPolicyRefreshRate);
127 ASSERT_FALSE(last_callback_.is_null()); 127 ASSERT_FALSE(last_callback_.is_null());
128 EXPECT_CALL(client_, FetchPolicy()).Times(1); 128 EXPECT_CALL(client_, FetchPolicy()).Times(1);
129 last_callback_.Run(); 129 last_callback_.Run();
130 } 130 }
131 131
132 TEST_F(CloudPolicyRefreshSchedulerTest, Unregistered) { 132 TEST_F(CloudPolicyRefreshSchedulerTest, Unregistered) {
133 client_.SetDMToken(""); 133 client_.SetDMToken("");
134 EXPECT_CALL(*task_runner_, PostDelayedTask(_, _, _)).Times(0); 134 EXPECT_CALL(*task_runner_.get(), PostDelayedTask(_, _, _)).Times(0);
135 scoped_ptr<CloudPolicyRefreshScheduler> scheduler(CreateRefreshScheduler()); 135 scoped_ptr<CloudPolicyRefreshScheduler> scheduler(CreateRefreshScheduler());
136 client_.NotifyPolicyFetched(); 136 client_.NotifyPolicyFetched();
137 client_.NotifyRegistrationStateChanged(); 137 client_.NotifyRegistrationStateChanged();
138 client_.NotifyClientError(); 138 client_.NotifyClientError();
139 store_.NotifyStoreLoaded(); 139 store_.NotifyStoreLoaded();
140 store_.NotifyStoreError(); 140 store_.NotifyStoreError();
141 prefs_.SetInteger(prefs::kUserPolicyRefreshRate, 12 * 60 * 60 * 1000); 141 prefs_.SetInteger(prefs::kUserPolicyRefreshRate, 12 * 60 * 60 * 1000);
142 } 142 }
143 143
144 class CloudPolicyRefreshSchedulerSteadyStateTest 144 class CloudPolicyRefreshSchedulerSteadyStateTest
(...skipping 16 matching lines...) Expand all
161 TEST_F(CloudPolicyRefreshSchedulerSteadyStateTest, OnPolicyFetched) { 161 TEST_F(CloudPolicyRefreshSchedulerSteadyStateTest, OnPolicyFetched) {
162 client_.NotifyPolicyFetched(); 162 client_.NotifyPolicyFetched();
163 CheckTiming(kPolicyRefreshRate); 163 CheckTiming(kPolicyRefreshRate);
164 } 164 }
165 165
166 TEST_F(CloudPolicyRefreshSchedulerSteadyStateTest, OnRegistrationStateChanged) { 166 TEST_F(CloudPolicyRefreshSchedulerSteadyStateTest, OnRegistrationStateChanged) {
167 client_.SetDMToken("new_token"); 167 client_.SetDMToken("new_token");
168 client_.NotifyRegistrationStateChanged(); 168 client_.NotifyRegistrationStateChanged();
169 EXPECT_EQ(last_delay_, base::TimeDelta()); 169 EXPECT_EQ(last_delay_, base::TimeDelta());
170 170
171 EXPECT_CALL(*task_runner_, PostDelayedTask(_, _, _)).Times(0); 171 EXPECT_CALL(*task_runner_.get(), PostDelayedTask(_, _, _)).Times(0);
172 client_.SetDMToken(""); 172 client_.SetDMToken("");
173 client_.NotifyRegistrationStateChanged(); 173 client_.NotifyRegistrationStateChanged();
174 } 174 }
175 175
176 TEST_F(CloudPolicyRefreshSchedulerSteadyStateTest, OnStoreLoaded) { 176 TEST_F(CloudPolicyRefreshSchedulerSteadyStateTest, OnStoreLoaded) {
177 store_.NotifyStoreLoaded(); 177 store_.NotifyStoreLoaded();
178 CheckTiming(kPolicyRefreshRate); 178 CheckTiming(kPolicyRefreshRate);
179 } 179 }
180 180
181 TEST_F(CloudPolicyRefreshSchedulerSteadyStateTest, OnStoreError) { 181 TEST_F(CloudPolicyRefreshSchedulerSteadyStateTest, OnStoreError) {
182 EXPECT_CALL(*task_runner_, PostDelayedTask(_, _, _)).Times(0); 182 EXPECT_CALL(*task_runner_.get(), PostDelayedTask(_, _, _)).Times(0);
183 store_.NotifyStoreError(); 183 store_.NotifyStoreError();
184 } 184 }
185 185
186 TEST_F(CloudPolicyRefreshSchedulerSteadyStateTest, RefreshDelayChange) { 186 TEST_F(CloudPolicyRefreshSchedulerSteadyStateTest, RefreshDelayChange) {
187 const int delay_short_ms = 5 * 60 * 1000; 187 const int delay_short_ms = 5 * 60 * 1000;
188 prefs_.SetInteger(prefs::kUserPolicyRefreshRate, delay_short_ms); 188 prefs_.SetInteger(prefs::kUserPolicyRefreshRate, delay_short_ms);
189 CheckTiming(CloudPolicyRefreshScheduler::kRefreshDelayMinMs); 189 CheckTiming(CloudPolicyRefreshScheduler::kRefreshDelayMinMs);
190 190
191 const int delay_ms = 12 * 60 * 60 * 1000; 191 const int delay_ms = 12 * 60 * 60 * 1000;
192 prefs_.SetInteger(prefs::kUserPolicyRefreshRate, delay_ms); 192 prefs_.SetInteger(prefs::kUserPolicyRefreshRate, delay_ms);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 EXPECT_EQ(base::TimeDelta(), last_delay_); 271 EXPECT_EQ(base::TimeDelta(), last_delay_);
272 EXPECT_TRUE(last_callback_.is_null()); 272 EXPECT_TRUE(last_callback_.is_null());
273 } 273 }
274 } 274 }
275 275
276 INSTANTIATE_TEST_CASE_P(CloudPolicyRefreshSchedulerClientErrorTest, 276 INSTANTIATE_TEST_CASE_P(CloudPolicyRefreshSchedulerClientErrorTest,
277 CloudPolicyRefreshSchedulerClientErrorTest, 277 CloudPolicyRefreshSchedulerClientErrorTest,
278 testing::ValuesIn(kClientErrorTestCases)); 278 testing::ValuesIn(kClientErrorTestCases));
279 279
280 } // namespace policy 280 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_x_unittest.cc ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698