| 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_local_account_policy_service.h" | 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.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/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 27 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| 28 #include "chrome/browser/policy/cloud/cloud_policy_service.h" | 28 #include "chrome/browser/policy/cloud/cloud_policy_service.h" |
| 29 #include "chrome/browser/policy/cloud/mock_device_management_service.h" | 29 #include "chrome/browser/policy/cloud/mock_device_management_service.h" |
| 30 #include "chrome/browser/policy/cloud/policy_builder.h" | 30 #include "chrome/browser/policy/cloud/policy_builder.h" |
| 31 #include "chrome/browser/policy/external_data_fetcher.h" | 31 #include "chrome/browser/policy/external_data_fetcher.h" |
| 32 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 32 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 33 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" | 33 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" |
| 34 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
| 35 #include "chromeos/chromeos_paths.h" | 35 #include "chromeos/chromeos_paths.h" |
| 36 #include "chromeos/dbus/power_policy_controller.h" | 36 #include "chromeos/dbus/power_policy_controller.h" |
| 37 #include "net/url_request/url_request_context_getter.h" |
| 37 #include "policy/policy_constants.h" | 38 #include "policy/policy_constants.h" |
| 38 #include "policy/proto/cloud_policy.pb.h" | 39 #include "policy/proto/cloud_policy.pb.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 40 | 41 |
| 41 using testing::AnyNumber; | 42 using testing::AnyNumber; |
| 42 using testing::AtLeast; | 43 using testing::AtLeast; |
| 43 using testing::Mock; | 44 using testing::Mock; |
| 44 using testing::SaveArg; | 45 using testing::SaveArg; |
| 45 using testing::_; | 46 using testing::_; |
| 46 | 47 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 Value::CreateBooleanValue(true), | 162 Value::CreateBooleanValue(true), |
| 162 NULL); | 163 NULL); |
| 163 | 164 |
| 164 device_local_account_policy_.payload().mutable_disablespdy()->set_value( | 165 device_local_account_policy_.payload().mutable_disablespdy()->set_value( |
| 165 true); | 166 true); |
| 166 device_local_account_policy_.policy_data().set_policy_type( | 167 device_local_account_policy_.policy_data().set_policy_type( |
| 167 dm_protocol::kChromePublicAccountPolicyType); | 168 dm_protocol::kChromePublicAccountPolicyType); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void DeviceLocalAccountPolicyServiceTestBase::TearDown() { | 171 void DeviceLocalAccountPolicyServiceTestBase::TearDown() { |
| 172 service_->Shutdown(); |
| 171 service_.reset(); | 173 service_.reset(); |
| 172 extension_cache_task_runner_->RunUntilIdle(); | 174 extension_cache_task_runner_->RunUntilIdle(); |
| 173 chromeos::DeviceSettingsTestBase::TearDown(); | 175 chromeos::DeviceSettingsTestBase::TearDown(); |
| 174 } | 176 } |
| 175 | 177 |
| 176 void DeviceLocalAccountPolicyServiceTestBase::CreatePolicyService() { | 178 void DeviceLocalAccountPolicyServiceTestBase::CreatePolicyService() { |
| 177 service_.reset(new DeviceLocalAccountPolicyService( | 179 service_.reset(new DeviceLocalAccountPolicyService( |
| 178 &device_settings_test_helper_, | 180 &device_settings_test_helper_, |
| 179 &device_settings_service_, | 181 &device_settings_service_, |
| 180 &cros_settings_, | 182 &cros_settings_, |
| 181 loop_.message_loop_proxy(), | 183 loop_.message_loop_proxy(), |
| 182 extension_cache_task_runner_)); | 184 extension_cache_task_runner_, |
| 185 loop_.message_loop_proxy(), |
| 186 loop_.message_loop_proxy(), |
| 187 NULL)); |
| 183 } | 188 } |
| 184 | 189 |
| 185 void DeviceLocalAccountPolicyServiceTestBase:: | 190 void DeviceLocalAccountPolicyServiceTestBase:: |
| 186 InstallDeviceLocalAccountPolicy(const std::string& account_id) { | 191 InstallDeviceLocalAccountPolicy(const std::string& account_id) { |
| 187 device_local_account_policy_.policy_data().set_settings_entity_id(account_id); | 192 device_local_account_policy_.policy_data().set_settings_entity_id(account_id); |
| 188 device_local_account_policy_.policy_data().set_username(account_id); | 193 device_local_account_policy_.policy_data().set_username(account_id); |
| 189 device_local_account_policy_.Build(); | 194 device_local_account_policy_.Build(); |
| 190 device_settings_test_helper_.set_device_local_account_policy_blob( | 195 device_settings_test_helper_.set_device_local_account_policy_blob( |
| 191 account_id, device_local_account_policy_.GetBlob()); | 196 account_id, device_local_account_policy_.GetBlob()); |
| 192 } | 197 } |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 | 441 |
| 437 ASSERT_TRUE(broker->core()->store()); | 442 ASSERT_TRUE(broker->core()->store()); |
| 438 EXPECT_EQ(CloudPolicyStore::STATUS_OK, | 443 EXPECT_EQ(CloudPolicyStore::STATUS_OK, |
| 439 broker->core()->store()->status()); | 444 broker->core()->store()->status()); |
| 440 ASSERT_TRUE(broker->core()->store()->policy()); | 445 ASSERT_TRUE(broker->core()->store()->policy()); |
| 441 EXPECT_EQ(device_local_account_policy_.policy_data().SerializeAsString(), | 446 EXPECT_EQ(device_local_account_policy_.policy_data().SerializeAsString(), |
| 442 broker->core()->store()->policy()->SerializeAsString()); | 447 broker->core()->store()->policy()->SerializeAsString()); |
| 443 EXPECT_TRUE(expected_policy_map_.Equals( | 448 EXPECT_TRUE(expected_policy_map_.Equals( |
| 444 broker->core()->store()->policy_map())); | 449 broker->core()->store()->policy_map())); |
| 445 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_)); | 450 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_)); |
| 446 | |
| 447 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_)) | |
| 448 .Times(0); | |
| 449 service_->Disconnect(); | |
| 450 EXPECT_FALSE(broker->core()->client()); | |
| 451 Mock::VerifyAndClearExpectations(&service_observer_); | |
| 452 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_)); | |
| 453 } | 451 } |
| 454 | 452 |
| 455 TEST_F(DeviceLocalAccountPolicyServiceTest, RefreshPolicy) { | 453 TEST_F(DeviceLocalAccountPolicyServiceTest, RefreshPolicy) { |
| 456 InstallDeviceLocalAccountPolicy(kAccount1); | 454 InstallDeviceLocalAccountPolicy(kAccount1); |
| 457 AddDeviceLocalAccountToPolicy(kAccount1); | 455 AddDeviceLocalAccountToPolicy(kAccount1); |
| 458 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_)); | 456 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_)); |
| 459 InstallDevicePolicy(); | 457 InstallDevicePolicy(); |
| 460 | 458 |
| 461 DeviceLocalAccountPolicyBroker* broker = | 459 DeviceLocalAccountPolicyBroker* broker = |
| 462 service_->GetBrokerForUser(account_1_user_id_); | 460 service_->GetBrokerForUser(account_1_user_id_); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 }; | 508 }; |
| 511 | 509 |
| 512 DeviceLocalAccountPolicyExtensionCacheTest:: | 510 DeviceLocalAccountPolicyExtensionCacheTest:: |
| 513 DeviceLocalAccountPolicyExtensionCacheTest() { | 511 DeviceLocalAccountPolicyExtensionCacheTest() { |
| 514 } | 512 } |
| 515 | 513 |
| 516 void DeviceLocalAccountPolicyExtensionCacheTest::SetUp() { | 514 void DeviceLocalAccountPolicyExtensionCacheTest::SetUp() { |
| 517 DeviceLocalAccountPolicyServiceTestBase::SetUp(); | 515 DeviceLocalAccountPolicyServiceTestBase::SetUp(); |
| 518 ASSERT_TRUE(cache_root_dir_.CreateUniqueTempDir()); | 516 ASSERT_TRUE(cache_root_dir_.CreateUniqueTempDir()); |
| 519 cache_root_dir_override_.reset(new base::ScopedPathOverride( | 517 cache_root_dir_override_.reset(new base::ScopedPathOverride( |
| 520 chromeos::DIR_DEVICE_LOCAL_ACCOUNT_CACHE, | 518 chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, |
| 521 cache_root_dir_.path())); | 519 cache_root_dir_.path())); |
| 522 | 520 |
| 523 cache_dir_1_ = GetCacheDirectoryForAccountID(kAccount1); | 521 cache_dir_1_ = GetCacheDirectoryForAccountID(kAccount1); |
| 524 cache_dir_2_ = GetCacheDirectoryForAccountID(kAccount2); | 522 cache_dir_2_ = GetCacheDirectoryForAccountID(kAccount2); |
| 525 cache_dir_3_ = GetCacheDirectoryForAccountID(kAccount3); | 523 cache_dir_3_ = GetCacheDirectoryForAccountID(kAccount3); |
| 526 | 524 |
| 527 em::StringList* forcelist = device_local_account_policy_.payload() | 525 em::StringList* forcelist = device_local_account_policy_.payload() |
| 528 .mutable_extensioninstallforcelist()->mutable_value(); | 526 .mutable_extensioninstallforcelist()->mutable_value(); |
| 529 forcelist->add_entries(base::StringPrintf("%s;%s", kExtensionID, kUpdateURL)); | 527 forcelist->add_entries(base::StringPrintf("%s;%s", kExtensionID, kUpdateURL)); |
| 530 } | 528 } |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 em::DeviceManagementResponse response; | 940 em::DeviceManagementResponse response; |
| 943 device_local_account_policy_.Build(); | 941 device_local_account_policy_.Build(); |
| 944 response.mutable_policy_response()->add_response()->CopyFrom( | 942 response.mutable_policy_response()->add_response()->CopyFrom( |
| 945 device_local_account_policy_.policy()); | 943 device_local_account_policy_.policy()); |
| 946 request_job->SendResponse(DM_STATUS_SUCCESS, response); | 944 request_job->SendResponse(DM_STATUS_SUCCESS, response); |
| 947 FlushDeviceSettings(); | 945 FlushDeviceSettings(); |
| 948 Mock::VerifyAndClearExpectations(&provider_observer_); | 946 Mock::VerifyAndClearExpectations(&provider_observer_); |
| 949 } | 947 } |
| 950 | 948 |
| 951 } // namespace policy | 949 } // namespace policy |
| OLD | NEW |