Chromium Code Reviews| Index: chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
| diff --git a/chrome/browser/prefs/profile_pref_store_manager_unittest.cc b/chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
| index 13f054f9e7fd79be471f736b2815dd5041e995eb..c21b76be891b42f2ccdd8037a4a16b385eb359cd 100644 |
| --- a/chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
| +++ b/chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
| @@ -24,6 +24,7 @@ |
| #include "base/values.h" |
| #include "chrome/browser/prefs/mock_validation_delegate.h" |
| #include "chrome/browser/prefs/pref_hash_filter.h" |
| +#include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" |
| #include "chrome/common/pref_names.h" |
| #include "components/pref_registry/pref_registry_syncable.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -151,6 +152,16 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
| return !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null(); |
| } |
| + void ClearResetRecorded() { |
| + base::PrefServiceFactory pref_service_factory; |
| + pref_service_factory.set_user_prefs(pref_store_); |
| + |
| + scoped_ptr<PrefService> pref_service( |
| + pref_service_factory.Create(profile_pref_registry_)); |
| + |
| + ProfilePrefStoreManager::ClearResetTime(pref_service.get()); |
| + } |
| + |
| void InitializePrefs() { |
| // According to the implementation of ProfilePrefStoreManager, this is |
| // actually a SegregatedPrefStore backed by two underlying pref stores. |
| @@ -165,6 +176,7 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
| void DestroyPrefStore() { |
| if (pref_store_) { |
| + ClearResetRecorded(); |
| // Force everything to be written to disk, triggering the PrefHashFilter |
| // while our RegistryVerifier is watching. |
| pref_store_->CommitPendingWrite(); |
| @@ -307,11 +319,68 @@ TEST_F(ProfilePrefStoreManagerTest, ProtectValues) { |
| TEST_F(ProfilePrefStoreManagerTest, MigrateFromOneFile) { |
| InitializeDeprecatedCombinedProfilePrefStore(); |
| + // The deprecated model stores hashes in local state. |
| + ASSERT_TRUE(local_state_.GetUserPrefValue( |
|
gab
2014/06/17 22:08:22
Tests appear to be choking on this; as if there wa
erikwright (departed)
2014/06/18 15:10:46
Done.
|
| + PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
| + |
| LoadExistingPrefs(); |
| + // After a first migration, the hashes were copied to the two user preference |
| + // files but were not cleaned. |
| + ASSERT_TRUE(local_state_.GetUserPrefValue( |
| + PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
| + |
| ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
| ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
| EXPECT_FALSE(WasResetRecorded()); |
| + |
| + LoadExistingPrefs(); |
| + |
| + // In a subsequent launch, the local state hash store would be reset. |
| + ASSERT_FALSE(local_state_.GetUserPrefValue( |
| + PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
| + |
| + ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
| + ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
| + EXPECT_FALSE(WasResetRecorded()); |
| +} |
| + |
| +TEST_F(ProfilePrefStoreManagerTest, MigrateWithTampering) { |
| + InitializeDeprecatedCombinedProfilePrefStore(); |
| + |
| + ReplaceStringInPrefs(kFoobar, kBarfoo); |
| + ReplaceStringInPrefs(kHelloWorld, kGoodbyeWorld); |
| + |
| + // The deprecated model stores hashes in local state. |
| + ASSERT_TRUE(local_state_.GetUserPrefValue( |
| + PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
| + |
| + LoadExistingPrefs(); |
| + |
| + // After a first migration, the hashes were copied to the two user preference |
| + // files but were not cleaned. |
| + ASSERT_TRUE(local_state_.GetUserPrefValue( |
| + PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
| + |
| + // kTrackedAtomic is unprotected and thus will be loaded as it appears on |
| + // disk. |
| + ExpectStringValueEquals(kTrackedAtomic, kBarfoo); |
| + |
| + // If preference tracking is supported, the tampered value of kProtectedAtomic |
| + // will be discarded at load time, leaving this preference undefined. |
| + EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| + pref_store_->GetValue(kProtectedAtomic, NULL)); |
| + EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| + WasResetRecorded()); |
| + |
| + LoadExistingPrefs(); |
| + |
| + // In a subsequent launch, the local state hash store would be reset. |
| + ASSERT_FALSE(local_state_.GetUserPrefValue( |
| + PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
| + |
| + ExpectStringValueEquals(kTrackedAtomic, kBarfoo); |
| + EXPECT_FALSE(WasResetRecorded()); |
| } |
| TEST_F(ProfilePrefStoreManagerTest, InitializePrefsFromMasterPrefs) { |
| @@ -375,6 +444,45 @@ TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) { |
| WasResetRecorded()); |
| } |
| +TEST_F(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { |
| + std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
| + original_configuration = configuration_; |
| + for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = |
| + configuration_.begin(); |
| + it != configuration_.end(); |
| + ++it) { |
| + it->enforcement_level = PrefHashFilter::NO_ENFORCEMENT; |
| + } |
| + ReloadConfiguration(); |
| + |
| + InitializePrefs(); |
| + |
| + ExpectValidationObserved(kTrackedAtomic); |
| + ExpectValidationObserved(kProtectedAtomic); |
| + |
| + LoadExistingPrefs(); |
| + ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
| + |
| + // Ensure everything is written out to disk. |
| + DestroyPrefStore(); |
| + |
| + // Now introduce protection, including the never-before tracked "new_pref". |
| + configuration_ = original_configuration; |
| + PrefHashFilter::TrackedPreferenceMetadata new_protected = { |
| + kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD, |
| + PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; |
| + configuration_.push_back(new_protected); |
| + ReloadConfiguration(); |
| + |
| + // And try loading with the new configuration. |
| + LoadExistingPrefs(); |
| + |
| + // Since there was a valid super MAC we were able to extend the existing trust |
| + // to the newly tracked & protected preference. |
| + ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
| + EXPECT_FALSE(WasResetRecorded()); |
| +} |
| + |
| TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { |
| InitializePrefs(); |