| 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/device_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 class TestingDeviceCloudPolicyManagerChromeOS | 76 class TestingDeviceCloudPolicyManagerChromeOS |
| 77 : public DeviceCloudPolicyManagerChromeOS { | 77 : public DeviceCloudPolicyManagerChromeOS { |
| 78 public: | 78 public: |
| 79 TestingDeviceCloudPolicyManagerChromeOS( | 79 TestingDeviceCloudPolicyManagerChromeOS( |
| 80 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store, | 80 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store, |
| 81 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 81 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 82 ServerBackedStateKeysBroker* state_keys_broker) | 82 ServerBackedStateKeysBroker* state_keys_broker) |
| 83 : DeviceCloudPolicyManagerChromeOS( | 83 : DeviceCloudPolicyManagerChromeOS( |
| 84 store.Pass(), task_runner, state_keys_broker) {} | 84 store.Pass(), task_runner, state_keys_broker) {} |
| 85 ~TestingDeviceCloudPolicyManagerChromeOS() override {} | 85 ~TestingDeviceCloudPolicyManagerChromeOS() override {} |
| 86 | |
| 87 bool HasStatusProvider() { | |
| 88 return client() ? client()->HasStatusProviderForTest() : false; | |
| 89 } | |
| 90 }; | 86 }; |
| 91 | 87 |
| 92 class DeviceCloudPolicyManagerChromeOSTest | 88 class DeviceCloudPolicyManagerChromeOSTest |
| 93 : public chromeos::DeviceSettingsTestBase, | 89 : public chromeos::DeviceSettingsTestBase, |
| 94 public DeviceCloudPolicyManagerChromeOS::Observer { | 90 public DeviceCloudPolicyManagerChromeOS::Observer { |
| 95 protected: | 91 protected: |
| 96 DeviceCloudPolicyManagerChromeOSTest() | 92 DeviceCloudPolicyManagerChromeOSTest() |
| 97 : fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), | 93 : fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), |
| 98 state_keys_broker_(&fake_session_manager_client_, | 94 state_keys_broker_(&fake_session_manager_client_, |
| 99 base::MessageLoopProxy::current()), | 95 base::MessageLoopProxy::current()), |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 EXPECT_CALL(device_management_service_, | 244 EXPECT_CALL(device_management_service_, |
| 249 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, _)) | 245 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, _)) |
| 250 .Times(AtMost(1)) | 246 .Times(AtMost(1)) |
| 251 .WillOnce(device_management_service_.CreateAsyncJob(&policy_fetch_job)); | 247 .WillOnce(device_management_service_.CreateAsyncJob(&policy_fetch_job)); |
| 252 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)) | 248 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)) |
| 253 .Times(AtMost(1)); | 249 .Times(AtMost(1)); |
| 254 ConnectManager(); | 250 ConnectManager(); |
| 255 base::RunLoop().RunUntilIdle(); | 251 base::RunLoop().RunUntilIdle(); |
| 256 Mock::VerifyAndClearExpectations(&device_management_service_); | 252 Mock::VerifyAndClearExpectations(&device_management_service_); |
| 257 ASSERT_TRUE(policy_fetch_job); | 253 ASSERT_TRUE(policy_fetch_job); |
| 258 // Should create a status provider for reporting on enrolled devices. | 254 // Should create a status uploader for reporting on enrolled devices. |
| 259 EXPECT_TRUE(manager_->HasStatusProvider()); | 255 EXPECT_TRUE(manager_->HasStatusUploaderForTest()); |
| 260 VerifyPolicyPopulated(); | 256 VerifyPolicyPopulated(); |
| 261 | 257 |
| 262 manager_->Shutdown(); | 258 manager_->Shutdown(); |
| 263 VerifyPolicyPopulated(); | 259 VerifyPolicyPopulated(); |
| 264 | 260 |
| 265 EXPECT_EQ(store_->policy()->service_account_identity(), | 261 EXPECT_EQ(store_->policy()->service_account_identity(), |
| 266 PolicyBuilder::kFakeServiceAccountIdentity); | 262 PolicyBuilder::kFakeServiceAccountIdentity); |
| 267 } | 263 } |
| 268 | 264 |
| 269 TEST_F(DeviceCloudPolicyManagerChromeOSTest, UnmanagedDevice) { | 265 TEST_F(DeviceCloudPolicyManagerChromeOSTest, UnmanagedDevice) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 287 .Times(AtMost(1)) | 283 .Times(AtMost(1)) |
| 288 .WillOnce(device_management_service_.CreateAsyncJob(&policy_fetch_job)); | 284 .WillOnce(device_management_service_.CreateAsyncJob(&policy_fetch_job)); |
| 289 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)) | 285 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)) |
| 290 .Times(AtMost(1)); | 286 .Times(AtMost(1)); |
| 291 ConnectManager(); | 287 ConnectManager(); |
| 292 base::RunLoop().RunUntilIdle(); | 288 base::RunLoop().RunUntilIdle(); |
| 293 Mock::VerifyAndClearExpectations(&device_management_service_); | 289 Mock::VerifyAndClearExpectations(&device_management_service_); |
| 294 ASSERT_TRUE(policy_fetch_job); | 290 ASSERT_TRUE(policy_fetch_job); |
| 295 // Should create a status provider for reporting on enrolled devices, even | 291 // Should create a status provider for reporting on enrolled devices, even |
| 296 // those that aren't managed. | 292 // those that aren't managed. |
| 297 EXPECT_TRUE(manager_->HasStatusProvider()); | 293 EXPECT_TRUE(manager_->HasStatusUploaderForTest()); |
| 298 | 294 |
| 299 // Switch back to ACTIVE, service the policy fetch and let it propagate. | 295 // Switch back to ACTIVE, service the policy fetch and let it propagate. |
| 300 device_policy_.policy_data().set_state(em::PolicyData::ACTIVE); | 296 device_policy_.policy_data().set_state(em::PolicyData::ACTIVE); |
| 301 device_policy_.Build(); | 297 device_policy_.Build(); |
| 302 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 298 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
| 303 em::DeviceManagementResponse policy_fetch_response; | 299 em::DeviceManagementResponse policy_fetch_response; |
| 304 policy_fetch_response.mutable_policy_response()->add_response()->CopyFrom( | 300 policy_fetch_response.mutable_policy_response()->add_response()->CopyFrom( |
| 305 device_policy_.policy()); | 301 device_policy_.policy()); |
| 306 policy_fetch_job->SendResponse(DM_STATUS_SUCCESS, policy_fetch_response); | 302 policy_fetch_job->SendResponse(DM_STATUS_SUCCESS, policy_fetch_response); |
| 307 FlushDeviceSettings(); | 303 FlushDeviceSettings(); |
| 308 | 304 |
| 309 // Policy state should now be active and the policy map should be populated. | 305 // Policy state should now be active and the policy map should be populated. |
| 310 EXPECT_TRUE(store_->is_managed()); | 306 EXPECT_TRUE(store_->is_managed()); |
| 311 VerifyPolicyPopulated(); | 307 VerifyPolicyPopulated(); |
| 312 } | 308 } |
| 313 | 309 |
| 314 TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConsumerDevice) { | 310 TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConsumerDevice) { |
| 315 FlushDeviceSettings(); | 311 FlushDeviceSettings(); |
| 316 EXPECT_EQ(CloudPolicyStore::STATUS_BAD_STATE, store_->status()); | 312 EXPECT_EQ(CloudPolicyStore::STATUS_BAD_STATE, store_->status()); |
| 317 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); | 313 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); |
| 318 | 314 |
| 319 PolicyBundle bundle; | 315 PolicyBundle bundle; |
| 320 EXPECT_TRUE(manager_->policies().Equals(bundle)); | 316 EXPECT_TRUE(manager_->policies().Equals(bundle)); |
| 321 | 317 |
| 322 ConnectManager(); | 318 ConnectManager(); |
| 323 EXPECT_TRUE(manager_->policies().Equals(bundle)); | 319 EXPECT_TRUE(manager_->policies().Equals(bundle)); |
| 324 // Should not create a status provider for reporting on consumer devices. | 320 // Should not create a status provider for reporting on consumer devices. |
| 325 EXPECT_FALSE(manager_->HasStatusProvider()); | 321 EXPECT_FALSE(manager_->HasStatusUploaderForTest()); |
| 326 | 322 |
| 327 manager_->Shutdown(); | 323 manager_->Shutdown(); |
| 328 EXPECT_TRUE(manager_->policies().Equals(bundle)); | 324 EXPECT_TRUE(manager_->policies().Equals(bundle)); |
| 329 } | 325 } |
| 330 | 326 |
| 331 TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConnectAndDisconnect) { | 327 TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConnectAndDisconnect) { |
| 332 LockDevice(); | 328 LockDevice(); |
| 333 FlushDeviceSettings(); | 329 FlushDeviceSettings(); |
| 334 EXPECT_FALSE(manager_->core()->service()); // Not connected. | 330 EXPECT_FALSE(manager_->core()->service()); // Not connected. |
| 335 | 331 |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 | 721 |
| 726 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, | 722 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
| 727 RobotRefreshSaveFailed) { | 723 RobotRefreshSaveFailed) { |
| 728 // Without the system salt, the robot token can't be stored. | 724 // Without the system salt, the robot token can't be stored. |
| 729 RunTest(); | 725 RunTest(); |
| 730 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); | 726 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
| 731 } | 727 } |
| 732 | 728 |
| 733 } // namespace | 729 } // namespace |
| 734 } // namespace policy | 730 } // namespace policy |
| OLD | NEW |