| 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 330879a89e3e1a0fcde6dc3bab2a3f1acece35b5..9d1af8209b9a3e8f1071a8654294c095a805fa34 100644
|
| --- a/chrome/browser/prefs/pref_hash_store_impl_unittest.cc
|
| +++ b/chrome/browser/prefs/pref_hash_store_impl_unittest.cc
|
| @@ -14,7 +14,7 @@
|
| #include "chrome/common/pref_names.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| -TEST(PrefHashStoreImplTest, TestCase) {
|
| +TEST(PrefHashStoreImplTest, AtomicHashStoreAndCheck) {
|
| base::StringValue string_1("string1");
|
| base::StringValue string_2("string2");
|
|
|
| @@ -23,7 +23,7 @@ TEST(PrefHashStoreImplTest, TestCase) {
|
|
|
| // 32 NULL bytes is the seed that was used to generate the legacy hash.
|
| PrefHashStoreImpl pref_hash_store(
|
| - "store_id", std::string(32,0), "device_id", &local_state);
|
| + "store_id", std::string(32, 0), "device_id", &local_state);
|
|
|
| ASSERT_EQ(PrefHashStore::UNKNOWN_VALUE,
|
| pref_hash_store.CheckValue("path1", &string_1));
|
| @@ -37,7 +37,7 @@ TEST(PrefHashStoreImplTest, TestCase) {
|
| ASSERT_EQ(PrefHashStore::CHANGED,
|
| pref_hash_store.CheckValue("path1", &string_2));
|
|
|
| - DictionaryValue dict;
|
| + base::DictionaryValue dict;
|
| dict.Set("a", new StringValue("foo"));
|
| dict.Set("d", new StringValue("bad"));
|
| dict.Set("b", new StringValue("bar"));
|
| @@ -45,7 +45,7 @@ TEST(PrefHashStoreImplTest, TestCase) {
|
|
|
| // Manually shove in a legacy hash.
|
| DictionaryPrefUpdate update(&local_state, prefs::kProfilePreferenceHashes);
|
| - DictionaryValue* child_dictionary = NULL;
|
| + base::DictionaryValue* child_dictionary = NULL;
|
| ASSERT_TRUE(update->GetDictionary("store_id", &child_dictionary));
|
| child_dictionary->SetString(
|
| "path1",
|
| @@ -57,3 +57,103 @@ TEST(PrefHashStoreImplTest, TestCase) {
|
| ASSERT_EQ(PrefHashStore::UNCHANGED,
|
| pref_hash_store.CheckValue("path1", &dict));
|
| }
|
| +
|
| +TEST(PrefHashStoreImplTest, SplitHashStoreAndCheck) {
|
| + base::DictionaryValue dict;
|
| + dict.Set("a", new StringValue("to be replaced"));
|
| + dict.Set("b", new StringValue("same"));
|
| + dict.Set("o", new StringValue("old"));
|
| +
|
| + base::DictionaryValue modified_dict;
|
| + modified_dict.Set("a", new StringValue("replaced"));
|
| + modified_dict.Set("b", new StringValue("same"));
|
| + modified_dict.Set("c", new StringValue("new"));
|
| +
|
| + base::DictionaryValue empty_dict;
|
| +
|
| + TestingPrefServiceSimple local_state;
|
| + PrefHashStoreImpl::RegisterPrefs(local_state.registry());
|
| +
|
| + PrefHashStoreImpl pref_hash_store(
|
| + "store_id", std::string(32, 0), "device_id", &local_state);
|
| +
|
| + std::vector<std::string> invalid_keys;
|
| +
|
| + // No hashes stored yet.
|
| + ASSERT_EQ(PrefHashStore::UNKNOWN_VALUE,
|
| + pref_hash_store.CheckSplitValue("path1", &dict, &invalid_keys));
|
| + ASSERT_TRUE(invalid_keys.empty());
|
| +
|
| + pref_hash_store.StoreSplitHash("path1", &dict);
|
| +
|
| + // Verify match post storage.
|
| + ASSERT_EQ(PrefHashStore::UNCHANGED,
|
| + pref_hash_store.CheckSplitValue("path1", &dict, &invalid_keys));
|
| + ASSERT_TRUE(invalid_keys.empty());
|
| +
|
| + // Verify new path is still unknown.
|
| + ASSERT_EQ(PrefHashStore::UNKNOWN_VALUE,
|
| + pref_hash_store.CheckSplitValue("path2", &dict, &invalid_keys));
|
| + ASSERT_TRUE(invalid_keys.empty());
|
| +
|
| + // Verify NULL or empty dicts are declared as having been cleared.
|
| + ASSERT_EQ(PrefHashStore::CLEARED,
|
| + pref_hash_store.CheckSplitValue("path1", NULL, &invalid_keys));
|
| + ASSERT_TRUE(invalid_keys.empty());
|
| + ASSERT_EQ(PrefHashStore::CLEARED,
|
| + pref_hash_store.CheckSplitValue("path1", &empty_dict,
|
| + &invalid_keys));
|
| + ASSERT_TRUE(invalid_keys.empty());
|
| +
|
| + // Verify changes are properly detected.
|
| + ASSERT_EQ(PrefHashStore::CHANGED,
|
| + pref_hash_store.CheckSplitValue("path1", &modified_dict,
|
| + &invalid_keys));
|
| + std::vector<std::string> expected_invalid_keys1;
|
| + expected_invalid_keys1.push_back("a");
|
| + expected_invalid_keys1.push_back("c");
|
| + ASSERT_EQ(expected_invalid_keys1, invalid_keys);
|
| + invalid_keys.clear();
|
| +
|
| + // Verify still match post check.
|
| + ASSERT_EQ(PrefHashStore::UNCHANGED,
|
| + pref_hash_store.CheckSplitValue("path1", &dict, &invalid_keys));
|
| + ASSERT_TRUE(invalid_keys.empty());
|
| +
|
| + pref_hash_store.StoreSplitHash("path1", &modified_dict);
|
| +
|
| + // Verify |modified_dict| is now the one that verifies correctly.
|
| + ASSERT_EQ(PrefHashStore::UNCHANGED,
|
| + pref_hash_store.CheckSplitValue("path1", &modified_dict,
|
| + &invalid_keys));
|
| + ASSERT_TRUE(invalid_keys.empty());
|
| +
|
| + // Verify old dict no longer matches.
|
| + ASSERT_EQ(PrefHashStore::CHANGED,
|
| + pref_hash_store.CheckSplitValue("path1", &dict, &invalid_keys));
|
| + std::vector<std::string> expected_invalid_keys2;
|
| + expected_invalid_keys2.push_back("a");
|
| + expected_invalid_keys2.push_back("o");
|
| + ASSERT_EQ(expected_invalid_keys2, invalid_keys);
|
| + invalid_keys.clear();
|
| +
|
| + // Verify stored empty dictionary matches NULL and empty dictionary back.
|
| + pref_hash_store.StoreSplitHash("path1", &empty_dict);
|
| + ASSERT_EQ(PrefHashStore::UNCHANGED,
|
| + pref_hash_store.CheckSplitValue("path1", NULL, &invalid_keys));
|
| + ASSERT_TRUE(invalid_keys.empty());
|
| + ASSERT_EQ(PrefHashStore::UNCHANGED,
|
| + pref_hash_store.CheckSplitValue("path1", &empty_dict,
|
| + &invalid_keys));
|
| + ASSERT_TRUE(invalid_keys.empty());
|
| +
|
| + // Same when storing NULL directly.
|
| + pref_hash_store.StoreSplitHash("path1", NULL);
|
| + ASSERT_EQ(PrefHashStore::UNCHANGED,
|
| + pref_hash_store.CheckSplitValue("path1", NULL, &invalid_keys));
|
| + ASSERT_TRUE(invalid_keys.empty());
|
| + ASSERT_EQ(PrefHashStore::UNCHANGED,
|
| + pref_hash_store.CheckSplitValue("path1", &empty_dict,
|
| + &invalid_keys));
|
| + ASSERT_TRUE(invalid_keys.empty());
|
| +}
|
|
|