| OLD | NEW |
| 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" |
| 11 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/prefs/json_pref_store.h" | 16 #include "base/prefs/json_pref_store.h" |
| 17 #include "base/prefs/persistent_pref_store.h" | 17 #include "base/prefs/persistent_pref_store.h" |
| 18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 19 #include "base/prefs/pref_service_factory.h" | 19 #include "base/prefs/pref_service_factory.h" |
| 20 #include "base/prefs/pref_store.h" | 20 #include "base/prefs/pref_store.h" |
| 21 #include "base/prefs/testing_pref_service.h" | 21 #include "base/prefs/testing_pref_service.h" |
| 22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "chrome/browser/prefs/mock_validation_observer.h" |
| 25 #include "chrome/browser/prefs/pref_hash_filter.h" | 26 #include "chrome/browser/prefs/pref_hash_filter.h" |
| 27 #include "chrome/browser/prefs/tracked/tracked_preference_validation_observer.h" |
| 26 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 27 #include "components/user_prefs/pref_registry_syncable.h" | 29 #include "components/user_prefs/pref_registry_syncable.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 class FirstEqualsPredicate { | 34 class FirstEqualsPredicate { |
| 33 public: | 35 public: |
| 34 explicit FirstEqualsPredicate(const std::string& expected) | 36 explicit FirstEqualsPredicate(const std::string& expected) |
| 35 : expected_(expected) {} | 37 : expected_(expected) {} |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 const size_t kReportingIdCount = 3u; | 84 const size_t kReportingIdCount = 3u; |
| 83 | 85 |
| 84 } // namespace | 86 } // namespace |
| 85 | 87 |
| 86 class ProfilePrefStoreManagerTest : public testing::Test { | 88 class ProfilePrefStoreManagerTest : public testing::Test { |
| 87 public: | 89 public: |
| 88 ProfilePrefStoreManagerTest() | 90 ProfilePrefStoreManagerTest() |
| 89 : configuration_(kConfiguration, | 91 : configuration_(kConfiguration, |
| 90 kConfiguration + arraysize(kConfiguration)), | 92 kConfiguration + arraysize(kConfiguration)), |
| 91 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), | 93 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), |
| 92 registry_verifier_(profile_pref_registry_) {} | 94 registry_verifier_(profile_pref_registry_), |
| 95 validation_data_(new MockValidationObserver::ValidationData) {} |
| 93 | 96 |
| 94 virtual void SetUp() OVERRIDE { | 97 virtual void SetUp() OVERRIDE { |
| 95 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); | 98 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); |
| 96 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_); | 99 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_); |
| 97 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; | 100 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; |
| 98 it != kConfiguration + arraysize(kConfiguration); | 101 it != kConfiguration + arraysize(kConfiguration); |
| 99 ++it) { | 102 ++it) { |
| 100 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) { | 103 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) { |
| 101 profile_pref_registry_->RegisterStringPref( | 104 profile_pref_registry_->RegisterStringPref( |
| 102 it->name, | 105 it->name, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 base::PrefServiceFactory pref_service_factory; | 146 base::PrefServiceFactory pref_service_factory; |
| 144 pref_service_factory.set_user_prefs(pref_store_); | 147 pref_service_factory.set_user_prefs(pref_store_); |
| 145 | 148 |
| 146 scoped_ptr<PrefService> pref_service( | 149 scoped_ptr<PrefService> pref_service( |
| 147 pref_service_factory.Create(profile_pref_registry_)); | 150 pref_service_factory.Create(profile_pref_registry_)); |
| 148 | 151 |
| 149 return !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null(); | 152 return !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null(); |
| 150 } | 153 } |
| 151 | 154 |
| 152 void InitializePrefs() { | 155 void InitializePrefs() { |
| 156 // Provide a validation observer that collects events for verification. |
| 157 scoped_ptr<MockValidationObserver> mock_validation_observer( |
| 158 new MockValidationObserver(validation_data_)); |
| 159 |
| 153 // According to the implementation of ProfilePrefStoreManager, this is | 160 // According to the implementation of ProfilePrefStoreManager, this is |
| 154 // actually a SegregatedPrefStore backed by two underlying pref stores. | 161 // actually a SegregatedPrefStore backed by two underlying pref stores. |
| 155 scoped_refptr<PersistentPrefStore> pref_store = | 162 scoped_refptr<PersistentPrefStore> pref_store = |
| 156 manager_->CreateProfilePrefStore( | 163 manager_->CreateProfilePrefStore( |
| 157 main_message_loop_.message_loop_proxy()); | 164 main_message_loop_.message_loop_proxy(), |
| 165 mock_validation_observer |
| 166 .PassAs<TrackedPreferenceValidationObserver>()); |
| 158 InitializePrefStore(pref_store); | 167 InitializePrefStore(pref_store); |
| 168 base::RunLoop().RunUntilIdle(); |
| 169 |
| 159 pref_store = NULL; | 170 pref_store = NULL; |
| 160 base::RunLoop().RunUntilIdle(); | |
| 161 } | 171 } |
| 162 | 172 |
| 163 void DestroyPrefStore() { | 173 void DestroyPrefStore() { |
| 164 if (pref_store_) { | 174 if (pref_store_) { |
| 165 // Force everything to be written to disk, triggering the PrefHashFilter | 175 // Force everything to be written to disk, triggering the PrefHashFilter |
| 166 // while our RegistryVerifier is watching. | 176 // while our RegistryVerifier is watching. |
| 167 pref_store_->CommitPendingWrite(); | 177 pref_store_->CommitPendingWrite(); |
| 168 base::RunLoop().RunUntilIdle(); | 178 base::RunLoop().RunUntilIdle(); |
| 169 | 179 |
| 170 pref_store_->RemoveObserver(®istry_verifier_); | 180 pref_store_->RemoveObserver(®istry_verifier_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 192 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld)); | 202 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld)); |
| 193 pref_store->SetValue(kUnprotectedPref, new base::StringValue(kFoobar)); | 203 pref_store->SetValue(kUnprotectedPref, new base::StringValue(kFoobar)); |
| 194 pref_store->RemoveObserver(®istry_verifier_); | 204 pref_store->RemoveObserver(®istry_verifier_); |
| 195 pref_store->CommitPendingWrite(); | 205 pref_store->CommitPendingWrite(); |
| 196 base::RunLoop().RunUntilIdle(); | 206 base::RunLoop().RunUntilIdle(); |
| 197 } | 207 } |
| 198 | 208 |
| 199 void LoadExistingPrefs() { | 209 void LoadExistingPrefs() { |
| 200 DestroyPrefStore(); | 210 DestroyPrefStore(); |
| 201 pref_store_ = manager_->CreateProfilePrefStore( | 211 pref_store_ = manager_->CreateProfilePrefStore( |
| 202 main_message_loop_.message_loop_proxy()); | 212 main_message_loop_.message_loop_proxy(), |
| 213 scoped_ptr<TrackedPreferenceValidationObserver>()); |
| 203 pref_store_->AddObserver(®istry_verifier_); | 214 pref_store_->AddObserver(®istry_verifier_); |
| 204 pref_store_->ReadPrefs(); | 215 pref_store_->ReadPrefs(); |
| 205 } | 216 } |
| 206 | 217 |
| 207 void ReplaceStringInPrefs(const std::string& find, | 218 void ReplaceStringInPrefs(const std::string& find, |
| 208 const std::string& replace) { | 219 const std::string& replace) { |
| 209 base::FileEnumerator file_enum( | 220 base::FileEnumerator file_enum( |
| 210 profile_dir_.path(), true, base::FileEnumerator::FILES); | 221 profile_dir_.path(), true, base::FileEnumerator::FILES); |
| 211 | 222 |
| 212 for (base::FilePath path = file_enum.Next(); !path.empty(); | 223 for (base::FilePath path = file_enum.Next(); !path.empty(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 226 std::string as_string; | 237 std::string as_string; |
| 227 if (!pref_store_->GetValue(name, &value)) { | 238 if (!pref_store_->GetValue(name, &value)) { |
| 228 ADD_FAILURE() << name << " is not a defined value."; | 239 ADD_FAILURE() << name << " is not a defined value."; |
| 229 } else if (!value->GetAsString(&as_string)) { | 240 } else if (!value->GetAsString(&as_string)) { |
| 230 ADD_FAILURE() << name << " could not be coerced to a string."; | 241 ADD_FAILURE() << name << " could not be coerced to a string."; |
| 231 } else { | 242 } else { |
| 232 EXPECT_EQ(expected, as_string); | 243 EXPECT_EQ(expected, as_string); |
| 233 } | 244 } |
| 234 } | 245 } |
| 235 | 246 |
| 247 void ExpectValidationObserved(const std::string& pref_path) { |
| 248 // No validations are expected for platforms that do not support tracking. |
| 249 if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking) |
| 250 return; |
| 251 if (!validation_data_->GetEventForPath(pref_path)) |
| 252 ADD_FAILURE() << "No validation observed for preference: " << pref_path; |
| 253 } |
| 254 |
| 236 base::MessageLoop main_message_loop_; | 255 base::MessageLoop main_message_loop_; |
| 237 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; | 256 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; |
| 238 base::ScopedTempDir profile_dir_; | 257 base::ScopedTempDir profile_dir_; |
| 239 TestingPrefServiceSimple local_state_; | 258 TestingPrefServiceSimple local_state_; |
| 240 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; | 259 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; |
| 241 RegistryVerifier registry_verifier_; | 260 RegistryVerifier registry_verifier_; |
| 242 scoped_ptr<ProfilePrefStoreManager> manager_; | 261 scoped_ptr<ProfilePrefStoreManager> manager_; |
| 243 scoped_refptr<PersistentPrefStore> pref_store_; | 262 scoped_refptr<PersistentPrefStore> pref_store_; |
| 263 scoped_refptr<MockValidationObserver::ValidationData> validation_data_; |
| 244 }; | 264 }; |
| 245 | 265 |
| 246 TEST_F(ProfilePrefStoreManagerTest, StoreValues) { | 266 TEST_F(ProfilePrefStoreManagerTest, StoreValues) { |
| 247 InitializePrefs(); | 267 InitializePrefs(); |
| 248 | 268 |
| 249 LoadExistingPrefs(); | 269 LoadExistingPrefs(); |
| 250 | 270 |
| 251 ExpectStringValueEquals(kTrackedAtomic, kFoobar); | 271 ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
| 252 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 272 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
| 253 EXPECT_FALSE(WasResetRecorded()); | 273 EXPECT_FALSE(WasResetRecorded()); |
| 274 ExpectValidationObserved(kTrackedAtomic); |
| 275 ExpectValidationObserved(kProtectedAtomic); |
| 254 } | 276 } |
| 255 | 277 |
| 256 TEST_F(ProfilePrefStoreManagerTest, GetPrefFilePathFromProfilePath) { | 278 TEST_F(ProfilePrefStoreManagerTest, GetPrefFilePathFromProfilePath) { |
| 257 base::FilePath pref_file_path = | 279 base::FilePath pref_file_path = |
| 258 ProfilePrefStoreManager::GetPrefFilePathFromProfilePath( | 280 ProfilePrefStoreManager::GetPrefFilePathFromProfilePath( |
| 259 profile_dir_.path()); | 281 profile_dir_.path()); |
| 260 | 282 |
| 261 EXPECT_FALSE(base::PathExists(pref_file_path)); | 283 EXPECT_FALSE(base::PathExists(pref_file_path)); |
| 262 | 284 |
| 263 InitializePrefs(); | 285 InitializePrefs(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 276 // kTrackedAtomic is unprotected and thus will be loaded as it appears on | 298 // kTrackedAtomic is unprotected and thus will be loaded as it appears on |
| 277 // disk. | 299 // disk. |
| 278 ExpectStringValueEquals(kTrackedAtomic, kBarfoo); | 300 ExpectStringValueEquals(kTrackedAtomic, kBarfoo); |
| 279 | 301 |
| 280 // If preference tracking is supported, the tampered value of kProtectedAtomic | 302 // If preference tracking is supported, the tampered value of kProtectedAtomic |
| 281 // will be discarded at load time, leaving this preference undefined. | 303 // will be discarded at load time, leaving this preference undefined. |
| 282 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 304 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| 283 pref_store_->GetValue(kProtectedAtomic, NULL)); | 305 pref_store_->GetValue(kProtectedAtomic, NULL)); |
| 284 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 306 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| 285 WasResetRecorded()); | 307 WasResetRecorded()); |
| 308 |
| 309 ExpectValidationObserved(kTrackedAtomic); |
| 310 ExpectValidationObserved(kProtectedAtomic); |
| 286 } | 311 } |
| 287 | 312 |
| 288 TEST_F(ProfilePrefStoreManagerTest, ResetPrefHashStore) { | 313 TEST_F(ProfilePrefStoreManagerTest, ResetPrefHashStore) { |
| 289 InitializePrefs(); | 314 InitializePrefs(); |
| 290 | 315 |
| 291 manager_->ResetPrefHashStore(); | 316 manager_->ResetPrefHashStore(); |
| 292 | 317 |
| 293 LoadExistingPrefs(); | 318 LoadExistingPrefs(); |
| 294 | 319 |
| 295 // kTrackedAtomic is loaded as it appears on disk. | 320 // kTrackedAtomic is loaded as it appears on disk. |
| 296 ExpectStringValueEquals(kTrackedAtomic, kFoobar); | 321 ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
| 297 // If preference tracking is supported, kProtectedAtomic will be undefined | 322 // If preference tracking is supported, kProtectedAtomic will be undefined |
| 298 // because the value was discarded due to loss of the hash store contents. | 323 // because the value was discarded due to loss of the hash store contents. |
| 299 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 324 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| 300 pref_store_->GetValue(kProtectedAtomic, NULL)); | 325 pref_store_->GetValue(kProtectedAtomic, NULL)); |
| 301 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 326 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| 302 WasResetRecorded()); | 327 WasResetRecorded()); |
| 328 |
| 329 ExpectValidationObserved(kTrackedAtomic); |
| 330 ExpectValidationObserved(kProtectedAtomic); |
| 303 } | 331 } |
| 304 | 332 |
| 305 TEST_F(ProfilePrefStoreManagerTest, ResetAllPrefHashStores) { | 333 TEST_F(ProfilePrefStoreManagerTest, ResetAllPrefHashStores) { |
| 306 InitializePrefs(); | 334 InitializePrefs(); |
| 307 | 335 |
| 308 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_); | 336 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_); |
| 309 | 337 |
| 310 LoadExistingPrefs(); | 338 LoadExistingPrefs(); |
| 311 | 339 |
| 312 // kTrackedAtomic is loaded as it appears on disk. | 340 // kTrackedAtomic is loaded as it appears on disk. |
| 313 ExpectStringValueEquals(kTrackedAtomic, kFoobar); | 341 ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
| 314 // If preference tracking is supported, kProtectedAtomic will be undefined | 342 // If preference tracking is supported, kProtectedAtomic will be undefined |
| 315 // because the value was discarded due to loss of the hash store contents. | 343 // because the value was discarded due to loss of the hash store contents. |
| 316 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 344 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| 317 pref_store_->GetValue(kProtectedAtomic, NULL)); | 345 pref_store_->GetValue(kProtectedAtomic, NULL)); |
| 318 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 346 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| 319 WasResetRecorded()); | 347 WasResetRecorded()); |
| 348 |
| 349 ExpectValidationObserved(kTrackedAtomic); |
| 350 ExpectValidationObserved(kProtectedAtomic); |
| 320 } | 351 } |
| 321 | 352 |
| 322 TEST_F(ProfilePrefStoreManagerTest, MigrateFromOneFile) { | 353 TEST_F(ProfilePrefStoreManagerTest, MigrateFromOneFile) { |
| 323 InitializeDeprecatedCombinedProfilePrefStore(); | 354 InitializeDeprecatedCombinedProfilePrefStore(); |
| 324 | 355 |
| 325 LoadExistingPrefs(); | 356 LoadExistingPrefs(); |
| 326 | 357 |
| 327 ExpectStringValueEquals(kTrackedAtomic, kFoobar); | 358 ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
| 328 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 359 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
| 329 EXPECT_FALSE(WasResetRecorded()); | 360 EXPECT_FALSE(WasResetRecorded()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 396 |
| 366 // Verify that InitializePrefsFromMasterPrefs correctly applied the MACs | 397 // Verify that InitializePrefsFromMasterPrefs correctly applied the MACs |
| 367 // necessary to authenticate these values. | 398 // necessary to authenticate these values. |
| 368 ExpectStringValueEquals(kTrackedAtomic, kFoobar); | 399 ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
| 369 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 400 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
| 370 EXPECT_FALSE(WasResetRecorded()); | 401 EXPECT_FALSE(WasResetRecorded()); |
| 371 } | 402 } |
| 372 | 403 |
| 373 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) { | 404 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) { |
| 374 InitializePrefs(); | 405 InitializePrefs(); |
| 406 |
| 407 ExpectValidationObserved(kTrackedAtomic); |
| 408 ExpectValidationObserved(kProtectedAtomic); |
| 409 |
| 375 LoadExistingPrefs(); | 410 LoadExistingPrefs(); |
| 376 ExpectStringValueEquals(kUnprotectedPref, kFoobar); | 411 ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
| 377 | 412 |
| 378 // Ensure everything is written out to disk. | 413 // Ensure everything is written out to disk. |
| 379 DestroyPrefStore(); | 414 DestroyPrefStore(); |
| 380 | 415 |
| 381 ReplaceStringInPrefs(kFoobar, kBarfoo); | 416 ReplaceStringInPrefs(kFoobar, kBarfoo); |
| 382 | 417 |
| 383 // It's unprotected, so we can load the modified value. | 418 // It's unprotected, so we can load the modified value. |
| 384 LoadExistingPrefs(); | 419 LoadExistingPrefs(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 408 LoadExistingPrefs(); | 443 LoadExistingPrefs(); |
| 409 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 444 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| 410 pref_store_->GetValue(kUnprotectedPref, NULL)); | 445 pref_store_->GetValue(kUnprotectedPref, NULL)); |
| 411 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 446 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| 412 WasResetRecorded()); | 447 WasResetRecorded()); |
| 413 } | 448 } |
| 414 | 449 |
| 415 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { | 450 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { |
| 416 InitializePrefs(); | 451 InitializePrefs(); |
| 417 | 452 |
| 453 ExpectValidationObserved(kTrackedAtomic); |
| 454 ExpectValidationObserved(kProtectedAtomic); |
| 455 |
| 418 // Now update the configuration to protect it. | 456 // Now update the configuration to protect it. |
| 419 PrefHashFilter::TrackedPreferenceMetadata new_protected = { | 457 PrefHashFilter::TrackedPreferenceMetadata new_protected = { |
| 420 kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD, | 458 kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD, |
| 421 PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; | 459 PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; |
| 422 configuration_.push_back(new_protected); | 460 configuration_.push_back(new_protected); |
| 423 ReloadConfiguration(); | 461 ReloadConfiguration(); |
| 424 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_); | 462 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_); |
| 425 | 463 |
| 426 // And try loading with the new configuration. | 464 // And try loading with the new configuration. |
| 427 LoadExistingPrefs(); | 465 LoadExistingPrefs(); |
| 428 | 466 |
| 429 // If preference tracking is supported, kUnprotectedPref will have been | 467 // If preference tracking is supported, kUnprotectedPref will have been |
| 430 // discarded because new values are not accepted without a valid super MAC. | 468 // discarded because new values are not accepted without a valid super MAC. |
| 431 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 469 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| 432 pref_store_->GetValue(kUnprotectedPref, NULL)); | 470 pref_store_->GetValue(kUnprotectedPref, NULL)); |
| 433 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 471 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
| 434 WasResetRecorded()); | 472 WasResetRecorded()); |
| 435 } | 473 } |
| 436 | 474 |
| 437 // This test verifies that preference values are correctly maintained when a | 475 // This test verifies that preference values are correctly maintained when a |
| 438 // preference's protection state changes from protected to unprotected. | 476 // preference's protection state changes from protected to unprotected. |
| 439 TEST_F(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { | 477 TEST_F(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { |
| 440 InitializePrefs(); | 478 InitializePrefs(); |
| 479 |
| 480 ExpectValidationObserved(kTrackedAtomic); |
| 481 ExpectValidationObserved(kProtectedAtomic); |
| 482 |
| 441 DestroyPrefStore(); | 483 DestroyPrefStore(); |
| 442 | 484 |
| 443 // Unconfigure protection for kProtectedAtomic | 485 // Unconfigure protection for kProtectedAtomic |
| 444 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = | 486 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = |
| 445 configuration_.begin(); | 487 configuration_.begin(); |
| 446 it != configuration_.end(); | 488 it != configuration_.end(); |
| 447 ++it) { | 489 ++it) { |
| 448 if (it->name == kProtectedAtomic) { | 490 if (it->name == kProtectedAtomic) { |
| 449 it->enforcement_level = PrefHashFilter::NO_ENFORCEMENT; | 491 it->enforcement_level = PrefHashFilter::NO_ENFORCEMENT; |
| 450 break; | 492 break; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 466 LoadExistingPrefs(); | 508 LoadExistingPrefs(); |
| 467 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 509 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
| 468 | 510 |
| 469 // Trigger the logic that migrates it back to the unprotected preferences | 511 // Trigger the logic that migrates it back to the unprotected preferences |
| 470 // file. | 512 // file. |
| 471 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld)); | 513 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld)); |
| 472 LoadExistingPrefs(); | 514 LoadExistingPrefs(); |
| 473 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); | 515 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); |
| 474 EXPECT_FALSE(WasResetRecorded()); | 516 EXPECT_FALSE(WasResetRecorded()); |
| 475 } | 517 } |
| OLD | NEW |