OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 | |
7 #include "chrome/browser/policy/configuration_policy_pref_store.h" | |
8 #include "chrome/browser/prefs/browser_prefs.h" | |
9 #include "chrome/browser/prefs/command_line_pref_store.h" | |
10 #include "chrome/browser/prefs/default_pref_store.h" | |
11 #include "chrome/browser/prefs/pref_notifier.h" | |
12 #include "chrome/browser/prefs/pref_value_store.h" | |
13 #include "chrome/browser/prefs/testing_pref_store.h" | |
14 #include "chrome/test/testing_browser_process.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 | |
17 TestingPrefServiceBase::TestingPrefServiceBase( | |
18 TestingPrefStore* managed_platform_prefs, | |
19 TestingPrefStore* user_prefs, | |
20 TestingPrefStore* recommended_platform_prefs) | |
21 : PrefService(managed_platform_prefs, | |
22 NULL, | |
23 NULL, | |
24 NULL, | |
25 user_prefs, | |
26 recommended_platform_prefs, | |
27 NULL, | |
28 new DefaultPrefStore(), | |
29 false), | |
30 managed_platform_prefs_(managed_platform_prefs), | |
31 user_prefs_(user_prefs), | |
32 recommended_platform_prefs_(recommended_platform_prefs) { | |
33 } | |
34 | |
35 TestingPrefServiceBase::~TestingPrefServiceBase() { | |
36 } | |
37 | |
38 const Value* TestingPrefServiceBase::GetManagedPref(const char* path) const { | |
39 return GetPref(managed_platform_prefs_, path); | |
40 } | |
41 | |
42 void TestingPrefServiceBase::SetManagedPref(const char* path, Value* value) { | |
43 SetPref(managed_platform_prefs_, path, value); | |
44 } | |
45 | |
46 void TestingPrefServiceBase::RemoveManagedPref(const char* path) { | |
47 RemovePref(managed_platform_prefs_, path); | |
48 } | |
49 | |
50 const Value* TestingPrefServiceBase::GetUserPref(const char* path) const { | |
51 return GetPref(user_prefs_, path); | |
52 } | |
53 | |
54 void TestingPrefServiceBase::SetUserPref(const char* path, Value* value) { | |
55 SetPref(user_prefs_, path, value); | |
56 } | |
57 | |
58 void TestingPrefServiceBase::RemoveUserPref(const char* path) { | |
59 RemovePref(user_prefs_, path); | |
60 } | |
61 | |
62 const Value* TestingPrefServiceBase::GetRecommendedPref( | |
63 const char* path) const { | |
64 return GetPref(recommended_platform_prefs_, path); | |
65 } | |
66 | |
67 void TestingPrefServiceBase::SetRecommendedPref( | |
68 const char* path, Value* value) { | |
69 SetPref(recommended_platform_prefs_, path, value); | |
70 } | |
71 | |
72 void TestingPrefServiceBase::RemoveRecommendedPref(const char* path) { | |
73 RemovePref(recommended_platform_prefs_, path); | |
74 } | |
75 | |
76 const Value* TestingPrefServiceBase::GetPref(TestingPrefStore* pref_store, | |
77 const char* path) const { | |
78 const Value* res; | |
79 return pref_store->GetValue(path, &res) == PrefStore::READ_OK ? res : NULL; | |
80 } | |
81 | |
82 void TestingPrefServiceBase::SetPref(TestingPrefStore* pref_store, | |
83 const char* path, | |
84 Value* value) { | |
85 pref_store->SetValue(path, value); | |
86 } | |
87 | |
88 void TestingPrefServiceBase::RemovePref(TestingPrefStore* pref_store, | |
89 const char* path) { | |
90 pref_store->RemoveValue(path); | |
91 } | |
92 | |
93 TestingPrefService::TestingPrefService() | |
94 : TestingPrefServiceBase(new TestingPrefStore(), | |
95 new TestingPrefStore(), | |
96 new TestingPrefStore()) { | |
97 } | |
98 | |
99 TestingPrefService::~TestingPrefService() { | |
100 } | |
101 | |
102 ScopedTestingLocalState::ScopedTestingLocalState( | |
103 TestingBrowserProcess* browser_process) | |
104 : browser_process_(browser_process) { | |
105 browser::RegisterLocalState(&local_state_); | |
106 EXPECT_FALSE(browser_process->local_state()); | |
107 browser_process->SetLocalState(&local_state_); | |
108 } | |
109 | |
110 ScopedTestingLocalState::~ScopedTestingLocalState() { | |
111 EXPECT_EQ(&local_state_, browser_process_->local_state()); | |
112 browser_process_->SetLocalState(NULL); | |
113 } | |
OLD | NEW |