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

Side by Side Diff: chrome/browser/prefs/pref_value_store_unittest.cc

Issue 3323022: Create a DefaultPrefStore to hold registered application-default preference v... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/scoped_ptr.h" 5 #include "base/scoped_ptr.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "chrome/browser/chrome_thread.h" 7 #include "chrome/browser/chrome_thread.h"
8 #include "chrome/browser/policy/configuration_policy_pref_store.h" 8 #include "chrome/browser/policy/configuration_policy_pref_store.h"
9 #include "chrome/browser/prefs/dummy_pref_store.h" 9 #include "chrome/browser/prefs/dummy_pref_store.h"
10 #include "chrome/browser/prefs/pref_value_store.h" 10 #include "chrome/browser/prefs/pref_value_store.h"
(...skipping 17 matching lines...) Expand all
28 // Names of the preferences used in this test program. 28 // Names of the preferences used in this test program.
29 namespace prefs { 29 namespace prefs {
30 const char kCurrentThemeID[] = "extensions.theme.id"; 30 const char kCurrentThemeID[] = "extensions.theme.id";
31 const char kDeleteCache[] = "browser.clear_data.cache"; 31 const char kDeleteCache[] = "browser.clear_data.cache";
32 const char kHomepage[] = "homepage"; 32 const char kHomepage[] = "homepage";
33 const char kMaxTabs[] = "tabs.max_tabs"; 33 const char kMaxTabs[] = "tabs.max_tabs";
34 const char kMissingPref[] = "this.pref.does_not_exist"; 34 const char kMissingPref[] = "this.pref.does_not_exist";
35 const char kRecommendedPref[] = "this.pref.recommended_value_only"; 35 const char kRecommendedPref[] = "this.pref.recommended_value_only";
36 const char kSampleDict[] = "sample.dict"; 36 const char kSampleDict[] = "sample.dict";
37 const char kSampleList[] = "sample.list"; 37 const char kSampleList[] = "sample.list";
38 const char kDefaultPref[] = "default.pref";
38 39
39 // This must match the actual pref name so the command-line store knows about 40 // This must match the actual pref name so the command-line store knows about
40 // it. 41 // it.
41 const char kApplicationLocale[] = "intl.app_locale"; 42 const char kApplicationLocale[] = "intl.app_locale";
42 } 43 }
43 44
44 // Potentially expected values of all preferences used in this test program. 45 // Potentially expected values of all preferences used in this test program.
45 // The "user" namespace is defined globally in an ARM system header, so we need 46 // The "user" namespace is defined globally in an ARM system header, so we need
46 // something different here. 47 // something different here.
47 namespace user_pref { 48 namespace user_pref {
(...skipping 17 matching lines...) Expand all
65 const char kApplicationLocaleValue[] = "hi-MOM"; 66 const char kApplicationLocaleValue[] = "hi-MOM";
66 const char kCurrentThemeIDValue[] = "zyxwvut"; 67 const char kCurrentThemeIDValue[] = "zyxwvut";
67 const char kHomepageValue[] = "http://www.ferretcentral.org"; 68 const char kHomepageValue[] = "http://www.ferretcentral.org";
68 } 69 }
69 70
70 namespace recommended_pref { 71 namespace recommended_pref {
71 const int kMaxTabsValue = 10; 72 const int kMaxTabsValue = 10;
72 const bool kRecommendedPrefValue = true; 73 const bool kRecommendedPrefValue = true;
73 } 74 }
74 75
76 namespace default_pref {
77 const int kDefaultValue = 7;
78 }
79
75 class PrefValueStoreTest : public testing::Test { 80 class PrefValueStoreTest : public testing::Test {
76 protected: 81 protected:
77 virtual void SetUp() { 82 virtual void SetUp() {
78 // Create dummy user preferences. 83 // Create dummy user preferences.
79 enforced_prefs_= CreateEnforcedPrefs(); 84 enforced_prefs_= CreateEnforcedPrefs();
80 extension_prefs_ = CreateExtensionPrefs(); 85 extension_prefs_ = CreateExtensionPrefs();
81 command_line_prefs_ = CreateCommandLinePrefs(); 86 command_line_prefs_ = CreateCommandLinePrefs();
82 user_prefs_ = CreateUserPrefs(); 87 user_prefs_ = CreateUserPrefs();
83 recommended_prefs_ = CreateRecommendedPrefs(); 88 recommended_prefs_ = CreateRecommendedPrefs();
89 default_prefs_ = CreateDefaultPrefs();
84 90
85 // Create |DummyPrefStore|s. 91 // Create |DummyPrefStore|s.
86 enforced_pref_store_ = new DummyPrefStore(); 92 enforced_pref_store_ = new DummyPrefStore();
87 enforced_pref_store_->set_prefs(enforced_prefs_); 93 enforced_pref_store_->set_prefs(enforced_prefs_);
88 extension_pref_store_ = new DummyPrefStore(); 94 extension_pref_store_ = new DummyPrefStore();
89 extension_pref_store_->set_prefs(extension_prefs_); 95 extension_pref_store_->set_prefs(extension_prefs_);
90 command_line_pref_store_ = new DummyPrefStore(); 96 command_line_pref_store_ = new DummyPrefStore();
91 command_line_pref_store_->set_prefs(command_line_prefs_); 97 command_line_pref_store_->set_prefs(command_line_prefs_);
92 user_pref_store_ = new DummyPrefStore(); 98 user_pref_store_ = new DummyPrefStore();
93 user_pref_store_->set_read_only(false); 99 user_pref_store_->set_read_only(false);
94 user_pref_store_->set_prefs(user_prefs_); 100 user_pref_store_->set_prefs(user_prefs_);
95 recommended_pref_store_ = new DummyPrefStore(); 101 recommended_pref_store_ = new DummyPrefStore();
96 recommended_pref_store_->set_prefs(recommended_prefs_); 102 recommended_pref_store_->set_prefs(recommended_prefs_);
103 default_pref_store_ = new DummyPrefStore();
104 default_pref_store_->set_prefs(default_prefs_);
97 105
98 // Create a new pref-value-store. 106 // Create a new pref-value-store.
99 pref_value_store_ = new TestingPrefService::TestingPrefValueStore( 107 pref_value_store_ = new TestingPrefService::TestingPrefValueStore(
100 enforced_pref_store_, 108 enforced_pref_store_,
101 extension_pref_store_, 109 extension_pref_store_,
102 command_line_pref_store_, 110 command_line_pref_store_,
103 user_pref_store_, 111 user_pref_store_,
104 recommended_pref_store_); 112 recommended_pref_store_,
113 default_pref_store_);
105 114
106 ui_thread_.reset(new ChromeThread(ChromeThread::UI, &loop_)); 115 ui_thread_.reset(new ChromeThread(ChromeThread::UI, &loop_));
107 file_thread_.reset(new ChromeThread(ChromeThread::FILE, &loop_)); 116 file_thread_.reset(new ChromeThread(ChromeThread::FILE, &loop_));
108 } 117 }
109 118
110 // Creates a new dictionary and stores some sample user preferences 119 // Creates a new dictionary and stores some sample user preferences
111 // in it. 120 // in it.
112 DictionaryValue* CreateUserPrefs() { 121 DictionaryValue* CreateUserPrefs() {
113 DictionaryValue* user_prefs = new DictionaryValue(); 122 DictionaryValue* user_prefs = new DictionaryValue();
114 user_prefs->SetBoolean(prefs::kDeleteCache, user_pref::kDeleteCacheValue); 123 user_prefs->SetBoolean(prefs::kDeleteCache, user_pref::kDeleteCacheValue);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 prefs::kRecommendedPref, 165 prefs::kRecommendedPref,
157 recommended_pref::kRecommendedPrefValue); 166 recommended_pref::kRecommendedPrefValue);
158 167
159 // Expected differing paths must be added in lexicographic order 168 // Expected differing paths must be added in lexicographic order
160 // to work properly 169 // to work properly
161 expected_differing_paths_.push_back("tabs"); 170 expected_differing_paths_.push_back("tabs");
162 expected_differing_paths_.push_back(prefs::kMaxTabs); 171 expected_differing_paths_.push_back(prefs::kMaxTabs);
163 expected_differing_paths_.push_back("this"); 172 expected_differing_paths_.push_back("this");
164 expected_differing_paths_.push_back("this.pref"); 173 expected_differing_paths_.push_back("this.pref");
165 expected_differing_paths_.push_back(prefs::kRecommendedPref); 174 expected_differing_paths_.push_back(prefs::kRecommendedPref);
166 return recommended_prefs; } 175 return recommended_prefs;
176 }
177
178 DictionaryValue* CreateDefaultPrefs() {
179 DictionaryValue* default_prefs = new DictionaryValue();
180 default_prefs->SetInteger(prefs::kDefaultPref, default_pref::kDefaultValue);
181 return default_prefs;
182 }
167 183
168 DictionaryValue* CreateSampleDictValue() { 184 DictionaryValue* CreateSampleDictValue() {
169 DictionaryValue* sample_dict = new DictionaryValue(); 185 DictionaryValue* sample_dict = new DictionaryValue();
170 sample_dict->SetBoolean("issample", true); 186 sample_dict->SetBoolean("issample", true);
171 sample_dict->SetInteger("value", 4); 187 sample_dict->SetInteger("value", 4);
172 sample_dict->SetString("descr", "Sample Test Dictionary"); 188 sample_dict->SetString("descr", "Sample Test Dictionary");
173 return sample_dict; 189 return sample_dict;
174 } 190 }
175 191
176 ListValue* CreateSampleListValue() { 192 ListValue* CreateSampleListValue() {
(...skipping 10 matching lines...) Expand all
187 } 203 }
188 204
189 MessageLoop loop_; 205 MessageLoop loop_;
190 206
191 scoped_refptr<TestingPrefService::TestingPrefValueStore> pref_value_store_; 207 scoped_refptr<TestingPrefService::TestingPrefValueStore> pref_value_store_;
192 208
193 // |PrefStore|s are owned by the |PrefValueStore|. 209 // |PrefStore|s are owned by the |PrefValueStore|.
194 DummyPrefStore* enforced_pref_store_; 210 DummyPrefStore* enforced_pref_store_;
195 DummyPrefStore* extension_pref_store_; 211 DummyPrefStore* extension_pref_store_;
196 DummyPrefStore* command_line_pref_store_; 212 DummyPrefStore* command_line_pref_store_;
213 DummyPrefStore* user_pref_store_;
197 DummyPrefStore* recommended_pref_store_; 214 DummyPrefStore* recommended_pref_store_;
198 DummyPrefStore* user_pref_store_; 215 DummyPrefStore* default_pref_store_;
199 216
200 // A vector of the preferences paths in the managed and recommended 217 // A vector of the preferences paths in the managed and recommended
201 // PrefStores that are set at the beginning of a test. Can be modified 218 // PrefStores that are set at the beginning of a test. Can be modified
202 // by the test to track changes that it makes to the preferences 219 // by the test to track changes that it makes to the preferences
203 // stored in the managed and recommended PrefStores. 220 // stored in the managed and recommended PrefStores.
204 std::vector<std::string> expected_differing_paths_; 221 std::vector<std::string> expected_differing_paths_;
205 222
206 // Preferences are owned by the individual |DummyPrefStores|. 223 // Preferences are owned by the individual |DummyPrefStores|.
207 DictionaryValue* enforced_prefs_; 224 DictionaryValue* enforced_prefs_;
208 DictionaryValue* extension_prefs_; 225 DictionaryValue* extension_prefs_;
209 DictionaryValue* command_line_prefs_; 226 DictionaryValue* command_line_prefs_;
210 DictionaryValue* user_prefs_; 227 DictionaryValue* user_prefs_;
211 DictionaryValue* recommended_prefs_; 228 DictionaryValue* recommended_prefs_;
229 DictionaryValue* default_prefs_;
212 230
213 private: 231 private:
214 scoped_ptr<ChromeThread> ui_thread_; 232 scoped_ptr<ChromeThread> ui_thread_;
215 scoped_ptr<ChromeThread> file_thread_; 233 scoped_ptr<ChromeThread> file_thread_;
216 }; 234 };
217 235
218 TEST_F(PrefValueStoreTest, IsReadOnly) { 236 TEST_F(PrefValueStoreTest, IsReadOnly) {
219 enforced_pref_store_->set_read_only(true); 237 enforced_pref_store_->set_read_only(true);
220 extension_pref_store_->set_read_only(true); 238 extension_pref_store_->set_read_only(true);
221 command_line_pref_store_->set_read_only(true); 239 command_line_pref_store_->set_read_only(true);
222 user_pref_store_->set_read_only(true); 240 user_pref_store_->set_read_only(true);
223 recommended_pref_store_->set_read_only(true); 241 recommended_pref_store_->set_read_only(true);
242 default_pref_store_->set_read_only(true);
224 EXPECT_TRUE(pref_value_store_->ReadOnly()); 243 EXPECT_TRUE(pref_value_store_->ReadOnly());
225 244
226 user_pref_store_->set_read_only(false); 245 user_pref_store_->set_read_only(false);
227 EXPECT_FALSE(pref_value_store_->ReadOnly()); 246 EXPECT_FALSE(pref_value_store_->ReadOnly());
228 } 247 }
229 248
230 TEST_F(PrefValueStoreTest, GetValue) { 249 TEST_F(PrefValueStoreTest, GetValue) {
231 Value* value; 250 Value* value;
232 251
233 // Test getting an enforced value overwriting a user-defined and 252 // Test getting an enforced value overwriting a user-defined and
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); 284 EXPECT_TRUE(value->GetAsInteger(&actual_int_value));
266 EXPECT_EQ(user_pref::kMaxTabsValue, actual_int_value); 285 EXPECT_EQ(user_pref::kMaxTabsValue, actual_int_value);
267 286
268 // Test getting a recommended value. 287 // Test getting a recommended value.
269 value = NULL; 288 value = NULL;
270 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedPref, &value)); 289 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedPref, &value));
271 actual_bool_value = false; 290 actual_bool_value = false;
272 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); 291 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value));
273 EXPECT_EQ(recommended_pref::kRecommendedPrefValue, actual_bool_value); 292 EXPECT_EQ(recommended_pref::kRecommendedPrefValue, actual_bool_value);
274 293
294 // Test getting a default value.
295 value = NULL;
296 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultPref, &value));
297 actual_int_value = -1;
298 EXPECT_TRUE(value->GetAsInteger(&actual_int_value));
299 EXPECT_EQ(default_pref::kDefaultValue, actual_int_value);
300
275 // Test getting a preference value that the |PrefValueStore| 301 // Test getting a preference value that the |PrefValueStore|
276 // does not contain. 302 // does not contain.
277 FundamentalValue tmp_dummy_value(true); 303 FundamentalValue tmp_dummy_value(true);
278 Value* v_null = &tmp_dummy_value; 304 Value* v_null = &tmp_dummy_value;
279 ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref, &v_null)); 305 ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref, &v_null));
280 ASSERT_TRUE(v_null == NULL); 306 ASSERT_TRUE(v_null == NULL);
281 } 307 }
282 308
283 TEST_F(PrefValueStoreTest, HasPrefPath) { 309 TEST_F(PrefValueStoreTest, HasPrefPath) {
284 // Enforced preference 310 // Enforced preference
285 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage)); 311 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage));
286 // User preference 312 // User preference
287 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kDeleteCache)); 313 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kDeleteCache));
288 // Recommended preference 314 // Recommended preference
289 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); 315 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
316 // Default preference
317 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
290 // Unknown preference 318 // Unknown preference
291 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); 319 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
292 } 320 }
293 321
294 TEST_F(PrefValueStoreTest, PrefHasChanged) { 322 TEST_F(PrefValueStoreTest, PrefHasChanged) {
295 // Pref controlled by highest-priority store, set to same value in same store. 323 // Setup.
296 const char managed_pref_path[] = "managed_pref"; 324 const char managed_pref_path[] = "managed_pref";
297 const char same_str[] = "same value"; 325 enforced_pref_store_->prefs()->SetString(managed_pref_path, "managed value");
298 scoped_ptr<Value> same_value(Value::CreateStringValue(same_str)); 326 const char user_pref_path[] = "user_pref";
299 enforced_pref_store_->prefs()->SetString(managed_pref_path, same_str); 327 user_pref_store_->prefs()->SetString(user_pref_path, "user value");
328 const char default_pref_path[] = "default_pref";
329 default_pref_store_->prefs()->SetString(default_pref_path, "default value");
330
331 // Check pref controlled by highest-priority store.
332 EXPECT_TRUE(pref_value_store_->PrefHasChanged(managed_pref_path,
333 static_cast<PrefNotifier::PrefStoreType>(0)));
300 EXPECT_FALSE(pref_value_store_->PrefHasChanged(managed_pref_path, 334 EXPECT_FALSE(pref_value_store_->PrefHasChanged(managed_pref_path,
301 static_cast<PrefNotifier::PrefStoreType>(0), same_value.get())); 335 PrefNotifier::USER_STORE));
302 336
303 // Pref controlled by highest-priority store, set to different value in 337 // Check pref controlled by user store.
304 // same store. 338 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path,
305 const char other_str[] = "other value"; 339 static_cast<PrefNotifier::PrefStoreType>(0)));
306 scoped_ptr<Value> other_value(Value::CreateStringValue(other_str)); 340 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path,
307 EXPECT_TRUE(pref_value_store_->PrefHasChanged(managed_pref_path, 341 PrefNotifier::USER_STORE));
308 static_cast<PrefNotifier::PrefStoreType>(0), other_value.get())); 342 EXPECT_FALSE(pref_value_store_->PrefHasChanged(user_pref_path,
343 PrefNotifier::PREF_STORE_TYPE_MAX));
309 344
310 // Pref controlled by user store, set to same value in user store, no lower 345 // Check pref controlled by default-pref store.
311 // store has a value. 346 EXPECT_TRUE(pref_value_store_->PrefHasChanged(default_pref_path,
312 const char user_pref_path[] = "user_pref"; 347 PrefNotifier::USER_STORE));
313 user_pref_store_->prefs()->SetString(user_pref_path, same_str); 348 EXPECT_TRUE(pref_value_store_->PrefHasChanged(default_pref_path,
314 EXPECT_FALSE(pref_value_store_->PrefHasChanged(user_pref_path, 349 PrefNotifier::DEFAULT_STORE));
315 PrefNotifier::USER_STORE, same_value.get()));
316
317 // Pref controlled by user store, set to new value in user store, no lower
318 // store has a value.
319 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path,
320 PrefNotifier::USER_STORE, other_value.get()));
321
322 // Pref controlled by user store, set to same value in user store, some lower
323 // store has a value.
324 const char third_str[] = "third value";
325 recommended_pref_store_->prefs()->SetString(user_pref_path, third_str);
326 // This is not necessarily the correct behavior, but it is the current
327 // behavior. See comments in pref_value_store.h and .cc.
328 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path,
329 PrefNotifier::USER_STORE, same_value.get()));
330
331 // Pref controlled by user store, set to new value in user store, some lower
332 // store has a value.
333 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path,
334 PrefNotifier::USER_STORE, other_value.get()));
335
336 // Pref controlled by user store, set to same value in managed store.
337 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path,
338 PrefNotifier::MANAGED_STORE, same_value.get()));
339
340 // Pref controlled by user store, set to new value in managed store.
341 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path,
342 PrefNotifier::MANAGED_STORE, other_value.get()));
343
344 // Pref controlled by highest-priority store, set to any value in user store.
345 EXPECT_FALSE(pref_value_store_->PrefHasChanged(managed_pref_path,
346 PrefNotifier::USER_STORE, same_value.get()));
347
348 // Pref controlled by lowest-priority store, set to same value in same store.
349 const char recommended_pref_path[] = "recommended_pref";
350 recommended_pref_store_->prefs()->SetString(recommended_pref_path, same_str);
351 EXPECT_FALSE(pref_value_store_->PrefHasChanged(recommended_pref_path,
352 PrefNotifier::PREF_STORE_TYPE_MAX, same_value.get()));
353
354 // Pref controlled by lowest-priority store, set to different value in same
355 // store.
356 EXPECT_TRUE(pref_value_store_->PrefHasChanged(recommended_pref_path,
357 PrefNotifier::PREF_STORE_TYPE_MAX, other_value.get()));
358 } 350 }
359 351
360 TEST_F(PrefValueStoreTest, ReadPrefs) { 352 TEST_F(PrefValueStoreTest, ReadPrefs) {
361 pref_value_store_->ReadPrefs(); 353 pref_value_store_->ReadPrefs();
362 // The ReadPrefs method of the |DummyPrefStore| deletes the |pref_store|s 354 // The ReadPrefs method of the |DummyPrefStore| deletes the |pref_store|s
363 // internal dictionary and creates a new empty dictionary. Hence this 355 // internal dictionary and creates a new empty dictionary. Hence this
364 // dictionary does not contain any of the preloaded preferences. 356 // dictionary does not contain any of the preloaded preferences.
365 // This shows that the ReadPrefs method of the |DummyPrefStore| was called. 357 // This shows that the ReadPrefs method of the |DummyPrefStore| was called.
366 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDeleteCache)); 358 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDeleteCache));
367 } 359 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 433
442 // Test a user preference. 434 // Test a user preference.
443 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs)); 435 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs));
444 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMaxTabs)); 436 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMaxTabs));
445 437
446 // Test a preference from the recommended pref store. 438 // Test a preference from the recommended pref store.
447 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); 439 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
448 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore( 440 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
449 prefs::kRecommendedPref)); 441 prefs::kRecommendedPref));
450 442
443 // Test a preference from the default pref store.
444 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
445 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
446 prefs::kDefaultPref));
447
451 // Test a preference for which the PrefValueStore does not contain a value. 448 // Test a preference for which the PrefValueStore does not contain a value.
452 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); 449 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
453 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMissingPref)); 450 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMissingPref));
454 } 451 }
455 452
456 TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) { 453 TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) {
457 // Test an enforced preference. 454 // Test an enforced preference.
458 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage)); 455 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage));
459 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(prefs::kHomepage)); 456 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(prefs::kHomepage));
460 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore( 457 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
(...skipping 18 matching lines...) Expand all
479 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(prefs::kMaxTabs)); 476 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(prefs::kMaxTabs));
480 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(prefs::kMaxTabs)); 477 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(prefs::kMaxTabs));
481 478
482 // Test a preference from the recommended pref store. 479 // Test a preference from the recommended pref store.
483 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); 480 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
484 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore( 481 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
485 prefs::kRecommendedPref)); 482 prefs::kRecommendedPref));
486 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore( 483 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
487 prefs::kRecommendedPref)); 484 prefs::kRecommendedPref));
488 485
486 // Test a preference from the default pref store.
487 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
488 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
489 prefs::kDefaultPref));
490 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
491 prefs::kDefaultPref));
492
489 // Test a preference for which the PrefValueStore does not contain a value. 493 // Test a preference for which the PrefValueStore does not contain a value.
490 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); 494 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
491 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore( 495 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
492 prefs::kMissingPref)); 496 prefs::kMissingPref));
493 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore( 497 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
494 prefs::kMissingPref)); 498 prefs::kMissingPref));
495 } 499 }
496 500
497 TEST_F(PrefValueStoreTest, PrefValueInUserStore) { 501 TEST_F(PrefValueStoreTest, PrefValueInUserStore) {
498 // Test an enforced preference. 502 // Test an enforced preference.
(...skipping 20 matching lines...) Expand all
519 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kMaxTabs)); 523 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kMaxTabs));
520 EXPECT_TRUE(pref_value_store_->PrefValueFromUserStore(prefs::kMaxTabs)); 524 EXPECT_TRUE(pref_value_store_->PrefValueFromUserStore(prefs::kMaxTabs));
521 525
522 // Test a preference from the recommended pref store. 526 // Test a preference from the recommended pref store.
523 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); 527 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
524 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore( 528 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
525 prefs::kRecommendedPref)); 529 prefs::kRecommendedPref));
526 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore( 530 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
527 prefs::kRecommendedPref)); 531 prefs::kRecommendedPref));
528 532
533 // Test a preference from the default pref store.
534 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
535 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kDefaultPref));
536 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kDefaultPref));
537
529 // Test a preference for which the PrefValueStore does not contain a value. 538 // Test a preference for which the PrefValueStore does not contain a value.
530 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); 539 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
531 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kMissingPref)); 540 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kMissingPref));
532 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kMissingPref)); 541 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kMissingPref));
533 } 542 }
534 543
544 TEST_F(PrefValueStoreTest, PrefValueFromDefaultStore) {
545 // Test an enforced preference.
546 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage));
547 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(prefs::kHomepage));
548
549 // Test an extension preference.
550 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
551 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
552 prefs::kCurrentThemeID));
553
554 // Test a command-line preference.
555 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
556 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
557 prefs::kApplicationLocale));
558
559 // Test a user preference.
560 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs));
561 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(prefs::kMaxTabs));
562
563 // Test a preference from the recommended pref store.
564 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
565 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
566 prefs::kRecommendedPref));
567
568 // Test a preference from the default pref store.
569 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
570 EXPECT_TRUE(
571 pref_value_store_->PrefValueFromDefaultStore(prefs::kDefaultPref));
572
573 // Test a preference for which the PrefValueStore does not contain a value.
574 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
575 EXPECT_FALSE(
576 pref_value_store_->PrefValueFromDefaultStore(prefs::kMissingPref));
577 }
578
535 TEST_F(PrefValueStoreTest, TestPolicyRefresh) { 579 TEST_F(PrefValueStoreTest, TestPolicyRefresh) {
536 // pref_value_store_ is initialized by PrefValueStoreTest to have values 580 // pref_value_store_ is initialized by PrefValueStoreTest to have values
537 // in both it's managed and recommended store. By replacing them with 581 // in both it's managed and recommended store. By replacing them with
538 // dummy stores, all of the paths of the prefs originally managed and 582 // dummy stores, all of the paths of the prefs originally managed and
539 // recommended stores should change. 583 // recommended stores should change.
540 MockPolicyRefreshCallback callback; 584 MockPolicyRefreshCallback callback;
541 EXPECT_CALL(callback, DoCallback(_)).Times(0); 585 EXPECT_CALL(callback, DoCallback(_)).Times(0);
542 ChromeThread::PostTask( 586 ChromeThread::PostTask(
543 ChromeThread::UI, FROM_HERE, 587 ChromeThread::UI, FROM_HERE,
544 NewRunnableMethod( 588 NewRunnableMethod(
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 Mock::VerifyAndClearExpectations(&callback1); 698 Mock::VerifyAndClearExpectations(&callback1);
655 Mock::VerifyAndClearExpectations(&callback2); 699 Mock::VerifyAndClearExpectations(&callback2);
656 Mock::VerifyAndClearExpectations(&callback3); 700 Mock::VerifyAndClearExpectations(&callback3);
657 701
658 EXPECT_CALL(callback1, DoCallback(expected_differing_paths_)).Times(1); 702 EXPECT_CALL(callback1, DoCallback(expected_differing_paths_)).Times(1);
659 std::vector<std::string> no_differing_paths; 703 std::vector<std::string> no_differing_paths;
660 EXPECT_CALL(callback2, DoCallback(no_differing_paths)).Times(1); 704 EXPECT_CALL(callback2, DoCallback(no_differing_paths)).Times(1);
661 EXPECT_CALL(callback3, DoCallback(no_differing_paths)).Times(1); 705 EXPECT_CALL(callback3, DoCallback(no_differing_paths)).Times(1);
662 loop_.RunAllPending(); 706 loop_.RunAllPending();
663 } 707 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698