| 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 .WillOnce(service_->CreateAsyncJob(job)); | 111 .WillOnce(service_->CreateAsyncJob(job)); |
| 112 } | 112 } |
| 113 | 113 |
| 114 bool HasCachedDecision() { | 114 bool HasCachedDecision() { |
| 115 return local_state_->GetUserPref(prefs::kShouldAutoEnroll); | 115 return local_state_->GetUserPref(prefs::kShouldAutoEnroll); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void VerifyCachedResult(bool should_enroll, int power_limit) { | 118 void VerifyCachedResult(bool should_enroll, int power_limit) { |
| 119 base::FundamentalValue value_should_enroll(should_enroll); | 119 base::FundamentalValue value_should_enroll(should_enroll); |
| 120 base::FundamentalValue value_power_limit(power_limit); | 120 base::FundamentalValue value_power_limit(power_limit); |
| 121 EXPECT_TRUE(Value::Equals( | 121 EXPECT_TRUE(base::Value::Equals( |
| 122 &value_should_enroll, | 122 &value_should_enroll, |
| 123 local_state_->GetUserPref(prefs::kShouldAutoEnroll))); | 123 local_state_->GetUserPref(prefs::kShouldAutoEnroll))); |
| 124 EXPECT_TRUE(Value::Equals( | 124 EXPECT_TRUE(base::Value::Equals( |
| 125 &value_power_limit, | 125 &value_power_limit, |
| 126 local_state_->GetUserPref(prefs::kAutoEnrollmentPowerLimit))); | 126 local_state_->GetUserPref(prefs::kAutoEnrollmentPowerLimit))); |
| 127 } | 127 } |
| 128 | 128 |
| 129 const em::DeviceAutoEnrollmentRequest& auto_enrollment_request() { | 129 const em::DeviceAutoEnrollmentRequest& auto_enrollment_request() { |
| 130 return last_request_.auto_enrollment_request(); | 130 return last_request_.auto_enrollment_request(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 content::TestBrowserThreadBundle browser_threads_; | 133 content::TestBrowserThreadBundle browser_threads_; |
| 134 ScopedTestingLocalState scoped_testing_local_state_; | 134 ScopedTestingLocalState scoped_testing_local_state_; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 ServerWillReply(-1, true, true); | 315 ServerWillReply(-1, true, true); |
| 316 client_->Start(); | 316 client_->Start(); |
| 317 EXPECT_TRUE(client_->should_auto_enroll()); | 317 EXPECT_TRUE(client_->should_auto_enroll()); |
| 318 EXPECT_EQ(1, completion_callback_count_); | 318 EXPECT_EQ(1, completion_callback_count_); |
| 319 VerifyCachedResult(true, 37); | 319 VerifyCachedResult(true, 37); |
| 320 } | 320 } |
| 321 | 321 |
| 322 TEST_F(AutoEnrollmentClientTest, ReuseCachedDecision) { | 322 TEST_F(AutoEnrollmentClientTest, ReuseCachedDecision) { |
| 323 EXPECT_CALL(*service_, CreateJob(_, _)).Times(0); | 323 EXPECT_CALL(*service_, CreateJob(_, _)).Times(0); |
| 324 local_state_->SetUserPref(prefs::kShouldAutoEnroll, | 324 local_state_->SetUserPref(prefs::kShouldAutoEnroll, |
| 325 Value::CreateBooleanValue(true)); | 325 base::Value::CreateBooleanValue(true)); |
| 326 local_state_->SetUserPref(prefs::kAutoEnrollmentPowerLimit, | 326 local_state_->SetUserPref(prefs::kAutoEnrollmentPowerLimit, |
| 327 Value::CreateIntegerValue(8)); | 327 base::Value::CreateIntegerValue(8)); |
| 328 client_->Start(); | 328 client_->Start(); |
| 329 EXPECT_TRUE(client_->should_auto_enroll()); | 329 EXPECT_TRUE(client_->should_auto_enroll()); |
| 330 EXPECT_EQ(1, completion_callback_count_); | 330 EXPECT_EQ(1, completion_callback_count_); |
| 331 AutoEnrollmentClient::CancelAutoEnrollment(); | 331 AutoEnrollmentClient::CancelAutoEnrollment(); |
| 332 client_->Start(); | 332 client_->Start(); |
| 333 EXPECT_FALSE(client_->should_auto_enroll()); | 333 EXPECT_FALSE(client_->should_auto_enroll()); |
| 334 EXPECT_EQ(2, completion_callback_count_); | 334 EXPECT_EQ(2, completion_callback_count_); |
| 335 } | 335 } |
| 336 | 336 |
| 337 TEST_F(AutoEnrollmentClientTest, RetryIfPowerLargerThanCached) { | 337 TEST_F(AutoEnrollmentClientTest, RetryIfPowerLargerThanCached) { |
| 338 local_state_->SetUserPref(prefs::kShouldAutoEnroll, | 338 local_state_->SetUserPref(prefs::kShouldAutoEnroll, |
| 339 Value::CreateBooleanValue(false)); | 339 base::Value::CreateBooleanValue(false)); |
| 340 local_state_->SetUserPref(prefs::kAutoEnrollmentPowerLimit, | 340 local_state_->SetUserPref(prefs::kAutoEnrollmentPowerLimit, |
| 341 Value::CreateIntegerValue(8)); | 341 base::Value::CreateIntegerValue(8)); |
| 342 CreateClient(kSerial, 5, 10); | 342 CreateClient(kSerial, 5, 10); |
| 343 ServerWillReply(-1, true, true); | 343 ServerWillReply(-1, true, true); |
| 344 client_->Start(); | 344 client_->Start(); |
| 345 EXPECT_TRUE(client_->should_auto_enroll()); | 345 EXPECT_TRUE(client_->should_auto_enroll()); |
| 346 EXPECT_EQ(1, completion_callback_count_); | 346 EXPECT_EQ(1, completion_callback_count_); |
| 347 } | 347 } |
| 348 | 348 |
| 349 TEST_F(AutoEnrollmentClientTest, NetworkChangeRetryAfterErrors) { | 349 TEST_F(AutoEnrollmentClientTest, NetworkChangeRetryAfterErrors) { |
| 350 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE); | 350 ServerWillFail(DM_STATUS_TEMPORARY_UNAVAILABLE); |
| 351 client_->Start(); | 351 client_->Start(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 // The client will delete itself immediately if there are no pending | 448 // The client will delete itself immediately if there are no pending |
| 449 // requests. | 449 // requests. |
| 450 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 450 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 451 client_.release()->CancelAndDeleteSoon(); | 451 client_.release()->CancelAndDeleteSoon(); |
| 452 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 452 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 453 } | 453 } |
| 454 | 454 |
| 455 } // namespace | 455 } // namespace |
| 456 | 456 |
| 457 } // namespace policy | 457 } // namespace policy |
| OLD | NEW |