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 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_MOCK_BUILDER_H_ 6 #define CHROME_BROWSER_PREFS_PREF_SERVICE_MOCK_BUILDER_H_ 7 #pragma once 8 9 #include "base/basictypes.h" 10 #include "base/memory/ref_counted.h" 11 #include "chrome/common/persistent_pref_store.h" 12 #include "chrome/common/pref_store.h" 13 14 class CommandLine; 15 class FilePath; 16 class PrefService; 17 class Profile; 18 19 namespace policy { 20 class ConfigurationPolicyProvider; 21 } 22 23 // A helper that allows convenient building of custom PrefServices in tests. 24 class PrefServiceMockBuilder { 25 public: 26 PrefServiceMockBuilder(); 27 ~PrefServiceMockBuilder(); 28 29 // Functions for setting the various parameters of the PrefService to build. 30 // These take ownership of the |store| parameter. 31 PrefServiceMockBuilder& WithManagedPlatformPrefs(PrefStore* store); 32 PrefServiceMockBuilder& WithManagedCloudPrefs(PrefStore* store); 33 PrefServiceMockBuilder& WithExtensionPrefs(PrefStore* store); 34 PrefServiceMockBuilder& WithCommandLinePrefs(PrefStore* store); 35 PrefServiceMockBuilder& WithUserPrefs(PersistentPrefStore* store); 36 PrefServiceMockBuilder& WithRecommendedPlatformPrefs(PrefStore* store); 37 PrefServiceMockBuilder& WithRecommendedCloudPrefs(PrefStore* store); 38 39 // Set up policy pref stores using the given policy provider. 40 PrefServiceMockBuilder& WithManagedPlatformProvider( 41 policy::ConfigurationPolicyProvider* provider); 42 PrefServiceMockBuilder& WithManagedCloudProvider( 43 policy::ConfigurationPolicyProvider* provider); 44 PrefServiceMockBuilder& WithRecommendedPlatformProvider( 45 policy::ConfigurationPolicyProvider* provider); 46 PrefServiceMockBuilder& WithRecommendedCloudProvider( 47 policy::ConfigurationPolicyProvider* provider); 48 49 // Specifies to use an actual command-line backed command-line pref store. 50 PrefServiceMockBuilder& WithCommandLine(CommandLine* command_line); 51 52 // Specifies to use an actual file-backed user pref store. 53 PrefServiceMockBuilder& WithUserFilePrefs(const FilePath& prefs_file); 54 55 // Creates the PrefService, invalidating the entire builder configuration. 56 PrefService* Create(); 57 58 private: 59 scoped_refptr<PrefStore> managed_platform_prefs_; 60 scoped_refptr<PrefStore> managed_cloud_prefs_; 61 scoped_refptr<PrefStore> extension_prefs_; 62 scoped_refptr<PrefStore> command_line_prefs_; 63 scoped_refptr<PersistentPrefStore> user_prefs_; 64 scoped_refptr<PrefStore> recommended_platform_prefs_; 65 scoped_refptr<PrefStore> recommended_cloud_prefs_; 66 67 DISALLOW_COPY_AND_ASSIGN(PrefServiceMockBuilder); 68 }; 69 70 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_MOCK_BUILDER_H_ 71