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 12 matching lines...) Expand all Loading... |
161 test_api.OverrideBinderForTesting( | 166 test_api.OverrideBinderForTesting( |
162 prefs::mojom::kServiceName, prefs::mojom::PrefServiceControl::Name_, | 167 prefs::mojom::kServiceName, prefs::mojom::PrefServiceControl::Name_, |
163 base::Bind(&ProfilePrefStoreManagerTest::BindInterface, | 168 base::Bind(&ProfilePrefStoreManagerTest::BindInterface, |
164 base::Unretained(this), | 169 base::Unretained(this), |
165 prefs::mojom::PrefServiceControl::Name_)); | 170 prefs::mojom::PrefServiceControl::Name_)); |
166 } else { | 171 } else { |
167 feature_list_.InitAndDisableFeature(features::kPrefService); | 172 feature_list_.InitAndDisableFeature(features::kPrefService); |
168 } | 173 } |
169 mock_validation_delegate_record_ = new MockValidationDelegateRecord; | 174 mock_validation_delegate_record_ = new MockValidationDelegateRecord; |
170 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_.get()); | 175 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_.get()); |
171 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; | 176 for (const prefs::TrackedPreferenceMetadata* it = kConfiguration; |
172 it != kConfiguration + arraysize(kConfiguration); | 177 it != kConfiguration + arraysize(kConfiguration); ++it) { |
173 ++it) { | 178 if (it->strategy == PrefTrackingStrategy::ATOMIC) { |
174 if (it->strategy == PrefHashFilter::PrefTrackingStrategy::ATOMIC) { | |
175 profile_pref_registry_->RegisterStringPref(it->name, std::string()); | 179 profile_pref_registry_->RegisterStringPref(it->name, std::string()); |
176 } else { | 180 } else { |
177 profile_pref_registry_->RegisterDictionaryPref(it->name); | 181 profile_pref_registry_->RegisterDictionaryPref(it->name); |
178 } | 182 } |
179 } | 183 } |
180 profile_pref_registry_->RegisterStringPref(kUnprotectedPref, std::string()); | 184 profile_pref_registry_->RegisterStringPref(kUnprotectedPref, std::string()); |
181 | 185 |
182 // As in chrome_pref_service_factory.cc, kPreferencesResetTime needs to be | 186 // As in chrome_pref_service_factory.cc, kPreferencesResetTime needs to be |
183 // declared as protected in order to be read from the proper store by the | 187 // declared as protected in order to be read from the proper store by the |
184 // SegregatedPrefStore. Only declare it after configured prefs have been | 188 // SegregatedPrefStore. Only declare it after configured prefs have been |
185 // registered above for this test as kPreferenceResetTime is already | 189 // registered above for this test as kPreferenceResetTime is already |
186 // registered in ProfilePrefStoreManager::RegisterProfilePrefs. | 190 // registered in ProfilePrefStoreManager::RegisterProfilePrefs. |
187 PrefHashFilter::TrackedPreferenceMetadata pref_reset_time_config = { | 191 prefs::TrackedPreferenceMetadata pref_reset_time_config = { |
188 configuration_.rbegin()->reporting_id + 1, | 192 (*configuration_.rbegin())->reporting_id + 1, |
189 user_prefs::kPreferenceResetTime, | 193 user_prefs::kPreferenceResetTime, EnforcementLevel::ENFORCE_ON_LOAD, |
190 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 194 PrefTrackingStrategy::ATOMIC}; |
191 PrefHashFilter::PrefTrackingStrategy::ATOMIC}; | 195 configuration_.push_back( |
192 configuration_.push_back(pref_reset_time_config); | 196 prefs::ConstructTrackedMetadata(pref_reset_time_config)); |
193 | 197 |
194 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 198 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
195 ReloadConfiguration(); | 199 ReloadConfiguration(); |
196 } | 200 } |
197 | 201 |
198 void ReloadConfiguration() { | 202 void ReloadConfiguration() { |
199 RelaunchPrefService(); | 203 RelaunchPrefService(); |
200 manager_.reset(new ProfilePrefStoreManager( | 204 manager_.reset(new ProfilePrefStoreManager( |
201 profile_dir_.GetPath(), configuration_, kReportingIdCount, seed_, | 205 profile_dir_.GetPath(), |
202 "device_id", &local_state_)); | 206 prefs::CloneTrackedConfiguration(configuration_), kReportingIdCount, |
| 207 seed_, "device_id", &local_state_)); |
203 } | 208 } |
204 | 209 |
205 void TearDown() override { | 210 void TearDown() override { |
206 DestroyPrefStore(); | 211 DestroyPrefStore(); |
207 if (GetParam()) { | 212 if (GetParam()) { |
208 connector_.reset(); | 213 connector_.reset(); |
209 pref_service_context_.reset(); | 214 pref_service_context_.reset(); |
210 } | 215 } |
211 worker_pool_.reset(); | 216 worker_pool_.reset(); |
212 } | 217 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 base::RunLoop run_loop; | 320 base::RunLoop run_loop; |
316 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), | 321 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), |
317 worker_pool_->pool().get()) | 322 worker_pool_->pool().get()) |
318 ->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing), | 323 ->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing), |
319 run_loop.QuitClosure()); | 324 run_loop.QuitClosure()); |
320 run_loop.Run(); | 325 run_loop.Run(); |
321 } | 326 } |
322 | 327 |
323 void LoadExistingPrefs() { | 328 void LoadExistingPrefs() { |
324 DestroyPrefStore(); | 329 DestroyPrefStore(); |
| 330 // Constructing the PrefStore consumes the tracking configuration in |
| 331 // |manager_|, so recreate it before constructing another PrefStore. |
| 332 ReloadConfiguration(); |
325 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( | 333 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( |
326 mock_validation_delegate_record_); | 334 mock_validation_delegate_record_); |
327 pref_store_ = manager_->CreateProfilePrefStore( | 335 pref_store_ = manager_->CreateProfilePrefStore( |
328 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), | 336 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), |
329 worker_pool_->pool().get()), | 337 worker_pool_->pool().get()), |
330 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, | 338 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
331 base::Unretained(this)), | 339 base::Unretained(this)), |
332 mock_validation_delegate_.get(), connector_.get(), | 340 mock_validation_delegate_.get(), connector_.get(), |
333 profile_pref_registry_); | 341 profile_pref_registry_); |
334 pref_store_->AddObserver(®istry_verifier_); | 342 pref_store_->AddObserver(®istry_verifier_); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 375 |
368 void ExpectValidationObserved(const std::string& pref_path) { | 376 void ExpectValidationObserved(const std::string& pref_path) { |
369 // No validations are expected for platforms that do not support tracking. | 377 // No validations are expected for platforms that do not support tracking. |
370 if (!SupportsPreferenceTracking()) | 378 if (!SupportsPreferenceTracking()) |
371 return; | 379 return; |
372 if (!mock_validation_delegate_record_->GetEventForPath(pref_path)) | 380 if (!mock_validation_delegate_record_->GetEventForPath(pref_path)) |
373 ADD_FAILURE() << "No validation observed for preference: " << pref_path; | 381 ADD_FAILURE() << "No validation observed for preference: " << pref_path; |
374 } | 382 } |
375 | 383 |
376 base::MessageLoop main_message_loop_; | 384 base::MessageLoop main_message_loop_; |
377 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; | 385 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> configuration_; |
378 base::ScopedTempDir profile_dir_; | 386 base::ScopedTempDir profile_dir_; |
379 TestingPrefServiceSimple local_state_; | 387 TestingPrefServiceSimple local_state_; |
380 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; | 388 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; |
381 RegistryVerifier registry_verifier_; | 389 RegistryVerifier registry_verifier_; |
382 scoped_refptr<MockValidationDelegateRecord> mock_validation_delegate_record_; | 390 scoped_refptr<MockValidationDelegateRecord> mock_validation_delegate_record_; |
383 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> | 391 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> |
384 mock_validation_delegate_; | 392 mock_validation_delegate_; |
385 std::unique_ptr<ProfilePrefStoreManager> manager_; | 393 std::unique_ptr<ProfilePrefStoreManager> manager_; |
386 scoped_refptr<PersistentPrefStore> pref_store_; | 394 scoped_refptr<PersistentPrefStore> pref_store_; |
387 | 395 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 // Ensure everything is written out to disk. | 485 // Ensure everything is written out to disk. |
478 DestroyPrefStore(); | 486 DestroyPrefStore(); |
479 | 487 |
480 ReplaceStringInPrefs(kFoobar, kBarfoo); | 488 ReplaceStringInPrefs(kFoobar, kBarfoo); |
481 | 489 |
482 // It's unprotected, so we can load the modified value. | 490 // It's unprotected, so we can load the modified value. |
483 LoadExistingPrefs(); | 491 LoadExistingPrefs(); |
484 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); | 492 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); |
485 | 493 |
486 // Now update the configuration to protect it. | 494 // Now update the configuration to protect it. |
487 PrefHashFilter::TrackedPreferenceMetadata new_protected = { | 495 prefs::TrackedPreferenceMetadata new_protected = { |
488 kExtraReportingId, kUnprotectedPref, | 496 kExtraReportingId, kUnprotectedPref, EnforcementLevel::ENFORCE_ON_LOAD, |
489 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 497 PrefTrackingStrategy::ATOMIC}; |
490 PrefHashFilter::PrefTrackingStrategy::ATOMIC}; | 498 configuration_.push_back(prefs::ConstructTrackedMetadata(new_protected)); |
491 configuration_.push_back(new_protected); | |
492 ReloadConfiguration(); | 499 ReloadConfiguration(); |
493 | 500 |
494 // And try loading with the new configuration. | 501 // And try loading with the new configuration. |
495 LoadExistingPrefs(); | 502 LoadExistingPrefs(); |
496 | 503 |
497 // Since there was a valid super MAC we were able to extend the existing trust | 504 // Since there was a valid super MAC we were able to extend the existing trust |
498 // to the newly protected preference. | 505 // to the newly protected preference. |
499 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); | 506 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); |
500 VerifyResetRecorded(false); | 507 VerifyResetRecorded(false); |
501 | 508 |
502 // Ensure everything is written out to disk. | 509 // Ensure everything is written out to disk. |
503 DestroyPrefStore(); | 510 DestroyPrefStore(); |
504 | 511 |
505 // It's protected now, so (if the platform supports it) any tampering should | 512 // It's protected now, so (if the platform supports it) any tampering should |
506 // lead to a reset. | 513 // lead to a reset. |
507 ReplaceStringInPrefs(kBarfoo, kFoobar); | 514 ReplaceStringInPrefs(kBarfoo, kFoobar); |
508 LoadExistingPrefs(); | 515 LoadExistingPrefs(); |
509 EXPECT_NE(SupportsPreferenceTracking(), | 516 EXPECT_NE(SupportsPreferenceTracking(), |
510 pref_store_->GetValue(kUnprotectedPref, NULL)); | 517 pref_store_->GetValue(kUnprotectedPref, NULL)); |
511 VerifyResetRecorded(SupportsPreferenceTracking()); | 518 VerifyResetRecorded(SupportsPreferenceTracking()); |
512 } | 519 } |
513 | 520 |
514 TEST_P(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { | 521 TEST_P(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { |
515 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 522 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> |
516 original_configuration = configuration_; | 523 original_configuration = prefs::CloneTrackedConfiguration(configuration_); |
517 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = | 524 for (const auto& metadata : configuration_) { |
518 configuration_.begin(); | 525 metadata->enforcement_level = EnforcementLevel::NO_ENFORCEMENT; |
519 it != configuration_.end(); | |
520 ++it) { | |
521 it->enforcement_level = PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT; | |
522 } | 526 } |
523 ReloadConfiguration(); | 527 ReloadConfiguration(); |
524 | 528 |
525 InitializePrefs(); | 529 InitializePrefs(); |
526 | 530 |
527 ExpectValidationObserved(kTrackedAtomic); | 531 ExpectValidationObserved(kTrackedAtomic); |
528 ExpectValidationObserved(kProtectedAtomic); | 532 ExpectValidationObserved(kProtectedAtomic); |
529 | 533 |
530 LoadExistingPrefs(); | 534 LoadExistingPrefs(); |
531 ExpectStringValueEquals(kUnprotectedPref, kFoobar); | 535 ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
532 | 536 |
533 // Ensure everything is written out to disk. | 537 // Ensure everything is written out to disk. |
534 DestroyPrefStore(); | 538 DestroyPrefStore(); |
535 | 539 |
536 // Now introduce protection, including the never-before tracked "new_pref". | 540 // Now introduce protection, including the never-before tracked "new_pref". |
537 configuration_ = original_configuration; | 541 configuration_ = std::move(original_configuration); |
538 PrefHashFilter::TrackedPreferenceMetadata new_protected = { | 542 prefs::TrackedPreferenceMetadata new_protected = { |
539 kExtraReportingId, kUnprotectedPref, | 543 kExtraReportingId, kUnprotectedPref, EnforcementLevel::ENFORCE_ON_LOAD, |
540 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 544 PrefTrackingStrategy::ATOMIC}; |
541 PrefHashFilter::PrefTrackingStrategy::ATOMIC}; | 545 configuration_.push_back(prefs::ConstructTrackedMetadata(new_protected)); |
542 configuration_.push_back(new_protected); | |
543 ReloadConfiguration(); | 546 ReloadConfiguration(); |
544 | 547 |
545 // And try loading with the new configuration. | 548 // And try loading with the new configuration. |
546 LoadExistingPrefs(); | 549 LoadExistingPrefs(); |
547 | 550 |
548 // Since there was a valid super MAC we were able to extend the existing trust | 551 // Since there was a valid super MAC we were able to extend the existing trust |
549 // to the newly tracked & protected preference. | 552 // to the newly tracked & protected preference. |
550 ExpectStringValueEquals(kUnprotectedPref, kFoobar); | 553 ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
551 VerifyResetRecorded(false); | 554 VerifyResetRecorded(false); |
552 } | 555 } |
553 | 556 |
554 TEST_P(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { | 557 TEST_P(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { |
555 InitializePrefs(); | 558 InitializePrefs(); |
556 | 559 |
557 ExpectValidationObserved(kTrackedAtomic); | 560 ExpectValidationObserved(kTrackedAtomic); |
558 ExpectValidationObserved(kProtectedAtomic); | 561 ExpectValidationObserved(kProtectedAtomic); |
559 | 562 |
560 // Now update the configuration to protect it. | 563 // Now update the configuration to protect it. |
561 PrefHashFilter::TrackedPreferenceMetadata new_protected = { | 564 prefs::TrackedPreferenceMetadata new_protected = { |
562 kExtraReportingId, kUnprotectedPref, | 565 kExtraReportingId, kUnprotectedPref, EnforcementLevel::ENFORCE_ON_LOAD, |
563 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 566 PrefTrackingStrategy::ATOMIC}; |
564 PrefHashFilter::PrefTrackingStrategy::ATOMIC}; | 567 configuration_.push_back(prefs::ConstructTrackedMetadata(new_protected)); |
565 configuration_.push_back(new_protected); | |
566 seed_ = "new-seed-to-break-trust"; | 568 seed_ = "new-seed-to-break-trust"; |
567 ReloadConfiguration(); | 569 ReloadConfiguration(); |
568 | 570 |
569 // And try loading with the new configuration. | 571 // And try loading with the new configuration. |
570 LoadExistingPrefs(); | 572 LoadExistingPrefs(); |
571 | 573 |
572 // If preference tracking is supported, kUnprotectedPref will have been | 574 // If preference tracking is supported, kUnprotectedPref will have been |
573 // discarded because new values are not accepted without a valid super MAC. | 575 // discarded because new values are not accepted without a valid super MAC. |
574 EXPECT_NE(SupportsPreferenceTracking(), | 576 EXPECT_NE(SupportsPreferenceTracking(), |
575 pref_store_->GetValue(kUnprotectedPref, NULL)); | 577 pref_store_->GetValue(kUnprotectedPref, NULL)); |
576 VerifyResetRecorded(SupportsPreferenceTracking()); | 578 VerifyResetRecorded(SupportsPreferenceTracking()); |
577 } | 579 } |
578 | 580 |
579 // This test verifies that preference values are correctly maintained when a | 581 // This test verifies that preference values are correctly maintained when a |
580 // preference's protection state changes from protected to unprotected. | 582 // preference's protection state changes from protected to unprotected. |
581 TEST_P(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { | 583 TEST_P(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { |
582 InitializePrefs(); | 584 InitializePrefs(); |
583 | 585 |
584 ExpectValidationObserved(kTrackedAtomic); | 586 ExpectValidationObserved(kTrackedAtomic); |
585 ExpectValidationObserved(kProtectedAtomic); | 587 ExpectValidationObserved(kProtectedAtomic); |
586 | 588 |
587 DestroyPrefStore(); | 589 DestroyPrefStore(); |
588 | 590 |
589 // Unconfigure protection for kProtectedAtomic | 591 // Unconfigure protection for kProtectedAtomic |
590 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = | 592 for (const auto& metadata : configuration_) { |
591 configuration_.begin(); | 593 if (metadata->name == kProtectedAtomic) { |
592 it != configuration_.end(); | 594 metadata->enforcement_level = EnforcementLevel::NO_ENFORCEMENT; |
593 ++it) { | |
594 if (it->name == kProtectedAtomic) { | |
595 it->enforcement_level = PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT; | |
596 break; | 595 break; |
597 } | 596 } |
598 } | 597 } |
599 | 598 |
600 seed_ = "new-seed-to-break-trust"; | 599 seed_ = "new-seed-to-break-trust"; |
601 ReloadConfiguration(); | 600 ReloadConfiguration(); |
602 LoadExistingPrefs(); | 601 LoadExistingPrefs(); |
603 | 602 |
604 // Verify that the value was not reset. | 603 // Verify that the value was not reset. |
605 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 604 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
(...skipping 11 matching lines...) Expand all Loading... |
617 base::WrapUnique(new base::Value(kGoodbyeWorld)), | 616 base::WrapUnique(new base::Value(kGoodbyeWorld)), |
618 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 617 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
619 LoadExistingPrefs(); | 618 LoadExistingPrefs(); |
620 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); | 619 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); |
621 VerifyResetRecorded(false); | 620 VerifyResetRecorded(false); |
622 } | 621 } |
623 | 622 |
624 INSTANTIATE_TEST_CASE_P(ProfilePrefStoreManagerTest, | 623 INSTANTIATE_TEST_CASE_P(ProfilePrefStoreManagerTest, |
625 ProfilePrefStoreManagerTest, | 624 ProfilePrefStoreManagerTest, |
626 testing::Bool()); | 625 testing::Bool()); |
OLD | NEW |