[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 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 | #include "chrome/test/testing_pref_service.h" |
| 6 | |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame^] | 7 | #include "chrome/browser/policy/configuration_policy_pref_store.h" |
[email protected] | ce1850e9 | 2010-10-15 08:40:58 | [diff] [blame] | 8 | #include "chrome/browser/prefs/command_line_pref_store.h" |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 9 | #include "chrome/browser/prefs/pref_notifier.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 10 | #include "chrome/browser/prefs/pref_value_store.h" |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame^] | 11 | #include "chrome/browser/prefs/testing_pref_store.h" |
[email protected] | fa26b3d5 | 2010-08-06 08:51:50 | [diff] [blame] | 12 | |
| 13 | // TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify |
| 14 | // which they want, and expand usage of this class to more unit tests. |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 15 | TestingPrefService::TestingPrefService() |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 16 | : PrefService( |
| 17 | managed_platform_prefs_ = new TestingPrefStore(), |
| 18 | device_management_prefs_ = new TestingPrefStore(), |
| 19 | NULL, |
| 20 | NULL, |
| 21 | user_prefs_ = new TestingPrefStore(), |
| 22 | NULL, |
| 23 | NULL) { |
[email protected] | ce1850e9 | 2010-10-15 08:40:58 | [diff] [blame] | 24 | } |
| 25 | |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame^] | 26 | const Value* TestingPrefService::GetManagedPref(const char* path) const { |
[email protected] | be1c6e92 | 2010-11-17 12:49:17 | [diff] [blame] | 27 | return GetPref(managed_platform_prefs_, path); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 28 | } |
| 29 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 30 | void TestingPrefService::SetManagedPref(const char* path, Value* value) { |
[email protected] | be1c6e92 | 2010-11-17 12:49:17 | [diff] [blame] | 31 | SetPref(managed_platform_prefs_, path, value); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 32 | } |
| 33 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 34 | void TestingPrefService::RemoveManagedPref(const char* path) { |
[email protected] | be1c6e92 | 2010-11-17 12:49:17 | [diff] [blame] | 35 | RemovePref(managed_platform_prefs_, path); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 36 | } |
| 37 | |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame^] | 38 | const Value* TestingPrefService::GetUserPref(const char* path) const { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 39 | return GetPref(user_prefs_, path); |
| 40 | } |
| 41 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 42 | void TestingPrefService::SetUserPref(const char* path, Value* value) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 43 | SetPref(user_prefs_, path, value); |
| 44 | } |
| 45 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 46 | void TestingPrefService::RemoveUserPref(const char* path) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 47 | RemovePref(user_prefs_, path); |
| 48 | } |
| 49 | |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame^] | 50 | const Value* TestingPrefService::GetPref(TestingPrefStore* pref_store, |
| 51 | const char* path) const { |
| 52 | Value* res; |
| 53 | return pref_store->GetValue(path, &res) == PrefStore::READ_OK ? res : NULL; |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 54 | } |
| 55 | |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame^] | 56 | void TestingPrefService::SetPref(TestingPrefStore* pref_store, |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 57 | const char* path, |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 58 | Value* value) { |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame^] | 59 | pref_store->SetValue(path, value); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame^] | 62 | void TestingPrefService::RemovePref(TestingPrefStore* pref_store, |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 63 | const char* path) { |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame^] | 64 | pref_store->RemoveValue(path); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 65 | } |