pref_service_mock_builder.h revision 3f50c38dc070f4bb515c1b64450dae14f316474e
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/scoped_ptr.h" 11#include "chrome/common/persistent_pref_store.h" 12#include "chrome/common/pref_store.h" 13 14class CommandLine; 15class FilePath; 16class PrefService; 17class Profile; 18 19namespace policy { 20class ConfigurationPolicyProvider; 21} 22 23// A helper that allows convenient building of custom PrefServices in tests. 24class 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& WithDeviceManagementPrefs(PrefStore* store); 33 PrefServiceMockBuilder& WithExtensionPrefs(PrefStore* store); 34 PrefServiceMockBuilder& WithCommandLinePrefs(PrefStore* store); 35 PrefServiceMockBuilder& WithUserPrefs(PersistentPrefStore* store); 36 PrefServiceMockBuilder& WithRecommendedPrefs(PrefStore* store); 37 38 // Set up policy pref stores using the given policy provider. 39 PrefServiceMockBuilder& WithManagedPlatformProvider( 40 policy::ConfigurationPolicyProvider* provider); 41 PrefServiceMockBuilder& WithDeviceManagementProvider( 42 policy::ConfigurationPolicyProvider* provider); 43 PrefServiceMockBuilder& WithRecommendedProvider( 44 policy::ConfigurationPolicyProvider* provider); 45 46 // Specifies to use an actual command-line backed command-line pref store. 47 PrefServiceMockBuilder& WithCommandLine(CommandLine* command_line); 48 49 // Specifies to use an actual file-backed user pref store. 50 PrefServiceMockBuilder& WithUserFilePrefs(const FilePath& prefs_file); 51 52 // Sets the profile to pass to the PrefService. 53 PrefServiceMockBuilder& WithRecommendedPrefs(Profile* profile); 54 55 // Creates the PrefService, invalidating the entire builder configuration. 56 PrefService* Create(); 57 58 private: 59 scoped_ptr<PrefStore> managed_platform_prefs_; 60 scoped_ptr<PrefStore> device_management_prefs_; 61 scoped_ptr<PrefStore> extension_prefs_; 62 scoped_ptr<PrefStore> command_line_prefs_; 63 scoped_ptr<PersistentPrefStore> user_prefs_; 64 scoped_ptr<PrefStore> recommended_prefs_; 65 66 DISALLOW_COPY_AND_ASSIGN(PrefServiceMockBuilder); 67}; 68 69#endif // CHROME_BROWSER_PREFS_PREF_SERVICE_MOCK_BUILDER_H_ 70