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

Side by Side Diff: chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc

Issue 2338733002: Use TestSimpleTaskRunner::HasPendingTask instead of GetPendingTasks().empty() (Closed)
Patch Set: +bluetooth_adapter_win_unittest.cc Created 4 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/status_uploader_unittest.cc » ('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) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 "chrome/browser/chromeos/policy/heartbeat_scheduler.h" 5 #include "chrome/browser/chromeos/policy/heartbeat_scheduler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 161 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
162 162
163 // The HeartbeatScheduler instance under test. 163 // The HeartbeatScheduler instance under test.
164 policy::HeartbeatScheduler scheduler_; 164 policy::HeartbeatScheduler scheduler_;
165 }; 165 };
166 166
167 TEST_F(HeartbeatSchedulerTest, Basic) { 167 TEST_F(HeartbeatSchedulerTest, Basic) {
168 // Just makes sure we can spin up and shutdown the scheduler with 168 // Just makes sure we can spin up and shutdown the scheduler with
169 // heartbeats disabled. 169 // heartbeats disabled.
170 settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, false); 170 settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, false);
171 ASSERT_TRUE(task_runner_->GetPendingTasks().empty()); 171 ASSERT_FALSE(task_runner_->HasPendingTask());
172 } 172 }
173 173
174 TEST_F(HeartbeatSchedulerTest, PermanentlyFailedGCMRegistration) { 174 TEST_F(HeartbeatSchedulerTest, PermanentlyFailedGCMRegistration) {
175 // If heartbeats are enabled, we should register with GCMDriver. 175 // If heartbeats are enabled, we should register with GCMDriver.
176 EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _)); 176 EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _));
177 settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true); 177 settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true);
178 gcm_driver_.CompleteRegistration( 178 gcm_driver_.CompleteRegistration(
179 kHeartbeatGCMAppID, gcm::GCMClient::GCM_DISABLED); 179 kHeartbeatGCMAppID, gcm::GCMClient::GCM_DISABLED);
180 180
181 // There should be no heartbeat tasks pending, because registration failed. 181 // There should be no heartbeat tasks pending, because registration failed.
182 ASSERT_TRUE(task_runner_->GetPendingTasks().empty()); 182 ASSERT_FALSE(task_runner_->HasPendingTask());
183 } 183 }
184 184
185 TEST_F(HeartbeatSchedulerTest, TemporarilyFailedGCMRegistration) { 185 TEST_F(HeartbeatSchedulerTest, TemporarilyFailedGCMRegistration) {
186 IgnoreUpstreamNotificationMsg(); 186 IgnoreUpstreamNotificationMsg();
187 187
188 EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _)); 188 EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _));
189 settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true); 189 settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true);
190 gcm_driver_.CompleteRegistration( 190 gcm_driver_.CompleteRegistration(
191 kHeartbeatGCMAppID, gcm::GCMClient::SERVER_ERROR); 191 kHeartbeatGCMAppID, gcm::GCMClient::SERVER_ERROR);
192 testing::Mock::VerifyAndClearExpectations(&gcm_driver_); 192 testing::Mock::VerifyAndClearExpectations(&gcm_driver_);
193 193
194 IgnoreUpstreamNotificationMsg(); 194 IgnoreUpstreamNotificationMsg();
195 gcm_driver_.IgnoreDefaultHeartbeatsInterval(); 195 gcm_driver_.IgnoreDefaultHeartbeatsInterval();
196 196
197 // Should have a pending task to try registering again. 197 // Should have a pending task to try registering again.
198 ASSERT_FALSE(task_runner_->GetPendingTasks().empty()); 198 ASSERT_TRUE(task_runner_->HasPendingTask());
199 EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _)); 199 EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _));
200 task_runner_->RunPendingTasks(); 200 task_runner_->RunPendingTasks();
201 testing::Mock::VerifyAndClearExpectations(&gcm_driver_); 201 testing::Mock::VerifyAndClearExpectations(&gcm_driver_);
202 202
203 IgnoreUpstreamNotificationMsg(); 203 IgnoreUpstreamNotificationMsg();
204 gcm_driver_.IgnoreDefaultHeartbeatsInterval(); 204 gcm_driver_.IgnoreDefaultHeartbeatsInterval();
205 205
206 // Once we have successfully registered, we should send a heartbeat. 206 // Once we have successfully registered, we should send a heartbeat.
207 EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, IsHeartbeatMsg())); 207 EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, IsHeartbeatMsg()));
208 gcm_driver_.CompleteRegistration( 208 gcm_driver_.CompleteRegistration(
(...skipping 18 matching lines...) Expand all
227 gcm_driver_.IgnoreDefaultHeartbeatsInterval(); 227 gcm_driver_.IgnoreDefaultHeartbeatsInterval();
228 228
229 const int new_delay = 1234*1000; // 1234 seconds. 229 const int new_delay = 1234*1000; // 1234 seconds.
230 EXPECT_CALL(gcm_driver_, AddHeartbeatInterval(_, new_delay)); 230 EXPECT_CALL(gcm_driver_, AddHeartbeatInterval(_, new_delay));
231 settings_helper_.SetInteger(chromeos::kHeartbeatFrequency, new_delay); 231 settings_helper_.SetInteger(chromeos::kHeartbeatFrequency, new_delay);
232 // Now run pending heartbeat task, should send a heartbeat. 232 // Now run pending heartbeat task, should send a heartbeat.
233 gcm::OutgoingMessage message; 233 gcm::OutgoingMessage message;
234 EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, IsHeartbeatMsg())) 234 EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, IsHeartbeatMsg()))
235 .WillOnce(SaveArg<2>(&message)); 235 .WillOnce(SaveArg<2>(&message));
236 task_runner_->RunPendingTasks(); 236 task_runner_->RunPendingTasks();
237 EXPECT_TRUE(task_runner_->GetPendingTasks().empty()); 237 EXPECT_FALSE(task_runner_->HasPendingTask());
238 238
239 // Complete sending a message - we should queue up the next heartbeat 239 // Complete sending a message - we should queue up the next heartbeat
240 // even if the previous attempt failed. 240 // even if the previous attempt failed.
241 gcm_driver_.CompleteSend( 241 gcm_driver_.CompleteSend(
242 kHeartbeatGCMAppID, message.id, gcm::GCMClient::SERVER_ERROR); 242 kHeartbeatGCMAppID, message.id, gcm::GCMClient::SERVER_ERROR);
243 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); 243 EXPECT_EQ(1U, task_runner_->NumPendingTasks());
244 CheckPendingTaskDelay(scheduler_.last_heartbeat(), 244 CheckPendingTaskDelay(scheduler_.last_heartbeat(),
245 base::TimeDelta::FromMilliseconds(new_delay)); 245 base::TimeDelta::FromMilliseconds(new_delay));
246 } 246 }
247 247
(...skipping 23 matching lines...) Expand all
271 base::TimeDelta::FromMilliseconds( 271 base::TimeDelta::FromMilliseconds(
272 policy::HeartbeatScheduler::kDefaultHeartbeatIntervalMs)); 272 policy::HeartbeatScheduler::kDefaultHeartbeatIntervalMs));
273 testing::Mock::VerifyAndClearExpectations(&gcm_driver_); 273 testing::Mock::VerifyAndClearExpectations(&gcm_driver_);
274 274
275 IgnoreUpstreamNotificationMsg(); 275 IgnoreUpstreamNotificationMsg();
276 gcm_driver_.IgnoreDefaultHeartbeatsInterval(); 276 gcm_driver_.IgnoreDefaultHeartbeatsInterval();
277 277
278 // Now disable heartbeats. Should get no more heartbeats sent. 278 // Now disable heartbeats. Should get no more heartbeats sent.
279 settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, false); 279 settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, false);
280 task_runner_->RunPendingTasks(); 280 task_runner_->RunPendingTasks();
281 EXPECT_TRUE(task_runner_->GetPendingTasks().empty()); 281 EXPECT_FALSE(task_runner_->HasPendingTask());
282 } 282 }
283 283
284 TEST_F(HeartbeatSchedulerTest, CheckMessageContents) { 284 TEST_F(HeartbeatSchedulerTest, CheckMessageContents) {
285 IgnoreUpstreamNotificationMsg(); 285 IgnoreUpstreamNotificationMsg();
286 286
287 gcm::OutgoingMessage message; 287 gcm::OutgoingMessage message;
288 EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _)); 288 EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _));
289 EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, IsHeartbeatMsg())) 289 EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, IsHeartbeatMsg()))
290 .WillOnce(SaveArg<2>(&message)); 290 .WillOnce(SaveArg<2>(&message));
291 settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true); 291 settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 350
351 EXPECT_CALL(gcm_driver_, 351 EXPECT_CALL(gcm_driver_,
352 SendImpl(kHeartbeatGCMAppID, _, IsUpstreamNotificationMsg())) 352 SendImpl(kHeartbeatGCMAppID, _, IsUpstreamNotificationMsg()))
353 .Times(AtLeast(1)); 353 .Times(AtLeast(1));
354 gcm_driver_.CompleteRegistration(kHeartbeatGCMAppID, gcm::GCMClient::SUCCESS); 354 gcm_driver_.CompleteRegistration(kHeartbeatGCMAppID, gcm::GCMClient::SUCCESS);
355 355
356 gcm_driver_.NotifyConnected(); 356 gcm_driver_.NotifyConnected();
357 } 357 }
358 358
359 } // namespace 359 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/status_uploader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698