Chromium Code Reviews| Index: chrome/test/base/testing_profile.cc |
| diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc |
| index 8eb70633218dcbcb8c79b44dd88e4df0bb2a89f6..33c78401849dc7a0b3db85e4e85e1bfd05fa561c 100644 |
| --- a/chrome/test/base/testing_profile.cc |
| +++ b/chrome/test/base/testing_profile.cc |
| @@ -75,6 +75,7 @@ |
| #include "components/policy/core/common/schema.h" |
| #include "components/prefs/testing_pref_store.h" |
| #include "components/proxy_config/pref_proxy_config_tracker.h" |
| +#include "components/syncable_prefs/pref_service_mock_factory.h" |
| #include "components/syncable_prefs/pref_service_syncable.h" |
| #include "components/syncable_prefs/testing_pref_service_syncable.h" |
| #include "components/ui/zoom/zoom_event_manager.h" |
| @@ -116,6 +117,7 @@ |
| #if defined(ENABLE_SUPERVISED_USERS) |
| #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| +#include "chrome/browser/supervised_user/supervised_user_pref_store.h" |
| #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h" |
| #endif |
| @@ -355,7 +357,8 @@ TestingProfile::TestingProfile( |
| it != factories.end(); ++it) { |
| it->first->SetTestingFactory(this, it->second); |
| } |
| - |
| + // Set supervised_user_id_ here, because Init() checks it. |
| + supervised_user_id_ = supervised_user_id; |
|
Marc Treib
2016/05/23 15:32:43
Set this in the initializer list above?
mamir
2016/05/23 19:35:14
Done.
|
| Init(); |
| // If caller supplied a delegate, delay the FinishInit invocation until other |
| // tasks have run. |
| @@ -419,10 +422,22 @@ void TestingProfile::Init() { |
| ChromeBrowserMainExtraPartsProfiles:: |
| EnsureBrowserContextKeyedServiceFactoriesBuilt(); |
| +#if defined(ENABLE_SUPERVISED_USERS) |
| + if (!IsOffTheRecord()) { |
| + SupervisedUserSettingsService* settings_service = |
| + SupervisedUserSettingsServiceFactory::GetForProfile(this); |
| + TestingPrefStore* store = new TestingPrefStore(); |
| + settings_service->Init(store); |
| + store->SetInitializationCompleted(); |
| + } |
| +#endif |
| + |
| if (prefs_.get()) |
| user_prefs::UserPrefs::Set(this, prefs_.get()); |
| else if (IsOffTheRecord()) |
| CreateIncognitoPrefService(); |
| + else if (!supervised_user_id_.empty()) |
| + CreatePrefServiceForSupervisedUser(); |
| else |
| CreateTestingPrefService(); |
| @@ -473,16 +488,6 @@ void TestingProfile::Init() { |
| browser_context_dependency_manager_->CreateBrowserContextServicesForTest( |
| this); |
| - |
| -#if defined(ENABLE_SUPERVISED_USERS) |
| - if (!IsOffTheRecord()) { |
| - SupervisedUserSettingsService* settings_service = |
| - SupervisedUserSettingsServiceFactory::GetForProfile(this); |
| - TestingPrefStore* store = new TestingPrefStore(); |
| - settings_service->Init(store); |
| - store->SetInitializationCompleted(); |
| - } |
| -#endif |
| } |
| void TestingProfile::FinishInit() { |
| @@ -748,6 +753,27 @@ void TestingProfile::CreateTestingPrefService() { |
| chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); |
| } |
| +void TestingProfile::CreatePrefServiceForSupervisedUser() { |
| + DCHECK(!prefs_.get()); |
| + DCHECK(!supervised_user_id_.empty()); |
| + syncable_prefs::PrefServiceMockFactory factory; |
| + SupervisedUserSettingsService* supervised_user_settings = |
| + SupervisedUserSettingsServiceFactory::GetForProfile(this); |
| + scoped_refptr<PrefStore> supervised_user_prefs = |
| + make_scoped_refptr(new SupervisedUserPrefStore(supervised_user_settings)); |
| + |
| + factory.set_supervised_user_prefs(supervised_user_prefs); |
| + |
| + scoped_refptr<user_prefs::PrefRegistrySyncable> registry( |
| + new user_prefs::PrefRegistrySyncable); |
| + |
| + std::unique_ptr<syncable_prefs::PrefServiceSyncable> prefs( |
| + factory.CreateSyncable(registry.get())); |
|
Marc Treib
2016/05/23 15:32:43
Can't you assign this directly to prefs_?
mamir
2016/05/23 19:35:14
Done.
|
| + chrome::RegisterUserProfilePrefs(registry.get()); |
| + prefs_ = std::move(prefs); |
| + user_prefs::UserPrefs::Set(this, prefs_.get()); |
| +} |
| + |
| void TestingProfile::CreateIncognitoPrefService() { |
| DCHECK(original_profile_); |
| DCHECK(!testing_prefs_); |