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

Unified Diff: chrome/browser/prefs/pref_hash_store_impl_unittest.cc

Issue 126093007: Introduce a hash_of_hashes dictionary. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wording Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/prefs/pref_hash_store_impl.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prefs/pref_hash_store_impl_unittest.cc
diff --git a/chrome/browser/prefs/pref_hash_store_impl_unittest.cc b/chrome/browser/prefs/pref_hash_store_impl_unittest.cc
index c6e3aee5366ba8fb412b269798973d92acd644ce..823269157756d7dabdca46d6446d873678e7a314 100644
--- a/chrome/browser/prefs/pref_hash_store_impl_unittest.cc
+++ b/chrome/browser/prefs/pref_hash_store_impl_unittest.cc
@@ -25,16 +25,20 @@ TEST(PrefHashStoreImplTest, TestCase) {
PrefHashStoreImpl pref_hash_store(
"store_id", std::string(32,0), "device_id", &local_state);
- ASSERT_EQ(PrefHashStore::UNKNOWN_VALUE,
+ // Only NULL should be trusted in the absence of a hash.
+ EXPECT_EQ(PrefHashStore::UNTRUSTED_UNKNOWN_VALUE,
pref_hash_store.CheckValue("path1", &string_1));
+ EXPECT_EQ(PrefHashStore::TRUSTED_UNKNOWN_VALUE,
+ pref_hash_store.CheckValue("path1", NULL));
+
pref_hash_store.StoreHash("path1", &string_1);
- ASSERT_EQ(PrefHashStore::UNCHANGED,
+ EXPECT_EQ(PrefHashStore::UNCHANGED,
pref_hash_store.CheckValue("path1", &string_1));
- ASSERT_EQ(PrefHashStore::CLEARED, pref_hash_store.CheckValue("path1", NULL));
+ EXPECT_EQ(PrefHashStore::CLEARED, pref_hash_store.CheckValue("path1", NULL));
pref_hash_store.StoreHash("path1", NULL);
- ASSERT_EQ(PrefHashStore::UNCHANGED,
+ EXPECT_EQ(PrefHashStore::UNCHANGED,
pref_hash_store.CheckValue("path1", NULL));
- ASSERT_EQ(PrefHashStore::CHANGED,
+ EXPECT_EQ(PrefHashStore::CHANGED,
pref_hash_store.CheckValue("path1", &string_2));
base::DictionaryValue dict;
@@ -43,17 +47,51 @@ TEST(PrefHashStoreImplTest, TestCase) {
dict.Set("b", new base::StringValue("bar"));
dict.Set("c", new base::StringValue("baz"));
- // Manually shove in a legacy hash.
- DictionaryPrefUpdate update(&local_state, prefs::kProfilePreferenceHashes);
- base::DictionaryValue* child_dictionary = NULL;
- ASSERT_TRUE(update->GetDictionary("store_id", &child_dictionary));
- child_dictionary->SetString(
- "path1",
- "C503FB7C65EEFD5C07185F616A0AA67923C069909933F362022B1F187E73E9A2");
-
- ASSERT_EQ(PrefHashStore::MIGRATED,
+ {
+ // Manually shove in a legacy hash.
+ DictionaryPrefUpdate update(&local_state, prefs::kProfilePreferenceHashes);
+ base::DictionaryValue* child_dictionary = NULL;
+ ASSERT_TRUE(update->GetDictionary("store_id", &child_dictionary));
+ child_dictionary->SetString(
+ "path1",
+ "C503FB7C65EEFD5C07185F616A0AA67923C069909933F362022B1F187E73E9A2");
+ }
+ EXPECT_EQ(PrefHashStore::MIGRATED,
pref_hash_store.CheckValue("path1", &dict));
pref_hash_store.StoreHash("path1", &dict);
- ASSERT_EQ(PrefHashStore::UNCHANGED,
+ EXPECT_EQ(PrefHashStore::UNCHANGED,
pref_hash_store.CheckValue("path1", &dict));
+
+ // |pref_hash_store2| should trust its initial hashes dictionary and thus
+ // trust new unknown values.
+ PrefHashStoreImpl pref_hash_store2(
+ "store_id", std::string(32, 0), "device_id", &local_state);
+ EXPECT_EQ(PrefHashStore::TRUSTED_UNKNOWN_VALUE,
+ pref_hash_store2.CheckValue("new_path", &string_1));
+ EXPECT_EQ(PrefHashStore::TRUSTED_UNKNOWN_VALUE,
+ pref_hash_store2.CheckValue("new_path", &string_2));
+ EXPECT_EQ(PrefHashStore::TRUSTED_UNKNOWN_VALUE,
+ pref_hash_store2.CheckValue("new_path", NULL));
+
+ {
+ // Manually corrupt the hash of hashes for "store_id".
+ DictionaryPrefUpdate update(&local_state, prefs::kProfilePreferenceHashes);
+ base::DictionaryValue* hash_of_hashes_dict = NULL;
+ ASSERT_TRUE(update->GetDictionaryWithoutPathExpansion(
+ internals::kHashOfHashesPref, &hash_of_hashes_dict));
+ hash_of_hashes_dict->SetString("store_id", std::string(64, 'A'));
+ // This shouldn't have increased the number of existing hash of hashes.
+ ASSERT_EQ(1U, hash_of_hashes_dict->size());
+ }
+
+ // |pref_hash_store3| should no longer trust its initial hashes dictionary and
+ // thus shouldn't trust non-NULL unknown values.
+ PrefHashStoreImpl pref_hash_store3(
+ "store_id", std::string(32, 0), "device_id", &local_state);
+ EXPECT_EQ(PrefHashStore::UNTRUSTED_UNKNOWN_VALUE,
+ pref_hash_store3.CheckValue("new_path", &string_1));
+ EXPECT_EQ(PrefHashStore::UNTRUSTED_UNKNOWN_VALUE,
+ pref_hash_store3.CheckValue("new_path", &string_2));
+ EXPECT_EQ(PrefHashStore::TRUSTED_UNKNOWN_VALUE,
+ pref_hash_store3.CheckValue("new_path", NULL));
}
« no previous file with comments | « chrome/browser/prefs/pref_hash_store_impl.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698