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