| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/user_prefs/tracked/pref_hash_filter.h" | 5 #include "components/user_prefs/tracked/pref_hash_filter.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 const char kAtomicPref[] = "atomic_pref"; | 36 const char kAtomicPref[] = "atomic_pref"; |
| 37 const char kAtomicPref2[] = "atomic_pref2"; | 37 const char kAtomicPref2[] = "atomic_pref2"; |
| 38 const char kAtomicPref3[] = "pref3"; | 38 const char kAtomicPref3[] = "pref3"; |
| 39 const char kAtomicPref4[] = "pref4"; | 39 const char kAtomicPref4[] = "pref4"; |
| 40 const char kReportOnlyPref[] = "report_only"; | 40 const char kReportOnlyPref[] = "report_only"; |
| 41 const char kReportOnlySplitPref[] = "report_only_split_pref"; | 41 const char kReportOnlySplitPref[] = "report_only_split_pref"; |
| 42 const char kSplitPref[] = "split_pref"; | 42 const char kSplitPref[] = "split_pref"; |
| 43 | 43 |
| 44 const PrefHashFilter::TrackedPreferenceMetadata kTestTrackedPrefs[] = { | 44 const PrefHashFilter::TrackedPreferenceMetadata kTestTrackedPrefs[] = { |
| 45 {0, | 45 {0, kAtomicPref, PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, |
| 46 kAtomicPref, | 46 PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 47 PrefHashFilter::ENFORCE_ON_LOAD, | 47 PrefHashFilter::ValueType::PERSONAL}, |
| 48 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 48 {1, kReportOnlyPref, PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT, |
| 49 PrefHashFilter::VALUE_PERSONAL}, | 49 PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 50 {1, | 50 PrefHashFilter::ValueType::IMPERSONAL}, |
| 51 kReportOnlyPref, | 51 {2, kSplitPref, PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, |
| 52 PrefHashFilter::NO_ENFORCEMENT, | 52 PrefHashFilter::PrefTrackingStrategy::SPLIT, |
| 53 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 53 PrefHashFilter::ValueType::IMPERSONAL}, |
| 54 PrefHashFilter::VALUE_IMPERSONAL}, | 54 {3, kReportOnlySplitPref, PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT, |
| 55 {2, | 55 PrefHashFilter::PrefTrackingStrategy::SPLIT, |
| 56 kSplitPref, | 56 PrefHashFilter::ValueType::IMPERSONAL}, |
| 57 PrefHashFilter::ENFORCE_ON_LOAD, | 57 {4, kAtomicPref2, PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, |
| 58 PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 58 PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 59 PrefHashFilter::VALUE_IMPERSONAL}, | 59 PrefHashFilter::ValueType::IMPERSONAL}, |
| 60 {3, | 60 {5, kAtomicPref3, PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, |
| 61 kReportOnlySplitPref, | 61 PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 62 PrefHashFilter::NO_ENFORCEMENT, | 62 PrefHashFilter::ValueType::IMPERSONAL}, |
| 63 PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 63 {6, kAtomicPref4, PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, |
| 64 PrefHashFilter::VALUE_IMPERSONAL}, | 64 PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 65 {4, | 65 PrefHashFilter::ValueType::IMPERSONAL}, |
| 66 kAtomicPref2, | |
| 67 PrefHashFilter::ENFORCE_ON_LOAD, | |
| 68 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | |
| 69 PrefHashFilter::VALUE_IMPERSONAL}, | |
| 70 {5, | |
| 71 kAtomicPref3, | |
| 72 PrefHashFilter::ENFORCE_ON_LOAD, | |
| 73 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | |
| 74 PrefHashFilter::VALUE_IMPERSONAL}, | |
| 75 {6, | |
| 76 kAtomicPref4, | |
| 77 PrefHashFilter::ENFORCE_ON_LOAD, | |
| 78 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | |
| 79 PrefHashFilter::VALUE_IMPERSONAL}, | |
| 80 }; | 66 }; |
| 81 | 67 |
| 82 } // namespace | 68 } // namespace |
| 83 | 69 |
| 84 // A PrefHashStore that allows simulation of CheckValue results and captures | 70 // A PrefHashStore that allows simulation of CheckValue results and captures |
| 85 // checked and stored values. | 71 // checked and stored values. |
| 86 class MockPrefHashStore : public PrefHashStore { | 72 class MockPrefHashStore : public PrefHashStore { |
| 87 public: | 73 public: |
| 88 typedef std::pair<const void*, PrefHashFilter::PrefTrackingStrategy> | 74 typedef std::pair<const void*, PrefHashFilter::PrefTrackingStrategy> |
| 89 ValuePtrStrategyPair; | 75 ValuePtrStrategyPair; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 base::StringPiece | 291 base::StringPiece |
| 306 MockPrefHashStore::MockPrefHashStoreTransaction::GetStoreUMASuffix() const { | 292 MockPrefHashStore::MockPrefHashStoreTransaction::GetStoreUMASuffix() const { |
| 307 return "unused"; | 293 return "unused"; |
| 308 } | 294 } |
| 309 | 295 |
| 310 PrefHashStoreTransaction::ValueState | 296 PrefHashStoreTransaction::ValueState |
| 311 MockPrefHashStore::MockPrefHashStoreTransaction::CheckValue( | 297 MockPrefHashStore::MockPrefHashStoreTransaction::CheckValue( |
| 312 const std::string& path, | 298 const std::string& path, |
| 313 const base::Value* value) const { | 299 const base::Value* value) const { |
| 314 return outer_->RecordCheckValue(path, value, | 300 return outer_->RecordCheckValue(path, value, |
| 315 PrefHashFilter::TRACKING_STRATEGY_ATOMIC); | 301 PrefHashFilter::PrefTrackingStrategy::ATOMIC); |
| 316 } | 302 } |
| 317 | 303 |
| 318 void MockPrefHashStore::MockPrefHashStoreTransaction::StoreHash( | 304 void MockPrefHashStore::MockPrefHashStoreTransaction::StoreHash( |
| 319 const std::string& path, | 305 const std::string& path, |
| 320 const base::Value* new_value) { | 306 const base::Value* new_value) { |
| 321 outer_->RecordStoreHash(path, new_value, | 307 outer_->RecordStoreHash(path, new_value, |
| 322 PrefHashFilter::TRACKING_STRATEGY_ATOMIC); | 308 PrefHashFilter::PrefTrackingStrategy::ATOMIC); |
| 323 } | 309 } |
| 324 | 310 |
| 325 PrefHashStoreTransaction::ValueState | 311 PrefHashStoreTransaction::ValueState |
| 326 MockPrefHashStore::MockPrefHashStoreTransaction::CheckSplitValue( | 312 MockPrefHashStore::MockPrefHashStoreTransaction::CheckSplitValue( |
| 327 const std::string& path, | 313 const std::string& path, |
| 328 const base::DictionaryValue* initial_split_value, | 314 const base::DictionaryValue* initial_split_value, |
| 329 std::vector<std::string>* invalid_keys) const { | 315 std::vector<std::string>* invalid_keys) const { |
| 330 EXPECT_TRUE(invalid_keys && invalid_keys->empty()); | 316 EXPECT_TRUE(invalid_keys && invalid_keys->empty()); |
| 331 | 317 |
| 332 std::map<std::string, std::vector<std::string>>::const_iterator | 318 std::map<std::string, std::vector<std::string>>::const_iterator |
| 333 invalid_keys_result = outer_->invalid_keys_results_.find(path); | 319 invalid_keys_result = outer_->invalid_keys_results_.find(path); |
| 334 if (invalid_keys_result != outer_->invalid_keys_results_.end()) { | 320 if (invalid_keys_result != outer_->invalid_keys_results_.end()) { |
| 335 invalid_keys->insert(invalid_keys->begin(), | 321 invalid_keys->insert(invalid_keys->begin(), |
| 336 invalid_keys_result->second.begin(), | 322 invalid_keys_result->second.begin(), |
| 337 invalid_keys_result->second.end()); | 323 invalid_keys_result->second.end()); |
| 338 } | 324 } |
| 339 | 325 |
| 340 return outer_->RecordCheckValue(path, initial_split_value, | 326 return outer_->RecordCheckValue(path, initial_split_value, |
| 341 PrefHashFilter::TRACKING_STRATEGY_SPLIT); | 327 PrefHashFilter::PrefTrackingStrategy::SPLIT); |
| 342 } | 328 } |
| 343 | 329 |
| 344 void MockPrefHashStore::MockPrefHashStoreTransaction::StoreSplitHash( | 330 void MockPrefHashStore::MockPrefHashStoreTransaction::StoreSplitHash( |
| 345 const std::string& path, | 331 const std::string& path, |
| 346 const base::DictionaryValue* new_value) { | 332 const base::DictionaryValue* new_value) { |
| 347 outer_->RecordStoreHash(path, new_value, | 333 outer_->RecordStoreHash(path, new_value, |
| 348 PrefHashFilter::TRACKING_STRATEGY_SPLIT); | 334 PrefHashFilter::PrefTrackingStrategy::SPLIT); |
| 349 } | 335 } |
| 350 | 336 |
| 351 bool MockPrefHashStore::MockPrefHashStoreTransaction::HasHash( | 337 bool MockPrefHashStore::MockPrefHashStoreTransaction::HasHash( |
| 352 const std::string& path) const { | 338 const std::string& path) const { |
| 353 ADD_FAILURE() << "Unexpected call."; | 339 ADD_FAILURE() << "Unexpected call."; |
| 354 return false; | 340 return false; |
| 355 } | 341 } |
| 356 | 342 |
| 357 void MockPrefHashStore::MockPrefHashStoreTransaction::ImportHash( | 343 void MockPrefHashStore::MockPrefHashStoreTransaction::ImportHash( |
| 358 const std::string& path, | 344 const std::string& path, |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 // No path should be stored on FilterUpdate. | 698 // No path should be stored on FilterUpdate. |
| 713 pref_hash_filter_->FilterUpdate(kAtomicPref); | 699 pref_hash_filter_->FilterUpdate(kAtomicPref); |
| 714 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 700 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
| 715 | 701 |
| 716 // One path should be stored on FilterSerializeData. | 702 // One path should be stored on FilterSerializeData. |
| 717 pref_hash_filter_->FilterSerializeData(&root_dict); | 703 pref_hash_filter_->FilterSerializeData(&root_dict); |
| 718 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count()); | 704 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count()); |
| 719 MockPrefHashStore::ValuePtrStrategyPair stored_value = | 705 MockPrefHashStore::ValuePtrStrategyPair stored_value = |
| 720 mock_pref_hash_store_->stored_value(kAtomicPref); | 706 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 721 ASSERT_EQ(string_value, stored_value.first); | 707 ASSERT_EQ(string_value, stored_value.first); |
| 722 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, stored_value.second); | 708 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::ATOMIC, stored_value.second); |
| 723 | 709 |
| 724 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 710 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 725 VerifyRecordedReset(false); | 711 VerifyRecordedReset(false); |
| 726 } | 712 } |
| 727 | 713 |
| 728 TEST_P(PrefHashFilterTest, ReportSuperMacValidity) { | 714 TEST_P(PrefHashFilterTest, ReportSuperMacValidity) { |
| 729 // Do this once just to force the histogram to be defined. | 715 // Do this once just to force the histogram to be defined. |
| 730 DoFilterOnLoad(false); | 716 DoFilterOnLoad(false); |
| 731 | 717 |
| 732 base::HistogramBase* histogram = base::StatisticsRecorder::FindHistogram( | 718 base::HistogramBase* histogram = base::StatisticsRecorder::FindHistogram( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 // No path should be stored on FilterUpdate. | 758 // No path should be stored on FilterUpdate. |
| 773 pref_hash_filter_->FilterUpdate(kSplitPref); | 759 pref_hash_filter_->FilterUpdate(kSplitPref); |
| 774 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 760 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
| 775 | 761 |
| 776 // One path should be stored on FilterSerializeData. | 762 // One path should be stored on FilterSerializeData. |
| 777 pref_hash_filter_->FilterSerializeData(&root_dict); | 763 pref_hash_filter_->FilterSerializeData(&root_dict); |
| 778 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count()); | 764 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count()); |
| 779 MockPrefHashStore::ValuePtrStrategyPair stored_value = | 765 MockPrefHashStore::ValuePtrStrategyPair stored_value = |
| 780 mock_pref_hash_store_->stored_value(kSplitPref); | 766 mock_pref_hash_store_->stored_value(kSplitPref); |
| 781 ASSERT_EQ(dict_value, stored_value.first); | 767 ASSERT_EQ(dict_value, stored_value.first); |
| 782 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_value.second); | 768 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::SPLIT, stored_value.second); |
| 783 | 769 |
| 784 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 770 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 785 VerifyRecordedReset(false); | 771 VerifyRecordedReset(false); |
| 786 } | 772 } |
| 787 | 773 |
| 788 TEST_P(PrefHashFilterTest, FilterUntrackedPrefUpdate) { | 774 TEST_P(PrefHashFilterTest, FilterUntrackedPrefUpdate) { |
| 789 base::DictionaryValue root_dict; | 775 base::DictionaryValue root_dict; |
| 790 root_dict.Set("untracked", new base::Value("some value")); | 776 root_dict.Set("untracked", new base::Value("some value")); |
| 791 pref_hash_filter_->FilterUpdate("untracked"); | 777 pref_hash_filter_->FilterUpdate("untracked"); |
| 792 | 778 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 root_dict.Set(kAtomicPref3, int_value5); | 814 root_dict.Set(kAtomicPref3, int_value5); |
| 829 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 815 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
| 830 | 816 |
| 831 // On FilterSerializeData, only kAtomicPref, kAtomicPref3, and kSplitPref | 817 // On FilterSerializeData, only kAtomicPref, kAtomicPref3, and kSplitPref |
| 832 // should get a new hash. | 818 // should get a new hash. |
| 833 pref_hash_filter_->FilterSerializeData(&root_dict); | 819 pref_hash_filter_->FilterSerializeData(&root_dict); |
| 834 ASSERT_EQ(3u, mock_pref_hash_store_->stored_paths_count()); | 820 ASSERT_EQ(3u, mock_pref_hash_store_->stored_paths_count()); |
| 835 MockPrefHashStore::ValuePtrStrategyPair stored_value_atomic1 = | 821 MockPrefHashStore::ValuePtrStrategyPair stored_value_atomic1 = |
| 836 mock_pref_hash_store_->stored_value(kAtomicPref); | 822 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 837 ASSERT_EQ(int_value1, stored_value_atomic1.first); | 823 ASSERT_EQ(int_value1, stored_value_atomic1.first); |
| 838 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 824 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 839 stored_value_atomic1.second); | 825 stored_value_atomic1.second); |
| 840 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 826 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 841 | 827 |
| 842 MockPrefHashStore::ValuePtrStrategyPair stored_value_atomic3 = | 828 MockPrefHashStore::ValuePtrStrategyPair stored_value_atomic3 = |
| 843 mock_pref_hash_store_->stored_value(kAtomicPref3); | 829 mock_pref_hash_store_->stored_value(kAtomicPref3); |
| 844 ASSERT_EQ(int_value5, stored_value_atomic3.first); | 830 ASSERT_EQ(int_value5, stored_value_atomic3.first); |
| 845 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 831 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 846 stored_value_atomic3.second); | 832 stored_value_atomic3.second); |
| 847 | 833 |
| 848 MockPrefHashStore::ValuePtrStrategyPair stored_value_split = | 834 MockPrefHashStore::ValuePtrStrategyPair stored_value_split = |
| 849 mock_pref_hash_store_->stored_value(kSplitPref); | 835 mock_pref_hash_store_->stored_value(kSplitPref); |
| 850 ASSERT_EQ(dict_value, stored_value_split.first); | 836 ASSERT_EQ(dict_value, stored_value_split.first); |
| 851 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_value_split.second); | 837 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::SPLIT, |
| 838 stored_value_split.second); |
| 852 } | 839 } |
| 853 | 840 |
| 854 TEST_P(PrefHashFilterTest, UnknownNullValue) { | 841 TEST_P(PrefHashFilterTest, UnknownNullValue) { |
| 855 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); | 842 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 856 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); | 843 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); |
| 857 // NULL values are always trusted by the PrefHashStore. | 844 // NULL values are always trusted by the PrefHashStore. |
| 858 mock_pref_hash_store_->SetCheckResult( | 845 mock_pref_hash_store_->SetCheckResult( |
| 859 kAtomicPref, PrefHashStoreTransaction::TRUSTED_NULL_VALUE); | 846 kAtomicPref, PrefHashStoreTransaction::TRUSTED_NULL_VALUE); |
| 860 mock_pref_hash_store_->SetCheckResult( | 847 mock_pref_hash_store_->SetCheckResult( |
| 861 kSplitPref, PrefHashStoreTransaction::TRUSTED_NULL_VALUE); | 848 kSplitPref, PrefHashStoreTransaction::TRUSTED_NULL_VALUE); |
| 862 DoFilterOnLoad(false); | 849 DoFilterOnLoad(false); |
| 863 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 850 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 864 mock_pref_hash_store_->checked_paths_count()); | 851 mock_pref_hash_store_->checked_paths_count()); |
| 865 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); | 852 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); |
| 866 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 853 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 867 | 854 |
| 868 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 855 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 869 mock_pref_hash_store_->stored_value(kAtomicPref); | 856 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 870 ASSERT_EQ(NULL, stored_atomic_value.first); | 857 ASSERT_EQ(NULL, stored_atomic_value.first); |
| 871 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 858 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 872 stored_atomic_value.second); | 859 stored_atomic_value.second); |
| 873 | 860 |
| 874 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 861 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 875 mock_pref_hash_store_->stored_value(kSplitPref); | 862 mock_pref_hash_store_->stored_value(kSplitPref); |
| 876 ASSERT_EQ(NULL, stored_split_value.first); | 863 ASSERT_EQ(NULL, stored_split_value.first); |
| 877 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); | 864 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::SPLIT, |
| 865 stored_split_value.second); |
| 878 | 866 |
| 879 // Delegate saw all prefs, two of which had the expected value_state. | 867 // Delegate saw all prefs, two of which had the expected value_state. |
| 880 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 868 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 881 mock_validation_delegate_record_->recorded_validations_count()); | 869 mock_validation_delegate_record_->recorded_validations_count()); |
| 882 ASSERT_EQ(2u, mock_validation_delegate_record_->CountValidationsOfState( | 870 ASSERT_EQ(2u, mock_validation_delegate_record_->CountValidationsOfState( |
| 883 PrefHashStoreTransaction::TRUSTED_NULL_VALUE)); | 871 PrefHashStoreTransaction::TRUSTED_NULL_VALUE)); |
| 884 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, | 872 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, |
| 885 mock_validation_delegate_record_->CountValidationsOfState( | 873 mock_validation_delegate_record_->CountValidationsOfState( |
| 886 PrefHashStoreTransaction::UNCHANGED)); | 874 PrefHashStoreTransaction::UNCHANGED)); |
| 887 | 875 |
| 888 const MockValidationDelegateRecord::ValidationEvent* validated_split_pref = | 876 const MockValidationDelegateRecord::ValidationEvent* validated_split_pref = |
| 889 mock_validation_delegate_record_->GetEventForPath(kSplitPref); | 877 mock_validation_delegate_record_->GetEventForPath(kSplitPref); |
| 890 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 878 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::SPLIT, |
| 891 validated_split_pref->strategy); | 879 validated_split_pref->strategy); |
| 892 ASSERT_FALSE(validated_split_pref->is_personal); | 880 ASSERT_FALSE(validated_split_pref->is_personal); |
| 893 const MockValidationDelegateRecord::ValidationEvent* validated_atomic_pref = | 881 const MockValidationDelegateRecord::ValidationEvent* validated_atomic_pref = |
| 894 mock_validation_delegate_record_->GetEventForPath(kAtomicPref); | 882 mock_validation_delegate_record_->GetEventForPath(kAtomicPref); |
| 895 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 883 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 896 validated_atomic_pref->strategy); | 884 validated_atomic_pref->strategy); |
| 897 ASSERT_TRUE(validated_atomic_pref->is_personal); | 885 ASSERT_TRUE(validated_atomic_pref->is_personal); |
| 898 } | 886 } |
| 899 | 887 |
| 900 TEST_P(PrefHashFilterTest, InitialValueUnknown) { | 888 TEST_P(PrefHashFilterTest, InitialValueUnknown) { |
| 901 // Ownership of these values is transfered to |pref_store_contents_|. | 889 // Ownership of these values is transfered to |pref_store_contents_|. |
| 902 base::Value* string_value = new base::Value("string value"); | 890 base::Value* string_value = new base::Value("string value"); |
| 903 pref_store_contents_->Set(kAtomicPref, string_value); | 891 pref_store_contents_->Set(kAtomicPref, string_value); |
| 904 | 892 |
| 905 base::DictionaryValue* dict_value = new base::DictionaryValue; | 893 base::DictionaryValue* dict_value = new base::DictionaryValue; |
| 906 dict_value->SetString("a", "foo"); | 894 dict_value->SetString("a", "foo"); |
| 907 dict_value->SetInteger("b", 1234); | 895 dict_value->SetInteger("b", 1234); |
| 908 pref_store_contents_->Set(kSplitPref, dict_value); | 896 pref_store_contents_->Set(kSplitPref, dict_value); |
| 909 | 897 |
| 910 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); | 898 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 911 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); | 899 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); |
| 912 | 900 |
| 913 mock_pref_hash_store_->SetCheckResult( | 901 mock_pref_hash_store_->SetCheckResult( |
| 914 kAtomicPref, PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE); | 902 kAtomicPref, PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE); |
| 915 mock_pref_hash_store_->SetCheckResult( | 903 mock_pref_hash_store_->SetCheckResult( |
| 916 kSplitPref, PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE); | 904 kSplitPref, PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE); |
| 917 // If we are enforcing, expect this to report changes. | 905 // If we are enforcing, expect this to report changes. |
| 918 DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD); | 906 DoFilterOnLoad(GetParam() >= |
| 907 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD); |
| 919 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 908 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 920 mock_pref_hash_store_->checked_paths_count()); | 909 mock_pref_hash_store_->checked_paths_count()); |
| 921 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); | 910 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); |
| 922 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 911 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 923 | 912 |
| 924 // Delegate saw all prefs, two of which had the expected value_state. | 913 // Delegate saw all prefs, two of which had the expected value_state. |
| 925 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 914 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 926 mock_validation_delegate_record_->recorded_validations_count()); | 915 mock_validation_delegate_record_->recorded_validations_count()); |
| 927 ASSERT_EQ(2u, mock_validation_delegate_record_->CountValidationsOfState( | 916 ASSERT_EQ(2u, mock_validation_delegate_record_->CountValidationsOfState( |
| 928 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE)); | 917 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE)); |
| 929 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, | 918 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, |
| 930 mock_validation_delegate_record_->CountValidationsOfState( | 919 mock_validation_delegate_record_->CountValidationsOfState( |
| 931 PrefHashStoreTransaction::UNCHANGED)); | 920 PrefHashStoreTransaction::UNCHANGED)); |
| 932 | 921 |
| 933 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 922 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 934 mock_pref_hash_store_->stored_value(kAtomicPref); | 923 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 935 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 924 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 936 mock_pref_hash_store_->stored_value(kSplitPref); | 925 mock_pref_hash_store_->stored_value(kSplitPref); |
| 937 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 926 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 938 stored_atomic_value.second); | 927 stored_atomic_value.second); |
| 939 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); | 928 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::SPLIT, |
| 940 if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) { | 929 stored_split_value.second); |
| 930 if (GetParam() == PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD) { |
| 941 // Ensure the prefs were cleared and the hashes for NULL were restored if | 931 // Ensure the prefs were cleared and the hashes for NULL were restored if |
| 942 // the current enforcement level denies seeding. | 932 // the current enforcement level denies seeding. |
| 943 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); | 933 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 944 ASSERT_EQ(NULL, stored_atomic_value.first); | 934 ASSERT_EQ(NULL, stored_atomic_value.first); |
| 945 | 935 |
| 946 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); | 936 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); |
| 947 ASSERT_EQ(NULL, stored_split_value.first); | 937 ASSERT_EQ(NULL, stored_split_value.first); |
| 948 | 938 |
| 949 VerifyRecordedReset(true); | 939 VerifyRecordedReset(true); |
| 950 } else { | 940 } else { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 mock_validation_delegate_record_->CountValidationsOfState( | 986 mock_validation_delegate_record_->CountValidationsOfState( |
| 997 PrefHashStoreTransaction::UNCHANGED)); | 987 PrefHashStoreTransaction::UNCHANGED)); |
| 998 | 988 |
| 999 // Seeding is always allowed for trusted unknown values. | 989 // Seeding is always allowed for trusted unknown values. |
| 1000 const base::Value* atomic_value_in_store; | 990 const base::Value* atomic_value_in_store; |
| 1001 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store)); | 991 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store)); |
| 1002 ASSERT_EQ(string_value, atomic_value_in_store); | 992 ASSERT_EQ(string_value, atomic_value_in_store); |
| 1003 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 993 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 1004 mock_pref_hash_store_->stored_value(kAtomicPref); | 994 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 1005 ASSERT_EQ(string_value, stored_atomic_value.first); | 995 ASSERT_EQ(string_value, stored_atomic_value.first); |
| 1006 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 996 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 1007 stored_atomic_value.second); | 997 stored_atomic_value.second); |
| 1008 | 998 |
| 1009 const base::Value* split_value_in_store; | 999 const base::Value* split_value_in_store; |
| 1010 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); | 1000 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); |
| 1011 ASSERT_EQ(dict_value, split_value_in_store); | 1001 ASSERT_EQ(dict_value, split_value_in_store); |
| 1012 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 1002 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 1013 mock_pref_hash_store_->stored_value(kSplitPref); | 1003 mock_pref_hash_store_->stored_value(kSplitPref); |
| 1014 ASSERT_EQ(dict_value, stored_split_value.first); | 1004 ASSERT_EQ(dict_value, stored_split_value.first); |
| 1015 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); | 1005 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::SPLIT, |
| 1006 stored_split_value.second); |
| 1016 } | 1007 } |
| 1017 | 1008 |
| 1018 TEST_P(PrefHashFilterTest, InitialValueChanged) { | 1009 TEST_P(PrefHashFilterTest, InitialValueChanged) { |
| 1019 // Ownership of this value is transfered to |pref_store_contents_|. | 1010 // Ownership of this value is transfered to |pref_store_contents_|. |
| 1020 base::Value* int_value = new base::Value(1234); | 1011 base::Value* int_value = new base::Value(1234); |
| 1021 pref_store_contents_->Set(kAtomicPref, int_value); | 1012 pref_store_contents_->Set(kAtomicPref, int_value); |
| 1022 | 1013 |
| 1023 base::DictionaryValue* dict_value = new base::DictionaryValue; | 1014 base::DictionaryValue* dict_value = new base::DictionaryValue; |
| 1024 dict_value->SetString("a", "foo"); | 1015 dict_value->SetString("a", "foo"); |
| 1025 dict_value->SetInteger("b", 1234); | 1016 dict_value->SetInteger("b", 1234); |
| 1026 dict_value->SetInteger("c", 56); | 1017 dict_value->SetInteger("c", 56); |
| 1027 dict_value->SetBoolean("d", false); | 1018 dict_value->SetBoolean("d", false); |
| 1028 pref_store_contents_->Set(kSplitPref, dict_value); | 1019 pref_store_contents_->Set(kSplitPref, dict_value); |
| 1029 | 1020 |
| 1030 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); | 1021 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 1031 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); | 1022 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); |
| 1032 | 1023 |
| 1033 mock_pref_hash_store_->SetCheckResult(kAtomicPref, | 1024 mock_pref_hash_store_->SetCheckResult(kAtomicPref, |
| 1034 PrefHashStoreTransaction::CHANGED); | 1025 PrefHashStoreTransaction::CHANGED); |
| 1035 mock_pref_hash_store_->SetCheckResult(kSplitPref, | 1026 mock_pref_hash_store_->SetCheckResult(kSplitPref, |
| 1036 PrefHashStoreTransaction::CHANGED); | 1027 PrefHashStoreTransaction::CHANGED); |
| 1037 | 1028 |
| 1038 std::vector<std::string> mock_invalid_keys; | 1029 std::vector<std::string> mock_invalid_keys; |
| 1039 mock_invalid_keys.push_back("a"); | 1030 mock_invalid_keys.push_back("a"); |
| 1040 mock_invalid_keys.push_back("c"); | 1031 mock_invalid_keys.push_back("c"); |
| 1041 mock_pref_hash_store_->SetInvalidKeysResult(kSplitPref, mock_invalid_keys); | 1032 mock_pref_hash_store_->SetInvalidKeysResult(kSplitPref, mock_invalid_keys); |
| 1042 | 1033 |
| 1043 DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD); | 1034 DoFilterOnLoad(GetParam() >= |
| 1035 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD); |
| 1044 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 1036 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 1045 mock_pref_hash_store_->checked_paths_count()); | 1037 mock_pref_hash_store_->checked_paths_count()); |
| 1046 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); | 1038 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); |
| 1047 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 1039 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 1048 | 1040 |
| 1049 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 1041 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 1050 mock_pref_hash_store_->stored_value(kAtomicPref); | 1042 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 1051 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 1043 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 1052 mock_pref_hash_store_->stored_value(kSplitPref); | 1044 mock_pref_hash_store_->stored_value(kSplitPref); |
| 1053 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 1045 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 1054 stored_atomic_value.second); | 1046 stored_atomic_value.second); |
| 1055 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); | 1047 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::SPLIT, |
| 1056 if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) { | 1048 stored_split_value.second); |
| 1049 if (GetParam() == PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD) { |
| 1057 // Ensure the atomic pref was cleared and the hash for NULL was restored if | 1050 // Ensure the atomic pref was cleared and the hash for NULL was restored if |
| 1058 // the current enforcement level prevents changes. | 1051 // the current enforcement level prevents changes. |
| 1059 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); | 1052 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 1060 ASSERT_EQ(NULL, stored_atomic_value.first); | 1053 ASSERT_EQ(NULL, stored_atomic_value.first); |
| 1061 | 1054 |
| 1062 // The split pref on the other hand should only have been stripped of its | 1055 // The split pref on the other hand should only have been stripped of its |
| 1063 // invalid keys. | 1056 // invalid keys. |
| 1064 const base::Value* split_value_in_store; | 1057 const base::Value* split_value_in_store; |
| 1065 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); | 1058 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); |
| 1066 ASSERT_EQ(2U, dict_value->size()); | 1059 ASSERT_EQ(2U, dict_value->size()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, | 1107 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, |
| 1115 mock_validation_delegate_record_->CountValidationsOfState( | 1108 mock_validation_delegate_record_->CountValidationsOfState( |
| 1116 PrefHashStoreTransaction::UNCHANGED)); | 1109 PrefHashStoreTransaction::UNCHANGED)); |
| 1117 | 1110 |
| 1118 // Regardless of the enforcement level, the only thing that should be done is | 1111 // Regardless of the enforcement level, the only thing that should be done is |
| 1119 // to restore the hash for NULL. The value itself should still be NULL. | 1112 // to restore the hash for NULL. The value itself should still be NULL. |
| 1120 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); | 1113 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 1121 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 1114 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 1122 mock_pref_hash_store_->stored_value(kAtomicPref); | 1115 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 1123 ASSERT_EQ(NULL, stored_atomic_value.first); | 1116 ASSERT_EQ(NULL, stored_atomic_value.first); |
| 1124 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 1117 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 1125 stored_atomic_value.second); | 1118 stored_atomic_value.second); |
| 1126 | 1119 |
| 1127 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); | 1120 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); |
| 1128 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 1121 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 1129 mock_pref_hash_store_->stored_value(kSplitPref); | 1122 mock_pref_hash_store_->stored_value(kSplitPref); |
| 1130 ASSERT_EQ(NULL, stored_split_value.first); | 1123 ASSERT_EQ(NULL, stored_split_value.first); |
| 1131 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); | 1124 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::SPLIT, |
| 1125 stored_split_value.second); |
| 1132 } | 1126 } |
| 1133 | 1127 |
| 1134 TEST_P(PrefHashFilterTest, InitialValueUnchangedLegacyId) { | 1128 TEST_P(PrefHashFilterTest, InitialValueUnchangedLegacyId) { |
| 1135 // Ownership of these values is transfered to |pref_store_contents_|. | 1129 // Ownership of these values is transfered to |pref_store_contents_|. |
| 1136 base::Value* string_value = new base::Value("string value"); | 1130 base::Value* string_value = new base::Value("string value"); |
| 1137 pref_store_contents_->Set(kAtomicPref, string_value); | 1131 pref_store_contents_->Set(kAtomicPref, string_value); |
| 1138 | 1132 |
| 1139 base::DictionaryValue* dict_value = new base::DictionaryValue; | 1133 base::DictionaryValue* dict_value = new base::DictionaryValue; |
| 1140 dict_value->SetString("a", "foo"); | 1134 dict_value->SetString("a", "foo"); |
| 1141 dict_value->SetInteger("b", 1234); | 1135 dict_value->SetInteger("b", 1234); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1163 PrefHashStoreTransaction::UNCHANGED)); | 1157 PrefHashStoreTransaction::UNCHANGED)); |
| 1164 | 1158 |
| 1165 // Ensure that both the atomic and split hashes were restored. | 1159 // Ensure that both the atomic and split hashes were restored. |
| 1166 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); | 1160 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); |
| 1167 | 1161 |
| 1168 // In all cases, the values should have remained intact and the hashes should | 1162 // In all cases, the values should have remained intact and the hashes should |
| 1169 // have been updated to match them. | 1163 // have been updated to match them. |
| 1170 | 1164 |
| 1171 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 1165 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 1172 mock_pref_hash_store_->stored_value(kAtomicPref); | 1166 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 1173 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 1167 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::ATOMIC, |
| 1174 stored_atomic_value.second); | 1168 stored_atomic_value.second); |
| 1175 const base::Value* atomic_value_in_store; | 1169 const base::Value* atomic_value_in_store; |
| 1176 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store)); | 1170 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store)); |
| 1177 ASSERT_EQ(string_value, atomic_value_in_store); | 1171 ASSERT_EQ(string_value, atomic_value_in_store); |
| 1178 ASSERT_EQ(string_value, stored_atomic_value.first); | 1172 ASSERT_EQ(string_value, stored_atomic_value.first); |
| 1179 | 1173 |
| 1180 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 1174 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 1181 mock_pref_hash_store_->stored_value(kSplitPref); | 1175 mock_pref_hash_store_->stored_value(kSplitPref); |
| 1182 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); | 1176 ASSERT_EQ(PrefHashFilter::PrefTrackingStrategy::SPLIT, |
| 1177 stored_split_value.second); |
| 1183 const base::Value* split_value_in_store; | 1178 const base::Value* split_value_in_store; |
| 1184 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); | 1179 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); |
| 1185 ASSERT_EQ(dict_value, split_value_in_store); | 1180 ASSERT_EQ(dict_value, split_value_in_store); |
| 1186 ASSERT_EQ(dict_value, stored_split_value.first); | 1181 ASSERT_EQ(dict_value, stored_split_value.first); |
| 1187 | 1182 |
| 1188 VerifyRecordedReset(false); | 1183 VerifyRecordedReset(false); |
| 1189 } | 1184 } |
| 1190 | 1185 |
| 1191 TEST_P(PrefHashFilterTest, DontResetReportOnly) { | 1186 TEST_P(PrefHashFilterTest, DontResetReportOnly) { |
| 1192 // Ownership of these values is transfered to |pref_store_contents_|. | 1187 // Ownership of these values is transfered to |pref_store_contents_|. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1207 | 1202 |
| 1208 mock_pref_hash_store_->SetCheckResult(kAtomicPref, | 1203 mock_pref_hash_store_->SetCheckResult(kAtomicPref, |
| 1209 PrefHashStoreTransaction::CHANGED); | 1204 PrefHashStoreTransaction::CHANGED); |
| 1210 mock_pref_hash_store_->SetCheckResult(kAtomicPref2, | 1205 mock_pref_hash_store_->SetCheckResult(kAtomicPref2, |
| 1211 PrefHashStoreTransaction::CHANGED); | 1206 PrefHashStoreTransaction::CHANGED); |
| 1212 mock_pref_hash_store_->SetCheckResult(kReportOnlyPref, | 1207 mock_pref_hash_store_->SetCheckResult(kReportOnlyPref, |
| 1213 PrefHashStoreTransaction::CHANGED); | 1208 PrefHashStoreTransaction::CHANGED); |
| 1214 mock_pref_hash_store_->SetCheckResult(kReportOnlySplitPref, | 1209 mock_pref_hash_store_->SetCheckResult(kReportOnlySplitPref, |
| 1215 PrefHashStoreTransaction::CHANGED); | 1210 PrefHashStoreTransaction::CHANGED); |
| 1216 | 1211 |
| 1217 DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD); | 1212 DoFilterOnLoad(GetParam() >= |
| 1213 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD); |
| 1218 // All prefs should be checked and a new hash should be stored for each tested | 1214 // All prefs should be checked and a new hash should be stored for each tested |
| 1219 // pref. | 1215 // pref. |
| 1220 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 1216 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 1221 mock_pref_hash_store_->checked_paths_count()); | 1217 mock_pref_hash_store_->checked_paths_count()); |
| 1222 ASSERT_EQ(4u, mock_pref_hash_store_->stored_paths_count()); | 1218 ASSERT_EQ(4u, mock_pref_hash_store_->stored_paths_count()); |
| 1223 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 1219 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 1224 | 1220 |
| 1225 // Delegate saw all prefs, four of which had the expected value_state. | 1221 // Delegate saw all prefs, four of which had the expected value_state. |
| 1226 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 1222 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 1227 mock_validation_delegate_record_->recorded_validations_count()); | 1223 mock_validation_delegate_record_->recorded_validations_count()); |
| 1228 ASSERT_EQ(4u, mock_validation_delegate_record_->CountValidationsOfState( | 1224 ASSERT_EQ(4u, mock_validation_delegate_record_->CountValidationsOfState( |
| 1229 PrefHashStoreTransaction::CHANGED)); | 1225 PrefHashStoreTransaction::CHANGED)); |
| 1230 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 4u, | 1226 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 4u, |
| 1231 mock_validation_delegate_record_->CountValidationsOfState( | 1227 mock_validation_delegate_record_->CountValidationsOfState( |
| 1232 PrefHashStoreTransaction::UNCHANGED)); | 1228 PrefHashStoreTransaction::UNCHANGED)); |
| 1233 | 1229 |
| 1234 // No matter what the enforcement level is, the report only pref should never | 1230 // No matter what the enforcement level is, the report only pref should never |
| 1235 // be reset. | 1231 // be reset. |
| 1236 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlyPref, NULL)); | 1232 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlyPref, NULL)); |
| 1237 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlySplitPref, NULL)); | 1233 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlySplitPref, NULL)); |
| 1238 ASSERT_EQ(report_only_val, | 1234 ASSERT_EQ(report_only_val, |
| 1239 mock_pref_hash_store_->stored_value(kReportOnlyPref).first); | 1235 mock_pref_hash_store_->stored_value(kReportOnlyPref).first); |
| 1240 ASSERT_EQ(report_only_split_val, | 1236 ASSERT_EQ(report_only_split_val, |
| 1241 mock_pref_hash_store_->stored_value(kReportOnlySplitPref).first); | 1237 mock_pref_hash_store_->stored_value(kReportOnlySplitPref).first); |
| 1242 | 1238 |
| 1243 // All other prefs should have been reset if the enforcement level allows it. | 1239 // All other prefs should have been reset if the enforcement level allows it. |
| 1244 if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) { | 1240 if (GetParam() == PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD) { |
| 1245 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); | 1241 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 1246 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref2, NULL)); | 1242 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref2, NULL)); |
| 1247 ASSERT_EQ(NULL, mock_pref_hash_store_->stored_value(kAtomicPref).first); | 1243 ASSERT_EQ(NULL, mock_pref_hash_store_->stored_value(kAtomicPref).first); |
| 1248 ASSERT_EQ(NULL, mock_pref_hash_store_->stored_value(kAtomicPref2).first); | 1244 ASSERT_EQ(NULL, mock_pref_hash_store_->stored_value(kAtomicPref2).first); |
| 1249 | 1245 |
| 1250 VerifyRecordedReset(true); | 1246 VerifyRecordedReset(true); |
| 1251 } else { | 1247 } else { |
| 1252 const base::Value* value_in_store; | 1248 const base::Value* value_in_store; |
| 1253 const base::Value* value_in_store2; | 1249 const base::Value* value_in_store2; |
| 1254 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &value_in_store)); | 1250 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &value_in_store)); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 | 1380 |
| 1385 // External validation should have two CHANGED prefs (kAtomic and kSplit). | 1381 // External validation should have two CHANGED prefs (kAtomic and kSplit). |
| 1386 ASSERT_EQ(2u, | 1382 ASSERT_EQ(2u, |
| 1387 mock_validation_delegate_record_->CountExternalValidationsOfState( | 1383 mock_validation_delegate_record_->CountExternalValidationsOfState( |
| 1388 PrefHashStoreTransaction::CHANGED)); | 1384 PrefHashStoreTransaction::CHANGED)); |
| 1389 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, | 1385 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, |
| 1390 mock_validation_delegate_record_->CountExternalValidationsOfState( | 1386 mock_validation_delegate_record_->CountExternalValidationsOfState( |
| 1391 PrefHashStoreTransaction::UNCHANGED)); | 1387 PrefHashStoreTransaction::UNCHANGED)); |
| 1392 } | 1388 } |
| 1393 | 1389 |
| 1394 INSTANTIATE_TEST_CASE_P(PrefHashFilterTestInstance, | 1390 INSTANTIATE_TEST_CASE_P( |
| 1395 PrefHashFilterTest, | 1391 PrefHashFilterTestInstance, |
| 1396 testing::Values(PrefHashFilter::NO_ENFORCEMENT, | 1392 PrefHashFilterTest, |
| 1397 PrefHashFilter::ENFORCE_ON_LOAD)); | 1393 testing::Values(PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT, |
| 1394 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD)); |
| OLD | NEW |