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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 base::RunLoop run_loop; | 322 base::RunLoop run_loop; |
318 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), | 323 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), |
319 worker_pool_->pool().get()) | 324 worker_pool_->pool().get()) |
320 ->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing), | 325 ->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing), |
321 run_loop.QuitClosure()); | 326 run_loop.QuitClosure()); |
322 run_loop.Run(); | 327 run_loop.Run(); |
323 } | 328 } |
324 | 329 |
325 void LoadExistingPrefs() { | 330 void LoadExistingPrefs() { |
326 DestroyPrefStore(); | 331 DestroyPrefStore(); |
332 ReloadConfiguration(); | |
gab
2017/03/30 14:56:34
Why is this now required? Add a comment if it's no
Sam McNally
2017/03/31 02:55:51
|manger_->tracking_configuration_| is consumed whe
| |
327 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( | 333 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( |
328 mock_validation_delegate_record_); | 334 mock_validation_delegate_record_); |
329 pref_store_ = manager_->CreateProfilePrefStore( | 335 pref_store_ = manager_->CreateProfilePrefStore( |
330 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), | 336 JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), |
331 worker_pool_->pool().get()), | 337 worker_pool_->pool().get()), |
332 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, | 338 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
333 base::Unretained(this)), | 339 base::Unretained(this)), |
334 mock_validation_delegate_.get(), connector_.get(), | 340 mock_validation_delegate_.get(), connector_.get(), |
335 profile_pref_registry_); | 341 profile_pref_registry_); |
336 pref_store_->AddObserver(®istry_verifier_); | 342 pref_store_->AddObserver(®istry_verifier_); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 | 375 |
370 void ExpectValidationObserved(const std::string& pref_path) { | 376 void ExpectValidationObserved(const std::string& pref_path) { |
371 // No validations are expected for platforms that do not support tracking. | 377 // No validations are expected for platforms that do not support tracking. |
372 if (!SupportsPreferenceTracking()) | 378 if (!SupportsPreferenceTracking()) |
373 return; | 379 return; |
374 if (!mock_validation_delegate_record_->GetEventForPath(pref_path)) | 380 if (!mock_validation_delegate_record_->GetEventForPath(pref_path)) |
375 ADD_FAILURE() << "No validation observed for preference: " << pref_path; | 381 ADD_FAILURE() << "No validation observed for preference: " << pref_path; |
376 } | 382 } |
377 | 383 |
378 base::MessageLoop main_message_loop_; | 384 base::MessageLoop main_message_loop_; |
379 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; | 385 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> configuration_; |
380 base::ScopedTempDir profile_dir_; | 386 base::ScopedTempDir profile_dir_; |
381 TestingPrefServiceSimple local_state_; | 387 TestingPrefServiceSimple local_state_; |
382 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; | 388 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; |
383 RegistryVerifier registry_verifier_; | 389 RegistryVerifier registry_verifier_; |
384 scoped_refptr<MockValidationDelegateRecord> mock_validation_delegate_record_; | 390 scoped_refptr<MockValidationDelegateRecord> mock_validation_delegate_record_; |
385 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> | 391 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> |
386 mock_validation_delegate_; | 392 mock_validation_delegate_; |
387 std::unique_ptr<ProfilePrefStoreManager> manager_; | 393 std::unique_ptr<ProfilePrefStoreManager> manager_; |
388 scoped_refptr<PersistentPrefStore> pref_store_; | 394 scoped_refptr<PersistentPrefStore> pref_store_; |
389 | 395 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 // Ensure everything is written out to disk. | 485 // Ensure everything is written out to disk. |
480 DestroyPrefStore(); | 486 DestroyPrefStore(); |
481 | 487 |
482 ReplaceStringInPrefs(kFoobar, kBarfoo); | 488 ReplaceStringInPrefs(kFoobar, kBarfoo); |
483 | 489 |
484 // It's unprotected, so we can load the modified value. | 490 // It's unprotected, so we can load the modified value. |
485 LoadExistingPrefs(); | 491 LoadExistingPrefs(); |
486 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); | 492 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); |
487 | 493 |
488 // Now update the configuration to protect it. | 494 // Now update the configuration to protect it. |
489 PrefHashFilter::TrackedPreferenceMetadata new_protected = { | 495 prefs::TrackedPreferenceMetadata new_protected = { |
490 kExtraReportingId, kUnprotectedPref, | 496 kExtraReportingId, kUnprotectedPref, EnforcementLevel::ENFORCE_ON_LOAD, |
491 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 497 PrefTrackingStrategy::ATOMIC}; |
492 PrefHashFilter::PrefTrackingStrategy::ATOMIC}; | 498 configuration_.push_back(prefs::ConstructTrackedMetadata(new_protected)); |
493 configuration_.push_back(new_protected); | |
494 ReloadConfiguration(); | 499 ReloadConfiguration(); |
495 | 500 |
496 // And try loading with the new configuration. | 501 // And try loading with the new configuration. |
497 LoadExistingPrefs(); | 502 LoadExistingPrefs(); |
498 | 503 |
499 // 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 |
500 // to the newly protected preference. | 505 // to the newly protected preference. |
501 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); | 506 ExpectStringValueEquals(kUnprotectedPref, kBarfoo); |
502 VerifyResetRecorded(false); | 507 VerifyResetRecorded(false); |
503 | 508 |
504 // Ensure everything is written out to disk. | 509 // Ensure everything is written out to disk. |
505 DestroyPrefStore(); | 510 DestroyPrefStore(); |
506 | 511 |
507 // 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 |
508 // lead to a reset. | 513 // lead to a reset. |
509 ReplaceStringInPrefs(kBarfoo, kFoobar); | 514 ReplaceStringInPrefs(kBarfoo, kFoobar); |
510 LoadExistingPrefs(); | 515 LoadExistingPrefs(); |
511 EXPECT_NE(SupportsPreferenceTracking(), | 516 EXPECT_NE(SupportsPreferenceTracking(), |
512 pref_store_->GetValue(kUnprotectedPref, NULL)); | 517 pref_store_->GetValue(kUnprotectedPref, NULL)); |
513 VerifyResetRecorded(SupportsPreferenceTracking()); | 518 VerifyResetRecorded(SupportsPreferenceTracking()); |
514 } | 519 } |
515 | 520 |
516 TEST_P(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { | 521 TEST_P(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { |
517 std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 522 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> |
518 original_configuration = configuration_; | 523 original_configuration = prefs::CloneTrackedConfiguration(configuration_); |
519 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = | 524 for (const auto& metadata : configuration_) { |
520 configuration_.begin(); | 525 metadata->enforcement_level = EnforcementLevel::NO_ENFORCEMENT; |
521 it != configuration_.end(); | |
522 ++it) { | |
523 it->enforcement_level = PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT; | |
524 } | 526 } |
525 ReloadConfiguration(); | 527 ReloadConfiguration(); |
526 | 528 |
527 InitializePrefs(); | 529 InitializePrefs(); |
528 | 530 |
529 ExpectValidationObserved(kTrackedAtomic); | 531 ExpectValidationObserved(kTrackedAtomic); |
530 ExpectValidationObserved(kProtectedAtomic); | 532 ExpectValidationObserved(kProtectedAtomic); |
531 | 533 |
532 LoadExistingPrefs(); | 534 LoadExistingPrefs(); |
533 ExpectStringValueEquals(kUnprotectedPref, kFoobar); | 535 ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
534 | 536 |
535 // Ensure everything is written out to disk. | 537 // Ensure everything is written out to disk. |
536 DestroyPrefStore(); | 538 DestroyPrefStore(); |
537 | 539 |
538 // Now introduce protection, including the never-before tracked "new_pref". | 540 // Now introduce protection, including the never-before tracked "new_pref". |
539 configuration_ = original_configuration; | 541 configuration_ = std::move(original_configuration); |
540 PrefHashFilter::TrackedPreferenceMetadata new_protected = { | 542 prefs::TrackedPreferenceMetadata new_protected = { |
541 kExtraReportingId, kUnprotectedPref, | 543 kExtraReportingId, kUnprotectedPref, EnforcementLevel::ENFORCE_ON_LOAD, |
542 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 544 PrefTrackingStrategy::ATOMIC}; |
543 PrefHashFilter::PrefTrackingStrategy::ATOMIC}; | 545 configuration_.push_back(prefs::ConstructTrackedMetadata(new_protected)); |
544 configuration_.push_back(new_protected); | |
545 ReloadConfiguration(); | 546 ReloadConfiguration(); |
546 | 547 |
547 // And try loading with the new configuration. | 548 // And try loading with the new configuration. |
548 LoadExistingPrefs(); | 549 LoadExistingPrefs(); |
549 | 550 |
550 // 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 |
551 // to the newly tracked & protected preference. | 552 // to the newly tracked & protected preference. |
552 ExpectStringValueEquals(kUnprotectedPref, kFoobar); | 553 ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
553 VerifyResetRecorded(false); | 554 VerifyResetRecorded(false); |
554 } | 555 } |
555 | 556 |
556 TEST_P(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { | 557 TEST_P(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { |
557 InitializePrefs(); | 558 InitializePrefs(); |
558 | 559 |
559 ExpectValidationObserved(kTrackedAtomic); | 560 ExpectValidationObserved(kTrackedAtomic); |
560 ExpectValidationObserved(kProtectedAtomic); | 561 ExpectValidationObserved(kProtectedAtomic); |
561 | 562 |
562 // Now update the configuration to protect it. | 563 // Now update the configuration to protect it. |
563 PrefHashFilter::TrackedPreferenceMetadata new_protected = { | 564 prefs::TrackedPreferenceMetadata new_protected = { |
564 kExtraReportingId, kUnprotectedPref, | 565 kExtraReportingId, kUnprotectedPref, EnforcementLevel::ENFORCE_ON_LOAD, |
565 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, | 566 PrefTrackingStrategy::ATOMIC}; |
566 PrefHashFilter::PrefTrackingStrategy::ATOMIC}; | 567 configuration_.push_back(prefs::ConstructTrackedMetadata(new_protected)); |
567 configuration_.push_back(new_protected); | |
568 seed_ = "new-seed-to-break-trust"; | 568 seed_ = "new-seed-to-break-trust"; |
569 ReloadConfiguration(); | 569 ReloadConfiguration(); |
570 | 570 |
571 // And try loading with the new configuration. | 571 // And try loading with the new configuration. |
572 LoadExistingPrefs(); | 572 LoadExistingPrefs(); |
573 | 573 |
574 // If preference tracking is supported, kUnprotectedPref will have been | 574 // If preference tracking is supported, kUnprotectedPref will have been |
575 // 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. |
576 EXPECT_NE(SupportsPreferenceTracking(), | 576 EXPECT_NE(SupportsPreferenceTracking(), |
577 pref_store_->GetValue(kUnprotectedPref, NULL)); | 577 pref_store_->GetValue(kUnprotectedPref, NULL)); |
578 VerifyResetRecorded(SupportsPreferenceTracking()); | 578 VerifyResetRecorded(SupportsPreferenceTracking()); |
579 } | 579 } |
580 | 580 |
581 // This test verifies that preference values are correctly maintained when a | 581 // This test verifies that preference values are correctly maintained when a |
582 // preference's protection state changes from protected to unprotected. | 582 // preference's protection state changes from protected to unprotected. |
583 TEST_P(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { | 583 TEST_P(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { |
584 InitializePrefs(); | 584 InitializePrefs(); |
585 | 585 |
586 ExpectValidationObserved(kTrackedAtomic); | 586 ExpectValidationObserved(kTrackedAtomic); |
587 ExpectValidationObserved(kProtectedAtomic); | 587 ExpectValidationObserved(kProtectedAtomic); |
588 | 588 |
589 DestroyPrefStore(); | 589 DestroyPrefStore(); |
590 | 590 |
591 // Unconfigure protection for kProtectedAtomic | 591 // Unconfigure protection for kProtectedAtomic |
592 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = | 592 for (const auto& metadata : configuration_) { |
593 configuration_.begin(); | 593 if (metadata->name == kProtectedAtomic) { |
594 it != configuration_.end(); | 594 metadata->enforcement_level = EnforcementLevel::NO_ENFORCEMENT; |
595 ++it) { | |
596 if (it->name == kProtectedAtomic) { | |
597 it->enforcement_level = PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT; | |
598 break; | 595 break; |
599 } | 596 } |
600 } | 597 } |
601 | 598 |
602 seed_ = "new-seed-to-break-trust"; | 599 seed_ = "new-seed-to-break-trust"; |
603 ReloadConfiguration(); | 600 ReloadConfiguration(); |
604 LoadExistingPrefs(); | 601 LoadExistingPrefs(); |
605 | 602 |
606 // Verify that the value was not reset. | 603 // Verify that the value was not reset. |
607 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 604 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
(...skipping 11 matching lines...) Expand all Loading... | |
619 base::WrapUnique(new base::Value(kGoodbyeWorld)), | 616 base::WrapUnique(new base::Value(kGoodbyeWorld)), |
620 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 617 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
621 LoadExistingPrefs(); | 618 LoadExistingPrefs(); |
622 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); | 619 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); |
623 VerifyResetRecorded(false); | 620 VerifyResetRecorded(false); |
624 } | 621 } |
625 | 622 |
626 INSTANTIATE_TEST_CASE_P(ProfilePrefStoreManagerTest, | 623 INSTANTIATE_TEST_CASE_P(ProfilePrefStoreManagerTest, |
627 ProfilePrefStoreManagerTest, | 624 ProfilePrefStoreManagerTest, |
628 testing::Bool()); | 625 testing::Bool()); |
OLD | NEW |