| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 387 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
| 388 EXPECT_TRUE(HasCachedDecision()); | 388 EXPECT_TRUE(HasCachedDecision()); |
| 389 | 389 |
| 390 // Subsequent network changes don't trigger retries. | 390 // Subsequent network changes don't trigger retries. |
| 391 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_NONE); | 391 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_NONE); |
| 392 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 392 client_->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
| 393 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 393 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
| 394 EXPECT_TRUE(HasCachedDecision()); | 394 EXPECT_TRUE(HasCachedDecision()); |
| 395 } | 395 } |
| 396 | 396 |
| 397 #if defined(OS_CHROMEOS) | 397 TEST_F(AutoEnrollmentClientTest, CancelAndDeleteSoonWithPendingRequest) { |
| 398 // crbug.com/422884 | |
| 399 #define MAYBE_CancelAndDeleteSoonWithPendingRequest DISABLED_CancelAndDeleteSoon
WithPendingRequest | |
| 400 #else | |
| 401 #define MAYBE_CancelAndDeleteSoonWithPendingRequest CancelAndDeleteSoonWithPendi
ngRequest | |
| 402 #endif | |
| 403 | |
| 404 TEST_F(AutoEnrollmentClientTest, MAYBE_CancelAndDeleteSoonWithPendingRequest) { | |
| 405 MockDeviceManagementJob* job = NULL; | 398 MockDeviceManagementJob* job = NULL; |
| 406 ServerWillReplyAsync(&job); | 399 ServerWillReplyAsync(&job); |
| 407 EXPECT_FALSE(job); | 400 EXPECT_FALSE(job); |
| 408 client_->Start(); | 401 client_->Start(); |
| 409 ASSERT_TRUE(job); | 402 ASSERT_TRUE(job); |
| 410 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); | 403 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); |
| 411 | 404 |
| 412 // Cancel while a request is in flight. | 405 // Cancel while a request is in flight. |
| 413 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 406 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 414 client_.release()->CancelAndDeleteSoon(); | 407 client_.release()->CancelAndDeleteSoon(); |
| 415 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 408 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 416 | 409 |
| 417 // The client cleans itself up once a reply is received. | 410 // The client cleans itself up once a reply is received. |
| 418 job->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE, | 411 job->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE, |
| 419 em::DeviceManagementResponse()); | 412 em::DeviceManagementResponse()); |
| 420 // The DeleteSoon task has been posted: | 413 // The DeleteSoon task has been posted: |
| 421 EXPECT_FALSE(base::MessageLoop::current()->IsIdleForTesting()); | 414 EXPECT_FALSE(base::MessageLoop::current()->IsIdleForTesting()); |
| 422 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); | 415 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); |
| 423 } | 416 } |
| 424 | 417 |
| 425 #if defined(OS_CHROMEOS) | 418 TEST_F(AutoEnrollmentClientTest, NetworkChangedAfterCancelAndDeleteSoon) { |
| 426 // crbug.com/422884 | |
| 427 #define MAYBE_NetworkChangedAfterCancelAndDeleteSoon DISABLED_NetworkChangedAfte
rCancelAndDeleteSoon | |
| 428 #else | |
| 429 #define MAYBE_NetworkChangedAfterCancelAndDeleteSoon | |
| 430 #endif | |
| 431 | |
| 432 TEST_F(AutoEnrollmentClientTest, MAYBE_NetworkChangedAfterCancelAndDeleteSoon) { | |
| 433 MockDeviceManagementJob* job = NULL; | 419 MockDeviceManagementJob* job = NULL; |
| 434 ServerWillReplyAsync(&job); | 420 ServerWillReplyAsync(&job); |
| 435 EXPECT_FALSE(job); | 421 EXPECT_FALSE(job); |
| 436 client_->Start(); | 422 client_->Start(); |
| 437 ASSERT_TRUE(job); | 423 ASSERT_TRUE(job); |
| 438 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); | 424 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); |
| 439 | 425 |
| 440 // Cancel while a request is in flight. | 426 // Cancel while a request is in flight. |
| 441 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 427 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 442 AutoEnrollmentClient* client = client_.release(); | 428 AutoEnrollmentClient* client = client_.release(); |
| 443 client->CancelAndDeleteSoon(); | 429 client->CancelAndDeleteSoon(); |
| 444 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 430 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 445 | 431 |
| 446 // Network change events are ignored while a request is pending. | 432 // Network change events are ignored while a request is pending. |
| 447 client->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 433 client->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
| 448 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); | 434 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); |
| 449 | 435 |
| 450 // The client cleans itself up once a reply is received. | 436 // The client cleans itself up once a reply is received. |
| 451 job->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE, | 437 job->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE, |
| 452 em::DeviceManagementResponse()); | 438 em::DeviceManagementResponse()); |
| 453 // The DeleteSoon task has been posted: | 439 // The DeleteSoon task has been posted: |
| 454 EXPECT_FALSE(base::MessageLoop::current()->IsIdleForTesting()); | 440 EXPECT_FALSE(base::MessageLoop::current()->IsIdleForTesting()); |
| 455 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); | 441 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); |
| 456 | 442 |
| 457 // Network changes that have been posted before are also ignored: | 443 // Network changes that have been posted before are also ignored: |
| 458 client->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 444 client->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_ETHERNET); |
| 459 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); | 445 EXPECT_EQ(AUTO_ENROLLMENT_STATE_PENDING, state_); |
| 460 } | 446 } |
| 461 | 447 |
| 462 #if defined(OS_CHROMEOS) | 448 TEST_F(AutoEnrollmentClientTest, CancelAndDeleteSoonAfterCompletion) { |
| 463 // crbug.com/422884 | |
| 464 #define MAYBE_CancelAndDeleteSoonAfterCompletion DISABLED_CancelAndDeleteSoonAft
erCompletion | |
| 465 #else | |
| 466 #define MAYBE_CancelAndDeleteSoonAfterCompletion CancelAndDeleteSoonAfterComplet
ion | |
| 467 #endif | |
| 468 | |
| 469 TEST_F(AutoEnrollmentClientTest, MAYBE_CancelAndDeleteSoonAfterCompletion) { | |
| 470 ServerWillReply(-1, true, true); | 449 ServerWillReply(-1, true, true); |
| 471 ServerWillSendState( | 450 ServerWillSendState( |
| 472 "example.com", | 451 "example.com", |
| 473 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED); | 452 em::DeviceStateRetrievalResponse::RESTORE_MODE_REENROLLMENT_ENFORCED); |
| 474 client_->Start(); | 453 client_->Start(); |
| 475 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 454 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
| 476 | 455 |
| 477 // The client will delete itself immediately if there are no pending | 456 // The client will delete itself immediately if there are no pending |
| 478 // requests. | 457 // requests. |
| 479 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 458 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 480 client_.release()->CancelAndDeleteSoon(); | 459 client_.release()->CancelAndDeleteSoon(); |
| 481 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 460 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 482 } | 461 } |
| 483 | 462 |
| 484 #if defined(OS_CHROMEOS) | 463 TEST_F(AutoEnrollmentClientTest, CancelAndDeleteSoonAfterNetworkFailure) { |
| 485 // crbug.com/422884 | |
| 486 #define MAYBE_CancelAndDeleteSoonAfterNetworkFailure DISABLED_CancelAndDeleteSoo
nAfterNetworkFailure | |
| 487 #else | |
| 488 #define MAYBE_CancelAndDeleteSoonAfterNetworkFailure CancelAndDeleteSoonAfterNet
workFailure | |
| 489 #endif | |
| 490 | |
| 491 TEST_F(AutoEnrollmentClientTest, MAYBE_CancelAndDeleteSoonAfterNetworkFailure) { | |
| 492 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE); | 464 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE); |
| 493 client_->Start(); | 465 client_->Start(); |
| 494 EXPECT_EQ(AUTO_ENROLLMENT_STATE_SERVER_ERROR, state_); | 466 EXPECT_EQ(AUTO_ENROLLMENT_STATE_SERVER_ERROR, state_); |
| 495 | 467 |
| 496 // The client will delete itself immediately if there are no pending | 468 // The client will delete itself immediately if there are no pending |
| 497 // requests. | 469 // requests. |
| 498 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 470 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 499 client_.release()->CancelAndDeleteSoon(); | 471 client_.release()->CancelAndDeleteSoon(); |
| 500 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 472 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 501 } | 473 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 EXPECT_CALL(*service_, | 510 EXPECT_CALL(*service_, |
| 539 CreateJob(DeviceManagementRequestJob::TYPE_DEVICE_STATE_RETRIEVAL, | 511 CreateJob(DeviceManagementRequestJob::TYPE_DEVICE_STATE_RETRIEVAL, |
| 540 _)).Times(0); | 512 _)).Times(0); |
| 541 client_->Start(); | 513 client_->Start(); |
| 542 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); | 514 EXPECT_EQ(AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT, state_); |
| 543 VerifyCachedResult(true, 8); | 515 VerifyCachedResult(true, 8); |
| 544 } | 516 } |
| 545 | 517 |
| 546 } // namespace | 518 } // namespace |
| 547 } // namespace policy | 519 } // namespace policy |
| OLD | NEW |