OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/prefs/pref_hash_store_impl.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/prefs/scoped_user_pref_update.h" |
| 12 #include "base/prefs/testing_pref_service.h" |
| 13 #include "base/values.h" |
| 14 #include "chrome/browser/prefs/pref_hash_calculator.h" |
| 15 #include "chrome/browser/prefs/pref_hash_store.h" |
| 16 #include "chrome/common/pref_names.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 scoped_ptr<PrefHashStore> CreatePrefHashStore(PrefService* local_state) { |
| 20 // 32 NULL bytes is the seed that was used to generate the legacy hash. |
| 21 return scoped_ptr<PrefHashStore>(new PrefHashStoreImpl( |
| 22 PrefHashCalculator(std::string(32,0), "device_id"), |
| 23 local_state, |
| 24 "store_id")); |
| 25 } |
| 26 |
| 27 TEST(PrefHashStoreImplTest, TestCase) { |
| 28 base::StringValue string_1("string1"); |
| 29 base::StringValue string_2("string2"); |
| 30 |
| 31 TestingPrefServiceSimple local_state; |
| 32 PrefHashStoreImpl::RegisterPrefs(local_state.registry()); |
| 33 |
| 34 { |
| 35 scoped_ptr<PrefHashStore> pref_hash_store( |
| 36 CreatePrefHashStore(&local_state)); |
| 37 ASSERT_EQ(PrefHashStore::INITIALIZED, |
| 38 pref_hash_store->InitializeTrackedValue("path1", &string_1)); |
| 39 pref_hash_store->OnPrefValueChanged("path1", &string_2); |
| 40 } |
| 41 { |
| 42 scoped_ptr<PrefHashStore> pref_hash_store( |
| 43 CreatePrefHashStore(&local_state)); |
| 44 ASSERT_EQ(PrefHashStore::UNCHANGED, |
| 45 pref_hash_store->InitializeTrackedValue("path1", &string_2)); |
| 46 } |
| 47 { |
| 48 scoped_ptr<PrefHashStore> pref_hash_store( |
| 49 CreatePrefHashStore(&local_state)); |
| 50 ASSERT_EQ(PrefHashStore::CLEARED, |
| 51 pref_hash_store->InitializeTrackedValue("path1", NULL)); |
| 52 } |
| 53 { |
| 54 scoped_ptr<PrefHashStore> pref_hash_store( |
| 55 CreatePrefHashStore(&local_state)); |
| 56 ASSERT_EQ(PrefHashStore::UNCHANGED, |
| 57 pref_hash_store->InitializeTrackedValue("path1", NULL)); |
| 58 } |
| 59 { |
| 60 scoped_ptr<PrefHashStore> pref_hash_store( |
| 61 CreatePrefHashStore(&local_state)); |
| 62 ASSERT_EQ(PrefHashStore::CHANGED, |
| 63 pref_hash_store->InitializeTrackedValue("path1", &string_2)); |
| 64 } |
| 65 |
| 66 DictionaryValue dict; |
| 67 dict.Set("a", new StringValue("foo")); |
| 68 dict.Set("d", new StringValue("bad")); |
| 69 dict.Set("b", new StringValue("bar")); |
| 70 dict.Set("c", new StringValue("baz")); |
| 71 |
| 72 { |
| 73 // Manually shove in a legacy hash. |
| 74 DictionaryPrefUpdate update(&local_state, prefs::kProfilePreferenceHashes); |
| 75 DictionaryValue* child_dictionary = NULL; |
| 76 ASSERT_TRUE(update->GetDictionary("store_id", &child_dictionary)); |
| 77 child_dictionary->SetString( |
| 78 "path1", |
| 79 "C503FB7C65EEFD5C07185F616A0AA67923C069909933F362022B1F187E73E9A2"); |
| 80 } |
| 81 { |
| 82 scoped_ptr<PrefHashStore> pref_hash_store( |
| 83 CreatePrefHashStore(&local_state)); |
| 84 ASSERT_EQ(PrefHashStore::MIGRATED, |
| 85 pref_hash_store->InitializeTrackedValue("path1", &dict)); |
| 86 } |
| 87 { |
| 88 scoped_ptr<PrefHashStore> pref_hash_store( |
| 89 CreatePrefHashStore(&local_state)); |
| 90 ASSERT_EQ(PrefHashStore::UNCHANGED, |
| 91 pref_hash_store->InitializeTrackedValue("path1", &dict)); |
| 92 } |
| 93 } |
OLD | NEW |