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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "base/threading/sequenced_worker_pool.h" | 25 #include "base/threading/sequenced_worker_pool.h" |
26 #include "base/values.h" | 26 #include "base/values.h" |
27 #include "chrome/common/chrome_features.h" | 27 #include "chrome/common/chrome_features.h" |
28 #include "components/pref_registry/pref_registry_syncable.h" | 28 #include "components/pref_registry/pref_registry_syncable.h" |
29 #include "components/prefs/json_pref_store.h" | 29 #include "components/prefs/json_pref_store.h" |
30 #include "components/prefs/persistent_pref_store.h" | 30 #include "components/prefs/persistent_pref_store.h" |
31 #include "components/prefs/pref_service.h" | 31 #include "components/prefs/pref_service.h" |
32 #include "components/prefs/pref_service_factory.h" | 32 #include "components/prefs/pref_service_factory.h" |
33 #include "components/prefs/pref_store.h" | 33 #include "components/prefs/pref_store.h" |
34 #include "components/prefs/testing_pref_service.h" | 34 #include "components/prefs/testing_pref_service.h" |
35 #include "components/user_prefs/tracked/mock_validation_delegate.h" | |
36 #include "components/user_prefs/tracked/pref_hash_filter.h" | |
37 #include "components/user_prefs/tracked/pref_names.h" | |
38 #include "content/public/common/service_names.mojom.h" | 35 #include "content/public/common/service_names.mojom.h" |
39 #include "services/preferences/public/cpp/pref_service_main.h" | 36 #include "services/preferences/public/cpp/pref_service_main.h" |
37 #include "services/preferences/public/cpp/tracked/configuration.h" | |
38 #include "services/preferences/public/cpp/tracked/mock_validation_delegate.h" | |
39 #include "services/preferences/public/cpp/tracked/pref_names.h" | |
40 #include "services/preferences/public/interfaces/preferences.mojom.h" | 40 #include "services/preferences/public/interfaces/preferences.mojom.h" |
41 #include "services/service_manager/public/cpp/connector.h" | 41 #include "services/service_manager/public/cpp/connector.h" |
42 #include "services/service_manager/public/cpp/service_context.h" | 42 #include "services/service_manager/public/cpp/service_context.h" |
43 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
47 using EnforcementLevel = | |
48 prefs::mojom::TrackedPreferenceMetadata::EnforcementLevel; | |
49 using PrefTrackingStrategy = | |
50 prefs::mojom::TrackedPreferenceMetadata::PrefTrackingStrategy; | |
51 using ValueType = prefs::mojom::TrackedPreferenceMetadata::ValueType; | |
52 | |
47 class FirstEqualsPredicate { | 53 class FirstEqualsPredicate { |
48 public: | 54 public: |
49 explicit FirstEqualsPredicate(const std::string& expected) | 55 explicit FirstEqualsPredicate(const std::string& expected) |
50 : expected_(expected) {} | 56 : expected_(expected) {} |
51 bool operator()(const PrefValueMap::Map::value_type& pair) { | 57 bool operator()(const PrefValueMap::Map::value_type& pair) { |
52 return pair.first == expected_; | 58 return pair.first == expected_; |
53 } | 59 } |
54 | 60 |
55 private: | 61 private: |
56 const std::string expected_; | 62 const std::string expected_; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 | 119 |
114 const char kUnprotectedPref[] = "unprotected_pref"; | 120 const char kUnprotectedPref[] = "unprotected_pref"; |
115 const char kTrackedAtomic[] = "tracked_atomic"; | 121 const char kTrackedAtomic[] = "tracked_atomic"; |
116 const char kProtectedAtomic[] = "protected_atomic"; | 122 const char kProtectedAtomic[] = "protected_atomic"; |
117 | 123 |
118 const char kFoobar[] = "FOOBAR"; | 124 const char kFoobar[] = "FOOBAR"; |
119 const char kBarfoo[] = "BARFOO"; | 125 const char kBarfoo[] = "BARFOO"; |
120 const char kHelloWorld[] = "HELLOWORLD"; | 126 const char kHelloWorld[] = "HELLOWORLD"; |
121 const char kGoodbyeWorld[] = "GOODBYEWORLD"; | 127 const char kGoodbyeWorld[] = "GOODBYEWORLD"; |
122 | 128 |
123 const PrefHashFilter::TrackedPreferenceMetadata kConfiguration[] = { | 129 const prefs::TrackedPreferenceMetadata kConfiguration[] = { |
124 {0u, kTrackedAtomic, PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT, | 130 {0u, kTrackedAtomic, EnforcementLevel::NO_ENFORCEMENT, |
125 PrefHashFilter::PrefTrackingStrategy::ATOMIC}, | 131 PrefTrackingStrategy::ATOMIC}, |
126 {1u, kProtectedAtomic, PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 132 {1u, kProtectedAtomic, EnforcementLevel::ENFORCE_ON_LOAD, |
127 PrefHashFilter::PrefTrackingStrategy::ATOMIC}}; | 133 PrefTrackingStrategy::ATOMIC}}; |
128 | 134 |
129 const size_t kExtraReportingId = 2u; | 135 const size_t kExtraReportingId = 2u; |
130 const size_t kReportingIdCount = 3u; | 136 const size_t kReportingIdCount = 3u; |
131 | 137 |
132 } // namespace | 138 } // namespace |
133 | 139 |
134 class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> { | 140 class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> { |
135 public: | 141 public: |
136 ProfilePrefStoreManagerTest() | 142 ProfilePrefStoreManagerTest() |
137 : configuration_(kConfiguration, | 143 : configuration_(prefs::ConstructTrackedConfiguration(kConfiguration)), |
138 kConfiguration + arraysize(kConfiguration)), | |
139 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), | 144 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), |
140 registry_verifier_(profile_pref_registry_.get()), | 145 registry_verifier_(profile_pref_registry_.get()), |
141 seed_("seed"), | 146 seed_("seed"), |
142 reset_recorded_(false) {} | 147 reset_recorded_(false) {} |
143 | 148 |
144 void SetUp() override { | 149 void SetUp() override { |
145 worker_pool_ = base::MakeUnique<base::SequencedWorkerPoolOwner>( | 150 worker_pool_ = base::MakeUnique<base::SequencedWorkerPoolOwner>( |
146 2, "ProfilePrefStoreManagerTest"); | 151 2, "ProfilePrefStoreManagerTest"); |
147 if (GetParam()) { | 152 if (GetParam()) { |
148 feature_list_.InitAndEnableFeature(features::kPrefService); | 153 feature_list_.InitAndEnableFeature(features::kPrefService); |
(...skipping 14 matching lines...) Expand all Loading... | |
163 prefs::mojom::kPrefStoreServiceName, | 168 prefs::mojom::kPrefStoreServiceName, |
164 prefs::mojom::PrefServiceControl::Name_, | 169 prefs::mojom::PrefServiceControl::Name_, |
165 base::Bind(&ProfilePrefStoreManagerTest::BindInterface, | 170 base::Bind(&ProfilePrefStoreManagerTest::BindInterface, |
166 base::Unretained(this), | 171 base::Unretained(this), |
167 prefs::mojom::PrefServiceControl::Name_)); | 172 prefs::mojom::PrefServiceControl::Name_)); |
168 } else { | 173 } else { |
169 feature_list_.InitAndDisableFeature(features::kPrefService); | 174 feature_list_.InitAndDisableFeature(features::kPrefService); |
170 } | 175 } |
171 mock_validation_delegate_record_ = new MockValidationDelegateRecord; | 176 mock_validation_delegate_record_ = new MockValidationDelegateRecord; |
172 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_.get()); | 177 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_.get()); |
173 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; | 178 for (const prefs::TrackedPreferenceMetadata* it = kConfiguration; |
174 it != kConfiguration + arraysize(kConfiguration); | 179 it != kConfiguration + arraysize(kConfiguration); ++it) { |
175 ++it) { | 180 if (it->strategy == PrefTrackingStrategy::ATOMIC) { |
176 if (it->strategy == PrefHashFilter::PrefTrackingStrategy::ATOMIC) { | |
177 profile_pref_registry_->RegisterStringPref(it->name, std::string()); | 181 profile_pref_registry_->RegisterStringPref(it->name, std::string()); |
178 } else { | 182 } else { |
179 profile_pref_registry_->RegisterDictionaryPref(it->name); | 183 profile_pref_registry_->RegisterDictionaryPref(it->name); |
180 } | 184 } |
181 } | 185 } |
182 profile_pref_registry_->RegisterStringPref(kUnprotectedPref, std::string()); | 186 profile_pref_registry_->RegisterStringPref(kUnprotectedPref, std::string()); |
183 | 187 |
184 // As in chrome_pref_service_factory.cc, kPreferencesResetTime needs to be | 188 // As in chrome_pref_service_factory.cc, kPreferencesResetTime needs to be |
185 // declared as protected in order to be read from the proper store by the | 189 // declared as protected in order to be read from the proper store by the |
186 // SegregatedPrefStore. Only declare it after configured prefs have been | 190 // SegregatedPrefStore. Only declare it after configured prefs have been |
187 // registered above for this test as kPreferenceResetTime is already | 191 // registered above for this test as kPreferenceResetTime is already |
188 // registered in ProfilePrefStoreManager::RegisterProfilePrefs. | 192 // registered in ProfilePrefStoreManager::RegisterProfilePrefs. |
189 PrefHashFilter::TrackedPreferenceMetadata pref_reset_time_config = { | 193 prefs::TrackedPreferenceMetadata pref_reset_time_config = { |
190 configuration_.rbegin()->reporting_id + 1, | 194 (*configuration_.rbegin())->reporting_id + 1, |
191 user_prefs::kPreferenceResetTime, | 195 user_prefs::kPreferenceResetTime, EnforcementLevel::ENFORCE_ON_LOAD, |
192 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 196 PrefTrackingStrategy::ATOMIC}; |
193 PrefHashFilter::PrefTrackingStrategy::ATOMIC}; | 197 configuration_.push_back( |
194 configuration_.push_back(pref_reset_time_config); | 198 prefs::ConstructTrackedMetadata(pref_reset_time_config)); |
195 | 199 |
196 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 200 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
197 ReloadConfiguration(); | 201 ReloadConfiguration(); |
198 } | 202 } |
199 | 203 |
200 void ReloadConfiguration() { | 204 void ReloadConfiguration() { |
201 RelaunchPrefService(); | 205 RelaunchPrefService(); |
202 manager_.reset(new ProfilePrefStoreManager( | 206 manager_.reset(new ProfilePrefStoreManager( |
203 profile_dir_.GetPath(), configuration_, kReportingIdCount, seed_, | 207 profile_dir_.GetPath(), |
204 "device_id", &local_state_)); | 208 prefs::CloneTrackedConfiguration(configuration_), kReportingIdCount, |
209 seed_, "device_id", &local_state_)); | |
205 } | 210 } |
206 | 211 |
207 void TearDown() override { | 212 void TearDown() override { |
208 DestroyPrefStore(); | 213 DestroyPrefStore(); |
209 if (GetParam()) { | 214 if (GetParam()) { |
210 connector_.reset(); | 215 connector_.reset(); |
211 pref_service_context_.reset(); | 216 pref_service_context_.reset(); |
212 } | 217 } |
213 worker_pool_.reset(); | 218 worker_pool_.reset(); |
214 } | 219 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 | 374 |
370 void ExpectValidationObserved(const std::string& pref_path) { | 375 void ExpectValidationObserved(const std::string& pref_path) { |
371 // No validations are expected for platforms that do not support tracking. | 376 // No validations are expected for platforms that do not support tracking. |
372 if (!SupportsPreferenceTracking()) | 377 if (!SupportsPreferenceTracking()) |
373 return; | 378 return; |
374 if (!mock_validation_delegate_record_->GetEventForPath(pref_path)) | 379 if (!mock_validation_delegate_record_->GetEventForPath(pref_path)) |
375 ADD_FAILURE() << "No validation observed for preference: " << pref_path; | 380 ADD_FAILURE() << "No validation observed for preference: " << pref_path; |
376 } | 381 } |
377 | 382 |
378 base::MessageLoop main_message_loop_; | 383 base::MessageLoop main_message_loop_; |
379 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; | 384 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> configuration_; |
380 base::ScopedTempDir profile_dir_; | 385 base::ScopedTempDir profile_dir_; |
381 TestingPrefServiceSimple local_state_; | 386 TestingPrefServiceSimple local_state_; |
382 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; | 387 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; |
383 RegistryVerifier registry_verifier_; | 388 RegistryVerifier registry_verifier_; |
384 scoped_refptr<MockValidationDelegateRecord> mock_validation_delegate_record_; | 389 scoped_refptr<MockValidationDelegateRecord> mock_validation_delegate_record_; |
385 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> | 390 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> |
386 mock_validation_delegate_; | 391 mock_validation_delegate_; |
387 std::unique_ptr<ProfilePrefStoreManager> manager_; | 392 std::unique_ptr<ProfilePrefStoreManager> manager_; |
388 scoped_refptr<PersistentPrefStore> pref_store_; | 393 scoped_refptr<PersistentPrefStore> pref_store_; |
389 | 394 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 // Ensure everything is written out to disk. | 484 // Ensure everything is written out to disk. |
480 DestroyPrefStore(); | 485 DestroyPrefStore(); |
481 | 486 |
482 ReplaceStringInPrefs(kFoobar, kBarfoo); | 487 ReplaceStringInPrefs(kFoobar, kBarfoo); |
483 | 488 |
484 // It's unprotected, so we can load the modified value. | 489 // It's unprotected, so we can load the modified value. |
485 LoadExistingPrefs(); | 490 LoadExistingPrefs(); |
486 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); | 491 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); |
487 | 492 |
488 // Now update the configuration to protect it. | 493 // Now update the configuration to protect it. |
489 PrefHashFilter::TrackedPreferenceMetadata new_protected = { | 494 prefs::TrackedPreferenceMetadata new_protected = { |
490 kExtraReportingId, kUnprotectedPref, | 495 kExtraReportingId, kUnprotectedPref, EnforcementLevel::ENFORCE_ON_LOAD, |
491 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 496 PrefTrackingStrategy::ATOMIC}; |
492 PrefHashFilter::PrefTrackingStrategy::ATOMIC}; | 497 configuration_.push_back(prefs::ConstructTrackedMetadata(new_protected)); |
493 configuration_.push_back(new_protected); | |
494 ReloadConfiguration(); | 498 ReloadConfiguration(); |
495 | 499 |
496 // And try loading with the new configuration. | 500 // And try loading with the new configuration. |
497 LoadExistingPrefs(); | 501 LoadExistingPrefs(); |
498 | 502 |
499 // Since there was a valid super MAC we were able to extend the existing trust | 503 // Since there was a valid super MAC we were able to extend the existing trust |
500 // to the newly protected preference. | 504 // to the newly protected preference. |
501 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); | 505 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); |
502 VerifyResetRecorded(false); | 506 VerifyResetRecorded(false); |
503 | 507 |
504 // Ensure everything is written out to disk. | 508 // Ensure everything is written out to disk. |
505 DestroyPrefStore(); | 509 DestroyPrefStore(); |
506 | 510 |
507 // It's protected now, so (if the platform supports it) any tampering should | 511 // It's protected now, so (if the platform supports it) any tampering should |
508 // lead to a reset. | 512 // lead to a reset. |
509 ReplaceStringInPrefs(kBarfoo, kFoobar); | 513 ReplaceStringInPrefs(kBarfoo, kFoobar); |
510 LoadExistingPrefs(); | 514 LoadExistingPrefs(); |
511 EXPECT_NE(SupportsPreferenceTracking(), | 515 EXPECT_NE(SupportsPreferenceTracking(), |
512 pref_store_->GetValue(kUnprotectedPref, NULL)); | 516 pref_store_->GetValue(kUnprotectedPref, NULL)); |
513 VerifyResetRecorded(SupportsPreferenceTracking()); | 517 VerifyResetRecorded(SupportsPreferenceTracking()); |
514 } | 518 } |
515 | 519 |
516 TEST_P(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { | 520 TEST_P(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { |
517 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 521 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> |
518 original_configuration = configuration_; | 522 original_configuration = prefs::CloneTrackedConfiguration(configuration_); |
519 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = | 523 for (const auto& metadata : configuration_) { |
520 configuration_.begin(); | 524 metadata->enforcement_level = EnforcementLevel::NO_ENFORCEMENT; |
521 it != configuration_.end(); | |
522 ++it) { | |
523 it->enforcement_level = PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT; | |
524 } | 525 } |
525 ReloadConfiguration(); | 526 ReloadConfiguration(); |
526 | 527 |
527 InitializePrefs(); | 528 InitializePrefs(); |
528 | 529 |
529 ExpectValidationObserved(kTrackedAtomic); | 530 ExpectValidationObserved(kTrackedAtomic); |
530 ExpectValidationObserved(kProtectedAtomic); | 531 ExpectValidationObserved(kProtectedAtomic); |
531 | 532 |
532 LoadExistingPrefs(); | 533 LoadExistingPrefs(); |
533 ExpectStringValueEquals(kUnprotectedPref, kFoobar); | 534 ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
534 | 535 |
535 // Ensure everything is written out to disk. | 536 // Ensure everything is written out to disk. |
536 DestroyPrefStore(); | 537 DestroyPrefStore(); |
537 | 538 |
538 // Now introduce protection, including the never-before tracked "new_pref". | 539 // Now introduce protection, including the never-before tracked "new_pref". |
539 configuration_ = original_configuration; | 540 configuration_ = std::move(original_configuration); |
540 PrefHashFilter::TrackedPreferenceMetadata new_protected = { | 541 prefs::TrackedPreferenceMetadata new_protected = { |
541 kExtraReportingId, kUnprotectedPref, | 542 kExtraReportingId, kUnprotectedPref, EnforcementLevel::ENFORCE_ON_LOAD, |
542 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 543 PrefTrackingStrategy::ATOMIC}; |
543 PrefHashFilter::PrefTrackingStrategy::ATOMIC}; | 544 configuration_.push_back(prefs::ConstructTrackedMetadata(new_protected)); |
544 configuration_.push_back(new_protected); | |
545 ReloadConfiguration(); | 545 ReloadConfiguration(); |
546 | 546 |
547 // And try loading with the new configuration. | 547 // And try loading with the new configuration. |
548 LoadExistingPrefs(); | 548 LoadExistingPrefs(); |
549 | 549 |
550 // Since there was a valid super MAC we were able to extend the existing trust | 550 // Since there was a valid super MAC we were able to extend the existing trust |
551 // to the newly tracked & protected preference. | 551 // to the newly tracked & protected preference. |
552 ExpectStringValueEquals(kUnprotectedPref, kFoobar); | 552 ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
553 VerifyResetRecorded(false); | 553 VerifyResetRecorded(false); |
554 } | 554 } |
555 | 555 |
556 TEST_P(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { | 556 TEST_P(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { |
557 InitializePrefs(); | 557 InitializePrefs(); |
558 | 558 |
559 ExpectValidationObserved(kTrackedAtomic); | 559 ExpectValidationObserved(kTrackedAtomic); |
560 ExpectValidationObserved(kProtectedAtomic); | 560 ExpectValidationObserved(kProtectedAtomic); |
561 | 561 |
562 // Now update the configuration to protect it. | 562 // Now update the configuration to protect it. |
563 PrefHashFilter::TrackedPreferenceMetadata new_protected = { | 563 prefs::TrackedPreferenceMetadata new_protected = { |
564 kExtraReportingId, kUnprotectedPref, | 564 kExtraReportingId, kUnprotectedPref, EnforcementLevel::ENFORCE_ON_LOAD, |
565 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 565 PrefTrackingStrategy::ATOMIC}; |
566 PrefHashFilter::PrefTrackingStrategy::ATOMIC}; | 566 configuration_.push_back(prefs::ConstructTrackedMetadata(new_protected)); |
567 configuration_.push_back(new_protected); | |
568 seed_ = "new-seed-to-break-trust"; | 567 seed_ = "new-seed-to-break-trust"; |
569 ReloadConfiguration(); | 568 ReloadConfiguration(); |
570 | 569 |
571 // And try loading with the new configuration. | 570 // And try loading with the new configuration. |
572 LoadExistingPrefs(); | 571 LoadExistingPrefs(); |
573 | 572 |
574 // If preference tracking is supported, kUnprotectedPref will have been | 573 // If preference tracking is supported, kUnprotectedPref will have been |
575 // discarded because new values are not accepted without a valid super MAC. | 574 // discarded because new values are not accepted without a valid super MAC. |
576 EXPECT_NE(SupportsPreferenceTracking(), | 575 EXPECT_NE(SupportsPreferenceTracking(), |
577 pref_store_->GetValue(kUnprotectedPref, NULL)); | 576 pref_store_->GetValue(kUnprotectedPref, NULL)); |
578 VerifyResetRecorded(SupportsPreferenceTracking()); | 577 VerifyResetRecorded(SupportsPreferenceTracking()); |
579 } | 578 } |
580 | 579 |
581 // This test verifies that preference values are correctly maintained when a | 580 // This test verifies that preference values are correctly maintained when a |
582 // preference's protection state changes from protected to unprotected. | 581 // preference's protection state changes from protected to unprotected. |
583 TEST_P(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { | 582 TEST_P(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { |
584 InitializePrefs(); | 583 InitializePrefs(); |
585 | 584 |
586 ExpectValidationObserved(kTrackedAtomic); | 585 ExpectValidationObserved(kTrackedAtomic); |
587 ExpectValidationObserved(kProtectedAtomic); | 586 ExpectValidationObserved(kProtectedAtomic); |
588 | 587 |
589 DestroyPrefStore(); | 588 DestroyPrefStore(); |
590 | 589 |
591 // Unconfigure protection for kProtectedAtomic | 590 // Unconfigure protection for kProtectedAtomic |
592 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = | 591 for (const auto& metadata : configuration_) { |
593 configuration_.begin(); | 592 if (metadata->name == kProtectedAtomic) { |
594 it != configuration_.end(); | 593 metadata->enforcement_level = EnforcementLevel::NO_ENFORCEMENT; |
gab
2017/03/29 16:27:56
How does this compile when |metadata| is const&? I
Sam McNally
2017/03/30 02:23:22
Yes.
| |
595 ++it) { | |
596 if (it->name == kProtectedAtomic) { | |
597 it->enforcement_level = PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT; | |
598 break; | 594 break; |
599 } | 595 } |
600 } | 596 } |
601 | 597 |
602 seed_ = "new-seed-to-break-trust"; | 598 seed_ = "new-seed-to-break-trust"; |
603 ReloadConfiguration(); | 599 ReloadConfiguration(); |
604 LoadExistingPrefs(); | 600 LoadExistingPrefs(); |
605 | 601 |
606 // Verify that the value was not reset. | 602 // Verify that the value was not reset. |
607 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 603 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
(...skipping 11 matching lines...) Expand all Loading... | |
619 base::WrapUnique(new base::Value(kGoodbyeWorld)), | 615 base::WrapUnique(new base::Value(kGoodbyeWorld)), |
620 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 616 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
621 LoadExistingPrefs(); | 617 LoadExistingPrefs(); |
622 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); | 618 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); |
623 VerifyResetRecorded(false); | 619 VerifyResetRecorded(false); |
624 } | 620 } |
625 | 621 |
626 INSTANTIATE_TEST_CASE_P(ProfilePrefStoreManagerTest, | 622 INSTANTIATE_TEST_CASE_P(ProfilePrefStoreManagerTest, |
627 ProfilePrefStoreManagerTest, | 623 ProfilePrefStoreManagerTest, |
628 testing::Bool()); | 624 testing::Bool()); |
OLD | NEW |