| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cloud_external_data_policy_observer.h" | 5 #include "chrome/browser/chromeos/policy/cloud_external_data_policy_observer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 17 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u
til.h" | 21 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u
til.h" |
| 21 #include "chrome/browser/chromeos/policy/device_local_account.h" | 22 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 22 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana
ger.h" | 23 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana
ger.h" |
| 23 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" | 24 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 void SetUp() override; | 102 void SetUp() override; |
| 102 void TearDown() override; | 103 void TearDown() override; |
| 103 | 104 |
| 104 // CloudExternalDataPolicyObserver::Delegate: | 105 // CloudExternalDataPolicyObserver::Delegate: |
| 105 void OnExternalDataSet(const std::string& policy, | 106 void OnExternalDataSet(const std::string& policy, |
| 106 const std::string& user_id) override; | 107 const std::string& user_id) override; |
| 107 void OnExternalDataCleared(const std::string& policy, | 108 void OnExternalDataCleared(const std::string& policy, |
| 108 const std::string& user_id) override; | 109 const std::string& user_id) override; |
| 109 void OnExternalDataFetched(const std::string& policy, | 110 void OnExternalDataFetched(const std::string& policy, |
| 110 const std::string& user_id, | 111 const std::string& user_id, |
| 111 scoped_ptr<std::string> data) override; | 112 std::unique_ptr<std::string> data) override; |
| 112 | 113 |
| 113 void CreateObserver(); | 114 void CreateObserver(); |
| 114 | 115 |
| 115 void ClearObservations(); | 116 void ClearObservations(); |
| 116 | 117 |
| 117 void SetDeviceLocalAccountAvatarPolicy(const std::string& account_id, | 118 void SetDeviceLocalAccountAvatarPolicy(const std::string& account_id, |
| 118 const std::string& value); | 119 const std::string& value); |
| 119 | 120 |
| 120 void AddDeviceLocalAccount(const std::string& account_id); | 121 void AddDeviceLocalAccount(const std::string& account_id); |
| 121 void RemoveDeviceLocalAccount(const std::string& account_id); | 122 void RemoveDeviceLocalAccount(const std::string& account_id); |
| 122 | 123 |
| 123 DeviceLocalAccountPolicyBroker* GetBrokerForDeviceLocalAccountUser(); | 124 DeviceLocalAccountPolicyBroker* GetBrokerForDeviceLocalAccountUser(); |
| 124 | 125 |
| 125 void RefreshDeviceLocalAccountPolicy(DeviceLocalAccountPolicyBroker* broker); | 126 void RefreshDeviceLocalAccountPolicy(DeviceLocalAccountPolicyBroker* broker); |
| 126 | 127 |
| 127 void LogInAsDeviceLocalAccount(const AccountId& account_id); | 128 void LogInAsDeviceLocalAccount(const AccountId& account_id); |
| 128 | 129 |
| 129 void SetRegularUserAvatarPolicy(const std::string& value); | 130 void SetRegularUserAvatarPolicy(const std::string& value); |
| 130 | 131 |
| 131 void LogInAsRegularUser(); | 132 void LogInAsRegularUser(); |
| 132 | 133 |
| 133 const std::string device_local_account_user_id_; | 134 const std::string device_local_account_user_id_; |
| 134 | 135 |
| 135 std::string avatar_policy_1_data_; | 136 std::string avatar_policy_1_data_; |
| 136 std::string avatar_policy_2_data_; | 137 std::string avatar_policy_2_data_; |
| 137 std::string avatar_policy_1_; | 138 std::string avatar_policy_1_; |
| 138 std::string avatar_policy_2_; | 139 std::string avatar_policy_2_; |
| 139 | 140 |
| 140 chromeos::CrosSettings cros_settings_; | 141 chromeos::CrosSettings cros_settings_; |
| 141 scoped_ptr<DeviceLocalAccountPolicyService> | 142 std::unique_ptr<DeviceLocalAccountPolicyService> |
| 142 device_local_account_policy_service_; | 143 device_local_account_policy_service_; |
| 143 FakeAffiliatedInvalidationServiceProvider | 144 FakeAffiliatedInvalidationServiceProvider |
| 144 affiliated_invalidation_service_provider_; | 145 affiliated_invalidation_service_provider_; |
| 145 net::TestURLFetcherFactory url_fetcher_factory_; | 146 net::TestURLFetcherFactory url_fetcher_factory_; |
| 146 | 147 |
| 147 scoped_ptr<DeviceLocalAccountPolicyProvider> | 148 std::unique_ptr<DeviceLocalAccountPolicyProvider> |
| 148 device_local_account_policy_provider_; | 149 device_local_account_policy_provider_; |
| 149 | 150 |
| 150 MockCloudExternalDataManager external_data_manager_; | 151 MockCloudExternalDataManager external_data_manager_; |
| 151 MockConfigurationPolicyProvider user_policy_provider_; | 152 MockConfigurationPolicyProvider user_policy_provider_; |
| 152 | 153 |
| 153 scoped_ptr<TestingProfile> profile_; | 154 std::unique_ptr<TestingProfile> profile_; |
| 154 | 155 |
| 155 scoped_ptr<CloudExternalDataPolicyObserver> observer_; | 156 std::unique_ptr<CloudExternalDataPolicyObserver> observer_; |
| 156 | 157 |
| 157 std::vector<std::string> set_calls_; | 158 std::vector<std::string> set_calls_; |
| 158 std::vector<std::string> cleared_calls_; | 159 std::vector<std::string> cleared_calls_; |
| 159 std::vector<FetchedCall> fetched_calls_; | 160 std::vector<FetchedCall> fetched_calls_; |
| 160 | 161 |
| 161 ExternalDataFetcher::FetchCallback fetch_callback_; | 162 ExternalDataFetcher::FetchCallback fetch_callback_; |
| 162 | 163 |
| 163 TestingProfileManager profile_manager_; | 164 TestingProfileManager profile_manager_; |
| 164 | 165 |
| 165 private: | 166 private: |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 void CloudExternalDataPolicyObserverTest::OnExternalDataCleared( | 231 void CloudExternalDataPolicyObserverTest::OnExternalDataCleared( |
| 231 const std::string& policy, | 232 const std::string& policy, |
| 232 const std::string& user_id) { | 233 const std::string& user_id) { |
| 233 EXPECT_EQ(key::kUserAvatarImage, policy); | 234 EXPECT_EQ(key::kUserAvatarImage, policy); |
| 234 cleared_calls_.push_back(user_id); | 235 cleared_calls_.push_back(user_id); |
| 235 } | 236 } |
| 236 | 237 |
| 237 void CloudExternalDataPolicyObserverTest::OnExternalDataFetched( | 238 void CloudExternalDataPolicyObserverTest::OnExternalDataFetched( |
| 238 const std::string& policy, | 239 const std::string& policy, |
| 239 const std::string& user_id, | 240 const std::string& user_id, |
| 240 scoped_ptr<std::string> data) { | 241 std::unique_ptr<std::string> data) { |
| 241 EXPECT_EQ(key::kUserAvatarImage, policy); | 242 EXPECT_EQ(key::kUserAvatarImage, policy); |
| 242 fetched_calls_.push_back(make_pair(user_id, std::string())); | 243 fetched_calls_.push_back(make_pair(user_id, std::string())); |
| 243 fetched_calls_.back().second.swap(*data); | 244 fetched_calls_.back().second.swap(*data); |
| 244 } | 245 } |
| 245 | 246 |
| 246 void CloudExternalDataPolicyObserverTest::CreateObserver() { | 247 void CloudExternalDataPolicyObserverTest::CreateObserver() { |
| 247 observer_.reset(new CloudExternalDataPolicyObserver( | 248 observer_.reset(new CloudExternalDataPolicyObserver( |
| 248 &cros_settings_, | 249 &cros_settings_, |
| 249 device_local_account_policy_service_.get(), | 250 device_local_account_policy_service_.get(), |
| 250 key::kUserAvatarImage, | 251 key::kUserAvatarImage, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 device_settings_test_helper_.Flush(); | 321 device_settings_test_helper_.Flush(); |
| 321 } | 322 } |
| 322 | 323 |
| 323 void CloudExternalDataPolicyObserverTest::LogInAsDeviceLocalAccount( | 324 void CloudExternalDataPolicyObserverTest::LogInAsDeviceLocalAccount( |
| 324 const AccountId& account_id) { | 325 const AccountId& account_id) { |
| 325 user_manager_->AddUser(account_id); | 326 user_manager_->AddUser(account_id); |
| 326 | 327 |
| 327 device_local_account_policy_provider_.reset( | 328 device_local_account_policy_provider_.reset( |
| 328 new DeviceLocalAccountPolicyProvider( | 329 new DeviceLocalAccountPolicyProvider( |
| 329 account_id.GetUserEmail(), device_local_account_policy_service_.get(), | 330 account_id.GetUserEmail(), device_local_account_policy_service_.get(), |
| 330 scoped_ptr<PolicyMap>())); | 331 std::unique_ptr<PolicyMap>())); |
| 331 | 332 |
| 332 PolicyServiceImpl::Providers providers; | 333 PolicyServiceImpl::Providers providers; |
| 333 providers.push_back(device_local_account_policy_provider_.get()); | 334 providers.push_back(device_local_account_policy_provider_.get()); |
| 334 TestingProfile::Builder builder; | 335 TestingProfile::Builder builder; |
| 335 builder.SetPolicyService( | 336 builder.SetPolicyService( |
| 336 scoped_ptr<PolicyService>(new PolicyServiceImpl(providers))); | 337 std::unique_ptr<PolicyService>(new PolicyServiceImpl(providers))); |
| 337 builder.SetPath(chromeos::ProfileHelper::Get()->GetProfilePathByUserIdHash( | 338 builder.SetPath(chromeos::ProfileHelper::Get()->GetProfilePathByUserIdHash( |
| 338 chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting( | 339 chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting( |
| 339 account_id.GetUserEmail()))); | 340 account_id.GetUserEmail()))); |
| 340 | 341 |
| 341 profile_ = builder.Build(); | 342 profile_ = builder.Build(); |
| 342 profile_->set_profile_name(account_id.GetUserEmail()); | 343 profile_->set_profile_name(account_id.GetUserEmail()); |
| 343 | 344 |
| 344 content::NotificationService::current()->Notify( | 345 content::NotificationService::current()->Notify( |
| 345 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 346 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 346 content::NotificationService::AllSources(), | 347 content::NotificationService::AllSources(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 363 user_policy_provider_.UpdateChromePolicy(policy_map); | 364 user_policy_provider_.UpdateChromePolicy(policy_map); |
| 364 } | 365 } |
| 365 | 366 |
| 366 void CloudExternalDataPolicyObserverTest::LogInAsRegularUser() { | 367 void CloudExternalDataPolicyObserverTest::LogInAsRegularUser() { |
| 367 user_manager_->AddUser(AccountId::FromUserEmail(kRegularUserID)); | 368 user_manager_->AddUser(AccountId::FromUserEmail(kRegularUserID)); |
| 368 | 369 |
| 369 PolicyServiceImpl::Providers providers; | 370 PolicyServiceImpl::Providers providers; |
| 370 providers.push_back(&user_policy_provider_); | 371 providers.push_back(&user_policy_provider_); |
| 371 TestingProfile::Builder builder; | 372 TestingProfile::Builder builder; |
| 372 builder.SetPolicyService( | 373 builder.SetPolicyService( |
| 373 scoped_ptr<PolicyService>(new PolicyServiceImpl(providers))); | 374 std::unique_ptr<PolicyService>(new PolicyServiceImpl(providers))); |
| 374 builder.SetPath(chromeos::ProfileHelper::Get()->GetProfilePathByUserIdHash( | 375 builder.SetPath(chromeos::ProfileHelper::Get()->GetProfilePathByUserIdHash( |
| 375 chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting( | 376 chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting( |
| 376 kRegularUserID))); | 377 kRegularUserID))); |
| 377 | 378 |
| 378 profile_ = builder.Build(); | 379 profile_ = builder.Build(); |
| 379 profile_->set_profile_name(kRegularUserID); | 380 profile_->set_profile_name(kRegularUserID); |
| 380 | 381 |
| 381 content::NotificationService::current()->Notify( | 382 content::NotificationService::current()->Notify( |
| 382 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 383 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 383 content::NotificationService::AllSources(), | 384 content::NotificationService::AllSources(), |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 | 786 |
| 786 EXPECT_TRUE(cleared_calls_.empty()); | 787 EXPECT_TRUE(cleared_calls_.empty()); |
| 787 EXPECT_TRUE(fetched_calls_.empty()); | 788 EXPECT_TRUE(fetched_calls_.empty()); |
| 788 ASSERT_EQ(1u, set_calls_.size()); | 789 ASSERT_EQ(1u, set_calls_.size()); |
| 789 EXPECT_EQ(kRegularUserID, set_calls_.front()); | 790 EXPECT_EQ(kRegularUserID, set_calls_.front()); |
| 790 ClearObservations(); | 791 ClearObservations(); |
| 791 | 792 |
| 792 Mock::VerifyAndClear(&external_data_manager_); | 793 Mock::VerifyAndClear(&external_data_manager_); |
| 793 EXPECT_CALL(external_data_manager_, Fetch(key::kUserAvatarImage, _)).Times(0); | 794 EXPECT_CALL(external_data_manager_, Fetch(key::kUserAvatarImage, _)).Times(0); |
| 794 | 795 |
| 795 fetch_callback_.Run(make_scoped_ptr(new std::string(avatar_policy_1_data_))); | 796 fetch_callback_.Run(base::WrapUnique(new std::string(avatar_policy_1_data_))); |
| 796 | 797 |
| 797 EXPECT_TRUE(set_calls_.empty()); | 798 EXPECT_TRUE(set_calls_.empty()); |
| 798 EXPECT_TRUE(cleared_calls_.empty()); | 799 EXPECT_TRUE(cleared_calls_.empty()); |
| 799 ASSERT_EQ(1u, fetched_calls_.size()); | 800 ASSERT_EQ(1u, fetched_calls_.size()); |
| 800 EXPECT_EQ(kRegularUserID, fetched_calls_.front().first); | 801 EXPECT_EQ(kRegularUserID, fetched_calls_.front().first); |
| 801 EXPECT_EQ(avatar_policy_1_data_, fetched_calls_.front().second); | 802 EXPECT_EQ(avatar_policy_1_data_, fetched_calls_.front().second); |
| 802 ClearObservations(); | 803 ClearObservations(); |
| 803 } | 804 } |
| 804 | 805 |
| 805 // Verifies that when the external data reference for a regular user is not set | 806 // Verifies that when the external data reference for a regular user is not set |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 | 892 |
| 892 EXPECT_TRUE(cleared_calls_.empty()); | 893 EXPECT_TRUE(cleared_calls_.empty()); |
| 893 EXPECT_TRUE(fetched_calls_.empty()); | 894 EXPECT_TRUE(fetched_calls_.empty()); |
| 894 ASSERT_EQ(1u, set_calls_.size()); | 895 ASSERT_EQ(1u, set_calls_.size()); |
| 895 EXPECT_EQ(kRegularUserID, set_calls_.front()); | 896 EXPECT_EQ(kRegularUserID, set_calls_.front()); |
| 896 ClearObservations(); | 897 ClearObservations(); |
| 897 | 898 |
| 898 Mock::VerifyAndClear(&external_data_manager_); | 899 Mock::VerifyAndClear(&external_data_manager_); |
| 899 EXPECT_CALL(external_data_manager_, Fetch(key::kUserAvatarImage, _)).Times(0); | 900 EXPECT_CALL(external_data_manager_, Fetch(key::kUserAvatarImage, _)).Times(0); |
| 900 | 901 |
| 901 fetch_callback_.Run(make_scoped_ptr(new std::string(avatar_policy_1_data_))); | 902 fetch_callback_.Run(base::WrapUnique(new std::string(avatar_policy_1_data_))); |
| 902 | 903 |
| 903 EXPECT_TRUE(set_calls_.empty()); | 904 EXPECT_TRUE(set_calls_.empty()); |
| 904 EXPECT_TRUE(cleared_calls_.empty()); | 905 EXPECT_TRUE(cleared_calls_.empty()); |
| 905 ASSERT_EQ(1u, fetched_calls_.size()); | 906 ASSERT_EQ(1u, fetched_calls_.size()); |
| 906 EXPECT_EQ(kRegularUserID, fetched_calls_.front().first); | 907 EXPECT_EQ(kRegularUserID, fetched_calls_.front().first); |
| 907 EXPECT_EQ(avatar_policy_1_data_, fetched_calls_.front().second); | 908 EXPECT_EQ(avatar_policy_1_data_, fetched_calls_.front().second); |
| 908 ClearObservations(); | 909 ClearObservations(); |
| 909 } | 910 } |
| 910 | 911 |
| 911 // Verifies that when the external data reference for a regular user is set | 912 // Verifies that when the external data reference for a regular user is set |
| (...skipping 28 matching lines...) Expand all Loading... |
| 940 | 941 |
| 941 EXPECT_TRUE(cleared_calls_.empty()); | 942 EXPECT_TRUE(cleared_calls_.empty()); |
| 942 EXPECT_TRUE(fetched_calls_.empty()); | 943 EXPECT_TRUE(fetched_calls_.empty()); |
| 943 ASSERT_EQ(1u, set_calls_.size()); | 944 ASSERT_EQ(1u, set_calls_.size()); |
| 944 EXPECT_EQ(kRegularUserID, set_calls_.front()); | 945 EXPECT_EQ(kRegularUserID, set_calls_.front()); |
| 945 ClearObservations(); | 946 ClearObservations(); |
| 946 | 947 |
| 947 Mock::VerifyAndClear(&external_data_manager_); | 948 Mock::VerifyAndClear(&external_data_manager_); |
| 948 EXPECT_CALL(external_data_manager_, Fetch(key::kUserAvatarImage, _)).Times(0); | 949 EXPECT_CALL(external_data_manager_, Fetch(key::kUserAvatarImage, _)).Times(0); |
| 949 | 950 |
| 950 fetch_callback_.Run(make_scoped_ptr(new std::string(avatar_policy_2_data_))); | 951 fetch_callback_.Run(base::WrapUnique(new std::string(avatar_policy_2_data_))); |
| 951 | 952 |
| 952 EXPECT_TRUE(set_calls_.empty()); | 953 EXPECT_TRUE(set_calls_.empty()); |
| 953 EXPECT_TRUE(cleared_calls_.empty()); | 954 EXPECT_TRUE(cleared_calls_.empty()); |
| 954 ASSERT_EQ(1u, fetched_calls_.size()); | 955 ASSERT_EQ(1u, fetched_calls_.size()); |
| 955 EXPECT_EQ(kRegularUserID, fetched_calls_.front().first); | 956 EXPECT_EQ(kRegularUserID, fetched_calls_.front().first); |
| 956 EXPECT_EQ(avatar_policy_2_data_, fetched_calls_.front().second); | 957 EXPECT_EQ(avatar_policy_2_data_, fetched_calls_.front().second); |
| 957 ClearObservations(); | 958 ClearObservations(); |
| 958 } | 959 } |
| 959 | 960 |
| 960 } // namespace policy | 961 } // namespace policy |
| OLD | NEW |