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

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

Issue 220203011: Changes requested by gab for previously committed CLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't commit if we didn't make any changes. Created 6 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/prefs/profile_pref_store_manager.h" 5 #include "chrome/browser/prefs/profile_pref_store_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 FirstEqualsPredicate(key))) 55 FirstEqualsPredicate(key)))
56 << "Unregistered key " << key << " was changed."; 56 << "Unregistered key " << key << " was changed.";
57 } 57 }
58 58
59 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE {} 59 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE {}
60 60
61 private: 61 private:
62 scoped_refptr<PrefRegistry> pref_registry_; 62 scoped_refptr<PrefRegistry> pref_registry_;
63 }; 63 };
64 64
65 const char kUnprotectedAtomic[] = "unprotected_atomic"; 65 const char kUnprotectedPref[] = "unprotected_pref";
66 const char kTrackedAtomic[] = "tracked_atomic"; 66 const char kTrackedAtomic[] = "tracked_atomic";
67 const char kProtectedAtomic[] = "protected_atomic"; 67 const char kProtectedAtomic[] = "protected_atomic";
68 68
69 const char kFoobar[] = "FOOBAR"; 69 const char kFoobar[] = "FOOBAR";
70 const char kBarfoo[] = "BARFOO"; 70 const char kBarfoo[] = "BARFOO";
71 const char kHelloWorld[] = "HELLOWORLD"; 71 const char kHelloWorld[] = "HELLOWORLD";
72 const char kGoodbyeWorld[] = "GOODBYEWORLD"; 72 const char kGoodbyeWorld[] = "GOODBYEWORLD";
73 73
74 const PrefHashFilter::TrackedPreferenceMetadata kConfiguration[] = { 74 const PrefHashFilter::TrackedPreferenceMetadata kConfiguration[] = {
75 {0u, kTrackedAtomic, PrefHashFilter::NO_ENFORCEMENT, 75 {0u, kTrackedAtomic, PrefHashFilter::NO_ENFORCEMENT,
(...skipping 15 matching lines...) Expand all
91 registry_verifier_(profile_pref_registry_) {} 91 registry_verifier_(profile_pref_registry_) {}
92 92
93 virtual void SetUp() OVERRIDE { 93 virtual void SetUp() OVERRIDE {
94 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); 94 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry());
95 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_); 95 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_);
96 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; 96 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration;
97 it != kConfiguration + arraysize(kConfiguration); 97 it != kConfiguration + arraysize(kConfiguration);
98 ++it) { 98 ++it) {
99 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) { 99 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) {
100 profile_pref_registry_->RegisterStringPref( 100 profile_pref_registry_->RegisterStringPref(
101 it->name, "", user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 101 it->name,
102 std::string(),
103 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
102 } else { 104 } else {
103 profile_pref_registry_->RegisterDictionaryPref( 105 profile_pref_registry_->RegisterDictionaryPref(
104 it->name, user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 106 it->name, user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
105 } 107 }
106 } 108 }
107 profile_pref_registry_->RegisterStringPref( 109 profile_pref_registry_->RegisterStringPref(
108 kUnprotectedAtomic, 110 kUnprotectedPref,
109 std::string(), 111 std::string(),
110 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 112 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
111 113
112 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); 114 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir());
113 ReloadConfiguration(); 115 ReloadConfiguration();
114 } 116 }
115 117
116 void ReloadConfiguration() { 118 void ReloadConfiguration() {
117 manager_.reset(new ProfilePrefStoreManager(profile_dir_.path(), 119 manager_.reset(new ProfilePrefStoreManager(profile_dir_.path(),
118 configuration_, 120 configuration_,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 pref_store = NULL; 171 pref_store = NULL;
170 base::RunLoop().RunUntilIdle(); 172 base::RunLoop().RunUntilIdle();
171 } 173 }
172 174
173 void InitializePrefStore(PersistentPrefStore* pref_store) { 175 void InitializePrefStore(PersistentPrefStore* pref_store) {
174 pref_store->AddObserver(&registry_verifier_); 176 pref_store->AddObserver(&registry_verifier_);
175 PersistentPrefStore::PrefReadError error = pref_store->ReadPrefs(); 177 PersistentPrefStore::PrefReadError error = pref_store->ReadPrefs();
176 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE, error); 178 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE, error);
177 pref_store->SetValue(kTrackedAtomic, new base::StringValue(kFoobar)); 179 pref_store->SetValue(kTrackedAtomic, new base::StringValue(kFoobar));
178 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld)); 180 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld));
179 pref_store->SetValue(kUnprotectedAtomic, new base::StringValue(kFoobar)); 181 pref_store->SetValue(kUnprotectedPref, new base::StringValue(kFoobar));
180 pref_store->RemoveObserver(&registry_verifier_); 182 pref_store->RemoveObserver(&registry_verifier_);
181 pref_store->CommitPendingWrite(); 183 pref_store->CommitPendingWrite();
182 base::RunLoop().RunUntilIdle(); 184 base::RunLoop().RunUntilIdle();
183 } 185 }
184 186
185 void LoadExistingPrefs() { 187 void LoadExistingPrefs() {
186 DestroyPrefStore(); 188 DestroyPrefStore();
187 pref_store_ = manager_->CreateProfilePrefStore( 189 pref_store_ = manager_->CreateProfilePrefStore(
188 main_message_loop_.message_loop_proxy()); 190 main_message_loop_.message_loop_proxy());
189 pref_store_->AddObserver(&registry_verifier_); 191 pref_store_->AddObserver(&registry_verifier_);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 275
274 TEST_F(ProfilePrefStoreManagerTest, ResetPrefHashStore) { 276 TEST_F(ProfilePrefStoreManagerTest, ResetPrefHashStore) {
275 InitializePrefs(); 277 InitializePrefs();
276 278
277 manager_->ResetPrefHashStore(); 279 manager_->ResetPrefHashStore();
278 280
279 LoadExistingPrefs(); 281 LoadExistingPrefs();
280 282
281 // kTrackedAtomic is loaded as it appears on disk. 283 // kTrackedAtomic is loaded as it appears on disk.
282 ExpectStringValueEquals(kTrackedAtomic, kFoobar); 284 ExpectStringValueEquals(kTrackedAtomic, kFoobar);
283 // If preference tracking is supported, the tampered value of kProtectedAtomic 285 // If preference tracking is supported, kProtectedAtomic will be undefined
284 // will be discarded at load time, leaving this preference undefined. 286 // because the value was discarded due to loss of the hash store contents.
285 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 287 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
286 pref_store_->GetValue(kProtectedAtomic, NULL)); 288 pref_store_->GetValue(kProtectedAtomic, NULL));
287 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 289 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
288 WasResetRecorded()); 290 WasResetRecorded());
289 } 291 }
290 292
291 TEST_F(ProfilePrefStoreManagerTest, ResetAllPrefHashStores) { 293 TEST_F(ProfilePrefStoreManagerTest, ResetAllPrefHashStores) {
292 InitializePrefs(); 294 InitializePrefs();
293 295
294 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_); 296 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // values. 337 // values.
336 LoadExistingPrefs(); 338 LoadExistingPrefs();
337 339
338 // These expectations hold whether or not tracking is supported. 340 // These expectations hold whether or not tracking is supported.
339 ExpectStringValueEquals(kTrackedAtomic, kFoobar); 341 ExpectStringValueEquals(kTrackedAtomic, kFoobar);
340 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); 342 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld);
341 EXPECT_FALSE(WasResetRecorded()); 343 EXPECT_FALSE(WasResetRecorded());
342 } 344 }
343 345
344 TEST_F(ProfilePrefStoreManagerTest, InitializePrefsFromMasterPrefs) { 346 TEST_F(ProfilePrefStoreManagerTest, InitializePrefsFromMasterPrefs) {
345 scoped_ptr<base::DictionaryValue> master_prefs( 347 base::DictionaryValue master_prefs;
346 new base::DictionaryValue); 348 master_prefs.Set(kTrackedAtomic, new base::StringValue(kFoobar));
347 master_prefs->Set(kTrackedAtomic, new base::StringValue(kFoobar)); 349 master_prefs.Set(kProtectedAtomic, new base::StringValue(kHelloWorld));
348 master_prefs->Set(kProtectedAtomic, new base::StringValue(kHelloWorld)); 350 EXPECT_TRUE(manager_->InitializePrefsFromMasterPrefs(master_prefs));
349 EXPECT_TRUE(
350 manager_->InitializePrefsFromMasterPrefs(*master_prefs));
351 351
352 LoadExistingPrefs(); 352 LoadExistingPrefs();
353 353
354 // Verify that InitializePrefsFromMasterPrefs correctly applied the MACs 354 // Verify that InitializePrefsFromMasterPrefs correctly applied the MACs
355 // necessary to authenticate these values. 355 // necessary to authenticate these values.
356 ExpectStringValueEquals(kTrackedAtomic, kFoobar); 356 ExpectStringValueEquals(kTrackedAtomic, kFoobar);
357 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); 357 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld);
358 EXPECT_FALSE(WasResetRecorded()); 358 EXPECT_FALSE(WasResetRecorded());
359 } 359 }
360 360
361 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) { 361 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) {
362 InitializePrefs(); 362 InitializePrefs();
363 LoadExistingPrefs(); 363 LoadExistingPrefs();
364 ExpectStringValueEquals(kUnprotectedAtomic, kFoobar); 364 ExpectStringValueEquals(kUnprotectedPref, kFoobar);
365 365
366 // Ensure everything is written out to disk. 366 // Ensure everything is written out to disk.
367 DestroyPrefStore(); 367 DestroyPrefStore();
368 368
369 ReplaceStringInPrefs(kFoobar, kBarfoo); 369 ReplaceStringInPrefs(kFoobar, kBarfoo);
370 370
371 // It's unprotected, so we can load the modified value. 371 // It's unprotected, so we can load the modified value.
372 LoadExistingPrefs(); 372 LoadExistingPrefs();
373 ExpectStringValueEquals(kUnprotectedAtomic, kBarfoo); 373 ExpectStringValueEquals(kUnprotectedPref, kBarfoo);
374 374
375 // Now update the configuration to protect it. 375 // Now update the configuration to protect it.
376 PrefHashFilter::TrackedPreferenceMetadata new_protected = { 376 PrefHashFilter::TrackedPreferenceMetadata new_protected = {
377 kExtraReportingId, kUnprotectedAtomic, PrefHashFilter::ENFORCE_ON_LOAD, 377 kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD,
378 PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; 378 PrefHashFilter::TRACKING_STRATEGY_ATOMIC};
379 configuration_.push_back(new_protected); 379 configuration_.push_back(new_protected);
380 ReloadConfiguration(); 380 ReloadConfiguration();
381 381
382 // And try loading with the new configuration. 382 // And try loading with the new configuration.
383 LoadExistingPrefs(); 383 LoadExistingPrefs();
384 384
385 // Since there was a valid super MAC we were able to extend the existing trust 385 // Since there was a valid super MAC we were able to extend the existing trust
386 // to the newly proteted preference. 386 // to the newly proteted preference.
387 ExpectStringValueEquals(kUnprotectedAtomic, kBarfoo); 387 ExpectStringValueEquals(kUnprotectedPref, kBarfoo);
388 EXPECT_FALSE(WasResetRecorded()); 388 EXPECT_FALSE(WasResetRecorded());
389 389
390 // Ensure everything is written out to disk. 390 // Ensure everything is written out to disk.
391 DestroyPrefStore(); 391 DestroyPrefStore();
392 392
393 // It's protected now, so (if the platform supports it) any tampering should 393 // It's protected now, so (if the platform supports it) any tampering should
394 // lead to a reset. 394 // lead to a reset.
395 ReplaceStringInPrefs(kBarfoo, kFoobar); 395 ReplaceStringInPrefs(kBarfoo, kFoobar);
396 LoadExistingPrefs(); 396 LoadExistingPrefs();
397 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 397 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
398 pref_store_->GetValue(kUnprotectedAtomic, NULL)); 398 pref_store_->GetValue(kUnprotectedPref, NULL));
399 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 399 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
400 WasResetRecorded()); 400 WasResetRecorded());
401 } 401 }
402 402
403 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { 403 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) {
404 InitializePrefs(); 404 InitializePrefs();
405 405
406 // Now update the configuration to protect it. 406 // Now update the configuration to protect it.
407 PrefHashFilter::TrackedPreferenceMetadata new_protected = { 407 PrefHashFilter::TrackedPreferenceMetadata new_protected = {
408 kExtraReportingId, kUnprotectedAtomic, PrefHashFilter::ENFORCE_ON_LOAD, 408 kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD,
409 PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; 409 PrefHashFilter::TRACKING_STRATEGY_ATOMIC};
410 configuration_.push_back(new_protected); 410 configuration_.push_back(new_protected);
411 ReloadConfiguration(); 411 ReloadConfiguration();
412 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_); 412 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_);
413 413
414 // And try loading with the new configuration. 414 // And try loading with the new configuration.
415 LoadExistingPrefs(); 415 LoadExistingPrefs();
416 416
417 // If preference tracking is supported, kUnprotectedAtomic will have been 417 // If preference tracking is supported, kUnprotectedPref will have been
418 // discarded because new values are not accepted without a valid super MAC. 418 // discarded because new values are not accepted without a valid super MAC.
419 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 419 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
420 pref_store_->GetValue(kUnprotectedAtomic, NULL)); 420 pref_store_->GetValue(kUnprotectedPref, NULL));
421 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 421 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
422 WasResetRecorded()); 422 WasResetRecorded());
423 } 423 }
424 424
425 // This test does not directly verify that the values are moved from one pref 425 // This test does not directly verify that the values are moved from one pref
426 // store to the other. segregated_pref_store_unittest.cc _does_ verify that 426 // store to the other. segregated_pref_store_unittest.cc _does_ verify that
427 // functionality. 427 // functionality.
428 // 428 //
429 // _This_ test verifies that preference values are correctly maintained when a 429 // _This_ test verifies that preference values are correctly maintained when a
430 // preference's protection state changes from protected to unprotected. 430 // preference's protection state changes from protected to unprotected.
(...skipping 27 matching lines...) Expand all
458 LoadExistingPrefs(); 458 LoadExistingPrefs();
459 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); 459 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld);
460 460
461 // Trigger the logic that migrates it back to the unprotected preferences 461 // Trigger the logic that migrates it back to the unprotected preferences
462 // file. 462 // file.
463 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld)); 463 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld));
464 LoadExistingPrefs(); 464 LoadExistingPrefs();
465 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); 465 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld);
466 EXPECT_FALSE(WasResetRecorded()); 466 EXPECT_FALSE(WasResetRecorded());
467 } 467 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/profile_pref_store_manager.cc ('k') | chrome/browser/prefs/tracked/segregated_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698