| 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_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 EnterpriseInstallAttributes::LockResult result; | 64 EnterpriseInstallAttributes::LockResult result; |
| 65 install_attributes_->LockDevice( | 65 install_attributes_->LockDevice( |
| 66 PolicyBuilder::kFakeUsername, | 66 PolicyBuilder::kFakeUsername, |
| 67 DEVICE_MODE_ENTERPRISE, | 67 DEVICE_MODE_ENTERPRISE, |
| 68 PolicyBuilder::kFakeDeviceId, | 68 PolicyBuilder::kFakeDeviceId, |
| 69 base::Bind(&CopyLockResult, &loop, &result)); | 69 base::Bind(&CopyLockResult, &loop, &result)); |
| 70 loop.Run(); | 70 loop.Run(); |
| 71 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, result); | 71 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, result); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void SetManagementModeAndLoad(em::PolicyData::ManagementMode mode) { | |
| 75 device_policy_.policy_data().set_management_mode(mode); | |
| 76 device_policy_.Build(); | |
| 77 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | |
| 78 device_settings_service_.Load(); | |
| 79 FlushDeviceSettings(); | |
| 80 EXPECT_EQ(chromeos::DeviceSettingsService::STORE_SUCCESS, | |
| 81 device_settings_service_.status()); | |
| 82 } | |
| 83 | |
| 84 void ExpectFailure(CloudPolicyStore::Status expected_status) { | 74 void ExpectFailure(CloudPolicyStore::Status expected_status) { |
| 85 EXPECT_EQ(expected_status, store_->status()); | 75 EXPECT_EQ(expected_status, store_->status()); |
| 86 EXPECT_TRUE(store_->is_initialized()); | 76 EXPECT_TRUE(store_->is_initialized()); |
| 87 EXPECT_FALSE(store_->has_policy()); | 77 EXPECT_FALSE(store_->has_policy()); |
| 88 EXPECT_FALSE(store_->is_managed()); | 78 EXPECT_FALSE(store_->is_managed()); |
| 89 } | 79 } |
| 90 | 80 |
| 91 void ExpectSuccessWithManagementMode(ManagementMode mode) { | |
| 92 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); | |
| 93 EXPECT_TRUE(store_->is_initialized()); | |
| 94 EXPECT_TRUE(store_->has_policy()); | |
| 95 EXPECT_TRUE(store_->is_managed()); | |
| 96 EXPECT_TRUE(store_->policy()); | |
| 97 EXPECT_TRUE(store_->policy_map().empty()); | |
| 98 if (store_->policy()) | |
| 99 EXPECT_EQ(mode, GetManagementMode(*store_->policy())); | |
| 100 } | |
| 101 | |
| 102 void ExpectSuccess() { | 81 void ExpectSuccess() { |
| 103 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); | 82 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); |
| 104 EXPECT_TRUE(store_->is_initialized()); | 83 EXPECT_TRUE(store_->is_initialized()); |
| 105 EXPECT_TRUE(store_->has_policy()); | 84 EXPECT_TRUE(store_->has_policy()); |
| 106 EXPECT_TRUE(store_->is_managed()); | 85 EXPECT_TRUE(store_->is_managed()); |
| 107 EXPECT_TRUE(store_->policy()); | 86 EXPECT_TRUE(store_->policy()); |
| 108 base::FundamentalValue expected(false); | 87 base::FundamentalValue expected(false); |
| 109 EXPECT_TRUE( | 88 EXPECT_TRUE( |
| 110 base::Value::Equals(&expected, | 89 base::Value::Equals(&expected, |
| 111 store_->policy_map().GetValue( | 90 store_->policy_map().GetValue( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 FlushDeviceSettings(); | 148 FlushDeviceSettings(); |
| 170 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); | 149 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); |
| 171 } | 150 } |
| 172 | 151 |
| 173 TEST_F(DeviceCloudPolicyStoreChromeOSTest, LoadSuccess) { | 152 TEST_F(DeviceCloudPolicyStoreChromeOSTest, LoadSuccess) { |
| 174 store_->Load(); | 153 store_->Load(); |
| 175 FlushDeviceSettings(); | 154 FlushDeviceSettings(); |
| 176 ExpectSuccess(); | 155 ExpectSuccess(); |
| 177 } | 156 } |
| 178 | 157 |
| 179 TEST_F(DeviceCloudPolicyStoreChromeOSTest, UpdateFromServiceOnConsumerDevices) { | |
| 180 ResetToNonEnterprise(); | |
| 181 | |
| 182 SetManagementModeAndLoad(em::PolicyData::CONSUMER_MANAGED); | |
| 183 ExpectSuccessWithManagementMode(MANAGEMENT_MODE_CONSUMER_MANAGED); | |
| 184 | |
| 185 // Unenroll from consumer management. | |
| 186 SetManagementModeAndLoad(em::PolicyData::LOCAL_OWNER); | |
| 187 ExpectSuccessWithManagementMode(MANAGEMENT_MODE_LOCAL_OWNER); | |
| 188 } | |
| 189 | |
| 190 TEST_F(DeviceCloudPolicyStoreChromeOSTest, StoreSuccess) { | 158 TEST_F(DeviceCloudPolicyStoreChromeOSTest, StoreSuccess) { |
| 191 PrepareExistingPolicy(); | 159 PrepareExistingPolicy(); |
| 192 store_->Store(device_policy_.policy()); | 160 store_->Store(device_policy_.policy()); |
| 193 FlushDeviceSettings(); | 161 FlushDeviceSettings(); |
| 194 ExpectSuccess(); | 162 ExpectSuccess(); |
| 195 } | 163 } |
| 196 | 164 |
| 197 TEST_F(DeviceCloudPolicyStoreChromeOSTest, StoreNoSignature) { | 165 TEST_F(DeviceCloudPolicyStoreChromeOSTest, StoreNoSignature) { |
| 198 PrepareExistingPolicy(); | 166 PrepareExistingPolicy(); |
| 199 device_policy_.policy().clear_policy_data_signature(); | 167 device_policy_.policy().clear_policy_data_signature(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 274 |
| 307 TEST_F(DeviceCloudPolicyStoreChromeOSTest, InstallInitialPolicyNotEnterprise) { | 275 TEST_F(DeviceCloudPolicyStoreChromeOSTest, InstallInitialPolicyNotEnterprise) { |
| 308 PrepareNewSigningKey(); | 276 PrepareNewSigningKey(); |
| 309 ResetToNonEnterprise(); | 277 ResetToNonEnterprise(); |
| 310 store_->InstallInitialPolicy(device_policy_.policy()); | 278 store_->InstallInitialPolicy(device_policy_.policy()); |
| 311 FlushDeviceSettings(); | 279 FlushDeviceSettings(); |
| 312 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); | 280 ExpectFailure(CloudPolicyStore::STATUS_BAD_STATE); |
| 313 } | 281 } |
| 314 | 282 |
| 315 } // namespace policy | 283 } // namespace policy |
| OLD | NEW |