pref_service_mock_builder.h revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
1// Copyright (c) 2010 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 28 // Functions for setting the various parameters of the PrefService to build. 29 // These take ownership of the |store| parameter. 30 PrefServiceMockBuilder& WithManagedPlatformPrefs(PrefStore* store); 31 PrefServiceMockBuilder& WithDeviceManagementPrefs(PrefStore* store); 32 PrefServiceMockBuilder& WithExtensionPrefs(PrefStore* store); 33 PrefServiceMockBuilder& WithCommandLinePrefs(PrefStore* store); 34 PrefServiceMockBuilder& WithUserPrefs(PersistentPrefStore* store); 35 PrefServiceMockBuilder& WithRecommendedPrefs(PrefStore* store); 36 37 // Set up policy pref stores using the given policy provider. 38 PrefServiceMockBuilder& WithManagedPlatformProvider( 39 policy::ConfigurationPolicyProvider* provider); 40 PrefServiceMockBuilder& WithDeviceManagementProvider( 41 policy::ConfigurationPolicyProvider* provider); 42 PrefServiceMockBuilder& WithRecommendedProvider( 43 policy::ConfigurationPolicyProvider* provider); 44 45 // Specifies to use an actual command-line backed command-line pref store. 46 PrefServiceMockBuilder& WithCommandLine(CommandLine* command_line); 47 48 // Specifies to use an actual file-backed user pref store. 49 PrefServiceMockBuilder& WithUserFilePrefs(const FilePath& prefs_file); 50 51 // Sets the profile to pass to the PrefService. 52 PrefServiceMockBuilder& WithRecommendedPrefs(Profile* profile); 53 54 // Creates the PrefService, invalidating the entire builder configuration. 55 PrefService* Create(); 56 57 private: 58 scoped_ptr<PrefStore> managed_platform_prefs_; 59 scoped_ptr<PrefStore> device_management_prefs_; 60 scoped_ptr<PrefStore> extension_prefs_; 61 scoped_ptr<PrefStore> command_line_prefs_; 62 scoped_ptr<PersistentPrefStore> user_prefs_; 63 scoped_ptr<PrefStore> recommended_prefs_; 64 65 DISALLOW_COPY_AND_ASSIGN(PrefServiceMockBuilder); 66}; 67 68#endif // CHROME_BROWSER_PREFS_PREF_SERVICE_MOCK_BUILDER_H_ 69