1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/prefs/pref_service_mock_builder.h" 6 7 #include "chrome/browser/policy/configuration_policy_pref_store.h" 8 #include "chrome/browser/prefs/command_line_pref_store.h" 9 #include "chrome/browser/prefs/default_pref_store.h" 10 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/testing_pref_store.h" 12 #include "chrome/common/json_pref_store.h" 13 #include "content/browser/browser_thread.h" 14 15 PrefServiceMockBuilder::PrefServiceMockBuilder() 16 : user_prefs_(new TestingPrefStore) { 17 } 18 19 PrefServiceMockBuilder::~PrefServiceMockBuilder() {} 20 21 PrefServiceMockBuilder& 22 PrefServiceMockBuilder::WithManagedPlatformPrefs(PrefStore* store) { 23 managed_platform_prefs_ = store; 24 return *this; 25 } 26 27 PrefServiceMockBuilder& 28 PrefServiceMockBuilder::WithManagedCloudPrefs(PrefStore* store) { 29 managed_cloud_prefs_ = store; 30 return *this; 31 } 32 33 PrefServiceMockBuilder& 34 PrefServiceMockBuilder::WithExtensionPrefs(PrefStore* store) { 35 extension_prefs_ = store; 36 return *this; 37 } 38 39 PrefServiceMockBuilder& 40 PrefServiceMockBuilder::WithCommandLinePrefs(PrefStore* store) { 41 command_line_prefs_ = store; 42 return *this; 43 } 44 45 PrefServiceMockBuilder& 46 PrefServiceMockBuilder::WithUserPrefs(PersistentPrefStore* store) { 47 user_prefs_ = store; 48 return *this; 49 } 50 51 PrefServiceMockBuilder& 52 PrefServiceMockBuilder::WithRecommendedPlatformPrefs(PrefStore* store) { 53 recommended_platform_prefs_ = store; 54 return *this; 55 } 56 57 PrefServiceMockBuilder& 58 PrefServiceMockBuilder::WithRecommendedCloudPrefs(PrefStore* store) { 59 recommended_cloud_prefs_ = store; 60 return *this; 61 } 62 63 PrefServiceMockBuilder& 64 PrefServiceMockBuilder::WithManagedPlatformProvider( 65 policy::ConfigurationPolicyProvider* provider) { 66 managed_platform_prefs_ = new policy::ConfigurationPolicyPrefStore(provider); 67 return *this; 68 } 69 70 PrefServiceMockBuilder& 71 PrefServiceMockBuilder::WithManagedCloudProvider( 72 policy::ConfigurationPolicyProvider* provider) { 73 managed_cloud_prefs_ = new policy::ConfigurationPolicyPrefStore(provider); 74 return *this; 75 } 76 77 PrefServiceMockBuilder& 78 PrefServiceMockBuilder::WithRecommendedPlatformProvider( 79 policy::ConfigurationPolicyProvider* provider) { 80 recommended_platform_prefs_ = 81 new policy::ConfigurationPolicyPrefStore(provider); 82 return *this; 83 } 84 85 PrefServiceMockBuilder& 86 PrefServiceMockBuilder::WithRecommendedCloudProvider( 87 policy::ConfigurationPolicyProvider* provider) { 88 recommended_cloud_prefs_ = new policy::ConfigurationPolicyPrefStore(provider); 89 return *this; 90 } 91 92 PrefServiceMockBuilder& 93 PrefServiceMockBuilder::WithCommandLine(CommandLine* command_line) { 94 command_line_prefs_ = new CommandLinePrefStore(command_line); 95 return *this; 96 } 97 98 PrefServiceMockBuilder& 99 PrefServiceMockBuilder::WithUserFilePrefs(const FilePath& prefs_file) { 100 user_prefs_ = 101 new JsonPrefStore(prefs_file, 102 BrowserThread::GetMessageLoopProxyForThread( 103 BrowserThread::FILE)); 104 return *this; 105 } 106 107 PrefService* PrefServiceMockBuilder::Create() { 108 PrefService* pref_service = 109 new PrefService(managed_platform_prefs_.get(), 110 managed_cloud_prefs_.get(), 111 extension_prefs_.get(), 112 command_line_prefs_.get(), 113 user_prefs_.get(), 114 recommended_platform_prefs_.get(), 115 recommended_cloud_prefs_.get(), 116 new DefaultPrefStore(), 117 NULL); 118 managed_platform_prefs_ = NULL; 119 managed_cloud_prefs_ = NULL; 120 extension_prefs_ = NULL; 121 command_line_prefs_ = NULL; 122 user_prefs_ = NULL; 123 recommended_platform_prefs_ = NULL; 124 recommended_cloud_prefs_ = NULL; 125 user_prefs_ = new TestingPrefStore; 126 return pref_service; 127 } 128