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

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

Issue 11573065: Not for check-in. Manually reviewable parts of https://codereview.chromium.org/11570009/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years 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
« no previous file with comments | « chrome/test/base/testing_pref_service.h ('k') | chrome/test/reliability/page_load_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/prefs/default_pref_store.h" 8 #include "base/prefs/default_pref_store.h"
9 #include "base/prefs/testing_pref_store.h"
10 #include "chrome/browser/policy/configuration_policy_pref_store.h"
11 #include "chrome/browser/prefs/browser_prefs.h" 9 #include "chrome/browser/prefs/browser_prefs.h"
12 #include "chrome/browser/prefs/command_line_pref_store.h"
13 #include "chrome/browser/prefs/pref_model_associator.h"
14 #include "chrome/browser/prefs/pref_notifier_impl.h" 10 #include "chrome/browser/prefs/pref_notifier_impl.h"
15 #include "chrome/browser/prefs/pref_value_store.h" 11 #include "chrome/browser/prefs/pref_value_store.h"
16 #include "chrome/test/base/testing_browser_process.h" 12 #include "chrome/test/base/testing_browser_process.h"
17 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/base/l10n/l10n_util.h"
19 14
20 namespace { 15 namespace {
21 16
22 // Do-nothing implementation for PrefService. 17 // Do-nothing implementation for TestingPrefService.
23 void HandleReadError(PersistentPrefStore::PrefReadError error) { 18 void HandleReadError(PersistentPrefStore::PrefReadError error) {
24 } 19 }
25 20
26 } // namespace 21 } // namespace
27 22
28 TestingPrefServiceBase::TestingPrefServiceBase( 23 template<>
24 TestingPrefServiceBase<PrefServiceSimple>::TestingPrefServiceBase(
29 TestingPrefStore* managed_prefs, 25 TestingPrefStore* managed_prefs,
30 TestingPrefStore* user_prefs, 26 TestingPrefStore* user_prefs,
31 TestingPrefStore* recommended_prefs, 27 TestingPrefStore* recommended_prefs,
32 DefaultPrefStore* default_store, 28 DefaultPrefStore* default_store,
33 PrefModelAssociator* pref_sync_associator,
34 PrefNotifierImpl* pref_notifier) 29 PrefNotifierImpl* pref_notifier)
35 : PrefService(pref_notifier, 30 : managed_prefs_(managed_prefs),
36 new PrefValueStore(
37 managed_prefs,
38 NULL,
39 NULL,
40 user_prefs,
41 recommended_prefs,
42 default_store,
43 pref_sync_associator,
44 pref_notifier),
45 user_prefs,
46 default_store,
47 pref_sync_associator,
48 base::Bind(&l10n_util::GetStringUTF8),
49 base::Bind(&HandleReadError),
50 false),
51 managed_prefs_(managed_prefs),
52 user_prefs_(user_prefs), 31 user_prefs_(user_prefs),
53 recommended_prefs_(recommended_prefs) { 32 recommended_prefs_(recommended_prefs) {
33 PrefServiceSimple::Initialize(pref_notifier,
34 new PrefValueStore(
35 managed_prefs,
36 NULL,
37 NULL,
38 user_prefs,
39 recommended_prefs,
40 default_store,
41 pref_notifier),
42 user_prefs,
43 default_store,
44 base::Bind(&HandleReadError),
45 false);
54 } 46 }
55 47
56 TestingPrefServiceBase::~TestingPrefServiceBase() { 48 template<>
49 TestingPrefServiceBase<PrefServiceSyncable>::TestingPrefServiceBase(
50 TestingPrefStore* managed_prefs,
51 TestingPrefStore* user_prefs,
52 TestingPrefStore* recommended_prefs,
53 DefaultPrefStore* default_store,
54 PrefNotifierImpl* pref_notifier)
55 : managed_prefs_(managed_prefs),
56 user_prefs_(user_prefs),
57 recommended_prefs_(recommended_prefs) {
58 PrefServiceSyncable::Initialize(pref_notifier,
59 new PrefValueStore(
60 managed_prefs,
61 NULL,
62 NULL,
63 user_prefs,
64 recommended_prefs,
65 default_store,
66 pref_notifier),
67 user_prefs,
68 default_store,
69 base::Bind(&HandleReadError),
70 false);
57 } 71 }
58 72
59 const Value* TestingPrefServiceBase::GetManagedPref(const char* path) const { 73 TestingPrefServiceSimple::TestingPrefServiceSimple()
60 return GetPref(managed_prefs_, path); 74 : TestingPrefServiceBase<PrefServiceSimple>(new TestingPrefStore(),
75 new TestingPrefStore(),
76 new TestingPrefStore(),
77 new DefaultPrefStore(),
78 new PrefNotifierImpl()) {
61 } 79 }
62 80
63 void TestingPrefServiceBase::SetManagedPref(const char* path, Value* value) { 81 TestingPrefServiceSimple::~TestingPrefServiceSimple() {
64 SetPref(managed_prefs_, path, value);
65 } 82 }
66 83
67 void TestingPrefServiceBase::RemoveManagedPref(const char* path) { 84 TestingPrefServiceSyncable::TestingPrefServiceSyncable()
68 RemovePref(managed_prefs_, path); 85 : TestingPrefServiceBase<PrefServiceSyncable>(new TestingPrefStore(),
86 new TestingPrefStore(),
87 new TestingPrefStore(),
88 new DefaultPrefStore(),
89 new PrefNotifierImpl()) {
69 } 90 }
70 91
71 const Value* TestingPrefServiceBase::GetUserPref(const char* path) const { 92 TestingPrefServiceSyncable::~TestingPrefServiceSyncable() {
72 return GetPref(user_prefs_, path);
73 }
74
75 void TestingPrefServiceBase::SetUserPref(const char* path, Value* value) {
76 SetPref(user_prefs_, path, value);
77 }
78
79 void TestingPrefServiceBase::RemoveUserPref(const char* path) {
80 RemovePref(user_prefs_, path);
81 }
82
83 const Value* TestingPrefServiceBase::GetRecommendedPref(
84 const char* path) const {
85 return GetPref(recommended_prefs_, path);
86 }
87
88 void TestingPrefServiceBase::SetRecommendedPref(
89 const char* path, Value* value) {
90 SetPref(recommended_prefs_, path, value);
91 }
92
93 void TestingPrefServiceBase::RemoveRecommendedPref(const char* path) {
94 RemovePref(recommended_prefs_, path);
95 }
96
97 const Value* TestingPrefServiceBase::GetPref(TestingPrefStore* pref_store,
98 const char* path) const {
99 const Value* res;
100 return pref_store->GetValue(path, &res) ? res : NULL;
101 }
102
103 void TestingPrefServiceBase::SetPref(TestingPrefStore* pref_store,
104 const char* path,
105 Value* value) {
106 pref_store->SetValue(path, value);
107 }
108
109 void TestingPrefServiceBase::RemovePref(TestingPrefStore* pref_store,
110 const char* path) {
111 pref_store->RemoveValue(path);
112 }
113
114 TestingPrefService::TestingPrefService()
115 : TestingPrefServiceBase(new TestingPrefStore(),
116 new TestingPrefStore(),
117 new TestingPrefStore(),
118 new DefaultPrefStore(),
119 new PrefModelAssociator(),
120 new PrefNotifierImpl()) {
121 }
122
123 TestingPrefService::~TestingPrefService() {
124 } 93 }
125 94
126 ScopedTestingLocalState::ScopedTestingLocalState( 95 ScopedTestingLocalState::ScopedTestingLocalState(
127 TestingBrowserProcess* browser_process) 96 TestingBrowserProcess* browser_process)
128 : browser_process_(browser_process) { 97 : browser_process_(browser_process) {
129 chrome::RegisterLocalState(&local_state_); 98 chrome::RegisterLocalState(&local_state_);
130 EXPECT_FALSE(browser_process->local_state()); 99 EXPECT_FALSE(browser_process->local_state());
131 browser_process->SetLocalState(&local_state_); 100 browser_process->SetLocalState(&local_state_);
132 } 101 }
133 102
134 ScopedTestingLocalState::~ScopedTestingLocalState() { 103 ScopedTestingLocalState::~ScopedTestingLocalState() {
135 EXPECT_EQ(&local_state_, browser_process_->local_state()); 104 EXPECT_EQ(&local_state_, browser_process_->local_state());
136 browser_process_->SetLocalState(NULL); 105 browser_process_->SetLocalState(NULL);
137 } 106 }
OLDNEW
« no previous file with comments | « chrome/test/base/testing_pref_service.h ('k') | chrome/test/reliability/page_load_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698