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..27c3682daba86661df3e4d7f96754d96b7f01ccc 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,13 +319,70 @@ TEST_F(ProfilePrefStoreManagerTest, ProtectValues) { |
| TEST_F(ProfilePrefStoreManagerTest, MigrateFromOneFile) { |
| InitializeDeprecatedCombinedProfilePrefStore(); |
| + // 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)); |
| + |
| + ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
| + ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
| + EXPECT_FALSE(WasResetRecorded()); |
| + |
| LoadExistingPrefs(); |
| + // In a subsequent launch, the local state hash store would be reset. |
|
gab
2014/06/17 22:08:21
s/would/should
erikwright (departed)
2014/06/18 15:10:46
Done.
|
| + 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) { |
| base::DictionaryValue master_prefs; |
| master_prefs.Set(kTrackedAtomic, new base::StringValue(kFoobar)); |