blob: aeeb9c77df81e88d037c918b2964957f2223f2c8 [file] [log] [blame]
[email protected]74379bc52010-07-21 13:54:081// 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#include "chrome/test/testing_pref_service.h"
6
[email protected]ce1850e92010-10-15 08:40:587#include "chrome/browser/prefs/command_line_pref_store.h"
[email protected]37858e52010-08-26 00:22:028#include "chrome/browser/prefs/dummy_pref_store.h"
9#include "chrome/browser/prefs/pref_value_store.h"
[email protected]ce1850e92010-10-15 08:40:5810#include "chrome/browser/policy/configuration_policy_pref_store.h"
[email protected]74379bc52010-07-21 13:54:0811
[email protected]fa26b3d52010-08-06 08:51:5012TestingPrefService::TestingPrefValueStore::TestingPrefValueStore(
[email protected]be1c6e922010-11-17 12:49:1713 PrefStore* managed_platform_prefs,
14 PrefStore* device_management_prefs,
[email protected]fa26b3d52010-08-06 08:51:5015 PrefStore* extension_prefs,
16 PrefStore* command_line_prefs,
17 PrefStore* user_prefs,
[email protected]c3b54f372010-09-14 08:25:0718 PrefStore* recommended_prefs,
19 PrefStore* default_prefs)
[email protected]be1c6e922010-11-17 12:49:1720 : PrefValueStore(managed_platform_prefs, device_management_prefs,
21 extension_prefs, command_line_prefs,
[email protected]c3b54f372010-09-14 08:25:0722 user_prefs, recommended_prefs, default_prefs) {
[email protected]fa26b3d52010-08-06 08:51:5023}
24
25// TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify
26// which they want, and expand usage of this class to more unit tests.
[email protected]74379bc52010-07-21 13:54:0827TestingPrefService::TestingPrefService()
[email protected]fa26b3d52010-08-06 08:51:5028 : PrefService(new TestingPrefValueStore(
[email protected]be1c6e922010-11-17 12:49:1729 managed_platform_prefs_ = new DummyPrefStore(),
30 device_management_prefs_ = new DummyPrefStore(),
[email protected]ce1850e92010-10-15 08:40:5831 NULL,
32 NULL,
33 user_prefs_ = new DummyPrefStore(),
34 NULL,
35 default_prefs_ = new DummyPrefStore())) {
36}
37
38TestingPrefService::TestingPrefService(
[email protected]be1c6e922010-11-17 12:49:1739 policy::ConfigurationPolicyProvider* managed_platform_provider,
40 policy::ConfigurationPolicyProvider* device_management_provider,
[email protected]ce1850e92010-10-15 08:40:5841 CommandLine* command_line)
42 : PrefService(new TestingPrefValueStore(
[email protected]be1c6e922010-11-17 12:49:1743 managed_platform_prefs_ = CreatePolicyPrefStoreFromProvider(
44 managed_platform_provider),
45 device_management_prefs_ =
46 CreatePolicyPrefStoreFromProvider(device_management_provider),
[email protected]ce1850e92010-10-15 08:40:5847 NULL,
48 CreateCommandLinePrefStore(command_line),
49 user_prefs_ = new DummyPrefStore(),
50 NULL,
51 default_prefs_ = new DummyPrefStore())) {
52}
53
[email protected]be1c6e922010-11-17 12:49:1754PrefStore* TestingPrefService::CreatePolicyPrefStoreFromProvider(
[email protected]ce1850e92010-10-15 08:40:5855 policy::ConfigurationPolicyProvider* provider) {
56 if (provider)
57 return new policy::ConfigurationPolicyPrefStore(provider);
58 return new DummyPrefStore();
59}
60
61PrefStore* TestingPrefService::CreateCommandLinePrefStore(
62 CommandLine* command_line) {
63 if (command_line)
64 return new CommandLinePrefStore(command_line);
65 return new DummyPrefStore();
[email protected]74379bc52010-07-21 13:54:0866}
67
[email protected]57ecc4b2010-08-11 03:02:5168const Value* TestingPrefService::GetManagedPref(const char* path) {
[email protected]be1c6e922010-11-17 12:49:1769 return GetPref(managed_platform_prefs_, path);
[email protected]74379bc52010-07-21 13:54:0870}
71
[email protected]57ecc4b2010-08-11 03:02:5172void TestingPrefService::SetManagedPref(const char* path, Value* value) {
[email protected]be1c6e922010-11-17 12:49:1773 SetPref(managed_platform_prefs_, path, value);
[email protected]74379bc52010-07-21 13:54:0874}
75
[email protected]57ecc4b2010-08-11 03:02:5176void TestingPrefService::RemoveManagedPref(const char* path) {
[email protected]be1c6e922010-11-17 12:49:1777 RemovePref(managed_platform_prefs_, path);
[email protected]74379bc52010-07-21 13:54:0878}
79
[email protected]b6fd1fa72010-10-05 23:49:3180void TestingPrefService::SetManagedPrefWithoutNotification(const char* path,
81 Value* value) {
[email protected]be1c6e922010-11-17 12:49:1782 managed_platform_prefs_->prefs()->Set(path, value);
[email protected]b6fd1fa72010-10-05 23:49:3183}
84
85void TestingPrefService::RemoveManagedPrefWithoutNotification(
86 const char* path) {
[email protected]be1c6e922010-11-17 12:49:1787 managed_platform_prefs_->prefs()->Remove(path, NULL);
[email protected]b6fd1fa72010-10-05 23:49:3188}
89
[email protected]57ecc4b2010-08-11 03:02:5190const Value* TestingPrefService::GetUserPref(const char* path) {
[email protected]74379bc52010-07-21 13:54:0891 return GetPref(user_prefs_, path);
92}
93
[email protected]57ecc4b2010-08-11 03:02:5194void TestingPrefService::SetUserPref(const char* path, Value* value) {
[email protected]74379bc52010-07-21 13:54:0895 SetPref(user_prefs_, path, value);
96}
97
[email protected]57ecc4b2010-08-11 03:02:5198void TestingPrefService::RemoveUserPref(const char* path) {
[email protected]74379bc52010-07-21 13:54:0899 RemovePref(user_prefs_, path);
100}
101
102const Value* TestingPrefService::GetPref(PrefStore* pref_store,
[email protected]57ecc4b2010-08-11 03:02:51103 const char* path) {
[email protected]74379bc52010-07-21 13:54:08104 Value* result;
105 return pref_store->prefs()->Get(path, &result) ? result : NULL;
106}
107
108void TestingPrefService::SetPref(PrefStore* pref_store,
[email protected]57ecc4b2010-08-11 03:02:51109 const char* path,
[email protected]74379bc52010-07-21 13:54:08110 Value* value) {
111 pref_store->prefs()->Set(path, value);
[email protected]d81288a02010-08-18 07:25:50112 pref_notifier()->FireObservers(path);
[email protected]74379bc52010-07-21 13:54:08113}
114
115void TestingPrefService::RemovePref(PrefStore* pref_store,
[email protected]57ecc4b2010-08-11 03:02:51116 const char* path) {
[email protected]74379bc52010-07-21 13:54:08117 pref_store->prefs()->Remove(path, NULL);
[email protected]d81288a02010-08-18 07:25:50118 pref_notifier()->FireObservers(path);
[email protected]74379bc52010-07-21 13:54:08119}