OLD | NEW |
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 "chrome/browser/chromeos/policy/auto_enrollment_client.h" | 5 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 crypto::kSHA256Length); | 111 crypto::kSHA256Length); |
112 } | 112 } |
113 EXPECT_CALL(*service_, | 113 EXPECT_CALL(*service_, |
114 CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT, _)) | 114 CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT, _)) |
115 .WillOnce(service_->SucceedJob(response)); | 115 .WillOnce(service_->SucceedJob(response)); |
116 } | 116 } |
117 | 117 |
118 void ServerWillSendState( | 118 void ServerWillSendState( |
119 const std::string& management_domain, | 119 const std::string& management_domain, |
120 em::DeviceStateRetrievalResponse::RestoreMode restore_mode, | 120 em::DeviceStateRetrievalResponse::RestoreMode restore_mode, |
121 scoped_ptr<std::string> device_disabled_message) { | 121 const std::string& device_disabled_message) { |
122 em::DeviceManagementResponse response; | 122 em::DeviceManagementResponse response; |
123 em::DeviceStateRetrievalResponse* state_response = | 123 em::DeviceStateRetrievalResponse* state_response = |
124 response.mutable_device_state_retrieval_response(); | 124 response.mutable_device_state_retrieval_response(); |
125 state_response->set_restore_mode(restore_mode); | 125 state_response->set_restore_mode(restore_mode); |
126 state_response->set_management_domain(management_domain); | 126 state_response->set_management_domain(management_domain); |
127 if (device_disabled_message) { | 127 state_response->mutable_disabled_state()->set_message( |
128 em::DisabledState* disabled_state = | 128 device_disabled_message); |
129 state_response->mutable_disabled_state(); | |
130 disabled_state->set_message(*device_disabled_message); | |
131 } | |
132 EXPECT_CALL( | 129 EXPECT_CALL( |
133 *service_, | 130 *service_, |
134 CreateJob(DeviceManagementRequestJob::TYPE_DEVICE_STATE_RETRIEVAL, _)) | 131 CreateJob(DeviceManagementRequestJob::TYPE_DEVICE_STATE_RETRIEVAL, _)) |
135 .WillOnce(service_->SucceedJob(response)); | 132 .WillOnce(service_->SucceedJob(response)); |
136 } | 133 } |
137 | 134 |
138 void ServerWillReplyAsync(MockDeviceManagementJob** job) { | 135 void ServerWillReplyAsync(MockDeviceManagementJob** job) { |
139 EXPECT_CALL(*service_, | 136 EXPECT_CALL(*service_, |
140 CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT, _)) | 137 CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT, _)) |
141 .WillOnce(service_->CreateAsyncJob(job)); | 138 .WillOnce(service_->CreateAsyncJob(job)); |
(...skipping 14 matching lines...) Expand all Loading... |
156 local_state_->GetUserPref(prefs::kAutoEnrollmentPowerLimit))); | 153 local_state_->GetUserPref(prefs::kAutoEnrollmentPowerLimit))); |
157 } | 154 } |
158 | 155 |
159 bool HasServerBackedState() { | 156 bool HasServerBackedState() { |
160 return local_state_->GetUserPref(prefs::kServerBackedDeviceState); | 157 return local_state_->GetUserPref(prefs::kServerBackedDeviceState); |
161 } | 158 } |
162 | 159 |
163 void VerifyServerBackedState( | 160 void VerifyServerBackedState( |
164 const std::string& expected_management_domain, | 161 const std::string& expected_management_domain, |
165 const std::string& expected_restore_mode, | 162 const std::string& expected_restore_mode, |
166 scoped_ptr<std::string> expected_disabled_message) { | 163 const std::string& expected_disabled_message) { |
167 const base::Value* state = | 164 const base::Value* state = |
168 local_state_->GetUserPref(prefs::kServerBackedDeviceState); | 165 local_state_->GetUserPref(prefs::kServerBackedDeviceState); |
169 ASSERT_TRUE(state); | 166 ASSERT_TRUE(state); |
170 const base::DictionaryValue* state_dict = nullptr; | 167 const base::DictionaryValue* state_dict = nullptr; |
171 ASSERT_TRUE(state->GetAsDictionary(&state_dict)); | 168 ASSERT_TRUE(state->GetAsDictionary(&state_dict)); |
172 | 169 |
173 std::string actual_management_domain; | 170 std::string actual_management_domain; |
174 EXPECT_TRUE(state_dict->GetString(kDeviceStateManagementDomain, | 171 EXPECT_TRUE(state_dict->GetString(kDeviceStateManagementDomain, |
175 &actual_management_domain)); | 172 &actual_management_domain)); |
176 EXPECT_EQ(expected_management_domain, actual_management_domain); | 173 EXPECT_EQ(expected_management_domain, actual_management_domain); |
177 | 174 |
178 if (!expected_restore_mode.empty()) { | 175 if (!expected_restore_mode.empty()) { |
179 std::string actual_restore_mode; | 176 std::string actual_restore_mode; |
180 EXPECT_TRUE(state_dict->GetString(kDeviceStateRestoreMode, | 177 EXPECT_TRUE(state_dict->GetString(kDeviceStateRestoreMode, |
181 &actual_restore_mode)); | 178 &actual_restore_mode)); |
182 EXPECT_EQ(expected_restore_mode, actual_restore_mode); | 179 EXPECT_EQ(expected_restore_mode, actual_restore_mode); |
183 } else { | 180 } else { |
184 EXPECT_FALSE(state_dict->HasKey(kDeviceStateRestoreMode)); | 181 EXPECT_FALSE(state_dict->HasKey(kDeviceStateRestoreMode)); |
185 } | 182 } |
186 | 183 |
187 const bool expected_disabled_state = expected_disabled_message; | 184 std::string actual_disabled_message; |
188 bool actual_disabled_state = false; | 185 EXPECT_TRUE(state_dict->GetString(kDeviceStateDisabledMessage, |
189 EXPECT_TRUE(state_dict->GetBoolean(kDeviceStateDisabled, | 186 &actual_disabled_message)); |
190 &actual_disabled_state)); | 187 EXPECT_EQ(expected_disabled_message, actual_disabled_message); |
191 EXPECT_EQ(expected_disabled_state, actual_disabled_state); | |
192 | |
193 if (expected_disabled_message) { | |
194 std::string actual_disabled_message; | |
195 EXPECT_TRUE(state_dict->GetString(kDeviceStateDisabledMessage, | |
196 &actual_disabled_message)); | |
197 EXPECT_EQ(*expected_disabled_message, actual_disabled_message); | |
198 } else { | |
199 EXPECT_FALSE(state_dict->HasKey(kDeviceStateDisabledMessage)); | |
200 } | |
201 } | 188 } |
202 | 189 |
203 const em::DeviceAutoEnrollmentRequest& auto_enrollment_request() { | 190 const em::DeviceAutoEnrollmentRequest& auto_enrollment_request() { |
204 return last_request_.auto_enrollment_request(); | 191 return last_request_.auto_enrollment_request(); |
205 } | 192 } |
206 | 193 |
207 content::TestBrowserThreadBundle browser_threads_; | 194 content::TestBrowserThreadBundle browser_threads_; |
208 ScopedTestingLocalState scoped_testing_local_state_; | 195 ScopedTestingLocalState scoped_testing_local_state_; |
209 TestingPrefServiceSimple* local_state_; | 196 TestingPrefServiceSimple* local_state_; |
210 scoped_ptr<MockDeviceManagementService> service_; | 197 scoped_ptr<MockDeviceManagementService> service_; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 EXPECT_FALSE(HasServerBackedState()); | 252 EXPECT_FALSE(HasServerBackedState()); |
266 } | 253 } |
267 | 254 |
268 TEST_F(AutoEnrollmentClientTest, AskForLess) { | 255 TEST_F(AutoEnrollmentClientTest, AskForLess) { |
269 InSequence sequence; | 256 InSequence sequence; |
270 ServerWillReply(8, false, false); | 257 ServerWillReply(8, false, false); |
271 ServerWillReply(-1, true, true); | 258 ServerWillReply(-1, true, true); |
272 ServerWillSendState( | 259 ServerWillSendState( |
273 "example.com", | 260 "example.com", |
274 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, | 261 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, |
275 make_scoped_ptr(new std::string(kDisabledMessage))); | 262 kDisabledMessage); |
276 client_->Start(); | 263 client_->Start(); |
277 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 264 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
278 VerifyCachedResult(true, 8); | 265 VerifyCachedResult(true, 8); |
279 VerifyServerBackedState("example.com", | 266 VerifyServerBackedState("example.com", |
280 kDeviceStateRestoreModeReEnrollmentEnforced, | 267 kDeviceStateRestoreModeReEnrollmentEnforced, |
281 make_scoped_ptr(new std::string(kDisabledMessage))); | 268 kDisabledMessage); |
282 } | 269 } |
283 | 270 |
284 TEST_F(AutoEnrollmentClientTest, AskForSame) { | 271 TEST_F(AutoEnrollmentClientTest, AskForSame) { |
285 InSequence sequence; | 272 InSequence sequence; |
286 ServerWillReply(16, false, false); | 273 ServerWillReply(16, false, false); |
287 ServerWillReply(-1, true, true); | 274 ServerWillReply(-1, true, true); |
288 ServerWillSendState( | 275 ServerWillSendState( |
289 "example.com", | 276 "example.com", |
290 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, | 277 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, |
291 make_scoped_ptr(new std::string(kDisabledMessage))); | 278 kDisabledMessage); |
292 client_->Start(); | 279 client_->Start(); |
293 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 280 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
294 VerifyCachedResult(true, 8); | 281 VerifyCachedResult(true, 8); |
295 VerifyServerBackedState("example.com", | 282 VerifyServerBackedState("example.com", |
296 kDeviceStateRestoreModeReEnrollmentEnforced, | 283 kDeviceStateRestoreModeReEnrollmentEnforced, |
297 make_scoped_ptr(new std::string(kDisabledMessage))); | 284 kDisabledMessage); |
298 } | 285 } |
299 | 286 |
300 TEST_F(AutoEnrollmentClientTest, AskForSameTwice) { | 287 TEST_F(AutoEnrollmentClientTest, AskForSameTwice) { |
301 InSequence sequence; | 288 InSequence sequence; |
302 ServerWillReply(16, false, false); | 289 ServerWillReply(16, false, false); |
303 ServerWillReply(16, false, false); | 290 ServerWillReply(16, false, false); |
304 client_->Start(); | 291 client_->Start(); |
305 EXPECT_EQ(AUTO_ENROLLMENT_STATE_SERVER_ERROR, state_); | 292 EXPECT_EQ(AUTO_ENROLLMENT_STATE_SERVER_ERROR, state_); |
306 EXPECT_FALSE(HasCachedDecision()); | 293 EXPECT_FALSE(HasCachedDecision()); |
307 EXPECT_FALSE(HasServerBackedState()); | 294 EXPECT_FALSE(HasServerBackedState()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 // the server. | 327 // the server. |
341 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 328 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
342 EXPECT_EQ(AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_); | 329 EXPECT_EQ(AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_); |
343 } | 330 } |
344 | 331 |
345 TEST_F(AutoEnrollmentClientTest, ForcedReEnrollment) { | 332 TEST_F(AutoEnrollmentClientTest, ForcedReEnrollment) { |
346 ServerWillReply(-1, true, true); | 333 ServerWillReply(-1, true, true); |
347 ServerWillSendState( | 334 ServerWillSendState( |
348 "example.com", | 335 "example.com", |
349 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, | 336 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, |
350 nullptr); | 337 kDisabledMessage); |
351 client_->Start(); | 338 client_->Start(); |
352 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 339 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
353 VerifyCachedResult(true, 8); | 340 VerifyCachedResult(true, 8); |
354 VerifyServerBackedState("example.com", | 341 VerifyServerBackedState("example.com", |
355 kDeviceStateRestoreModeReEnrollmentEnforced, | 342 kDeviceStateRestoreModeReEnrollmentEnforced, |
356 nullptr); | 343 kDisabledMessage); |
357 | 344 |
358 // Network changes don't trigger retries after obtaining a response from | 345 // Network changes don't trigger retries after obtaining a response from |
359 // the server. | 346 // the server. |
360 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 347 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
361 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 348 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
362 } | 349 } |
363 | 350 |
364 TEST_F(AutoEnrollmentClientTest, RequestedReEnrollment) { | 351 TEST_F(AutoEnrollmentClientTest, RequestedReEnrollment) { |
365 ServerWillReply(-1, true, true); | 352 ServerWillReply(-1, true, true); |
366 ServerWillSendState( | 353 ServerWillSendState( |
367 "example.com", | 354 "example.com", |
368 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_REQUESTED, | 355 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_REQUESTED, |
369 nullptr); | 356 kDisabledMessage); |
370 client_->Start(); | 357 client_->Start(); |
371 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 358 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
372 VerifyCachedResult(true, 8); | 359 VerifyCachedResult(true, 8); |
373 VerifyServerBackedState("example.com", | 360 VerifyServerBackedState("example.com", |
374 kDeviceStateRestoreModeReEnrollmentRequested, | 361 kDeviceStateRestoreModeReEnrollmentRequested, |
375 nullptr); | 362 kDisabledMessage); |
376 } | 363 } |
377 | 364 |
378 TEST_F(AutoEnrollmentClientTest, DeviceDisabled) { | 365 TEST_F(AutoEnrollmentClientTest, DeviceDisabled) { |
379 ServerWillReply(-1, true, true); | 366 ServerWillReply(-1, true, true); |
380 ServerWillSendState( | 367 ServerWillSendState( |
381 "example.com", | 368 "example.com", |
382 em::DeviceStateRetrievalResponse::RESTORE_MODE_NONE, | 369 em::DeviceStateRetrievalResponse::RESTORE_MODE_DISABLED, |
383 make_scoped_ptr(new std::string(kDisabledMessage))); | 370 kDisabledMessage); |
384 client_->Start(); | 371 client_->Start(); |
385 EXPECT_EQ(AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_); | 372 EXPECT_EQ(AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_); |
386 VerifyCachedResult(true, 8); | 373 VerifyCachedResult(true, 8); |
387 VerifyServerBackedState("example.com", | 374 VerifyServerBackedState("example.com", |
388 "", | 375 kDeviceStateRestoreModeDisabled, |
389 make_scoped_ptr(new std::string(kDisabledMessage))); | 376 kDisabledMessage); |
390 } | 377 } |
391 | 378 |
392 TEST_F(AutoEnrollmentClientTest, NoSerial) { | 379 TEST_F(AutoEnrollmentClientTest, NoSerial) { |
393 CreateClient("", true, 4, 8); | 380 CreateClient("", true, 4, 8); |
394 client_->Start(); | 381 client_->Start(); |
395 EXPECT_EQ(AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_); | 382 EXPECT_EQ(AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_); |
396 EXPECT_FALSE(HasCachedDecision()); | 383 EXPECT_FALSE(HasCachedDecision()); |
397 EXPECT_FALSE(HasServerBackedState()); | 384 EXPECT_FALSE(HasServerBackedState()); |
398 } | 385 } |
399 | 386 |
(...skipping 28 matching lines...) Expand all Loading... |
428 } | 415 } |
429 | 416 |
430 TEST_F(AutoEnrollmentClientTest, MoreThan32BitsUploaded) { | 417 TEST_F(AutoEnrollmentClientTest, MoreThan32BitsUploaded) { |
431 CreateClient(kStateKey, true, 10, 37); | 418 CreateClient(kStateKey, true, 10, 37); |
432 InSequence sequence; | 419 InSequence sequence; |
433 ServerWillReply(GG_INT64_C(1) << 37, false, false); | 420 ServerWillReply(GG_INT64_C(1) << 37, false, false); |
434 ServerWillReply(-1, true, true); | 421 ServerWillReply(-1, true, true); |
435 ServerWillSendState( | 422 ServerWillSendState( |
436 "example.com", | 423 "example.com", |
437 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, | 424 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, |
438 make_scoped_ptr(new std::string(kDisabledMessage))); | 425 kDisabledMessage); |
439 client_->Start(); | 426 client_->Start(); |
440 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 427 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
441 VerifyCachedResult(true, 37); | 428 VerifyCachedResult(true, 37); |
442 VerifyServerBackedState("example.com", | 429 VerifyServerBackedState("example.com", |
443 kDeviceStateRestoreModeReEnrollmentEnforced, | 430 kDeviceStateRestoreModeReEnrollmentEnforced, |
444 make_scoped_ptr(new std::string(kDisabledMessage))); | 431 kDisabledMessage); |
445 } | 432 } |
446 | 433 |
447 TEST_F(AutoEnrollmentClientTest, ReuseCachedDecision) { | 434 TEST_F(AutoEnrollmentClientTest, ReuseCachedDecision) { |
448 EXPECT_CALL(*service_, CreateJob(_, _)).Times(0); | 435 EXPECT_CALL(*service_, CreateJob(_, _)).Times(0); |
449 local_state_->SetUserPref(prefs::kShouldAutoEnroll, | 436 local_state_->SetUserPref(prefs::kShouldAutoEnroll, |
450 new base::FundamentalValue(true)); | 437 new base::FundamentalValue(true)); |
451 local_state_->SetUserPref(prefs::kAutoEnrollmentPowerLimit, | 438 local_state_->SetUserPref(prefs::kAutoEnrollmentPowerLimit, |
452 new base::FundamentalValue(8)); | 439 new base::FundamentalValue(8)); |
453 ServerWillSendState( | 440 ServerWillSendState( |
454 "example.com", | 441 "example.com", |
455 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, | 442 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, |
456 make_scoped_ptr(new std::string(kDisabledMessage))); | 443 kDisabledMessage); |
457 client_->Start(); | 444 client_->Start(); |
458 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 445 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
459 VerifyServerBackedState("example.com", | 446 VerifyServerBackedState("example.com", |
460 kDeviceStateRestoreModeReEnrollmentEnforced, | 447 kDeviceStateRestoreModeReEnrollmentEnforced, |
461 make_scoped_ptr(new std::string(kDisabledMessage))); | 448 kDisabledMessage); |
462 AutoEnrollmentClient::CancelAutoEnrollment(); | 449 AutoEnrollmentClient::CancelAutoEnrollment(); |
463 client_->Start(); | 450 client_->Start(); |
464 EXPECT_EQ(AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_); | 451 EXPECT_EQ(AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_); |
465 EXPECT_FALSE(HasServerBackedState()); | 452 EXPECT_FALSE(HasServerBackedState()); |
466 } | 453 } |
467 | 454 |
468 TEST_F(AutoEnrollmentClientTest, RetryIfPowerLargerThanCached) { | 455 TEST_F(AutoEnrollmentClientTest, RetryIfPowerLargerThanCached) { |
469 local_state_->SetUserPref(prefs::kShouldAutoEnroll, | 456 local_state_->SetUserPref(prefs::kShouldAutoEnroll, |
470 new base::FundamentalValue(false)); | 457 new base::FundamentalValue(false)); |
471 local_state_->SetUserPref(prefs::kAutoEnrollmentPowerLimit, | 458 local_state_->SetUserPref(prefs::kAutoEnrollmentPowerLimit, |
472 new base::FundamentalValue(8)); | 459 new base::FundamentalValue(8)); |
473 CreateClient(kStateKey, true, 5, 10); | 460 CreateClient(kStateKey, true, 5, 10); |
474 ServerWillReply(-1, true, true); | 461 ServerWillReply(-1, true, true); |
475 ServerWillSendState( | 462 ServerWillSendState( |
476 "example.com", | 463 "example.com", |
477 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, | 464 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, |
478 make_scoped_ptr(new std::string(kDisabledMessage))); | 465 kDisabledMessage); |
479 client_->Start(); | 466 client_->Start(); |
480 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 467 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
481 VerifyServerBackedState("example.com", | 468 VerifyServerBackedState("example.com", |
482 kDeviceStateRestoreModeReEnrollmentEnforced, | 469 kDeviceStateRestoreModeReEnrollmentEnforced, |
483 make_scoped_ptr(new std::string(kDisabledMessage))); | 470 kDisabledMessage); |
484 } | 471 } |
485 | 472 |
486 TEST_F(AutoEnrollmentClientTest, NetworkChangeRetryAfterErrors) { | 473 TEST_F(AutoEnrollmentClientTest, NetworkChangeRetryAfterErrors) { |
487 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE); | 474 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE); |
488 client_->Start(); | 475 client_->Start(); |
489 // Don't invoke the callback if there was a network failure. | 476 // Don't invoke the callback if there was a network failure. |
490 EXPECT_EQ(AUTO_ENROLLMENT_STATE_SERVER_ERROR, state_); | 477 EXPECT_EQ(AUTO_ENROLLMENT_STATE_SERVER_ERROR, state_); |
491 EXPECT_FALSE(HasCachedDecision()); | 478 EXPECT_FALSE(HasCachedDecision()); |
492 EXPECT_FALSE(HasServerBackedState()); | 479 EXPECT_FALSE(HasServerBackedState()); |
493 | 480 |
494 // The client doesn't retry if no new connection became available. | 481 // The client doesn't retry if no new connection became available. |
495 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_NONE); | 482 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_NONE); |
496 EXPECT_EQ(AUTO_ENROLLMENT_STATE_SERVER_ERROR, state_); | 483 EXPECT_EQ(AUTO_ENROLLMENT_STATE_SERVER_ERROR, state_); |
497 EXPECT_FALSE(HasCachedDecision()); | 484 EXPECT_FALSE(HasCachedDecision()); |
498 EXPECT_FALSE(HasServerBackedState()); | 485 EXPECT_FALSE(HasServerBackedState()); |
499 | 486 |
500 // Retry once the network is back. | 487 // Retry once the network is back. |
501 ServerWillReply(-1, true, true); | 488 ServerWillReply(-1, true, true); |
502 ServerWillSendState( | 489 ServerWillSendState( |
503 "example.com", | 490 "example.com", |
504 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, | 491 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, |
505 make_scoped_ptr(new std::string(kDisabledMessage))); | 492 kDisabledMessage); |
506 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 493 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
507 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 494 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
508 EXPECT_TRUE(HasCachedDecision()); | 495 EXPECT_TRUE(HasCachedDecision()); |
509 VerifyServerBackedState("example.com", | 496 VerifyServerBackedState("example.com", |
510 kDeviceStateRestoreModeReEnrollmentEnforced, | 497 kDeviceStateRestoreModeReEnrollmentEnforced, |
511 make_scoped_ptr(new std::string(kDisabledMessage))); | 498 kDisabledMessage); |
512 | 499 |
513 // Subsequent network changes don't trigger retries. | 500 // Subsequent network changes don't trigger retries. |
514 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_NONE); | 501 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_NONE); |
515 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 502 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
516 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 503 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
517 EXPECT_TRUE(HasCachedDecision()); | 504 EXPECT_TRUE(HasCachedDecision()); |
518 VerifyServerBackedState("example.com", | 505 VerifyServerBackedState("example.com", |
519 kDeviceStateRestoreModeReEnrollmentEnforced, | 506 kDeviceStateRestoreModeReEnrollmentEnforced, |
520 make_scoped_ptr(new std::string(kDisabledMessage))); | 507 kDisabledMessage); |
521 } | 508 } |
522 | 509 |
523 TEST_F(AutoEnrollmentClientTest, CancelAndDeleteSoonWithPendingRequest) { | 510 TEST_F(AutoEnrollmentClientTest, CancelAndDeleteSoonWithPendingRequest) { |
524 MockDeviceManagementJob* job = NULL; | 511 MockDeviceManagementJob* job = NULL; |
525 ServerWillReplyAsync(&job); | 512 ServerWillReplyAsync(&job); |
526 EXPECT_FALSE(job); | 513 EXPECT_FALSE(job); |
527 client_->Start(); | 514 client_->Start(); |
528 ASSERT_TRUE(job); | 515 ASSERT_TRUE(job); |
529 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); | 516 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); |
530 | 517 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 // Network changes that have been posted before are also ignored: | 556 // Network changes that have been posted before are also ignored: |
570 client->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 557 client->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
571 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); | 558 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); |
572 } | 559 } |
573 | 560 |
574 TEST_F(AutoEnrollmentClientTest, CancelAndDeleteSoonAfterCompletion) { | 561 TEST_F(AutoEnrollmentClientTest, CancelAndDeleteSoonAfterCompletion) { |
575 ServerWillReply(-1, true, true); | 562 ServerWillReply(-1, true, true); |
576 ServerWillSendState( | 563 ServerWillSendState( |
577 "example.com", | 564 "example.com", |
578 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, | 565 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, |
579 make_scoped_ptr(new std::string(kDisabledMessage))); | 566 kDisabledMessage); |
580 client_->Start(); | 567 client_->Start(); |
581 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 568 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
582 VerifyServerBackedState("example.com", | 569 VerifyServerBackedState("example.com", |
583 kDeviceStateRestoreModeReEnrollmentEnforced, | 570 kDeviceStateRestoreModeReEnrollmentEnforced, |
584 make_scoped_ptr(new std::string(kDisabledMessage))); | 571 kDisabledMessage); |
585 | 572 |
586 // The client will delete itself immediately if there are no pending | 573 // The client will delete itself immediately if there are no pending |
587 // requests. | 574 // requests. |
588 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 575 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
589 client_.release()->CancelAndDeleteSoon(); | 576 client_.release()->CancelAndDeleteSoon(); |
590 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 577 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
591 } | 578 } |
592 | 579 |
593 TEST_F(AutoEnrollmentClientTest, CancelAndDeleteSoonAfterNetworkFailure) { | 580 TEST_F(AutoEnrollmentClientTest, CancelAndDeleteSoonAfterNetworkFailure) { |
594 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE); | 581 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE); |
(...skipping 24 matching lines...) Expand all Loading... |
619 // The default client uploads 4 bits. Make the server ask for 5. | 606 // The default client uploads 4 bits. Make the server ask for 5. |
620 ServerWillReply(1 << 5, false, false); | 607 ServerWillReply(1 << 5, false, false); |
621 EXPECT_CALL(*service_, StartJob(_, _, _, _, _, _, _)); | 608 EXPECT_CALL(*service_, StartJob(_, _, _, _, _, _, _)); |
622 // Then reply with a valid response and include the hash. | 609 // Then reply with a valid response and include the hash. |
623 ServerWillReply(-1, true, true); | 610 ServerWillReply(-1, true, true); |
624 EXPECT_CALL(*service_, StartJob(_, _, _, _, _, _, _)); | 611 EXPECT_CALL(*service_, StartJob(_, _, _, _, _, _, _)); |
625 // State download triggers. | 612 // State download triggers. |
626 ServerWillSendState( | 613 ServerWillSendState( |
627 "example.com", | 614 "example.com", |
628 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, | 615 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED, |
629 make_scoped_ptr(new std::string(kDisabledMessage))); | 616 kDisabledMessage); |
630 EXPECT_CALL(*service_, StartJob(_, _, _, _, _, _, _)); | 617 EXPECT_CALL(*service_, StartJob(_, _, _, _, _, _, _)); |
631 | 618 |
632 // Trigger a network change event. | 619 // Trigger a network change event. |
633 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 620 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
634 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 621 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
635 EXPECT_TRUE(HasCachedDecision()); | 622 EXPECT_TRUE(HasCachedDecision()); |
636 VerifyServerBackedState("example.com", | 623 VerifyServerBackedState("example.com", |
637 kDeviceStateRestoreModeReEnrollmentEnforced, | 624 kDeviceStateRestoreModeReEnrollmentEnforced, |
638 make_scoped_ptr(new std::string(kDisabledMessage))); | 625 kDisabledMessage); |
639 Mock::VerifyAndClearExpectations(service_.get()); | 626 Mock::VerifyAndClearExpectations(service_.get()); |
640 } | 627 } |
641 | 628 |
642 TEST_F(AutoEnrollmentClientTest, NoDeviceStateRetrieval) { | 629 TEST_F(AutoEnrollmentClientTest, NoDeviceStateRetrieval) { |
643 CreateClient(kStateKey, false, 4, 8); | 630 CreateClient(kStateKey, false, 4, 8); |
644 ServerWillReply(-1, true, true); | 631 ServerWillReply(-1, true, true); |
645 EXPECT_CALL(*service_, | 632 EXPECT_CALL(*service_, |
646 CreateJob(DeviceManagementRequestJob::TYPE_DEVICE_STATE_RETRIEVAL, | 633 CreateJob(DeviceManagementRequestJob::TYPE_DEVICE_STATE_RETRIEVAL, |
647 _)).Times(0); | 634 _)).Times(0); |
648 client_->Start(); | 635 client_->Start(); |
649 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 636 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
650 VerifyCachedResult(true, 8); | 637 VerifyCachedResult(true, 8); |
651 EXPECT_FALSE(HasServerBackedState()); | 638 EXPECT_FALSE(HasServerBackedState()); |
652 } | 639 } |
653 | 640 |
654 } // namespace | 641 } // namespace |
655 } // namespace policy | 642 } // namespace policy |
OLD | NEW |