Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: chrome/browser/chromeos/policy/cloud_external_data_policy_observer_unittest.cc

Issue 442043002: ProfileManager doesn't depend on "--login-profile" switch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u til.h" 20 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u til.h"
21 #include "chrome/browser/chromeos/policy/device_local_account.h" 21 #include "chrome/browser/chromeos/policy/device_local_account.h"
22 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana ger.h" 22 #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" 23 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h"
24 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" 24 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
25 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 25 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
26 #include "chrome/browser/chromeos/profiles/profile_helper.h"
26 #include "chrome/browser/chromeos/settings/device_settings_service.h" 27 #include "chrome/browser/chromeos/settings/device_settings_service.h"
27 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 28 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
28 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
31 #include "chrome/test/base/testing_browser_process.h"
30 #include "chrome/test/base/testing_profile.h" 32 #include "chrome/test/base/testing_profile.h"
33 #include "chrome/test/base/testing_profile_manager.h"
31 #include "components/policy/core/common/cloud/cloud_policy_core.h" 34 #include "components/policy/core/common/cloud/cloud_policy_core.h"
32 #include "components/policy/core/common/cloud/cloud_policy_store.h" 35 #include "components/policy/core/common/cloud/cloud_policy_store.h"
33 #include "components/policy/core/common/cloud/mock_cloud_external_data_manager.h " 36 #include "components/policy/core/common/cloud/mock_cloud_external_data_manager.h "
34 #include "components/policy/core/common/cloud/policy_builder.h" 37 #include "components/policy/core/common/cloud/policy_builder.h"
35 #include "components/policy/core/common/external_data_fetcher.h" 38 #include "components/policy/core/common/external_data_fetcher.h"
36 #include "components/policy/core/common/mock_configuration_policy_provider.h" 39 #include "components/policy/core/common/mock_configuration_policy_provider.h"
37 #include "components/policy/core/common/policy_map.h" 40 #include "components/policy/core/common/policy_map.h"
38 #include "components/policy/core/common/policy_service.h" 41 #include "components/policy/core/common/policy_service.h"
39 #include "components/policy/core/common/policy_service_impl.h" 42 #include "components/policy/core/common/policy_service_impl.h"
40 #include "components/policy/core/common/policy_types.h" 43 #include "components/policy/core/common/policy_types.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 scoped_ptr<TestingProfile> profile_; 151 scoped_ptr<TestingProfile> profile_;
149 152
150 scoped_ptr<CloudExternalDataPolicyObserver> observer_; 153 scoped_ptr<CloudExternalDataPolicyObserver> observer_;
151 154
152 std::vector<std::string> set_calls_; 155 std::vector<std::string> set_calls_;
153 std::vector<std::string> cleared_calls_; 156 std::vector<std::string> cleared_calls_;
154 std::vector<FetchedCall> fetched_calls_; 157 std::vector<FetchedCall> fetched_calls_;
155 158
156 ExternalDataFetcher::FetchCallback fetch_callback_; 159 ExternalDataFetcher::FetchCallback fetch_callback_;
157 160
161 TestingProfileManager profile_manager_;
162
158 private: 163 private:
159 DISALLOW_COPY_AND_ASSIGN(CloudExternalDataPolicyObserverTest); 164 DISALLOW_COPY_AND_ASSIGN(CloudExternalDataPolicyObserverTest);
160 }; 165 };
161 166
162 CloudExternalDataPolicyObserverTest::CloudExternalDataPolicyObserverTest() 167 CloudExternalDataPolicyObserverTest::CloudExternalDataPolicyObserverTest()
163 : device_local_account_user_id_(GenerateDeviceLocalAccountUserId( 168 : device_local_account_user_id_(GenerateDeviceLocalAccountUserId(
164 kDeviceLocalAccount, 169 kDeviceLocalAccount,
165 DeviceLocalAccount::TYPE_PUBLIC_SESSION)), 170 DeviceLocalAccount::TYPE_PUBLIC_SESSION)),
166 cros_settings_(&device_settings_service_) { 171 cros_settings_(&device_settings_service_),
172 profile_manager_(TestingBrowserProcess::GetGlobal()) {
167 } 173 }
168 174
169 CloudExternalDataPolicyObserverTest::~CloudExternalDataPolicyObserverTest() { 175 CloudExternalDataPolicyObserverTest::~CloudExternalDataPolicyObserverTest() {
170 } 176 }
171 177
172 void CloudExternalDataPolicyObserverTest::SetUp() { 178 void CloudExternalDataPolicyObserverTest::SetUp() {
173 chromeos::DeviceSettingsTestBase::SetUp(); 179 chromeos::DeviceSettingsTestBase::SetUp();
180 ASSERT_TRUE(profile_manager_.SetUp());
174 device_local_account_policy_service_.reset( 181 device_local_account_policy_service_.reset(
175 new DeviceLocalAccountPolicyService(&device_settings_test_helper_, 182 new DeviceLocalAccountPolicyService(&device_settings_test_helper_,
176 &device_settings_service_, 183 &device_settings_service_,
177 &cros_settings_, 184 &cros_settings_,
178 base::MessageLoopProxy::current(), 185 base::MessageLoopProxy::current(),
179 base::MessageLoopProxy::current(), 186 base::MessageLoopProxy::current(),
180 base::MessageLoopProxy::current(), 187 base::MessageLoopProxy::current(),
181 base::MessageLoopProxy::current(), 188 base::MessageLoopProxy::current(),
182 NULL)); 189 NULL));
183 url_fetcher_factory_.set_remove_fetcher_on_delete(true); 190 url_fetcher_factory_.set_remove_fetcher_on_delete(true);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 312 }
306 313
307 void CloudExternalDataPolicyObserverTest::RefreshDeviceLocalAccountPolicy( 314 void CloudExternalDataPolicyObserverTest::RefreshDeviceLocalAccountPolicy(
308 DeviceLocalAccountPolicyBroker* broker) { 315 DeviceLocalAccountPolicyBroker* broker) {
309 broker->core()->store()->Load(); 316 broker->core()->store()->Load();
310 device_settings_test_helper_.Flush(); 317 device_settings_test_helper_.Flush();
311 } 318 }
312 319
313 void CloudExternalDataPolicyObserverTest::LogInAsDeviceLocalAccount( 320 void CloudExternalDataPolicyObserverTest::LogInAsDeviceLocalAccount(
314 const std::string& user_id) { 321 const std::string& user_id) {
322 user_manager_->AddUser(user_id);
323
315 device_local_account_policy_provider_.reset( 324 device_local_account_policy_provider_.reset(
316 new DeviceLocalAccountPolicyProvider( 325 new DeviceLocalAccountPolicyProvider(
317 user_id, 326 user_id,
318 device_local_account_policy_service_.get(), 327 device_local_account_policy_service_.get(),
319 scoped_ptr<PolicyMap>())); 328 scoped_ptr<PolicyMap>()));
320 329
321 PolicyServiceImpl::Providers providers; 330 PolicyServiceImpl::Providers providers;
322 providers.push_back(device_local_account_policy_provider_.get()); 331 providers.push_back(device_local_account_policy_provider_.get());
323 TestingProfile::Builder builder; 332 TestingProfile::Builder builder;
324 builder.SetPolicyService( 333 builder.SetPolicyService(
325 scoped_ptr<PolicyService>(new PolicyServiceImpl(providers))); 334 scoped_ptr<PolicyService>(new PolicyServiceImpl(providers)));
335 builder.SetPath(chromeos::ProfileHelper::Get()->GetProfilePathByUserIdHash(
336 chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting(user_id)));
326 337
327 profile_ = builder.Build(); 338 profile_ = builder.Build();
328 profile_->set_profile_name(user_id); 339 profile_->set_profile_name(user_id);
329 340
330 user_manager_->AddUser(user_id);
331 content::NotificationService::current()->Notify( 341 content::NotificationService::current()->Notify(
332 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 342 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
333 content::NotificationService::AllSources(), 343 content::NotificationService::AllSources(),
334 content::Details<Profile>(profile_.get())); 344 content::Details<Profile>(profile_.get()));
335 } 345 }
336 346
337 void CloudExternalDataPolicyObserverTest::SetRegularUserAvatarPolicy( 347 void CloudExternalDataPolicyObserverTest::SetRegularUserAvatarPolicy(
338 const std::string& value) { 348 const std::string& value) {
339 PolicyMap policy_map; 349 PolicyMap policy_map;
340 if (!value.empty()) { 350 if (!value.empty()) {
341 policy_map.Set( 351 policy_map.Set(
342 key::kUserAvatarImage, 352 key::kUserAvatarImage,
343 POLICY_LEVEL_MANDATORY, 353 POLICY_LEVEL_MANDATORY,
344 POLICY_SCOPE_USER, 354 POLICY_SCOPE_USER,
345 new base::StringValue(value), 355 new base::StringValue(value),
346 external_data_manager_.CreateExternalDataFetcher( 356 external_data_manager_.CreateExternalDataFetcher(
347 key::kUserAvatarImage).release()); 357 key::kUserAvatarImage).release());
348 } 358 }
349 user_policy_provider_.UpdateChromePolicy(policy_map); 359 user_policy_provider_.UpdateChromePolicy(policy_map);
350 } 360 }
351 361
352 void CloudExternalDataPolicyObserverTest::LogInAsRegularUser() { 362 void CloudExternalDataPolicyObserverTest::LogInAsRegularUser() {
363 user_manager_->AddUser(kRegularUserID);
364
353 PolicyServiceImpl::Providers providers; 365 PolicyServiceImpl::Providers providers;
354 providers.push_back(&user_policy_provider_); 366 providers.push_back(&user_policy_provider_);
355 TestingProfile::Builder builder; 367 TestingProfile::Builder builder;
356 builder.SetPolicyService( 368 builder.SetPolicyService(
357 scoped_ptr<PolicyService>(new PolicyServiceImpl(providers))); 369 scoped_ptr<PolicyService>(new PolicyServiceImpl(providers)));
370 builder.SetPath(chromeos::ProfileHelper::Get()->GetProfilePathByUserIdHash(
371 chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting(
372 kRegularUserID)));
358 373
359 profile_ = builder.Build(); 374 profile_ = builder.Build();
360 profile_->set_profile_name(kRegularUserID); 375 profile_->set_profile_name(kRegularUserID);
361 376
362 user_manager_->AddUser(kRegularUserID);
363 content::NotificationService::current()->Notify( 377 content::NotificationService::current()->Notify(
364 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 378 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
365 content::NotificationService::AllSources(), 379 content::NotificationService::AllSources(),
366 content::Details<Profile>(profile_.get())); 380 content::Details<Profile>(profile_.get()));
367 } 381 }
368 382
369 // Verifies that when an external data reference is set for a device-local 383 // Verifies that when an external data reference is set for a device-local
370 // account, a corresponding notification is emitted and a fetch is started. 384 // account, a corresponding notification is emitted and a fetch is started.
371 // Further verifies that when the fetch succeeds, a notification containing the 385 // Further verifies that when the fetch succeeds, a notification containing the
372 // external data is emitted. 386 // external data is emitted.
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 947
934 EXPECT_TRUE(set_calls_.empty()); 948 EXPECT_TRUE(set_calls_.empty());
935 EXPECT_TRUE(cleared_calls_.empty()); 949 EXPECT_TRUE(cleared_calls_.empty());
936 ASSERT_EQ(1u, fetched_calls_.size()); 950 ASSERT_EQ(1u, fetched_calls_.size());
937 EXPECT_EQ(kRegularUserID, fetched_calls_.front().first); 951 EXPECT_EQ(kRegularUserID, fetched_calls_.front().first);
938 EXPECT_EQ(avatar_policy_2_data_, fetched_calls_.front().second); 952 EXPECT_EQ(avatar_policy_2_data_, fetched_calls_.front().second);
939 ClearObservations(); 953 ClearObservations();
940 } 954 }
941 955
942 } // namespace policy 956 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698