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 "services/preferences/tracked/pref_hash_filter.h" | 5 #include "services/preferences/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 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 TEST_P(PrefHashFilterTest, StampSuperMACAltersStore) { | 675 TEST_P(PrefHashFilterTest, StampSuperMACAltersStore) { |
676 mock_pref_hash_store_->set_stamp_super_mac_result(true); | 676 mock_pref_hash_store_->set_stamp_super_mac_result(true); |
677 DoFilterOnLoad(true); | 677 DoFilterOnLoad(true); |
678 // No paths stored, since they all return |UNCHANGED|. The StampSuperMAC | 678 // No paths stored, since they all return |UNCHANGED|. The StampSuperMAC |
679 // result is the only reason the prefs were considered altered. | 679 // result is the only reason the prefs were considered altered. |
680 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 680 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
681 } | 681 } |
682 | 682 |
683 TEST_P(PrefHashFilterTest, FilterTrackedPrefUpdate) { | 683 TEST_P(PrefHashFilterTest, FilterTrackedPrefUpdate) { |
684 base::DictionaryValue root_dict; | 684 base::DictionaryValue root_dict; |
685 // Ownership of |string_value| is transfered to |root_dict|. | 685 base::Value* string_value = root_dict.SetString(kAtomicPref, "string value"); |
686 base::Value* string_value = new base::Value("string value"); | |
687 root_dict.Set(kAtomicPref, string_value); | |
688 | 686 |
689 // No path should be stored on FilterUpdate. | 687 // No path should be stored on FilterUpdate. |
690 pref_hash_filter_->FilterUpdate(kAtomicPref); | 688 pref_hash_filter_->FilterUpdate(kAtomicPref); |
691 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 689 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
692 | 690 |
693 // One path should be stored on FilterSerializeData. | 691 // One path should be stored on FilterSerializeData. |
694 pref_hash_filter_->FilterSerializeData(&root_dict); | 692 pref_hash_filter_->FilterSerializeData(&root_dict); |
695 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count()); | 693 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count()); |
696 MockPrefHashStore::ValuePtrStrategyPair stored_value = | 694 MockPrefHashStore::ValuePtrStrategyPair stored_value = |
697 mock_pref_hash_store_->stored_value(kAtomicPref); | 695 mock_pref_hash_store_->stored_value(kAtomicPref); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 | 731 |
734 DoFilterOnLoad(false); | 732 DoFilterOnLoad(false); |
735 | 733 |
736 // Verify that the validity was reported. | 734 // Verify that the validity was reported. |
737 ASSERT_EQ(initial_untrusted + 1, histogram->SnapshotSamples()->GetCount(0)); | 735 ASSERT_EQ(initial_untrusted + 1, histogram->SnapshotSamples()->GetCount(0)); |
738 ASSERT_EQ(initial_trusted + 1, histogram->SnapshotSamples()->GetCount(1)); | 736 ASSERT_EQ(initial_trusted + 1, histogram->SnapshotSamples()->GetCount(1)); |
739 } | 737 } |
740 | 738 |
741 TEST_P(PrefHashFilterTest, FilterSplitPrefUpdate) { | 739 TEST_P(PrefHashFilterTest, FilterSplitPrefUpdate) { |
742 base::DictionaryValue root_dict; | 740 base::DictionaryValue root_dict; |
743 // Ownership of |dict_value| is transfered to |root_dict|. | 741 base::DictionaryValue* dict_value = root_dict.SetDictionary( |
744 base::DictionaryValue* dict_value = new base::DictionaryValue; | 742 kSplitPref, base::MakeUnique<base::DictionaryValue>()); |
745 dict_value->SetString("a", "foo"); | 743 dict_value->SetString("a", "foo"); |
746 dict_value->SetInteger("b", 1234); | 744 dict_value->SetInteger("b", 1234); |
747 root_dict.Set(kSplitPref, dict_value); | |
748 | 745 |
749 // No path should be stored on FilterUpdate. | 746 // No path should be stored on FilterUpdate. |
750 pref_hash_filter_->FilterUpdate(kSplitPref); | 747 pref_hash_filter_->FilterUpdate(kSplitPref); |
751 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 748 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
752 | 749 |
753 // One path should be stored on FilterSerializeData. | 750 // One path should be stored on FilterSerializeData. |
754 pref_hash_filter_->FilterSerializeData(&root_dict); | 751 pref_hash_filter_->FilterSerializeData(&root_dict); |
755 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count()); | 752 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count()); |
756 MockPrefHashStore::ValuePtrStrategyPair stored_value = | 753 MockPrefHashStore::ValuePtrStrategyPair stored_value = |
757 mock_pref_hash_store_->stored_value(kSplitPref); | 754 mock_pref_hash_store_->stored_value(kSplitPref); |
758 ASSERT_EQ(dict_value, stored_value.first); | 755 ASSERT_EQ(dict_value, stored_value.first); |
759 ASSERT_EQ(PrefTrackingStrategy::SPLIT, stored_value.second); | 756 ASSERT_EQ(PrefTrackingStrategy::SPLIT, stored_value.second); |
760 | 757 |
761 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 758 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
762 VerifyRecordedReset(false); | 759 VerifyRecordedReset(false); |
763 } | 760 } |
764 | 761 |
765 TEST_P(PrefHashFilterTest, FilterUntrackedPrefUpdate) { | 762 TEST_P(PrefHashFilterTest, FilterUntrackedPrefUpdate) { |
766 base::DictionaryValue root_dict; | 763 base::DictionaryValue root_dict; |
767 root_dict.Set("untracked", new base::Value("some value")); | 764 root_dict.SetString("untracked", "some value"); |
768 pref_hash_filter_->FilterUpdate("untracked"); | 765 pref_hash_filter_->FilterUpdate("untracked"); |
769 | 766 |
770 // No paths should be stored on FilterUpdate. | 767 // No paths should be stored on FilterUpdate. |
771 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 768 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
772 | 769 |
773 // Nor on FilterSerializeData. | 770 // Nor on FilterSerializeData. |
774 pref_hash_filter_->FilterSerializeData(&root_dict); | 771 pref_hash_filter_->FilterSerializeData(&root_dict); |
775 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 772 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
776 | 773 |
777 // No transaction should even be started on FilterSerializeData() if there are | 774 // No transaction should even be started on FilterSerializeData() if there are |
778 // no updates to perform. | 775 // no updates to perform. |
779 ASSERT_EQ(0u, mock_pref_hash_store_->transactions_performed()); | 776 ASSERT_EQ(0u, mock_pref_hash_store_->transactions_performed()); |
780 } | 777 } |
781 | 778 |
782 TEST_P(PrefHashFilterTest, MultiplePrefsFilterSerializeData) { | 779 TEST_P(PrefHashFilterTest, MultiplePrefsFilterSerializeData) { |
783 base::DictionaryValue root_dict; | 780 base::DictionaryValue root_dict; |
784 // Ownership of the following values is transfered to |root_dict|. | 781 base::Value* int_value1 = root_dict.SetInteger(kAtomicPref, 1); |
785 base::Value* int_value1 = new base::Value(1); | 782 root_dict.SetInteger(kAtomicPref2, 2); |
786 base::Value* int_value2 = new base::Value(2); | 783 root_dict.SetInteger(kAtomicPref3, 3); |
787 base::Value* int_value3 = new base::Value(3); | 784 root_dict.SetInteger("untracked", 4); |
788 base::Value* int_value4 = new base::Value(4); | 785 base::DictionaryValue* dict_value = root_dict.SetDictionary( |
789 base::DictionaryValue* dict_value = new base::DictionaryValue; | 786 kSplitPref, base::MakeUnique<base::DictionaryValue>()); |
790 dict_value->Set("a", new base::Value(true)); | 787 dict_value->SetBoolean("a", true); |
791 root_dict.Set(kAtomicPref, int_value1); | |
792 root_dict.Set(kAtomicPref2, int_value2); | |
793 root_dict.Set(kAtomicPref3, int_value3); | |
794 root_dict.Set("untracked", int_value4); | |
795 root_dict.Set(kSplitPref, dict_value); | |
796 | 788 |
797 // Only update kAtomicPref, kAtomicPref3, and kSplitPref. | 789 // Only update kAtomicPref, kAtomicPref3, and kSplitPref. |
798 pref_hash_filter_->FilterUpdate(kAtomicPref); | 790 pref_hash_filter_->FilterUpdate(kAtomicPref); |
799 pref_hash_filter_->FilterUpdate(kAtomicPref3); | 791 pref_hash_filter_->FilterUpdate(kAtomicPref3); |
800 pref_hash_filter_->FilterUpdate(kSplitPref); | 792 pref_hash_filter_->FilterUpdate(kSplitPref); |
801 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 793 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
802 | 794 |
803 // Update kAtomicPref3 again, nothing should be stored still. | 795 // Update kAtomicPref3 again, nothing should be stored still. |
804 base::Value* int_value5 = new base::Value(5); | 796 base::Value* int_value5 = root_dict.SetInteger(kAtomicPref3, 5); |
805 root_dict.Set(kAtomicPref3, int_value5); | |
806 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 797 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
807 | 798 |
808 // On FilterSerializeData, only kAtomicPref, kAtomicPref3, and kSplitPref | 799 // On FilterSerializeData, only kAtomicPref, kAtomicPref3, and kSplitPref |
809 // should get a new hash. | 800 // should get a new hash. |
810 pref_hash_filter_->FilterSerializeData(&root_dict); | 801 pref_hash_filter_->FilterSerializeData(&root_dict); |
811 ASSERT_EQ(3u, mock_pref_hash_store_->stored_paths_count()); | 802 ASSERT_EQ(3u, mock_pref_hash_store_->stored_paths_count()); |
812 MockPrefHashStore::ValuePtrStrategyPair stored_value_atomic1 = | 803 MockPrefHashStore::ValuePtrStrategyPair stored_value_atomic1 = |
813 mock_pref_hash_store_->stored_value(kAtomicPref); | 804 mock_pref_hash_store_->stored_value(kAtomicPref); |
814 ASSERT_EQ(int_value1, stored_value_atomic1.first); | 805 ASSERT_EQ(int_value1, stored_value_atomic1.first); |
815 ASSERT_EQ(PrefTrackingStrategy::ATOMIC, stored_value_atomic1.second); | 806 ASSERT_EQ(PrefTrackingStrategy::ATOMIC, stored_value_atomic1.second); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 mock_validation_delegate_record_->GetEventForPath(kSplitPref); | 854 mock_validation_delegate_record_->GetEventForPath(kSplitPref); |
864 ASSERT_EQ(PrefTrackingStrategy::SPLIT, validated_split_pref->strategy); | 855 ASSERT_EQ(PrefTrackingStrategy::SPLIT, validated_split_pref->strategy); |
865 ASSERT_FALSE(validated_split_pref->is_personal); | 856 ASSERT_FALSE(validated_split_pref->is_personal); |
866 const MockValidationDelegateRecord::ValidationEvent* validated_atomic_pref = | 857 const MockValidationDelegateRecord::ValidationEvent* validated_atomic_pref = |
867 mock_validation_delegate_record_->GetEventForPath(kAtomicPref); | 858 mock_validation_delegate_record_->GetEventForPath(kAtomicPref); |
868 ASSERT_EQ(PrefTrackingStrategy::ATOMIC, validated_atomic_pref->strategy); | 859 ASSERT_EQ(PrefTrackingStrategy::ATOMIC, validated_atomic_pref->strategy); |
869 ASSERT_TRUE(validated_atomic_pref->is_personal); | 860 ASSERT_TRUE(validated_atomic_pref->is_personal); |
870 } | 861 } |
871 | 862 |
872 TEST_P(PrefHashFilterTest, InitialValueUnknown) { | 863 TEST_P(PrefHashFilterTest, InitialValueUnknown) { |
873 // Ownership of these values is transfered to |pref_store_contents_|. | 864 base::Value* string_value = |
874 base::Value* string_value = new base::Value("string value"); | 865 pref_store_contents_->SetString(kAtomicPref, "string value"); |
875 pref_store_contents_->Set(kAtomicPref, string_value); | |
876 | 866 |
877 base::DictionaryValue* dict_value = new base::DictionaryValue; | 867 base::DictionaryValue* dict_value = pref_store_contents_->SetDictionary( |
| 868 kSplitPref, base::MakeUnique<base::DictionaryValue>()); |
878 dict_value->SetString("a", "foo"); | 869 dict_value->SetString("a", "foo"); |
879 dict_value->SetInteger("b", 1234); | 870 dict_value->SetInteger("b", 1234); |
880 pref_store_contents_->Set(kSplitPref, dict_value); | |
881 | 871 |
882 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); | 872 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); |
883 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); | 873 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); |
884 | 874 |
885 mock_pref_hash_store_->SetCheckResult(kAtomicPref, | 875 mock_pref_hash_store_->SetCheckResult(kAtomicPref, |
886 ValueState::UNTRUSTED_UNKNOWN_VALUE); | 876 ValueState::UNTRUSTED_UNKNOWN_VALUE); |
887 mock_pref_hash_store_->SetCheckResult(kSplitPref, | 877 mock_pref_hash_store_->SetCheckResult(kSplitPref, |
888 ValueState::UNTRUSTED_UNKNOWN_VALUE); | 878 ValueState::UNTRUSTED_UNKNOWN_VALUE); |
889 // If we are enforcing, expect this to report changes. | 879 // If we are enforcing, expect this to report changes. |
890 DoFilterOnLoad(GetParam() >= EnforcementLevel::ENFORCE_ON_LOAD); | 880 DoFilterOnLoad(GetParam() >= EnforcementLevel::ENFORCE_ON_LOAD); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 const base::Value* split_value_in_store; | 919 const base::Value* split_value_in_store; |
930 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); | 920 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); |
931 ASSERT_EQ(dict_value, split_value_in_store); | 921 ASSERT_EQ(dict_value, split_value_in_store); |
932 ASSERT_EQ(dict_value, stored_split_value.first); | 922 ASSERT_EQ(dict_value, stored_split_value.first); |
933 | 923 |
934 VerifyRecordedReset(false); | 924 VerifyRecordedReset(false); |
935 } | 925 } |
936 } | 926 } |
937 | 927 |
938 TEST_P(PrefHashFilterTest, InitialValueTrustedUnknown) { | 928 TEST_P(PrefHashFilterTest, InitialValueTrustedUnknown) { |
939 // Ownership of this value is transfered to |pref_store_contents_|. | 929 base::Value* string_value = |
940 base::Value* string_value = new base::Value("test"); | 930 pref_store_contents_->SetString(kAtomicPref, "test"); |
941 pref_store_contents_->Set(kAtomicPref, string_value); | |
942 | 931 |
943 base::DictionaryValue* dict_value = new base::DictionaryValue; | 932 auto* dict_value = pref_store_contents_->SetDictionary( |
| 933 kSplitPref, base::MakeUnique<base::DictionaryValue>()); |
944 dict_value->SetString("a", "foo"); | 934 dict_value->SetString("a", "foo"); |
945 dict_value->SetInteger("b", 1234); | 935 dict_value->SetInteger("b", 1234); |
946 pref_store_contents_->Set(kSplitPref, dict_value); | |
947 | 936 |
948 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); | 937 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); |
949 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); | 938 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); |
950 | 939 |
951 mock_pref_hash_store_->SetCheckResult(kAtomicPref, | 940 mock_pref_hash_store_->SetCheckResult(kAtomicPref, |
952 ValueState::TRUSTED_UNKNOWN_VALUE); | 941 ValueState::TRUSTED_UNKNOWN_VALUE); |
953 mock_pref_hash_store_->SetCheckResult(kSplitPref, | 942 mock_pref_hash_store_->SetCheckResult(kSplitPref, |
954 ValueState::TRUSTED_UNKNOWN_VALUE); | 943 ValueState::TRUSTED_UNKNOWN_VALUE); |
955 DoFilterOnLoad(false); | 944 DoFilterOnLoad(false); |
956 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 945 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
(...skipping 22 matching lines...) Expand all Loading... |
979 const base::Value* split_value_in_store; | 968 const base::Value* split_value_in_store; |
980 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); | 969 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); |
981 ASSERT_EQ(dict_value, split_value_in_store); | 970 ASSERT_EQ(dict_value, split_value_in_store); |
982 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 971 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
983 mock_pref_hash_store_->stored_value(kSplitPref); | 972 mock_pref_hash_store_->stored_value(kSplitPref); |
984 ASSERT_EQ(dict_value, stored_split_value.first); | 973 ASSERT_EQ(dict_value, stored_split_value.first); |
985 ASSERT_EQ(PrefTrackingStrategy::SPLIT, stored_split_value.second); | 974 ASSERT_EQ(PrefTrackingStrategy::SPLIT, stored_split_value.second); |
986 } | 975 } |
987 | 976 |
988 TEST_P(PrefHashFilterTest, InitialValueChanged) { | 977 TEST_P(PrefHashFilterTest, InitialValueChanged) { |
989 // Ownership of this value is transfered to |pref_store_contents_|. | 978 base::Value* int_value = pref_store_contents_->SetInteger(kAtomicPref, 1234); |
990 base::Value* int_value = new base::Value(1234); | |
991 pref_store_contents_->Set(kAtomicPref, int_value); | |
992 | 979 |
993 base::DictionaryValue* dict_value = new base::DictionaryValue; | 980 base::DictionaryValue* dict_value = pref_store_contents_->SetDictionary( |
| 981 kSplitPref, base::MakeUnique<base::DictionaryValue>()); |
994 dict_value->SetString("a", "foo"); | 982 dict_value->SetString("a", "foo"); |
995 dict_value->SetInteger("b", 1234); | 983 dict_value->SetInteger("b", 1234); |
996 dict_value->SetInteger("c", 56); | 984 dict_value->SetInteger("c", 56); |
997 dict_value->SetBoolean("d", false); | 985 dict_value->SetBoolean("d", false); |
998 pref_store_contents_->Set(kSplitPref, dict_value); | |
999 | 986 |
1000 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); | 987 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); |
1001 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); | 988 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); |
1002 | 989 |
1003 mock_pref_hash_store_->SetCheckResult(kAtomicPref, ValueState::CHANGED); | 990 mock_pref_hash_store_->SetCheckResult(kAtomicPref, ValueState::CHANGED); |
1004 mock_pref_hash_store_->SetCheckResult(kSplitPref, ValueState::CHANGED); | 991 mock_pref_hash_store_->SetCheckResult(kSplitPref, ValueState::CHANGED); |
1005 | 992 |
1006 std::vector<std::string> mock_invalid_keys; | 993 std::vector<std::string> mock_invalid_keys; |
1007 mock_invalid_keys.push_back("a"); | 994 mock_invalid_keys.push_back("a"); |
1008 mock_invalid_keys.push_back("c"); | 995 mock_invalid_keys.push_back("c"); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 ASSERT_EQ(PrefTrackingStrategy::ATOMIC, stored_atomic_value.second); | 1076 ASSERT_EQ(PrefTrackingStrategy::ATOMIC, stored_atomic_value.second); |
1090 | 1077 |
1091 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); | 1078 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); |
1092 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 1079 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
1093 mock_pref_hash_store_->stored_value(kSplitPref); | 1080 mock_pref_hash_store_->stored_value(kSplitPref); |
1094 ASSERT_EQ(NULL, stored_split_value.first); | 1081 ASSERT_EQ(NULL, stored_split_value.first); |
1095 ASSERT_EQ(PrefTrackingStrategy::SPLIT, stored_split_value.second); | 1082 ASSERT_EQ(PrefTrackingStrategy::SPLIT, stored_split_value.second); |
1096 } | 1083 } |
1097 | 1084 |
1098 TEST_P(PrefHashFilterTest, InitialValueUnchangedLegacyId) { | 1085 TEST_P(PrefHashFilterTest, InitialValueUnchangedLegacyId) { |
1099 // Ownership of these values is transfered to |pref_store_contents_|. | 1086 base::Value* string_value = |
1100 base::Value* string_value = new base::Value("string value"); | 1087 pref_store_contents_->SetString(kAtomicPref, "string value"); |
1101 pref_store_contents_->Set(kAtomicPref, string_value); | |
1102 | 1088 |
1103 base::DictionaryValue* dict_value = new base::DictionaryValue; | 1089 base::DictionaryValue* dict_value = pref_store_contents_->SetDictionary( |
| 1090 kSplitPref, base::MakeUnique<base::DictionaryValue>()); |
1104 dict_value->SetString("a", "foo"); | 1091 dict_value->SetString("a", "foo"); |
1105 dict_value->SetInteger("b", 1234); | 1092 dict_value->SetInteger("b", 1234); |
1106 pref_store_contents_->Set(kSplitPref, dict_value); | |
1107 | 1093 |
1108 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); | 1094 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); |
1109 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); | 1095 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); |
1110 | 1096 |
1111 mock_pref_hash_store_->SetCheckResult(kAtomicPref, ValueState::SECURE_LEGACY); | 1097 mock_pref_hash_store_->SetCheckResult(kAtomicPref, ValueState::SECURE_LEGACY); |
1112 mock_pref_hash_store_->SetCheckResult(kSplitPref, ValueState::SECURE_LEGACY); | 1098 mock_pref_hash_store_->SetCheckResult(kSplitPref, ValueState::SECURE_LEGACY); |
1113 DoFilterOnLoad(false); | 1099 DoFilterOnLoad(false); |
1114 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 1100 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
1115 mock_pref_hash_store_->checked_paths_count()); | 1101 mock_pref_hash_store_->checked_paths_count()); |
1116 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 1102 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
(...skipping 26 matching lines...) Expand all Loading... |
1143 ASSERT_EQ(PrefTrackingStrategy::SPLIT, stored_split_value.second); | 1129 ASSERT_EQ(PrefTrackingStrategy::SPLIT, stored_split_value.second); |
1144 const base::Value* split_value_in_store; | 1130 const base::Value* split_value_in_store; |
1145 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); | 1131 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); |
1146 ASSERT_EQ(dict_value, split_value_in_store); | 1132 ASSERT_EQ(dict_value, split_value_in_store); |
1147 ASSERT_EQ(dict_value, stored_split_value.first); | 1133 ASSERT_EQ(dict_value, stored_split_value.first); |
1148 | 1134 |
1149 VerifyRecordedReset(false); | 1135 VerifyRecordedReset(false); |
1150 } | 1136 } |
1151 | 1137 |
1152 TEST_P(PrefHashFilterTest, DontResetReportOnly) { | 1138 TEST_P(PrefHashFilterTest, DontResetReportOnly) { |
1153 // Ownership of these values is transfered to |pref_store_contents_|. | 1139 base::Value* int_value1 = pref_store_contents_->SetInteger(kAtomicPref, 1); |
1154 base::Value* int_value1 = new base::Value(1); | 1140 base::Value* int_value2 = pref_store_contents_->SetInteger(kAtomicPref2, 2); |
1155 base::Value* int_value2 = new base::Value(2); | 1141 base::Value* report_only_val = |
1156 base::Value* report_only_val = new base::Value(3); | 1142 pref_store_contents_->SetInteger(kReportOnlyPref, 3); |
1157 base::DictionaryValue* report_only_split_val = new base::DictionaryValue; | 1143 base::DictionaryValue* report_only_split_val = |
| 1144 pref_store_contents_->SetDictionary( |
| 1145 kReportOnlySplitPref, base::MakeUnique<base::DictionaryValue>()); |
1158 report_only_split_val->SetInteger("a", 1234); | 1146 report_only_split_val->SetInteger("a", 1234); |
1159 pref_store_contents_->Set(kAtomicPref, int_value1); | |
1160 pref_store_contents_->Set(kAtomicPref2, int_value2); | |
1161 pref_store_contents_->Set(kReportOnlyPref, report_only_val); | |
1162 pref_store_contents_->Set(kReportOnlySplitPref, report_only_split_val); | |
1163 | 1147 |
1164 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); | 1148 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); |
1165 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref2, NULL)); | 1149 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref2, NULL)); |
1166 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlyPref, NULL)); | 1150 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlyPref, NULL)); |
1167 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlySplitPref, NULL)); | 1151 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlySplitPref, NULL)); |
1168 | 1152 |
1169 mock_pref_hash_store_->SetCheckResult(kAtomicPref, ValueState::CHANGED); | 1153 mock_pref_hash_store_->SetCheckResult(kAtomicPref, ValueState::CHANGED); |
1170 mock_pref_hash_store_->SetCheckResult(kAtomicPref2, ValueState::CHANGED); | 1154 mock_pref_hash_store_->SetCheckResult(kAtomicPref2, ValueState::CHANGED); |
1171 mock_pref_hash_store_->SetCheckResult(kReportOnlyPref, ValueState::CHANGED); | 1155 mock_pref_hash_store_->SetCheckResult(kReportOnlyPref, ValueState::CHANGED); |
1172 mock_pref_hash_store_->SetCheckResult(kReportOnlySplitPref, | 1156 mock_pref_hash_store_->SetCheckResult(kReportOnlySplitPref, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 ASSERT_EQ(int_value2, value_in_store2); | 1201 ASSERT_EQ(int_value2, value_in_store2); |
1218 ASSERT_EQ(int_value2, | 1202 ASSERT_EQ(int_value2, |
1219 mock_pref_hash_store_->stored_value(kAtomicPref2).first); | 1203 mock_pref_hash_store_->stored_value(kAtomicPref2).first); |
1220 | 1204 |
1221 VerifyRecordedReset(false); | 1205 VerifyRecordedReset(false); |
1222 } | 1206 } |
1223 } | 1207 } |
1224 | 1208 |
1225 TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacks) { | 1209 TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacks) { |
1226 base::DictionaryValue root_dict; | 1210 base::DictionaryValue root_dict; |
1227 // Ownership of the following values is transfered to |root_dict|. | 1211 auto dict_value = base::MakeUnique<base::DictionaryValue>(); |
1228 base::Value* int_value1 = new base::Value(1); | 1212 dict_value->SetBoolean("a", true); |
1229 base::Value* int_value2 = new base::Value(2); | 1213 root_dict.SetInteger(kAtomicPref, 1); |
1230 base::DictionaryValue* dict_value = new base::DictionaryValue; | 1214 root_dict.SetInteger(kAtomicPref2, 2); |
1231 dict_value->Set("a", new base::Value(true)); | 1215 root_dict.Set(kSplitPref, std::move(dict_value)); |
1232 root_dict.Set(kAtomicPref, int_value1); | |
1233 root_dict.Set(kAtomicPref2, int_value2); | |
1234 root_dict.Set(kSplitPref, dict_value); | |
1235 | 1216 |
1236 // Skip updating kAtomicPref2. | 1217 // Skip updating kAtomicPref2. |
1237 pref_hash_filter_->FilterUpdate(kAtomicPref); | 1218 pref_hash_filter_->FilterUpdate(kAtomicPref); |
1238 pref_hash_filter_->FilterUpdate(kSplitPref); | 1219 pref_hash_filter_->FilterUpdate(kSplitPref); |
1239 | 1220 |
1240 PrefHashFilter::OnWriteCallbackPair callbacks = | 1221 PrefHashFilter::OnWriteCallbackPair callbacks = |
1241 pref_hash_filter_->FilterSerializeData(&root_dict); | 1222 pref_hash_filter_->FilterSerializeData(&root_dict); |
1242 | 1223 |
1243 ASSERT_FALSE(callbacks.first.is_null()); | 1224 ASSERT_FALSE(callbacks.first.is_null()); |
1244 | 1225 |
(...skipping 21 matching lines...) Expand all Loading... |
1266 kSplitPref, "a")); | 1247 kSplitPref, "a")); |
1267 | 1248 |
1268 // The callbacks should write directly to the contents without going through | 1249 // The callbacks should write directly to the contents without going through |
1269 // a pref hash store. | 1250 // a pref hash store. |
1270 ASSERT_EQ(0u, | 1251 ASSERT_EQ(0u, |
1271 mock_external_validation_pref_hash_store_->stored_paths_count()); | 1252 mock_external_validation_pref_hash_store_->stored_paths_count()); |
1272 } | 1253 } |
1273 | 1254 |
1274 TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacksWithFailure) { | 1255 TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacksWithFailure) { |
1275 base::DictionaryValue root_dict; | 1256 base::DictionaryValue root_dict; |
1276 // Ownership of the following values is transfered to |root_dict|. | 1257 root_dict.SetInteger(kAtomicPref, 1); |
1277 base::Value* int_value1 = new base::Value(1); | |
1278 root_dict.Set(kAtomicPref, int_value1); | |
1279 | 1258 |
1280 // Only update kAtomicPref. | 1259 // Only update kAtomicPref. |
1281 pref_hash_filter_->FilterUpdate(kAtomicPref); | 1260 pref_hash_filter_->FilterUpdate(kAtomicPref); |
1282 | 1261 |
1283 PrefHashFilter::OnWriteCallbackPair callbacks = | 1262 PrefHashFilter::OnWriteCallbackPair callbacks = |
1284 pref_hash_filter_->FilterSerializeData(&root_dict); | 1263 pref_hash_filter_->FilterSerializeData(&root_dict); |
1285 | 1264 |
1286 ASSERT_FALSE(callbacks.first.is_null()); | 1265 ASSERT_FALSE(callbacks.first.is_null()); |
1287 | 1266 |
1288 callbacks.first.Run(); | 1267 callbacks.first.Run(); |
1289 | 1268 |
1290 // The pref should have been cleared from the external validation store. | 1269 // The pref should have been cleared from the external validation store. |
1291 ASSERT_EQ( | 1270 ASSERT_EQ( |
1292 1u, mock_external_validation_hash_store_contents_->cleared_paths_count()); | 1271 1u, mock_external_validation_hash_store_contents_->cleared_paths_count()); |
1293 | 1272 |
1294 callbacks.second.Run(false); | 1273 callbacks.second.Run(false); |
1295 | 1274 |
1296 // Expect no writes to the external validation hash store contents. | 1275 // Expect no writes to the external validation hash store contents. |
1297 ASSERT_EQ(0u, | 1276 ASSERT_EQ(0u, |
1298 mock_external_validation_pref_hash_store_->stored_paths_count()); | 1277 mock_external_validation_pref_hash_store_->stored_paths_count()); |
1299 ASSERT_EQ( | 1278 ASSERT_EQ( |
1300 0u, mock_external_validation_hash_store_contents_->stored_hashes_count()); | 1279 0u, mock_external_validation_hash_store_contents_->stored_hashes_count()); |
1301 } | 1280 } |
1302 | 1281 |
1303 TEST_P(PrefHashFilterTest, ExternalValidationValueChanged) { | 1282 TEST_P(PrefHashFilterTest, ExternalValidationValueChanged) { |
1304 // Ownership of this value is transfered to |pref_store_contents_|. | 1283 pref_store_contents_->SetInteger(kAtomicPref, 1234); |
1305 base::Value* int_value = new base::Value(1234); | |
1306 pref_store_contents_->Set(kAtomicPref, int_value); | |
1307 | 1284 |
1308 base::DictionaryValue* dict_value = new base::DictionaryValue; | 1285 auto dict_value = base::MakeUnique<base::DictionaryValue>(); |
1309 dict_value->SetString("a", "foo"); | 1286 dict_value->SetString("a", "foo"); |
1310 dict_value->SetInteger("b", 1234); | 1287 dict_value->SetInteger("b", 1234); |
1311 dict_value->SetInteger("c", 56); | 1288 dict_value->SetInteger("c", 56); |
1312 dict_value->SetBoolean("d", false); | 1289 dict_value->SetBoolean("d", false); |
1313 pref_store_contents_->Set(kSplitPref, dict_value); | 1290 pref_store_contents_->Set(kSplitPref, std::move(dict_value)); |
1314 | 1291 |
1315 mock_external_validation_pref_hash_store_->SetCheckResult( | 1292 mock_external_validation_pref_hash_store_->SetCheckResult( |
1316 kAtomicPref, ValueState::CHANGED); | 1293 kAtomicPref, ValueState::CHANGED); |
1317 mock_external_validation_pref_hash_store_->SetCheckResult( | 1294 mock_external_validation_pref_hash_store_->SetCheckResult( |
1318 kSplitPref, ValueState::CHANGED); | 1295 kSplitPref, ValueState::CHANGED); |
1319 | 1296 |
1320 std::vector<std::string> mock_invalid_keys; | 1297 std::vector<std::string> mock_invalid_keys; |
1321 mock_invalid_keys.push_back("a"); | 1298 mock_invalid_keys.push_back("a"); |
1322 mock_invalid_keys.push_back("c"); | 1299 mock_invalid_keys.push_back("c"); |
1323 mock_external_validation_pref_hash_store_->SetInvalidKeysResult( | 1300 mock_external_validation_pref_hash_store_->SetInvalidKeysResult( |
(...skipping 22 matching lines...) Expand all Loading... |
1346 ValueState::CHANGED)); | 1323 ValueState::CHANGED)); |
1347 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, | 1324 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, |
1348 mock_validation_delegate_record_->CountExternalValidationsOfState( | 1325 mock_validation_delegate_record_->CountExternalValidationsOfState( |
1349 ValueState::UNCHANGED)); | 1326 ValueState::UNCHANGED)); |
1350 } | 1327 } |
1351 | 1328 |
1352 INSTANTIATE_TEST_CASE_P(PrefHashFilterTestInstance, | 1329 INSTANTIATE_TEST_CASE_P(PrefHashFilterTestInstance, |
1353 PrefHashFilterTest, | 1330 PrefHashFilterTest, |
1354 testing::Values(EnforcementLevel::NO_ENFORCEMENT, | 1331 testing::Values(EnforcementLevel::NO_ENFORCEMENT, |
1355 EnforcementLevel::ENFORCE_ON_LOAD)); | 1332 EnforcementLevel::ENFORCE_ON_LOAD)); |
OLD | NEW |