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/prefs/pref_service.h" | |
10 #include "base/prefs/scoped_user_pref_update.h" | |
11 #include "base/prefs/testing_pref_service.h" | |
12 #include "base/values.h" | |
13 #include "chrome/browser/prefs/pref_hash_calculator.h" | |
14 #include "chrome/browser/prefs/pref_hash_store.h" | |
15 #include "chrome/common/pref_names.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | |
17 | |
18 TEST(PrefHashStoreImplTest, TestCase) { | |
19 base::StringValue string_1("string1"); | |
20 base::StringValue string_2("string2"); | |
21 | |
22 TestingPrefServiceSimple local_state; | |
23 PrefHashStoreImpl::RegisterPrefs(local_state.registry()); | |
24 | |
25 // 32 NULL bytes is the seed that was used to generate the legacy hash. | |
26 PrefHashStoreImpl pref_hash_store( | |
27 PrefHashCalculator(std::string(32,0), "device_id"), | |
28 &local_state, | |
29 "store_id"); | |
30 | |
31 ASSERT_EQ(PrefHashStore::UNKNOWN_VALUE, | |
32 pref_hash_store.CheckValue("path1", &string_1)); | |
33 ASSERT_EQ(PrefHashStore::UNKNOWN_VALUE, | |
34 pref_hash_store.CheckValue("path1", &string_1)); | |
gab
2013/12/06 17:23:38
Same check twice above, typo?
erikwright (departed)
2013/12/09 17:59:40
Previously it was a mutating operation. But with o
| |
35 pref_hash_store.StoreValue("path1", &string_1); | |
36 ASSERT_EQ(PrefHashStore::UNCHANGED, | |
37 pref_hash_store.CheckValue("path1", &string_1)); | |
38 ASSERT_EQ(PrefHashStore::CLEARED, pref_hash_store.CheckValue("path1", NULL)); | |
39 pref_hash_store.StoreValue("path1", NULL); | |
40 ASSERT_EQ(PrefHashStore::UNCHANGED, | |
41 pref_hash_store.CheckValue("path1", NULL)); | |
42 ASSERT_EQ(PrefHashStore::CHANGED, | |
43 pref_hash_store.CheckValue("path1", &string_2)); | |
44 | |
45 DictionaryValue dict; | |
46 dict.Set("a", new StringValue("foo")); | |
47 dict.Set("d", new StringValue("bad")); | |
48 dict.Set("b", new StringValue("bar")); | |
49 dict.Set("c", new StringValue("baz")); | |
50 | |
51 // Manually shove in a legacy hash. | |
52 DictionaryPrefUpdate update(&local_state, prefs::kProfilePreferenceHashes); | |
53 DictionaryValue* child_dictionary = NULL; | |
54 ASSERT_TRUE(update->GetDictionary("store_id", &child_dictionary)); | |
55 child_dictionary->SetString( | |
56 "path1", | |
57 "C503FB7C65EEFD5C07185F616A0AA67923C069909933F362022B1F187E73E9A2"); | |
58 | |
59 ASSERT_EQ(PrefHashStore::MIGRATED, | |
60 pref_hash_store.CheckValue("path1", &dict)); | |
61 pref_hash_store.StoreValue("path1", &dict); | |
62 ASSERT_EQ(PrefHashStore::UNCHANGED, | |
63 pref_hash_store.CheckValue("path1", &dict)); | |
64 } | |
OLD | NEW |