Chromium Code Reviews| 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/test/base/testing_profile.h" | 5 #include "chrome/test/base/testing_profile.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 #include "components/keyed_service/core/refcounted_keyed_service.h" | 68 #include "components/keyed_service/core/refcounted_keyed_service.h" |
| 69 #include "components/omnibox/browser/autocomplete_classifier.h" | 69 #include "components/omnibox/browser/autocomplete_classifier.h" |
| 70 #include "components/omnibox/browser/history_index_restore_observer.h" | 70 #include "components/omnibox/browser/history_index_restore_observer.h" |
| 71 #include "components/omnibox/browser/in_memory_url_index.h" | 71 #include "components/omnibox/browser/in_memory_url_index.h" |
| 72 #include "components/policy/core/common/configuration_policy_provider.h" | 72 #include "components/policy/core/common/configuration_policy_provider.h" |
| 73 #include "components/policy/core/common/policy_service.h" | 73 #include "components/policy/core/common/policy_service.h" |
| 74 #include "components/policy/core/common/policy_service_impl.h" | 74 #include "components/policy/core/common/policy_service_impl.h" |
| 75 #include "components/policy/core/common/schema.h" | 75 #include "components/policy/core/common/schema.h" |
| 76 #include "components/prefs/testing_pref_store.h" | 76 #include "components/prefs/testing_pref_store.h" |
| 77 #include "components/proxy_config/pref_proxy_config_tracker.h" | 77 #include "components/proxy_config/pref_proxy_config_tracker.h" |
| 78 #include "components/syncable_prefs/pref_service_mock_factory.h" | |
| 78 #include "components/syncable_prefs/pref_service_syncable.h" | 79 #include "components/syncable_prefs/pref_service_syncable.h" |
| 79 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 80 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
| 80 #include "components/ui/zoom/zoom_event_manager.h" | 81 #include "components/ui/zoom/zoom_event_manager.h" |
| 81 #include "components/user_prefs/user_prefs.h" | 82 #include "components/user_prefs/user_prefs.h" |
| 82 #include "components/webdata_services/web_data_service_wrapper.h" | 83 #include "components/webdata_services/web_data_service_wrapper.h" |
| 83 #include "content/public/browser/browser_thread.h" | 84 #include "content/public/browser/browser_thread.h" |
| 84 #include "content/public/browser/cookie_store_factory.h" | 85 #include "content/public/browser/cookie_store_factory.h" |
| 85 #include "content/public/browser/notification_service.h" | 86 #include "content/public/browser/notification_service.h" |
| 86 #include "content/public/browser/render_process_host.h" | 87 #include "content/public/browser/render_process_host.h" |
| 87 #include "content/public/browser/storage_partition.h" | 88 #include "content/public/browser/storage_partition.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 109 #include "extensions/browser/extension_prefs_observer.h" | 110 #include "extensions/browser/extension_prefs_observer.h" |
| 110 #include "extensions/browser/extension_system.h" | 111 #include "extensions/browser/extension_system.h" |
| 111 #endif | 112 #endif |
| 112 | 113 |
| 113 #if defined(OS_ANDROID) | 114 #if defined(OS_ANDROID) |
| 114 #include "chrome/browser/signin/oauth2_token_service_delegate_android.h" | 115 #include "chrome/browser/signin/oauth2_token_service_delegate_android.h" |
| 115 #endif | 116 #endif |
| 116 | 117 |
| 117 #if defined(ENABLE_SUPERVISED_USERS) | 118 #if defined(ENABLE_SUPERVISED_USERS) |
| 118 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 119 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 120 #include "chrome/browser/supervised_user/supervised_user_pref_store.h" | |
| 119 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 121 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 120 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" | 122 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" |
| 121 #endif | 123 #endif |
| 122 | 124 |
| 123 using base::Time; | 125 using base::Time; |
| 124 using bookmarks::BookmarkModel; | 126 using bookmarks::BookmarkModel; |
| 125 using content::BrowserThread; | 127 using content::BrowserThread; |
| 126 using content::DownloadManagerDelegate; | 128 using content::DownloadManagerDelegate; |
| 127 using testing::NiceMock; | 129 using testing::NiceMock; |
| 128 using testing::Return; | 130 using testing::Return; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 const std::string& supervised_user_id, | 325 const std::string& supervised_user_id, |
| 324 std::unique_ptr<policy::PolicyService> policy_service, | 326 std::unique_ptr<policy::PolicyService> policy_service, |
| 325 const TestingFactories& factories, | 327 const TestingFactories& factories, |
| 326 const std::string& profile_name) | 328 const std::string& profile_name) |
| 327 : start_time_(Time::Now()), | 329 : start_time_(Time::Now()), |
| 328 prefs_(prefs.release()), | 330 prefs_(prefs.release()), |
| 329 testing_prefs_(NULL), | 331 testing_prefs_(NULL), |
| 330 force_incognito_(false), | 332 force_incognito_(false), |
| 331 original_profile_(parent), | 333 original_profile_(parent), |
| 332 guest_session_(guest_session), | 334 guest_session_(guest_session), |
| 335 supervised_user_id_(supervised_user_id), | |
| 333 last_session_exited_cleanly_(true), | 336 last_session_exited_cleanly_(true), |
| 334 #if defined(ENABLE_EXTENSIONS) | 337 #if defined(ENABLE_EXTENSIONS) |
| 335 extension_special_storage_policy_(extension_policy), | 338 extension_special_storage_policy_(extension_policy), |
| 336 #endif | 339 #endif |
| 337 profile_path_(path), | 340 profile_path_(path), |
| 338 browser_context_dependency_manager_( | 341 browser_context_dependency_manager_( |
| 339 BrowserContextDependencyManager::GetInstance()), | 342 BrowserContextDependencyManager::GetInstance()), |
| 340 resource_context_(NULL), | 343 resource_context_(NULL), |
| 341 delegate_(delegate), | 344 delegate_(delegate), |
| 342 profile_name_(profile_name), | 345 profile_name_(profile_name), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 #if defined(OS_ANDROID) | 415 #if defined(OS_ANDROID) |
| 413 // Make sure token service knows its running in tests. | 416 // Make sure token service knows its running in tests. |
| 414 OAuth2TokenServiceDelegateAndroid::set_is_testing_profile(); | 417 OAuth2TokenServiceDelegateAndroid::set_is_testing_profile(); |
| 415 #endif | 418 #endif |
| 416 | 419 |
| 417 // Normally this would happen during browser startup, but for tests | 420 // Normally this would happen during browser startup, but for tests |
| 418 // we need to trigger creation of Profile-related services. | 421 // we need to trigger creation of Profile-related services. |
| 419 ChromeBrowserMainExtraPartsProfiles:: | 422 ChromeBrowserMainExtraPartsProfiles:: |
| 420 EnsureBrowserContextKeyedServiceFactoriesBuilt(); | 423 EnsureBrowserContextKeyedServiceFactoriesBuilt(); |
| 421 | 424 |
| 425 #if defined(ENABLE_SUPERVISED_USERS) | |
|
Marc Treib
2016/05/24 09:54:58
Is it necessary to move this up here?
It used to h
mamir
2016/06/03 09:45:55
Yes, it is.
Because CreatePrefServiceForSupervised
Marc Treib
2016/06/03 13:24:13
And moving all the PrefService stuff down, after t
mamir
2016/06/06 15:01:36
I checked but couldn't be 100% sure whether it cau
Marc Treib
2016/06/07 10:27:03
Acknowledged.
| |
| 426 if (!IsOffTheRecord()) { | |
| 427 SupervisedUserSettingsService* settings_service = | |
| 428 SupervisedUserSettingsServiceFactory::GetForProfile(this); | |
| 429 TestingPrefStore* store = new TestingPrefStore(); | |
| 430 settings_service->Init(store); | |
| 431 store->SetInitializationCompleted(); | |
| 432 } | |
| 433 #endif | |
| 434 | |
| 422 if (prefs_.get()) | 435 if (prefs_.get()) |
| 423 user_prefs::UserPrefs::Set(this, prefs_.get()); | 436 user_prefs::UserPrefs::Set(this, prefs_.get()); |
| 424 else if (IsOffTheRecord()) | 437 else if (IsOffTheRecord()) |
| 425 CreateIncognitoPrefService(); | 438 CreateIncognitoPrefService(); |
| 439 else if (!supervised_user_id_.empty()) | |
| 440 CreatePrefServiceForSupervisedUser(); | |
| 426 else | 441 else |
| 427 CreateTestingPrefService(); | 442 CreateTestingPrefService(); |
| 428 | 443 |
| 429 if (!base::PathExists(profile_path_)) | 444 if (!base::PathExists(profile_path_)) |
| 430 base::CreateDirectory(profile_path_); | 445 base::CreateDirectory(profile_path_); |
| 431 | 446 |
| 432 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl | 447 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl |
| 433 // anymore, after converting the PrefService to a PKS. Until then it must | 448 // anymore, after converting the PrefService to a PKS. Until then it must |
| 434 // be associated with a TestingProfile too. | 449 // be associated with a TestingProfile too. |
| 435 if (!IsOffTheRecord()) | 450 if (!IsOffTheRecord()) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 466 DCHECK(!original_profile_); | 481 DCHECK(!original_profile_); |
| 467 user_prefs::PrefRegistrySyncable* pref_registry = | 482 user_prefs::PrefRegistrySyncable* pref_registry = |
| 468 static_cast<user_prefs::PrefRegistrySyncable*>( | 483 static_cast<user_prefs::PrefRegistrySyncable*>( |
| 469 prefs_->DeprecatedGetPrefRegistry()); | 484 prefs_->DeprecatedGetPrefRegistry()); |
| 470 browser_context_dependency_manager_-> | 485 browser_context_dependency_manager_-> |
| 471 RegisterProfilePrefsForServices(this, pref_registry); | 486 RegisterProfilePrefsForServices(this, pref_registry); |
| 472 } | 487 } |
| 473 | 488 |
| 474 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( | 489 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( |
| 475 this); | 490 this); |
| 476 | |
| 477 #if defined(ENABLE_SUPERVISED_USERS) | |
| 478 if (!IsOffTheRecord()) { | |
| 479 SupervisedUserSettingsService* settings_service = | |
| 480 SupervisedUserSettingsServiceFactory::GetForProfile(this); | |
| 481 TestingPrefStore* store = new TestingPrefStore(); | |
| 482 settings_service->Init(store); | |
| 483 store->SetInitializationCompleted(); | |
| 484 } | |
| 485 #endif | |
| 486 } | 491 } |
| 487 | 492 |
| 488 void TestingProfile::FinishInit() { | 493 void TestingProfile::FinishInit() { |
| 489 DCHECK(content::NotificationService::current()); | 494 DCHECK(content::NotificationService::current()); |
| 490 content::NotificationService::current()->Notify( | 495 content::NotificationService::current()->Notify( |
| 491 chrome::NOTIFICATION_PROFILE_CREATED, | 496 chrome::NOTIFICATION_PROFILE_CREATED, |
| 492 content::Source<Profile>(static_cast<Profile*>(this)), | 497 content::Source<Profile>(static_cast<Profile*>(this)), |
| 493 content::NotificationService::NoDetails()); | 498 content::NotificationService::NoDetails()); |
| 494 | 499 |
| 495 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 500 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 } | 746 } |
| 742 | 747 |
| 743 void TestingProfile::CreateTestingPrefService() { | 748 void TestingProfile::CreateTestingPrefService() { |
| 744 DCHECK(!prefs_.get()); | 749 DCHECK(!prefs_.get()); |
| 745 testing_prefs_ = new syncable_prefs::TestingPrefServiceSyncable(); | 750 testing_prefs_ = new syncable_prefs::TestingPrefServiceSyncable(); |
| 746 prefs_.reset(testing_prefs_); | 751 prefs_.reset(testing_prefs_); |
| 747 user_prefs::UserPrefs::Set(this, prefs_.get()); | 752 user_prefs::UserPrefs::Set(this, prefs_.get()); |
| 748 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); | 753 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); |
| 749 } | 754 } |
| 750 | 755 |
| 756 void TestingProfile::CreatePrefServiceForSupervisedUser() { | |
| 757 DCHECK(!prefs_.get()); | |
| 758 DCHECK(!supervised_user_id_.empty()); | |
| 759 syncable_prefs::PrefServiceMockFactory factory; | |
| 760 SupervisedUserSettingsService* supervised_user_settings = | |
| 761 SupervisedUserSettingsServiceFactory::GetForProfile(this); | |
| 762 scoped_refptr<PrefStore> supervised_user_prefs = | |
| 763 make_scoped_refptr(new SupervisedUserPrefStore(supervised_user_settings)); | |
| 764 | |
| 765 factory.set_supervised_user_prefs(supervised_user_prefs); | |
| 766 | |
| 767 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( | |
| 768 new user_prefs::PrefRegistrySyncable); | |
| 769 | |
| 770 prefs_= factory.CreateSyncable(registry.get()); | |
| 771 chrome::RegisterUserProfilePrefs(registry.get()); | |
| 772 user_prefs::UserPrefs::Set(this, prefs_.get()); | |
| 773 } | |
| 774 | |
| 751 void TestingProfile::CreateIncognitoPrefService() { | 775 void TestingProfile::CreateIncognitoPrefService() { |
| 752 DCHECK(original_profile_); | 776 DCHECK(original_profile_); |
| 753 DCHECK(!testing_prefs_); | 777 DCHECK(!testing_prefs_); |
| 754 // Simplified version of ProfileImpl::GetOffTheRecordPrefs(). Note this | 778 // Simplified version of ProfileImpl::GetOffTheRecordPrefs(). Note this |
| 755 // leaves testing_prefs_ unset. | 779 // leaves testing_prefs_ unset. |
| 756 prefs_.reset(CreateIncognitoPrefServiceSyncable( | 780 prefs_.reset(CreateIncognitoPrefServiceSyncable( |
| 757 original_profile_->prefs_.get(), NULL)); | 781 original_profile_->prefs_.get(), NULL)); |
| 758 user_prefs::UserPrefs::Set(this, prefs_.get()); | 782 user_prefs::UserPrefs::Set(this, prefs_.get()); |
| 759 } | 783 } |
| 760 | 784 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1032 // Note: Owned by |original_profile|. | 1056 // Note: Owned by |original_profile|. |
| 1033 return new TestingProfile(path_, delegate_, | 1057 return new TestingProfile(path_, delegate_, |
| 1034 #if defined(ENABLE_EXTENSIONS) | 1058 #if defined(ENABLE_EXTENSIONS) |
| 1035 extension_policy_, | 1059 extension_policy_, |
| 1036 #endif | 1060 #endif |
| 1037 std::move(pref_service_), original_profile, | 1061 std::move(pref_service_), original_profile, |
| 1038 guest_session_, supervised_user_id_, | 1062 guest_session_, supervised_user_id_, |
| 1039 std::move(policy_service_), testing_factories_, | 1063 std::move(policy_service_), testing_factories_, |
| 1040 profile_name_); | 1064 profile_name_); |
| 1041 } | 1065 } |
| OLD | NEW |