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

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

Issue 2476493003: Remove FundamentalValue
Patch Set: Fix Created 4 years 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 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); 795 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count());
796 796
797 // No transaction should even be started on FilterSerializeData() if there are 797 // No transaction should even be started on FilterSerializeData() if there are
798 // no updates to perform. 798 // no updates to perform.
799 ASSERT_EQ(0u, mock_pref_hash_store_->transactions_performed()); 799 ASSERT_EQ(0u, mock_pref_hash_store_->transactions_performed());
800 } 800 }
801 801
802 TEST_P(PrefHashFilterTest, MultiplePrefsFilterSerializeData) { 802 TEST_P(PrefHashFilterTest, MultiplePrefsFilterSerializeData) {
803 base::DictionaryValue root_dict; 803 base::DictionaryValue root_dict;
804 // Ownership of the following values is transfered to |root_dict|. 804 // Ownership of the following values is transfered to |root_dict|.
805 base::Value* int_value1 = new base::FundamentalValue(1); 805 base::Value* int_value1 = new base::Value(1);
806 base::Value* int_value2 = new base::FundamentalValue(2); 806 base::Value* int_value2 = new base::Value(2);
807 base::Value* int_value3 = new base::FundamentalValue(3); 807 base::Value* int_value3 = new base::Value(3);
808 base::Value* int_value4 = new base::FundamentalValue(4); 808 base::Value* int_value4 = new base::Value(4);
809 base::DictionaryValue* dict_value = new base::DictionaryValue; 809 base::DictionaryValue* dict_value = new base::DictionaryValue;
810 dict_value->Set("a", new base::FundamentalValue(true)); 810 dict_value->Set("a", new base::Value(true));
811 root_dict.Set(kAtomicPref, int_value1); 811 root_dict.Set(kAtomicPref, int_value1);
812 root_dict.Set(kAtomicPref2, int_value2); 812 root_dict.Set(kAtomicPref2, int_value2);
813 root_dict.Set(kAtomicPref3, int_value3); 813 root_dict.Set(kAtomicPref3, int_value3);
814 root_dict.Set("untracked", int_value4); 814 root_dict.Set("untracked", int_value4);
815 root_dict.Set(kSplitPref, dict_value); 815 root_dict.Set(kSplitPref, dict_value);
816 816
817 // Only update kAtomicPref, kAtomicPref3, and kSplitPref. 817 // Only update kAtomicPref, kAtomicPref3, and kSplitPref.
818 pref_hash_filter_->FilterUpdate(kAtomicPref); 818 pref_hash_filter_->FilterUpdate(kAtomicPref);
819 pref_hash_filter_->FilterUpdate(kAtomicPref3); 819 pref_hash_filter_->FilterUpdate(kAtomicPref3);
820 pref_hash_filter_->FilterUpdate(kSplitPref); 820 pref_hash_filter_->FilterUpdate(kSplitPref);
821 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); 821 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count());
822 822
823 // Update kAtomicPref3 again, nothing should be stored still. 823 // Update kAtomicPref3 again, nothing should be stored still.
824 base::Value* int_value5 = new base::FundamentalValue(5); 824 base::Value* int_value5 = new base::Value(5);
825 root_dict.Set(kAtomicPref3, int_value5); 825 root_dict.Set(kAtomicPref3, int_value5);
826 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); 826 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count());
827 827
828 // On FilterSerializeData, only kAtomicPref, kAtomicPref3, and kSplitPref 828 // On FilterSerializeData, only kAtomicPref, kAtomicPref3, and kSplitPref
829 // should get a new hash. 829 // should get a new hash.
830 pref_hash_filter_->FilterSerializeData(&root_dict); 830 pref_hash_filter_->FilterSerializeData(&root_dict);
831 ASSERT_EQ(3u, mock_pref_hash_store_->stored_paths_count()); 831 ASSERT_EQ(3u, mock_pref_hash_store_->stored_paths_count());
832 MockPrefHashStore::ValuePtrStrategyPair stored_value_atomic1 = 832 MockPrefHashStore::ValuePtrStrategyPair stored_value_atomic1 =
833 mock_pref_hash_store_->stored_value(kAtomicPref); 833 mock_pref_hash_store_->stored_value(kAtomicPref);
834 ASSERT_EQ(int_value1, stored_value_atomic1.first); 834 ASSERT_EQ(int_value1, stored_value_atomic1.first);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); 1007 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store));
1008 ASSERT_EQ(dict_value, split_value_in_store); 1008 ASSERT_EQ(dict_value, split_value_in_store);
1009 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = 1009 MockPrefHashStore::ValuePtrStrategyPair stored_split_value =
1010 mock_pref_hash_store_->stored_value(kSplitPref); 1010 mock_pref_hash_store_->stored_value(kSplitPref);
1011 ASSERT_EQ(dict_value, stored_split_value.first); 1011 ASSERT_EQ(dict_value, stored_split_value.first);
1012 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); 1012 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second);
1013 } 1013 }
1014 1014
1015 TEST_P(PrefHashFilterTest, InitialValueChanged) { 1015 TEST_P(PrefHashFilterTest, InitialValueChanged) {
1016 // Ownership of this value is transfered to |pref_store_contents_|. 1016 // Ownership of this value is transfered to |pref_store_contents_|.
1017 base::Value* int_value = new base::FundamentalValue(1234); 1017 base::Value* int_value = new base::Value(1234);
1018 pref_store_contents_->Set(kAtomicPref, int_value); 1018 pref_store_contents_->Set(kAtomicPref, int_value);
1019 1019
1020 base::DictionaryValue* dict_value = new base::DictionaryValue; 1020 base::DictionaryValue* dict_value = new base::DictionaryValue;
1021 dict_value->SetString("a", "foo"); 1021 dict_value->SetString("a", "foo");
1022 dict_value->SetInteger("b", 1234); 1022 dict_value->SetInteger("b", 1234);
1023 dict_value->SetInteger("c", 56); 1023 dict_value->SetInteger("c", 56);
1024 dict_value->SetBoolean("d", false); 1024 dict_value->SetBoolean("d", false);
1025 pref_store_contents_->Set(kSplitPref, dict_value); 1025 pref_store_contents_->Set(kSplitPref, dict_value);
1026 1026
1027 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); 1027 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL));
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 const base::Value* split_value_in_store; 1180 const base::Value* split_value_in_store;
1181 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); 1181 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store));
1182 ASSERT_EQ(dict_value, split_value_in_store); 1182 ASSERT_EQ(dict_value, split_value_in_store);
1183 ASSERT_EQ(dict_value, stored_split_value.first); 1183 ASSERT_EQ(dict_value, stored_split_value.first);
1184 1184
1185 VerifyRecordedReset(false); 1185 VerifyRecordedReset(false);
1186 } 1186 }
1187 1187
1188 TEST_P(PrefHashFilterTest, DontResetReportOnly) { 1188 TEST_P(PrefHashFilterTest, DontResetReportOnly) {
1189 // Ownership of these values is transfered to |pref_store_contents_|. 1189 // Ownership of these values is transfered to |pref_store_contents_|.
1190 base::Value* int_value1 = new base::FundamentalValue(1); 1190 base::Value* int_value1 = new base::Value(1);
1191 base::Value* int_value2 = new base::FundamentalValue(2); 1191 base::Value* int_value2 = new base::Value(2);
1192 base::Value* report_only_val = new base::FundamentalValue(3); 1192 base::Value* report_only_val = new base::Value(3);
1193 base::DictionaryValue* report_only_split_val = new base::DictionaryValue; 1193 base::DictionaryValue* report_only_split_val = new base::DictionaryValue;
1194 report_only_split_val->SetInteger("a", 1234); 1194 report_only_split_val->SetInteger("a", 1234);
1195 pref_store_contents_->Set(kAtomicPref, int_value1); 1195 pref_store_contents_->Set(kAtomicPref, int_value1);
1196 pref_store_contents_->Set(kAtomicPref2, int_value2); 1196 pref_store_contents_->Set(kAtomicPref2, int_value2);
1197 pref_store_contents_->Set(kReportOnlyPref, report_only_val); 1197 pref_store_contents_->Set(kReportOnlyPref, report_only_val);
1198 pref_store_contents_->Set(kReportOnlySplitPref, report_only_split_val); 1198 pref_store_contents_->Set(kReportOnlySplitPref, report_only_split_val);
1199 1199
1200 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); 1200 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL));
1201 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref2, NULL)); 1201 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref2, NULL));
1202 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlyPref, NULL)); 1202 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlyPref, NULL));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 ASSERT_EQ(int_value2, 1257 ASSERT_EQ(int_value2,
1258 mock_pref_hash_store_->stored_value(kAtomicPref2).first); 1258 mock_pref_hash_store_->stored_value(kAtomicPref2).first);
1259 1259
1260 VerifyRecordedReset(false); 1260 VerifyRecordedReset(false);
1261 } 1261 }
1262 } 1262 }
1263 1263
1264 TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacks) { 1264 TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacks) {
1265 base::DictionaryValue root_dict; 1265 base::DictionaryValue root_dict;
1266 // Ownership of the following values is transfered to |root_dict|. 1266 // Ownership of the following values is transfered to |root_dict|.
1267 base::Value* int_value1 = new base::FundamentalValue(1); 1267 base::Value* int_value1 = new base::Value(1);
1268 base::Value* int_value2 = new base::FundamentalValue(2); 1268 base::Value* int_value2 = new base::Value(2);
1269 base::DictionaryValue* dict_value = new base::DictionaryValue; 1269 base::DictionaryValue* dict_value = new base::DictionaryValue;
1270 dict_value->Set("a", new base::FundamentalValue(true)); 1270 dict_value->Set("a", new base::Value(true));
1271 root_dict.Set(kAtomicPref, int_value1); 1271 root_dict.Set(kAtomicPref, int_value1);
1272 root_dict.Set(kAtomicPref2, int_value2); 1272 root_dict.Set(kAtomicPref2, int_value2);
1273 root_dict.Set(kSplitPref, dict_value); 1273 root_dict.Set(kSplitPref, dict_value);
1274 1274
1275 // Skip updating kAtomicPref2. 1275 // Skip updating kAtomicPref2.
1276 pref_hash_filter_->FilterUpdate(kAtomicPref); 1276 pref_hash_filter_->FilterUpdate(kAtomicPref);
1277 pref_hash_filter_->FilterUpdate(kSplitPref); 1277 pref_hash_filter_->FilterUpdate(kSplitPref);
1278 1278
1279 PrefHashFilter::OnWriteCallbackPair callbacks = 1279 PrefHashFilter::OnWriteCallbackPair callbacks =
1280 pref_hash_filter_->FilterSerializeData(&root_dict); 1280 pref_hash_filter_->FilterSerializeData(&root_dict);
(...skipping 25 matching lines...) Expand all
1306 1306
1307 // The callbacks should write directly to the contents without going through 1307 // The callbacks should write directly to the contents without going through
1308 // a pref hash store. 1308 // a pref hash store.
1309 ASSERT_EQ(0u, 1309 ASSERT_EQ(0u,
1310 mock_external_validation_pref_hash_store_->stored_paths_count()); 1310 mock_external_validation_pref_hash_store_->stored_paths_count());
1311 } 1311 }
1312 1312
1313 TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacksWithFailure) { 1313 TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacksWithFailure) {
1314 base::DictionaryValue root_dict; 1314 base::DictionaryValue root_dict;
1315 // Ownership of the following values is transfered to |root_dict|. 1315 // Ownership of the following values is transfered to |root_dict|.
1316 base::Value* int_value1 = new base::FundamentalValue(1); 1316 base::Value* int_value1 = new base::Value(1);
1317 root_dict.Set(kAtomicPref, int_value1); 1317 root_dict.Set(kAtomicPref, int_value1);
1318 1318
1319 // Only update kAtomicPref. 1319 // Only update kAtomicPref.
1320 pref_hash_filter_->FilterUpdate(kAtomicPref); 1320 pref_hash_filter_->FilterUpdate(kAtomicPref);
1321 1321
1322 PrefHashFilter::OnWriteCallbackPair callbacks = 1322 PrefHashFilter::OnWriteCallbackPair callbacks =
1323 pref_hash_filter_->FilterSerializeData(&root_dict); 1323 pref_hash_filter_->FilterSerializeData(&root_dict);
1324 1324
1325 ASSERT_FALSE(callbacks.first.is_null()); 1325 ASSERT_FALSE(callbacks.first.is_null());
1326 1326
1327 callbacks.first.Run(); 1327 callbacks.first.Run();
1328 1328
1329 // The pref should have been cleared from the external validation store. 1329 // The pref should have been cleared from the external validation store.
1330 ASSERT_EQ( 1330 ASSERT_EQ(
1331 1u, mock_external_validation_hash_store_contents_->cleared_paths_count()); 1331 1u, mock_external_validation_hash_store_contents_->cleared_paths_count());
1332 1332
1333 callbacks.second.Run(false); 1333 callbacks.second.Run(false);
1334 1334
1335 // Expect no writes to the external validation hash store contents. 1335 // Expect no writes to the external validation hash store contents.
1336 ASSERT_EQ(0u, 1336 ASSERT_EQ(0u,
1337 mock_external_validation_pref_hash_store_->stored_paths_count()); 1337 mock_external_validation_pref_hash_store_->stored_paths_count());
1338 ASSERT_EQ( 1338 ASSERT_EQ(
1339 0u, mock_external_validation_hash_store_contents_->stored_hashes_count()); 1339 0u, mock_external_validation_hash_store_contents_->stored_hashes_count());
1340 } 1340 }
1341 1341
1342 TEST_P(PrefHashFilterTest, ExternalValidationValueChanged) { 1342 TEST_P(PrefHashFilterTest, ExternalValidationValueChanged) {
1343 // Ownership of this value is transfered to |pref_store_contents_|. 1343 // Ownership of this value is transfered to |pref_store_contents_|.
1344 base::Value* int_value = new base::FundamentalValue(1234); 1344 base::Value* int_value = new base::Value(1234);
1345 pref_store_contents_->Set(kAtomicPref, int_value); 1345 pref_store_contents_->Set(kAtomicPref, int_value);
1346 1346
1347 base::DictionaryValue* dict_value = new base::DictionaryValue; 1347 base::DictionaryValue* dict_value = new base::DictionaryValue;
1348 dict_value->SetString("a", "foo"); 1348 dict_value->SetString("a", "foo");
1349 dict_value->SetInteger("b", 1234); 1349 dict_value->SetInteger("b", 1234);
1350 dict_value->SetInteger("c", 56); 1350 dict_value->SetInteger("c", 56);
1351 dict_value->SetBoolean("d", false); 1351 dict_value->SetBoolean("d", false);
1352 pref_store_contents_->Set(kSplitPref, dict_value); 1352 pref_store_contents_->Set(kSplitPref, dict_value);
1353 1353
1354 mock_external_validation_pref_hash_store_->SetCheckResult( 1354 mock_external_validation_pref_hash_store_->SetCheckResult(
(...skipping 29 matching lines...) Expand all
1384 PrefHashStoreTransaction::CHANGED)); 1384 PrefHashStoreTransaction::CHANGED));
1385 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, 1385 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u,
1386 mock_validation_delegate_.CountExternalValidationsOfState( 1386 mock_validation_delegate_.CountExternalValidationsOfState(
1387 PrefHashStoreTransaction::UNCHANGED)); 1387 PrefHashStoreTransaction::UNCHANGED));
1388 } 1388 }
1389 1389
1390 INSTANTIATE_TEST_CASE_P(PrefHashFilterTestInstance, 1390 INSTANTIATE_TEST_CASE_P(PrefHashFilterTestInstance,
1391 PrefHashFilterTest, 1391 PrefHashFilterTest,
1392 testing::Values(PrefHashFilter::NO_ENFORCEMENT, 1392 testing::Values(PrefHashFilter::NO_ENFORCEMENT,
1393 PrefHashFilter::ENFORCE_ON_LOAD)); 1393 PrefHashFilter::ENFORCE_ON_LOAD));
OLDNEW
« no previous file with comments | « components/user_prefs/tracked/pref_hash_calculator_unittest.cc ('k') | content/browser/appcache/appcache_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698