OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ | 5 #ifndef CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ |
6 #define CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ | 6 #define CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/testing_pref_store.h" | 10 #include "base/prefs/testing_pref_store.h" |
11 #include "chrome/browser/prefs/pref_registry.h" | 11 #include "chrome/browser/prefs/pref_registry.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/prefs/pref_service_syncable.h" |
13 | 14 |
14 class PrefModelAssociator; | 15 class PrefModelAssociator; |
15 class PrefNotifierImpl; | 16 class PrefNotifierImpl; |
16 class PrefRegistrySimple; | 17 class PrefRegistrySimple; |
| 18 class PrefRegistrySyncable; |
17 class TestingBrowserProcess; | 19 class TestingBrowserProcess; |
18 class TestingPrefStore; | 20 class TestingPrefStore; |
19 | 21 |
20 // A PrefService subclass for testing. It operates totally in memory and | 22 // A PrefService subclass for testing. It operates totally in memory and |
21 // provides additional API for manipulating preferences at the different levels | 23 // provides additional API for manipulating preferences at the different levels |
22 // (managed, extension, user) conveniently. | 24 // (managed, extension, user) conveniently. |
23 // | 25 // |
24 // Use this via its specializations, TestingPrefServiceSimple and | 26 // Use this via its specializations, TestingPrefServiceSimple and |
25 // TestingPrefServiceSyncable. | 27 // TestingPrefServiceSyncable. |
26 template <class SuperPrefService> | 28 template <class SuperPrefService> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSimple); | 97 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSimple); |
96 }; | 98 }; |
97 | 99 |
98 // Test version of PrefServiceSyncable. | 100 // Test version of PrefServiceSyncable. |
99 class TestingPrefServiceSyncable | 101 class TestingPrefServiceSyncable |
100 : public TestingPrefServiceBase<PrefServiceSyncable> { | 102 : public TestingPrefServiceBase<PrefServiceSyncable> { |
101 public: | 103 public: |
102 TestingPrefServiceSyncable(); | 104 TestingPrefServiceSyncable(); |
103 virtual ~TestingPrefServiceSyncable(); | 105 virtual ~TestingPrefServiceSyncable(); |
104 | 106 |
| 107 // This is provided as a convenience; on a production PrefService |
| 108 // you would do all registrations before constructing it, passing it |
| 109 // a PrefRegistry via its constructor (or via |
| 110 // e.g. PrefServiceBuilder). |
| 111 PrefRegistrySyncable* registry(); |
| 112 |
105 private: | 113 private: |
106 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSyncable); | 114 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSyncable); |
107 }; | 115 }; |
108 | 116 |
109 // Helper class to temporarily set up a |local_state| in the global | 117 // Helper class to temporarily set up a |local_state| in the global |
110 // TestingBrowserProcess (for most unit tests it's NULL). | 118 // TestingBrowserProcess (for most unit tests it's NULL). |
111 class ScopedTestingLocalState { | 119 class ScopedTestingLocalState { |
112 public: | 120 public: |
113 explicit ScopedTestingLocalState(TestingBrowserProcess* browser_process); | 121 explicit ScopedTestingLocalState(TestingBrowserProcess* browser_process); |
114 ~ScopedTestingLocalState(); | 122 ~ScopedTestingLocalState(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 pref_store->SetValue(path, value); | 219 pref_store->SetValue(path, value); |
212 } | 220 } |
213 | 221 |
214 template<class SuperPrefService> | 222 template<class SuperPrefService> |
215 void TestingPrefServiceBase<SuperPrefService>::RemovePref( | 223 void TestingPrefServiceBase<SuperPrefService>::RemovePref( |
216 TestingPrefStore* pref_store, const char* path) { | 224 TestingPrefStore* pref_store, const char* path) { |
217 pref_store->RemoveValue(path); | 225 pref_store->RemoveValue(path); |
218 } | 226 } |
219 | 227 |
220 #endif // CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ | 228 #endif // CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ |
OLD | NEW |