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

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

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase 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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 // of the copy, we make it forward calls to the mock it was created from. 456 // of the copy, we make it forward calls to the mock it was created from.
457 // Once set, |origin_mock_| must outlive this instance. 457 // Once set, |origin_mock_| must outlive this instance.
458 MockHashStoreContents* origin_mock_; 458 MockHashStoreContents* origin_mock_;
459 459
460 DISALLOW_COPY_AND_ASSIGN(MockHashStoreContents); 460 DISALLOW_COPY_AND_ASSIGN(MockHashStoreContents);
461 }; 461 };
462 462
463 std::string MockHashStoreContents::GetStoredMac(const std::string& path) const { 463 std::string MockHashStoreContents::GetStoredMac(const std::string& path) const {
464 const base::Value* out_value; 464 const base::Value* out_value;
465 if (dictionary_.GetWithoutPathExpansion(path, &out_value)) { 465 if (dictionary_.GetWithoutPathExpansion(path, &out_value)) {
466 const base::StringValue* value_as_string; 466 const base::Value* value_as_string;
467 EXPECT_TRUE(out_value->GetAsString(&value_as_string)); 467 EXPECT_TRUE(out_value->GetAsString(&value_as_string));
468 468
469 return value_as_string->GetString(); 469 return value_as_string->GetString();
470 } 470 }
471 471
472 return std::string(); 472 return std::string();
473 } 473 }
474 474
475 std::string MockHashStoreContents::GetStoredSplitMac( 475 std::string MockHashStoreContents::GetStoredSplitMac(
476 const std::string& path, 476 const std::string& path,
477 const std::string& split_path) const { 477 const std::string& split_path) const {
478 const base::Value* out_value; 478 const base::Value* out_value;
479 if (dictionary_.GetWithoutPathExpansion(path, &out_value)) { 479 if (dictionary_.GetWithoutPathExpansion(path, &out_value)) {
480 const base::DictionaryValue* value_as_dict; 480 const base::DictionaryValue* value_as_dict;
481 EXPECT_TRUE(out_value->GetAsDictionary(&value_as_dict)); 481 EXPECT_TRUE(out_value->GetAsDictionary(&value_as_dict));
482 482
483 if (value_as_dict->GetWithoutPathExpansion(split_path, &out_value)) { 483 if (value_as_dict->GetWithoutPathExpansion(split_path, &out_value)) {
484 const base::StringValue* value_as_string; 484 const base::Value* value_as_string;
485 EXPECT_TRUE(out_value->GetAsString(&value_as_string)); 485 EXPECT_TRUE(out_value->GetAsString(&value_as_string));
486 486
487 return value_as_string->GetString(); 487 return value_as_string->GetString();
488 } 488 }
489 } 489 }
490 490
491 return std::string(); 491 return std::string();
492 } 492 }
493 493
494 MockHashStoreContents::MockHashStoreContents(MockHashStoreContents* origin_mock) 494 MockHashStoreContents::MockHashStoreContents(MockHashStoreContents* origin_mock)
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 mock_pref_hash_store_->set_stamp_super_mac_result(true); 696 mock_pref_hash_store_->set_stamp_super_mac_result(true);
697 DoFilterOnLoad(true); 697 DoFilterOnLoad(true);
698 // No paths stored, since they all return |UNCHANGED|. The StampSuperMAC 698 // No paths stored, since they all return |UNCHANGED|. The StampSuperMAC
699 // result is the only reason the prefs were considered altered. 699 // result is the only reason the prefs were considered altered.
700 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); 700 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count());
701 } 701 }
702 702
703 TEST_P(PrefHashFilterTest, FilterTrackedPrefUpdate) { 703 TEST_P(PrefHashFilterTest, FilterTrackedPrefUpdate) {
704 base::DictionaryValue root_dict; 704 base::DictionaryValue root_dict;
705 // Ownership of |string_value| is transfered to |root_dict|. 705 // Ownership of |string_value| is transfered to |root_dict|.
706 base::Value* string_value = new base::StringValue("string value"); 706 base::Value* string_value = new base::Value("string value");
707 root_dict.Set(kAtomicPref, string_value); 707 root_dict.Set(kAtomicPref, string_value);
708 708
709 // No path should be stored on FilterUpdate. 709 // No path should be stored on FilterUpdate.
710 pref_hash_filter_->FilterUpdate(kAtomicPref); 710 pref_hash_filter_->FilterUpdate(kAtomicPref);
711 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); 711 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count());
712 712
713 // One path should be stored on FilterSerializeData. 713 // One path should be stored on FilterSerializeData.
714 pref_hash_filter_->FilterSerializeData(&root_dict); 714 pref_hash_filter_->FilterSerializeData(&root_dict);
715 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count()); 715 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count());
716 MockPrefHashStore::ValuePtrStrategyPair stored_value = 716 MockPrefHashStore::ValuePtrStrategyPair stored_value =
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 mock_pref_hash_store_->stored_value(kSplitPref); 777 mock_pref_hash_store_->stored_value(kSplitPref);
778 ASSERT_EQ(dict_value, stored_value.first); 778 ASSERT_EQ(dict_value, stored_value.first);
779 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_value.second); 779 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_value.second);
780 780
781 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); 781 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed());
782 VerifyRecordedReset(false); 782 VerifyRecordedReset(false);
783 } 783 }
784 784
785 TEST_P(PrefHashFilterTest, FilterUntrackedPrefUpdate) { 785 TEST_P(PrefHashFilterTest, FilterUntrackedPrefUpdate) {
786 base::DictionaryValue root_dict; 786 base::DictionaryValue root_dict;
787 root_dict.Set("untracked", new base::StringValue("some value")); 787 root_dict.Set("untracked", new base::Value("some value"));
788 pref_hash_filter_->FilterUpdate("untracked"); 788 pref_hash_filter_->FilterUpdate("untracked");
789 789
790 // No paths should be stored on FilterUpdate. 790 // No paths should be stored on FilterUpdate.
791 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); 791 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count());
792 792
793 // Nor on FilterSerializeData. 793 // Nor on FilterSerializeData.
794 pref_hash_filter_->FilterSerializeData(&root_dict); 794 pref_hash_filter_->FilterSerializeData(&root_dict);
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
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 ASSERT_FALSE(validated_split_pref->is_personal); 889 ASSERT_FALSE(validated_split_pref->is_personal);
890 const MockValidationDelegate::ValidationEvent* validated_atomic_pref = 890 const MockValidationDelegate::ValidationEvent* validated_atomic_pref =
891 mock_validation_delegate_.GetEventForPath(kAtomicPref); 891 mock_validation_delegate_.GetEventForPath(kAtomicPref);
892 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, 892 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC,
893 validated_atomic_pref->strategy); 893 validated_atomic_pref->strategy);
894 ASSERT_TRUE(validated_atomic_pref->is_personal); 894 ASSERT_TRUE(validated_atomic_pref->is_personal);
895 } 895 }
896 896
897 TEST_P(PrefHashFilterTest, InitialValueUnknown) { 897 TEST_P(PrefHashFilterTest, InitialValueUnknown) {
898 // Ownership of these values is transfered to |pref_store_contents_|. 898 // Ownership of these values is transfered to |pref_store_contents_|.
899 base::StringValue* string_value = new base::StringValue("string value"); 899 base::Value* string_value = new base::Value("string value");
900 pref_store_contents_->Set(kAtomicPref, string_value); 900 pref_store_contents_->Set(kAtomicPref, string_value);
901 901
902 base::DictionaryValue* dict_value = new base::DictionaryValue; 902 base::DictionaryValue* dict_value = new base::DictionaryValue;
903 dict_value->SetString("a", "foo"); 903 dict_value->SetString("a", "foo");
904 dict_value->SetInteger("b", 1234); 904 dict_value->SetInteger("b", 1234);
905 pref_store_contents_->Set(kSplitPref, dict_value); 905 pref_store_contents_->Set(kSplitPref, dict_value);
906 906
907 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); 907 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL));
908 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); 908 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL));
909 909
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); 956 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store));
957 ASSERT_EQ(dict_value, split_value_in_store); 957 ASSERT_EQ(dict_value, split_value_in_store);
958 ASSERT_EQ(dict_value, stored_split_value.first); 958 ASSERT_EQ(dict_value, stored_split_value.first);
959 959
960 VerifyRecordedReset(false); 960 VerifyRecordedReset(false);
961 } 961 }
962 } 962 }
963 963
964 TEST_P(PrefHashFilterTest, InitialValueTrustedUnknown) { 964 TEST_P(PrefHashFilterTest, InitialValueTrustedUnknown) {
965 // Ownership of this value is transfered to |pref_store_contents_|. 965 // Ownership of this value is transfered to |pref_store_contents_|.
966 base::Value* string_value = new base::StringValue("test"); 966 base::Value* string_value = new base::Value("test");
967 pref_store_contents_->Set(kAtomicPref, string_value); 967 pref_store_contents_->Set(kAtomicPref, string_value);
968 968
969 base::DictionaryValue* dict_value = new base::DictionaryValue; 969 base::DictionaryValue* dict_value = new base::DictionaryValue;
970 dict_value->SetString("a", "foo"); 970 dict_value->SetString("a", "foo");
971 dict_value->SetInteger("b", 1234); 971 dict_value->SetInteger("b", 1234);
972 pref_store_contents_->Set(kSplitPref, dict_value); 972 pref_store_contents_->Set(kSplitPref, dict_value);
973 973
974 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); 974 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL));
975 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); 975 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL));
976 976
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 1123
1124 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); 1124 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL));
1125 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = 1125 MockPrefHashStore::ValuePtrStrategyPair stored_split_value =
1126 mock_pref_hash_store_->stored_value(kSplitPref); 1126 mock_pref_hash_store_->stored_value(kSplitPref);
1127 ASSERT_EQ(NULL, stored_split_value.first); 1127 ASSERT_EQ(NULL, stored_split_value.first);
1128 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); 1128 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second);
1129 } 1129 }
1130 1130
1131 TEST_P(PrefHashFilterTest, InitialValueUnchangedLegacyId) { 1131 TEST_P(PrefHashFilterTest, InitialValueUnchangedLegacyId) {
1132 // Ownership of these values is transfered to |pref_store_contents_|. 1132 // Ownership of these values is transfered to |pref_store_contents_|.
1133 base::StringValue* string_value = new base::StringValue("string value"); 1133 base::Value* string_value = new base::Value("string value");
1134 pref_store_contents_->Set(kAtomicPref, string_value); 1134 pref_store_contents_->Set(kAtomicPref, string_value);
1135 1135
1136 base::DictionaryValue* dict_value = new base::DictionaryValue; 1136 base::DictionaryValue* dict_value = new base::DictionaryValue;
1137 dict_value->SetString("a", "foo"); 1137 dict_value->SetString("a", "foo");
1138 dict_value->SetInteger("b", 1234); 1138 dict_value->SetInteger("b", 1234);
1139 pref_store_contents_->Set(kSplitPref, dict_value); 1139 pref_store_contents_->Set(kSplitPref, dict_value);
1140 1140
1141 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); 1141 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL));
1142 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); 1142 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL));
1143 1143
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_filter.cc ('k') | components/user_prefs/tracked/pref_hash_store_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698