Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: chrome/test/base/testing_pref_service.cc

Issue 12223091: Split testing_pref_service.h/.cc into two parts, generic vs. Chrome-specific. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/test/base/testing_pref_service.h" 5 #include "chrome/test/base/testing_pref_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/prefs/default_pref_store.h" 9 #include "base/prefs/default_pref_store.h"
10 #include "base/prefs/pref_notifier_impl.h" 10 #include "base/prefs/pref_notifier_impl.h"
11 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/pref_value_store.h" 12 #include "base/prefs/pref_value_store.h"
13 #include "chrome/browser/prefs/browser_prefs.h"
14 #include "chrome/browser/prefs/pref_registry_syncable.h"
15 #include "chrome/test/base/testing_browser_process.h"
16 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
17 14
18 namespace {
19
20 // Do-nothing implementation for TestingPrefService.
21 void HandleReadError(PersistentPrefStore::PrefReadError error) {
22 }
23
24 } // namespace
25
26 template<> 15 template<>
27 TestingPrefServiceBase<PrefService>::TestingPrefServiceBase( 16 TestingPrefServiceBase<PrefService>::TestingPrefServiceBase(
28 TestingPrefStore* managed_prefs, 17 TestingPrefStore* managed_prefs,
29 TestingPrefStore* user_prefs, 18 TestingPrefStore* user_prefs,
30 TestingPrefStore* recommended_prefs, 19 TestingPrefStore* recommended_prefs,
31 PrefRegistry* pref_registry, 20 PrefRegistry* pref_registry,
32 PrefNotifierImpl* pref_notifier) 21 PrefNotifierImpl* pref_notifier)
33 : PrefService(pref_notifier, 22 : PrefService(pref_notifier,
34 new PrefValueStore( 23 new PrefValueStore(
35 managed_prefs, 24 managed_prefs,
36 NULL, 25 NULL,
37 NULL, 26 NULL,
38 user_prefs, 27 user_prefs,
39 recommended_prefs, 28 recommended_prefs,
40 pref_registry->defaults(), 29 pref_registry->defaults(),
41 pref_notifier), 30 pref_notifier),
42 user_prefs, 31 user_prefs,
43 pref_registry, 32 pref_registry,
44 base::Bind(&HandleReadError), 33 base::Bind(&TestingPrefServiceBase<PrefService>::
34 HandleReadError),
45 false), 35 false),
46 managed_prefs_(managed_prefs), 36 managed_prefs_(managed_prefs),
47 user_prefs_(user_prefs), 37 user_prefs_(user_prefs),
48 recommended_prefs_(recommended_prefs) { 38 recommended_prefs_(recommended_prefs) {
49 } 39 }
50 40
51 template<>
52 TestingPrefServiceBase<PrefServiceSyncable>::TestingPrefServiceBase(
53 TestingPrefStore* managed_prefs,
54 TestingPrefStore* user_prefs,
55 TestingPrefStore* recommended_prefs,
56 PrefRegistry* pref_registry,
57 PrefNotifierImpl* pref_notifier)
58 : PrefServiceSyncable(pref_notifier,
59 new PrefValueStore(
60 managed_prefs,
61 NULL,
62 NULL,
63 user_prefs,
64 recommended_prefs,
65 pref_registry->defaults(),
66 pref_notifier),
67 user_prefs,
68 static_cast<PrefRegistrySyncable*>(pref_registry),
69 base::Bind(&HandleReadError),
70 false),
71 managed_prefs_(managed_prefs),
72 user_prefs_(user_prefs),
73 recommended_prefs_(recommended_prefs) {
74 }
75
76 TestingPrefServiceSimple::TestingPrefServiceSimple() 41 TestingPrefServiceSimple::TestingPrefServiceSimple()
77 : TestingPrefServiceBase<PrefService>( 42 : TestingPrefServiceBase<PrefService>(
78 new TestingPrefStore(), 43 new TestingPrefStore(),
79 new TestingPrefStore(), 44 new TestingPrefStore(),
80 new TestingPrefStore(), 45 new TestingPrefStore(),
81 new PrefRegistrySimple(), 46 new PrefRegistrySimple(),
82 new PrefNotifierImpl()) { 47 new PrefNotifierImpl()) {
83 } 48 }
84 49
85 TestingPrefServiceSimple::~TestingPrefServiceSimple() { 50 TestingPrefServiceSimple::~TestingPrefServiceSimple() {
86 } 51 }
87 52
88 PrefRegistrySimple* TestingPrefServiceSimple::registry() { 53 PrefRegistrySimple* TestingPrefServiceSimple::registry() {
89 return static_cast<PrefRegistrySimple*>(DeprecatedGetPrefRegistry()); 54 return static_cast<PrefRegistrySimple*>(DeprecatedGetPrefRegistry());
90 } 55 }
91
92 TestingPrefServiceSyncable::TestingPrefServiceSyncable()
93 : TestingPrefServiceBase<PrefServiceSyncable>(
94 new TestingPrefStore(),
95 new TestingPrefStore(),
96 new TestingPrefStore(),
97 new PrefRegistrySyncable(),
98 new PrefNotifierImpl()) {
99 }
100
101 TestingPrefServiceSyncable::~TestingPrefServiceSyncable() {
102 }
103
104 PrefRegistrySyncable* TestingPrefServiceSyncable::registry() {
105 return static_cast<PrefRegistrySyncable*>(DeprecatedGetPrefRegistry());
106 }
107
108 ScopedTestingLocalState::ScopedTestingLocalState(
109 TestingBrowserProcess* browser_process)
110 : browser_process_(browser_process) {
111 chrome::RegisterLocalState(&local_state_,
112 local_state_.registry());
113 EXPECT_FALSE(browser_process->local_state());
114 browser_process->SetLocalState(&local_state_);
115 }
116
117 ScopedTestingLocalState::~ScopedTestingLocalState() {
118 EXPECT_EQ(&local_state_, browser_process_->local_state());
119 browser_process_->SetLocalState(NULL);
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698