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" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 } // namespace | 86 } // namespace |
87 | 87 |
88 class ProfilePrefStoreManagerTest : public testing::Test { | 88 class ProfilePrefStoreManagerTest : public testing::Test { |
89 public: | 89 public: |
90 ProfilePrefStoreManagerTest() | 90 ProfilePrefStoreManagerTest() |
91 : configuration_(kConfiguration, | 91 : configuration_(kConfiguration, |
92 kConfiguration + arraysize(kConfiguration)), | 92 kConfiguration + arraysize(kConfiguration)), |
93 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), | 93 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), |
94 registry_verifier_(profile_pref_registry_), | 94 registry_verifier_(profile_pref_registry_), |
95 seed_("seed") {} | 95 seed_("seed"), |
| 96 reset_recorded_(false) {} |
96 | 97 |
97 virtual void SetUp() OVERRIDE { | 98 virtual void SetUp() OVERRIDE { |
98 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); | 99 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); |
99 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_); | 100 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_); |
100 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; | 101 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; |
101 it != kConfiguration + arraysize(kConfiguration); | 102 it != kConfiguration + arraysize(kConfiguration); |
102 ++it) { | 103 ++it) { |
103 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) { | 104 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) { |
104 profile_pref_registry_->RegisterStringPref( | 105 profile_pref_registry_->RegisterStringPref( |
105 it->name, | 106 it->name, |
(...skipping 29 matching lines...) Expand all Loading... |
135 configuration_, | 136 configuration_, |
136 kReportingIdCount, | 137 kReportingIdCount, |
137 seed_, | 138 seed_, |
138 "device_id", | 139 "device_id", |
139 &local_state_)); | 140 &local_state_)); |
140 } | 141 } |
141 | 142 |
142 virtual void TearDown() OVERRIDE { DestroyPrefStore(); } | 143 virtual void TearDown() OVERRIDE { DestroyPrefStore(); } |
143 | 144 |
144 protected: | 145 protected: |
145 bool WasResetRecorded() { | 146 // Verifies whether a reset was reported via the RecordReset() hook. Also |
| 147 // verifies that GetResetTime() was set (or not) accordingly. |
| 148 void VerifyResetRecorded(bool reset_expected) { |
| 149 EXPECT_EQ(reset_expected, reset_recorded_); |
| 150 |
146 base::PrefServiceFactory pref_service_factory; | 151 base::PrefServiceFactory pref_service_factory; |
147 pref_service_factory.set_user_prefs(pref_store_); | 152 pref_service_factory.set_user_prefs(pref_store_); |
148 | 153 |
149 scoped_ptr<PrefService> pref_service( | 154 scoped_ptr<PrefService> pref_service( |
150 pref_service_factory.Create(profile_pref_registry_)); | 155 pref_service_factory.Create(profile_pref_registry_)); |
151 | 156 |
152 return !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null(); | 157 EXPECT_EQ( |
| 158 reset_expected, |
| 159 !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null()); |
153 } | 160 } |
154 | 161 |
155 void ClearResetRecorded() { | 162 void ClearResetRecorded() { |
| 163 reset_recorded_ = false; |
| 164 |
156 base::PrefServiceFactory pref_service_factory; | 165 base::PrefServiceFactory pref_service_factory; |
157 pref_service_factory.set_user_prefs(pref_store_); | 166 pref_service_factory.set_user_prefs(pref_store_); |
158 | 167 |
159 scoped_ptr<PrefService> pref_service( | 168 scoped_ptr<PrefService> pref_service( |
160 pref_service_factory.Create(profile_pref_registry_)); | 169 pref_service_factory.Create(profile_pref_registry_)); |
161 | 170 |
162 ProfilePrefStoreManager::ClearResetTime(pref_service.get()); | 171 ProfilePrefStoreManager::ClearResetTime(pref_service.get()); |
163 } | 172 } |
164 | 173 |
165 void InitializePrefs() { | 174 void InitializePrefs() { |
166 // According to the implementation of ProfilePrefStoreManager, this is | 175 // According to the implementation of ProfilePrefStoreManager, this is |
167 // actually a SegregatedPrefStore backed by two underlying pref stores. | 176 // actually a SegregatedPrefStore backed by two underlying pref stores. |
168 scoped_refptr<PersistentPrefStore> pref_store = | 177 scoped_refptr<PersistentPrefStore> pref_store = |
169 manager_->CreateProfilePrefStore( | 178 manager_->CreateProfilePrefStore( |
170 main_message_loop_.message_loop_proxy(), | 179 main_message_loop_.message_loop_proxy(), |
| 180 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
| 181 base::Unretained(this)), |
171 &mock_validation_delegate_); | 182 &mock_validation_delegate_); |
172 InitializePrefStore(pref_store); | 183 InitializePrefStore(pref_store); |
173 pref_store = NULL; | 184 pref_store = NULL; |
174 base::RunLoop().RunUntilIdle(); | 185 base::RunLoop().RunUntilIdle(); |
175 } | 186 } |
176 | 187 |
177 void DestroyPrefStore() { | 188 void DestroyPrefStore() { |
178 if (pref_store_) { | 189 if (pref_store_) { |
179 ClearResetRecorded(); | 190 ClearResetRecorded(); |
180 // Force everything to be written to disk, triggering the PrefHashFilter | 191 // Force everything to be written to disk, triggering the PrefHashFilter |
(...skipping 26 matching lines...) Expand all Loading... |
207 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld)); | 218 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld)); |
208 pref_store->SetValue(kUnprotectedPref, new base::StringValue(kFoobar)); | 219 pref_store->SetValue(kUnprotectedPref, new base::StringValue(kFoobar)); |
209 pref_store->RemoveObserver(®istry_verifier_); | 220 pref_store->RemoveObserver(®istry_verifier_); |
210 pref_store->CommitPendingWrite(); | 221 pref_store->CommitPendingWrite(); |
211 base::RunLoop().RunUntilIdle(); | 222 base::RunLoop().RunUntilIdle(); |
212 } | 223 } |
213 | 224 |
214 void LoadExistingPrefs() { | 225 void LoadExistingPrefs() { |
215 DestroyPrefStore(); | 226 DestroyPrefStore(); |
216 pref_store_ = manager_->CreateProfilePrefStore( | 227 pref_store_ = manager_->CreateProfilePrefStore( |
217 main_message_loop_.message_loop_proxy(), NULL); | 228 main_message_loop_.message_loop_proxy(), |
| 229 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
| 230 base::Unretained(this)), |
| 231 NULL); |
218 pref_store_->AddObserver(®istry_verifier_); | 232 pref_store_->AddObserver(®istry_verifier_); |
219 pref_store_->ReadPrefs(); | 233 pref_store_->ReadPrefs(); |
220 } | 234 } |
221 | 235 |
222 void ReplaceStringInPrefs(const std::string& find, | 236 void ReplaceStringInPrefs(const std::string& find, |
223 const std::string& replace) { | 237 const std::string& replace) { |
224 base::FileEnumerator file_enum( | 238 base::FileEnumerator file_enum( |
225 profile_dir_.path(), true, base::FileEnumerator::FILES); | 239 profile_dir_.path(), true, base::FileEnumerator::FILES); |
226 | 240 |
227 for (base::FilePath path = file_enum.Next(); !path.empty(); | 241 for (base::FilePath path = file_enum.Next(); !path.empty(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; | 274 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; |
261 base::ScopedTempDir profile_dir_; | 275 base::ScopedTempDir profile_dir_; |
262 TestingPrefServiceSimple local_state_; | 276 TestingPrefServiceSimple local_state_; |
263 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; | 277 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; |
264 RegistryVerifier registry_verifier_; | 278 RegistryVerifier registry_verifier_; |
265 MockValidationDelegate mock_validation_delegate_; | 279 MockValidationDelegate mock_validation_delegate_; |
266 scoped_ptr<ProfilePrefStoreManager> manager_; | 280 scoped_ptr<ProfilePrefStoreManager> manager_; |
267 scoped_refptr<PersistentPrefStore> pref_store_; | 281 scoped_refptr<PersistentPrefStore> pref_store_; |
268 | 282 |
269 std::string seed_; | 283 std::string seed_; |
| 284 |
| 285 private: |
| 286 void RecordReset() { |
| 287 // As-is |reset_recorded_| is only designed to remember a single reset, make |
| 288 // sure none was previously recorded (or that ClearResetRecorded() was |
| 289 // called). |
| 290 EXPECT_FALSE(reset_recorded_); |
| 291 reset_recorded_ = true; |
| 292 } |
| 293 |
| 294 bool reset_recorded_; |
270 }; | 295 }; |
271 | 296 |
272 TEST_F(ProfilePrefStoreManagerTest, StoreValues) { | 297 TEST_F(ProfilePrefStoreManagerTest, StoreValues) { |
273 InitializePrefs(); | 298 InitializePrefs(); |
274 | 299 |
275 LoadExistingPrefs(); | 300 LoadExistingPrefs(); |
276 | 301 |
277 ExpectStringValueEquals(kTrackedAtomic, kFoobar); | 302 ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
278 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 303 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
279 EXPECT_FALSE(WasResetRecorded()); | 304 VerifyResetRecorded(false); |
280 ExpectValidationObserved(kTrackedAtomic); | 305 ExpectValidationObserved(kTrackedAtomic); |
281 ExpectValidationObserved(kProtectedAtomic); | 306 ExpectValidationObserved(kProtectedAtomic); |
282 } | 307 } |
283 | 308 |
284 TEST_F(ProfilePrefStoreManagerTest, GetPrefFilePathFromProfilePath) { | 309 TEST_F(ProfilePrefStoreManagerTest, GetPrefFilePathFromProfilePath) { |
285 base::FilePath pref_file_path = | 310 base::FilePath pref_file_path = |
286 ProfilePrefStoreManager::GetPrefFilePathFromProfilePath( | 311 ProfilePrefStoreManager::GetPrefFilePathFromProfilePath( |
287 profile_dir_.path()); | 312 profile_dir_.path()); |
288 | 313 |
289 EXPECT_FALSE(base::PathExists(pref_file_path)); | 314 EXPECT_FALSE(base::PathExists(pref_file_path)); |
(...skipping 12 matching lines...) Expand all Loading... |
302 LoadExistingPrefs(); | 327 LoadExistingPrefs(); |
303 | 328 |
304 // kTrackedAtomic is unprotected and thus will be loaded as it appears on | 329 // kTrackedAtomic is unprotected and thus will be loaded as it appears on |
305 // disk. | 330 // disk. |
306 ExpectStringValueEquals(kTrackedAtomic, kBarfoo); | 331 ExpectStringValueEquals(kTrackedAtomic, kBarfoo); |
307 | 332 |
308 // If preference tracking is supported, the tampered value of kProtectedAtomic | 333 // If preference tracking is supported, the tampered value of kProtectedAtomic |
309 // will be discarded at load time, leaving this preference undefined. | 334 // will be discarded at load time, leaving this preference undefined. |
310 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 335 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
311 pref_store_->GetValue(kProtectedAtomic, NULL)); | 336 pref_store_->GetValue(kProtectedAtomic, NULL)); |
312 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 337 VerifyResetRecorded( |
313 WasResetRecorded()); | 338 ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking); |
314 | 339 |
315 ExpectValidationObserved(kTrackedAtomic); | 340 ExpectValidationObserved(kTrackedAtomic); |
316 ExpectValidationObserved(kProtectedAtomic); | 341 ExpectValidationObserved(kProtectedAtomic); |
317 } | 342 } |
318 | 343 |
319 TEST_F(ProfilePrefStoreManagerTest, MigrateFromOneFile) { | 344 TEST_F(ProfilePrefStoreManagerTest, MigrateFromOneFile) { |
320 InitializeDeprecatedCombinedProfilePrefStore(); | 345 InitializeDeprecatedCombinedProfilePrefStore(); |
321 | 346 |
322 // The deprecated model stores hashes in local state (on supported | 347 // The deprecated model stores hashes in local state (on supported |
323 // platforms).. | 348 // platforms).. |
324 ASSERT_EQ( | 349 ASSERT_EQ( |
325 ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 350 ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
326 local_state_.GetUserPrefValue( | 351 local_state_.GetUserPrefValue( |
327 PrefServiceHashStoreContents::kProfilePreferenceHashes) != NULL); | 352 PrefServiceHashStoreContents::kProfilePreferenceHashes) != NULL); |
328 | 353 |
329 LoadExistingPrefs(); | 354 LoadExistingPrefs(); |
330 | 355 |
331 // After a first migration, the hashes were copied to the two user preference | 356 // After a first migration, the hashes were copied to the two user preference |
332 // files but were not cleaned. | 357 // files but were not cleaned. |
333 ASSERT_EQ( | 358 ASSERT_EQ( |
334 ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 359 ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
335 local_state_.GetUserPrefValue( | 360 local_state_.GetUserPrefValue( |
336 PrefServiceHashStoreContents::kProfilePreferenceHashes) != NULL); | 361 PrefServiceHashStoreContents::kProfilePreferenceHashes) != NULL); |
337 | 362 |
338 ExpectStringValueEquals(kTrackedAtomic, kFoobar); | 363 ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
339 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 364 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
340 EXPECT_FALSE(WasResetRecorded()); | 365 VerifyResetRecorded(false); |
341 | 366 |
342 LoadExistingPrefs(); | 367 LoadExistingPrefs(); |
343 | 368 |
344 // In a subsequent launch, the local state hash store should be reset. | 369 // In a subsequent launch, the local state hash store should be reset. |
345 ASSERT_FALSE(local_state_.GetUserPrefValue( | 370 ASSERT_FALSE(local_state_.GetUserPrefValue( |
346 PrefServiceHashStoreContents::kProfilePreferenceHashes)); | 371 PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
347 | 372 |
348 ExpectStringValueEquals(kTrackedAtomic, kFoobar); | 373 ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
349 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 374 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
350 EXPECT_FALSE(WasResetRecorded()); | 375 VerifyResetRecorded(false); |
351 } | 376 } |
352 | 377 |
353 TEST_F(ProfilePrefStoreManagerTest, MigrateWithTampering) { | 378 TEST_F(ProfilePrefStoreManagerTest, MigrateWithTampering) { |
354 InitializeDeprecatedCombinedProfilePrefStore(); | 379 InitializeDeprecatedCombinedProfilePrefStore(); |
355 | 380 |
356 ReplaceStringInPrefs(kFoobar, kBarfoo); | 381 ReplaceStringInPrefs(kFoobar, kBarfoo); |
357 ReplaceStringInPrefs(kHelloWorld, kGoodbyeWorld); | 382 ReplaceStringInPrefs(kHelloWorld, kGoodbyeWorld); |
358 | 383 |
359 // The deprecated model stores hashes in local state (on supported | 384 // The deprecated model stores hashes in local state (on supported |
360 // platforms).. | 385 // platforms).. |
(...skipping 12 matching lines...) Expand all Loading... |
373 PrefServiceHashStoreContents::kProfilePreferenceHashes) != NULL); | 398 PrefServiceHashStoreContents::kProfilePreferenceHashes) != NULL); |
374 | 399 |
375 // kTrackedAtomic is unprotected and thus will be loaded as it appears on | 400 // kTrackedAtomic is unprotected and thus will be loaded as it appears on |
376 // disk. | 401 // disk. |
377 ExpectStringValueEquals(kTrackedAtomic, kBarfoo); | 402 ExpectStringValueEquals(kTrackedAtomic, kBarfoo); |
378 | 403 |
379 // If preference tracking is supported, the tampered value of kProtectedAtomic | 404 // If preference tracking is supported, the tampered value of kProtectedAtomic |
380 // will be discarded at load time, leaving this preference undefined. | 405 // will be discarded at load time, leaving this preference undefined. |
381 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 406 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
382 pref_store_->GetValue(kProtectedAtomic, NULL)); | 407 pref_store_->GetValue(kProtectedAtomic, NULL)); |
383 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 408 VerifyResetRecorded( |
384 WasResetRecorded()); | 409 ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking); |
385 | 410 |
386 LoadExistingPrefs(); | 411 LoadExistingPrefs(); |
387 | 412 |
388 // In a subsequent launch, the local state hash store would be reset. | 413 // In a subsequent launch, the local state hash store would be reset. |
389 ASSERT_FALSE(local_state_.GetUserPrefValue( | 414 ASSERT_FALSE(local_state_.GetUserPrefValue( |
390 PrefServiceHashStoreContents::kProfilePreferenceHashes)); | 415 PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
391 | 416 |
392 ExpectStringValueEquals(kTrackedAtomic, kBarfoo); | 417 ExpectStringValueEquals(kTrackedAtomic, kBarfoo); |
393 EXPECT_FALSE(WasResetRecorded()); | 418 VerifyResetRecorded(false); |
394 } | 419 } |
395 | 420 |
396 TEST_F(ProfilePrefStoreManagerTest, InitializePrefsFromMasterPrefs) { | 421 TEST_F(ProfilePrefStoreManagerTest, InitializePrefsFromMasterPrefs) { |
397 base::DictionaryValue master_prefs; | 422 base::DictionaryValue master_prefs; |
398 master_prefs.Set(kTrackedAtomic, new base::StringValue(kFoobar)); | 423 master_prefs.Set(kTrackedAtomic, new base::StringValue(kFoobar)); |
399 master_prefs.Set(kProtectedAtomic, new base::StringValue(kHelloWorld)); | 424 master_prefs.Set(kProtectedAtomic, new base::StringValue(kHelloWorld)); |
400 EXPECT_TRUE(manager_->InitializePrefsFromMasterPrefs(master_prefs)); | 425 EXPECT_TRUE(manager_->InitializePrefsFromMasterPrefs(master_prefs)); |
401 | 426 |
402 LoadExistingPrefs(); | 427 LoadExistingPrefs(); |
403 | 428 |
404 // Verify that InitializePrefsFromMasterPrefs correctly applied the MACs | 429 // Verify that InitializePrefsFromMasterPrefs correctly applied the MACs |
405 // necessary to authenticate these values. | 430 // necessary to authenticate these values. |
406 ExpectStringValueEquals(kTrackedAtomic, kFoobar); | 431 ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
407 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 432 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
408 EXPECT_FALSE(WasResetRecorded()); | 433 VerifyResetRecorded(false); |
409 } | 434 } |
410 | 435 |
411 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) { | 436 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) { |
412 InitializePrefs(); | 437 InitializePrefs(); |
413 | 438 |
414 ExpectValidationObserved(kTrackedAtomic); | 439 ExpectValidationObserved(kTrackedAtomic); |
415 ExpectValidationObserved(kProtectedAtomic); | 440 ExpectValidationObserved(kProtectedAtomic); |
416 | 441 |
417 LoadExistingPrefs(); | 442 LoadExistingPrefs(); |
418 ExpectStringValueEquals(kUnprotectedPref, kFoobar); | 443 ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
(...skipping 13 matching lines...) Expand all Loading... |
432 PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; | 457 PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; |
433 configuration_.push_back(new_protected); | 458 configuration_.push_back(new_protected); |
434 ReloadConfiguration(); | 459 ReloadConfiguration(); |
435 | 460 |
436 // And try loading with the new configuration. | 461 // And try loading with the new configuration. |
437 LoadExistingPrefs(); | 462 LoadExistingPrefs(); |
438 | 463 |
439 // Since there was a valid super MAC we were able to extend the existing trust | 464 // Since there was a valid super MAC we were able to extend the existing trust |
440 // to the newly protected preference. | 465 // to the newly protected preference. |
441 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); | 466 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); |
442 EXPECT_FALSE(WasResetRecorded()); | 467 VerifyResetRecorded(false); |
443 | 468 |
444 // Ensure everything is written out to disk. | 469 // Ensure everything is written out to disk. |
445 DestroyPrefStore(); | 470 DestroyPrefStore(); |
446 | 471 |
447 // It's protected now, so (if the platform supports it) any tampering should | 472 // It's protected now, so (if the platform supports it) any tampering should |
448 // lead to a reset. | 473 // lead to a reset. |
449 ReplaceStringInPrefs(kBarfoo, kFoobar); | 474 ReplaceStringInPrefs(kBarfoo, kFoobar); |
450 LoadExistingPrefs(); | 475 LoadExistingPrefs(); |
451 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 476 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
452 pref_store_->GetValue(kUnprotectedPref, NULL)); | 477 pref_store_->GetValue(kUnprotectedPref, NULL)); |
453 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 478 VerifyResetRecorded( |
454 WasResetRecorded()); | 479 ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking); |
455 } | 480 } |
456 | 481 |
457 TEST_F(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { | 482 TEST_F(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { |
458 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 483 std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
459 original_configuration = configuration_; | 484 original_configuration = configuration_; |
460 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = | 485 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = |
461 configuration_.begin(); | 486 configuration_.begin(); |
462 it != configuration_.end(); | 487 it != configuration_.end(); |
463 ++it) { | 488 ++it) { |
464 it->enforcement_level = PrefHashFilter::NO_ENFORCEMENT; | 489 it->enforcement_level = PrefHashFilter::NO_ENFORCEMENT; |
(...skipping 18 matching lines...) Expand all Loading... |
483 PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; | 508 PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; |
484 configuration_.push_back(new_protected); | 509 configuration_.push_back(new_protected); |
485 ReloadConfiguration(); | 510 ReloadConfiguration(); |
486 | 511 |
487 // And try loading with the new configuration. | 512 // And try loading with the new configuration. |
488 LoadExistingPrefs(); | 513 LoadExistingPrefs(); |
489 | 514 |
490 // Since there was a valid super MAC we were able to extend the existing trust | 515 // Since there was a valid super MAC we were able to extend the existing trust |
491 // to the newly tracked & protected preference. | 516 // to the newly tracked & protected preference. |
492 ExpectStringValueEquals(kUnprotectedPref, kFoobar); | 517 ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
493 EXPECT_FALSE(WasResetRecorded()); | 518 VerifyResetRecorded(false); |
494 } | 519 } |
495 | 520 |
496 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { | 521 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { |
497 InitializePrefs(); | 522 InitializePrefs(); |
498 | 523 |
499 ExpectValidationObserved(kTrackedAtomic); | 524 ExpectValidationObserved(kTrackedAtomic); |
500 ExpectValidationObserved(kProtectedAtomic); | 525 ExpectValidationObserved(kProtectedAtomic); |
501 | 526 |
502 // Now update the configuration to protect it. | 527 // Now update the configuration to protect it. |
503 PrefHashFilter::TrackedPreferenceMetadata new_protected = { | 528 PrefHashFilter::TrackedPreferenceMetadata new_protected = { |
504 kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD, | 529 kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD, |
505 PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; | 530 PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; |
506 configuration_.push_back(new_protected); | 531 configuration_.push_back(new_protected); |
507 seed_ = "new-seed-to-break-trust"; | 532 seed_ = "new-seed-to-break-trust"; |
508 ReloadConfiguration(); | 533 ReloadConfiguration(); |
509 | 534 |
510 // And try loading with the new configuration. | 535 // And try loading with the new configuration. |
511 LoadExistingPrefs(); | 536 LoadExistingPrefs(); |
512 | 537 |
513 // If preference tracking is supported, kUnprotectedPref will have been | 538 // If preference tracking is supported, kUnprotectedPref will have been |
514 // discarded because new values are not accepted without a valid super MAC. | 539 // discarded because new values are not accepted without a valid super MAC. |
515 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 540 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
516 pref_store_->GetValue(kUnprotectedPref, NULL)); | 541 pref_store_->GetValue(kUnprotectedPref, NULL)); |
517 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, | 542 VerifyResetRecorded( |
518 WasResetRecorded()); | 543 ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking); |
519 } | 544 } |
520 | 545 |
521 // This test verifies that preference values are correctly maintained when a | 546 // This test verifies that preference values are correctly maintained when a |
522 // preference's protection state changes from protected to unprotected. | 547 // preference's protection state changes from protected to unprotected. |
523 TEST_F(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { | 548 TEST_F(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { |
524 InitializePrefs(); | 549 InitializePrefs(); |
525 | 550 |
526 ExpectValidationObserved(kTrackedAtomic); | 551 ExpectValidationObserved(kTrackedAtomic); |
527 ExpectValidationObserved(kProtectedAtomic); | 552 ExpectValidationObserved(kProtectedAtomic); |
528 | 553 |
529 DestroyPrefStore(); | 554 DestroyPrefStore(); |
530 | 555 |
531 // Unconfigure protection for kProtectedAtomic | 556 // Unconfigure protection for kProtectedAtomic |
532 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = | 557 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = |
533 configuration_.begin(); | 558 configuration_.begin(); |
534 it != configuration_.end(); | 559 it != configuration_.end(); |
535 ++it) { | 560 ++it) { |
536 if (it->name == kProtectedAtomic) { | 561 if (it->name == kProtectedAtomic) { |
537 it->enforcement_level = PrefHashFilter::NO_ENFORCEMENT; | 562 it->enforcement_level = PrefHashFilter::NO_ENFORCEMENT; |
538 break; | 563 break; |
539 } | 564 } |
540 } | 565 } |
541 | 566 |
542 seed_ = "new-seed-to-break-trust"; | 567 seed_ = "new-seed-to-break-trust"; |
543 ReloadConfiguration(); | 568 ReloadConfiguration(); |
544 LoadExistingPrefs(); | 569 LoadExistingPrefs(); |
545 | 570 |
546 // Verify that the value was not reset. | 571 // Verify that the value was not reset. |
547 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 572 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
548 EXPECT_FALSE(WasResetRecorded()); | 573 VerifyResetRecorded(false); |
549 | 574 |
550 // Accessing the value of the previously protected pref didn't trigger its | 575 // Accessing the value of the previously protected pref didn't trigger its |
551 // move to the unprotected preferences file, though the loading of the pref | 576 // move to the unprotected preferences file, though the loading of the pref |
552 // store should still have caused the MAC store to be recalculated. | 577 // store should still have caused the MAC store to be recalculated. |
553 LoadExistingPrefs(); | 578 LoadExistingPrefs(); |
554 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 579 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
555 | 580 |
556 // Trigger the logic that migrates it back to the unprotected preferences | 581 // Trigger the logic that migrates it back to the unprotected preferences |
557 // file. | 582 // file. |
558 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld)); | 583 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld)); |
559 LoadExistingPrefs(); | 584 LoadExistingPrefs(); |
560 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); | 585 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); |
561 EXPECT_FALSE(WasResetRecorded()); | 586 VerifyResetRecorded(false); |
562 } | 587 } |
OLD | NEW |