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

Side by Side Diff: chrome/browser/pref_service_unittest.cc

Issue 2823037: Add an ExtensionPrefStore, layered between the user prefs nad the managed pre... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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
« no previous file with comments | « chrome/browser/pref_service.cc ('k') | chrome/browser/pref_value_store.h » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <string> 5 #include <string>
6 6
7 #include "app/test/data/resource.h" 7 #include "app/test/data/resource.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/dummy_pref_store.h" 10 #include "chrome/browser/dummy_pref_store.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 private: 57 private:
58 bool observer_fired_; 58 bool observer_fired_;
59 const PrefService* prefs_; 59 const PrefService* prefs_;
60 const std::wstring pref_name_; 60 const std::wstring pref_name_;
61 std::string new_pref_value_; 61 std::string new_pref_value_;
62 }; 62 };
63 63
64 // TODO(port): port this test to POSIX. 64 // TODO(port): port this test to POSIX.
65 #if defined(OS_WIN) 65 #if defined(OS_WIN)
66 TEST(PrefServiceTest, LocalizedPrefs) { 66 TEST(PrefServiceTest, LocalizedPrefs) {
67 PrefService prefs(new PrefValueStore(NULL, new DummyPrefStore(), NULL)); 67 PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
68 NULL));
68 const wchar_t kBoolean[] = L"boolean"; 69 const wchar_t kBoolean[] = L"boolean";
69 const wchar_t kInteger[] = L"integer"; 70 const wchar_t kInteger[] = L"integer";
70 const wchar_t kString[] = L"string"; 71 const wchar_t kString[] = L"string";
71 prefs.RegisterLocalizedBooleanPref(kBoolean, IDS_LOCALE_BOOL); 72 prefs.RegisterLocalizedBooleanPref(kBoolean, IDS_LOCALE_BOOL);
72 prefs.RegisterLocalizedIntegerPref(kInteger, IDS_LOCALE_INT); 73 prefs.RegisterLocalizedIntegerPref(kInteger, IDS_LOCALE_INT);
73 prefs.RegisterLocalizedStringPref(kString, IDS_LOCALE_STRING); 74 prefs.RegisterLocalizedStringPref(kString, IDS_LOCALE_STRING);
74 75
75 // The locale default should take preference over the user default. 76 // The locale default should take preference over the user default.
76 EXPECT_FALSE(prefs.GetBoolean(kBoolean)); 77 EXPECT_FALSE(prefs.GetBoolean(kBoolean));
77 EXPECT_EQ(1, prefs.GetInteger(kInteger)); 78 EXPECT_EQ(1, prefs.GetInteger(kInteger));
78 EXPECT_EQ("hello", prefs.GetString(kString)); 79 EXPECT_EQ("hello", prefs.GetString(kString));
79 80
80 prefs.SetBoolean(kBoolean, true); 81 prefs.SetBoolean(kBoolean, true);
81 EXPECT_TRUE(prefs.GetBoolean(kBoolean)); 82 EXPECT_TRUE(prefs.GetBoolean(kBoolean));
82 prefs.SetInteger(kInteger, 5); 83 prefs.SetInteger(kInteger, 5);
83 EXPECT_EQ(5, prefs.GetInteger(kInteger)); 84 EXPECT_EQ(5, prefs.GetInteger(kInteger));
84 prefs.SetString(kString, "foo"); 85 prefs.SetString(kString, "foo");
85 EXPECT_EQ("foo", prefs.GetString(kString)); 86 EXPECT_EQ("foo", prefs.GetString(kString));
86 } 87 }
87 #endif 88 #endif
88 89
89 TEST(PrefServiceTest, NoObserverFire) { 90 TEST(PrefServiceTest, NoObserverFire) {
90 PrefService prefs(new PrefValueStore(NULL, new DummyPrefStore(), NULL)); 91 PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
92 NULL));
91 93
92 const wchar_t pref_name[] = L"homepage"; 94 const wchar_t pref_name[] = L"homepage";
93 prefs.RegisterStringPref(pref_name, ""); 95 prefs.RegisterStringPref(pref_name, "");
94 96
95 const std::string new_pref_value("http://www.google.com/"); 97 const std::string new_pref_value("http://www.google.com/");
96 TestPrefObserver obs(&prefs, pref_name, new_pref_value); 98 TestPrefObserver obs(&prefs, pref_name, new_pref_value);
97 prefs.AddPrefObserver(pref_name, &obs); 99 prefs.AddPrefObserver(pref_name, &obs);
98 // This should fire the checks in TestPrefObserver::Observe. 100 // This should fire the checks in TestPrefObserver::Observe.
99 prefs.SetString(pref_name, new_pref_value); 101 prefs.SetString(pref_name, new_pref_value);
100 102
(...skipping 14 matching lines...) Expand all
115 // Clearing the pref again should not cause the pref to fire. 117 // Clearing the pref again should not cause the pref to fire.
116 obs.Reset(""); 118 obs.Reset("");
117 prefs.ClearPref(pref_name); 119 prefs.ClearPref(pref_name);
118 EXPECT_FALSE(obs.observer_fired()); 120 EXPECT_FALSE(obs.observer_fired());
119 121
120 // Ok, clean up. 122 // Ok, clean up.
121 prefs.RemovePrefObserver(pref_name, &obs); 123 prefs.RemovePrefObserver(pref_name, &obs);
122 } 124 }
123 125
124 TEST(PrefServiceTest, HasPrefPath) { 126 TEST(PrefServiceTest, HasPrefPath) {
125 PrefService prefs(new PrefValueStore(NULL, new DummyPrefStore(), NULL)); 127 PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
128 NULL));
126 129
127 const wchar_t path[] = L"fake.path"; 130 const wchar_t path[] = L"fake.path";
128 131
129 // Shouldn't initially have a path. 132 // Shouldn't initially have a path.
130 EXPECT_FALSE(prefs.HasPrefPath(path)); 133 EXPECT_FALSE(prefs.HasPrefPath(path));
131 134
132 // Register the path. This doesn't set a value, so the path still shouldn't 135 // Register the path. This doesn't set a value, so the path still shouldn't
133 // exist. 136 // exist.
134 prefs.RegisterStringPref(path, std::string()); 137 prefs.RegisterStringPref(path, std::string());
135 EXPECT_FALSE(prefs.HasPrefPath(path)); 138 EXPECT_FALSE(prefs.HasPrefPath(path));
136 139
137 // Set a value and make sure we have a path. 140 // Set a value and make sure we have a path.
138 prefs.SetString(path, "blah"); 141 prefs.SetString(path, "blah");
139 EXPECT_TRUE(prefs.HasPrefPath(path)); 142 EXPECT_TRUE(prefs.HasPrefPath(path));
140 } 143 }
141 144
142 TEST(PrefServiceTest, Observers) { 145 TEST(PrefServiceTest, Observers) {
143 const wchar_t pref_name[] = L"homepage"; 146 const wchar_t pref_name[] = L"homepage";
144 147
145 DictionaryValue* dict = new DictionaryValue(); 148 DictionaryValue* dict = new DictionaryValue();
146 dict->SetString(pref_name, std::string("http://www.cnn.com")); 149 dict->SetString(pref_name, std::string("http://www.cnn.com"));
147 DummyPrefStore* pref_store = new DummyPrefStore(); 150 DummyPrefStore* pref_store = new DummyPrefStore();
148 pref_store->set_prefs(dict); 151 pref_store->set_prefs(dict);
149 PrefService prefs(new PrefValueStore(NULL, pref_store, NULL)); 152 PrefService prefs(new PrefValueStore(NULL, NULL, pref_store, NULL));
150 prefs.RegisterStringPref(pref_name, ""); 153 prefs.RegisterStringPref(pref_name, "");
151 154
152 const std::string new_pref_value("http://www.google.com/"); 155 const std::string new_pref_value("http://www.google.com/");
153 TestPrefObserver obs(&prefs, pref_name, new_pref_value); 156 TestPrefObserver obs(&prefs, pref_name, new_pref_value);
154 prefs.AddPrefObserver(pref_name, &obs); 157 prefs.AddPrefObserver(pref_name, &obs);
155 // This should fire the checks in TestPrefObserver::Observe. 158 // This should fire the checks in TestPrefObserver::Observe.
156 prefs.SetString(pref_name, new_pref_value); 159 prefs.SetString(pref_name, new_pref_value);
157 160
158 // Make sure the tests were actually run. 161 // Make sure the tests were actually run.
159 EXPECT_TRUE(obs.observer_fired()); 162 EXPECT_TRUE(obs.observer_fired());
(...skipping 20 matching lines...) Expand all
180 // Ok, clean up. 183 // Ok, clean up.
181 prefs.RemovePrefObserver(pref_name, &obs2); 184 prefs.RemovePrefObserver(pref_name, &obs2);
182 } 185 }
183 186
184 class PrefServiceSetValueTest : public testing::Test { 187 class PrefServiceSetValueTest : public testing::Test {
185 protected: 188 protected:
186 static const wchar_t name_[]; 189 static const wchar_t name_[];
187 static const char value_[]; 190 static const char value_[];
188 191
189 PrefServiceSetValueTest() 192 PrefServiceSetValueTest()
190 : prefs_(new PrefValueStore(NULL, new DummyPrefStore(), NULL)), 193 : prefs_(new PrefValueStore(NULL, NULL, new DummyPrefStore(), NULL)),
191 name_string_(name_), 194 name_string_(name_),
192 null_value_(Value::CreateNullValue()) {} 195 null_value_(Value::CreateNullValue()) {}
193 196
194 void SetExpectNoNotification() { 197 void SetExpectNoNotification() {
195 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); 198 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0);
196 } 199 }
197 200
198 void SetExpectPrefChanged() { 201 void SetExpectPrefChanged() {
199 EXPECT_CALL(observer_, 202 EXPECT_CALL(observer_,
200 Observe(NotificationType(NotificationType::PREF_CHANGED), _, 203 Observe(NotificationType(NotificationType::PREF_CHANGED), _,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 Mock::VerifyAndClearExpectations(&observer_); 287 Mock::VerifyAndClearExpectations(&observer_);
285 288
286 SetExpectPrefChanged(); 289 SetExpectPrefChanged();
287 prefs_.Set(name_, *null_value_); 290 prefs_.Set(name_, *null_value_);
288 Mock::VerifyAndClearExpectations(&observer_); 291 Mock::VerifyAndClearExpectations(&observer_);
289 list = prefs_.GetMutableList(name_); 292 list = prefs_.GetMutableList(name_);
290 EXPECT_EQ(0U, list->GetSize()); 293 EXPECT_EQ(0U, list->GetSize());
291 294
292 prefs_.RemovePrefObserver(name_, &observer_); 295 prefs_.RemovePrefObserver(name_, &observer_);
293 } 296 }
OLDNEW
« no previous file with comments | « chrome/browser/pref_service.cc ('k') | chrome/browser/pref_value_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698