Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: components/user_prefs/tracked/pref_hash_filter_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698