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 | 13 |
14 class PrefModelAssociator; | 14 class PrefModelAssociator; |
15 class PrefNotifierImpl; | 15 class PrefNotifierImpl; |
16 class PrefRegistrySimple; | 16 class PrefRegistrySimple; |
| 17 class PrefRegistrySyncable; |
17 class TestingBrowserProcess; | 18 class TestingBrowserProcess; |
18 class TestingPrefStore; | 19 class TestingPrefStore; |
19 | 20 |
20 // A PrefService subclass for testing. It operates totally in memory and | 21 // A PrefService subclass for testing. It operates totally in memory and |
21 // provides additional API for manipulating preferences at the different levels | 22 // provides additional API for manipulating preferences at the different levels |
22 // (managed, extension, user) conveniently. | 23 // (managed, extension, user) conveniently. |
23 // | 24 // |
24 // Use this via its specializations, TestingPrefServiceSimple and | 25 // Use this via its specializations, TestingPrefServiceSimple and |
25 // TestingPrefServiceSyncable. | 26 // TestingPrefServiceSyncable. |
26 template <class SuperPrefService> | 27 template <class SuperPrefService> |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSimple); | 95 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSimple); |
95 }; | 96 }; |
96 | 97 |
97 // Test version of PrefServiceSyncable. | 98 // Test version of PrefServiceSyncable. |
98 class TestingPrefServiceSyncable | 99 class TestingPrefServiceSyncable |
99 : public TestingPrefServiceBase<PrefServiceSyncable> { | 100 : public TestingPrefServiceBase<PrefServiceSyncable> { |
100 public: | 101 public: |
101 TestingPrefServiceSyncable(); | 102 TestingPrefServiceSyncable(); |
102 virtual ~TestingPrefServiceSyncable(); | 103 virtual ~TestingPrefServiceSyncable(); |
103 | 104 |
| 105 // This is provided as a convenience; on a production PrefService |
| 106 // you would do all registrations before constructing it, passing it |
| 107 // a PrefRegistry via its constructor (or via |
| 108 // e.g. PrefServiceBuilder). |
| 109 PrefRegistrySyncable* registry(); |
| 110 |
104 private: | 111 private: |
105 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSyncable); | 112 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSyncable); |
106 }; | 113 }; |
107 | 114 |
108 // Helper class to temporarily set up a |local_state| in the global | 115 // Helper class to temporarily set up a |local_state| in the global |
109 // TestingBrowserProcess (for most unit tests it's NULL). | 116 // TestingBrowserProcess (for most unit tests it's NULL). |
110 class ScopedTestingLocalState { | 117 class ScopedTestingLocalState { |
111 public: | 118 public: |
112 explicit ScopedTestingLocalState(TestingBrowserProcess* browser_process); | 119 explicit ScopedTestingLocalState(TestingBrowserProcess* browser_process); |
113 ~ScopedTestingLocalState(); | 120 ~ScopedTestingLocalState(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 pref_store->SetValue(path, value); | 217 pref_store->SetValue(path, value); |
211 } | 218 } |
212 | 219 |
213 template<class SuperPrefService> | 220 template<class SuperPrefService> |
214 void TestingPrefServiceBase<SuperPrefService>::RemovePref( | 221 void TestingPrefServiceBase<SuperPrefService>::RemovePref( |
215 TestingPrefStore* pref_store, const char* path) { | 222 TestingPrefStore* pref_store, const char* path) { |
216 pref_store->RemoveValue(path); | 223 pref_store->RemoveValue(path); |
217 } | 224 } |
218 | 225 |
219 #endif // CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ | 226 #endif // CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ |
OLD | NEW |