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

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

Issue 2304573002: Add ComputeMac and ComputeSplitMacs methods to pref_hash_store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase-update'd Created 4 years, 3 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
« no previous file with comments | « components/user_prefs/tracked/pref_hash_store_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_store_impl.h" 5 #include "components/user_prefs/tracked/pref_hash_store_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 12 matching lines...) Expand all
23 23
24 private: 24 private:
25 base::DictionaryValue pref_store_contents_; 25 base::DictionaryValue pref_store_contents_;
26 // Must be declared after |pref_store_contents_| as it needs to be outlived 26 // Must be declared after |pref_store_contents_| as it needs to be outlived
27 // by it. 27 // by it.
28 DictionaryHashStoreContents contents_; 28 DictionaryHashStoreContents contents_;
29 29
30 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreImplTest); 30 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreImplTest);
31 }; 31 };
32 32
33 TEST_F(PrefHashStoreImplTest, ComputeMac) {
34 base::StringValue string_1("string1");
35 base::StringValue string_2("string2");
36 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true);
37
38 std::string computed_mac_1 = pref_hash_store.ComputeMac("path1", &string_1);
39 std::string computed_mac_2 = pref_hash_store.ComputeMac("path1", &string_2);
40 std::string computed_mac_3 = pref_hash_store.ComputeMac("path2", &string_1);
41
42 // Quick sanity checks here, see pref_hash_calculator_unittest.cc for more
43 // complete tests.
44 EXPECT_EQ(computed_mac_1, pref_hash_store.ComputeMac("path1", &string_1));
45 EXPECT_NE(computed_mac_1, computed_mac_2);
46 EXPECT_NE(computed_mac_1, computed_mac_3);
47 EXPECT_EQ(64U, computed_mac_1.size());
48 }
49
50 TEST_F(PrefHashStoreImplTest, ComputeSplitMacs) {
51 base::DictionaryValue dict;
52 dict.Set("a", new base::StringValue("string1"));
53 dict.Set("b", new base::StringValue("string2"));
54 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true);
55
56 std::unique_ptr<base::DictionaryValue> computed_macs =
57 pref_hash_store.ComputeSplitMacs("foo.bar", &dict);
58
59 std::string mac_1;
60 std::string mac_2;
61 ASSERT_TRUE(computed_macs->GetString("a", &mac_1));
62 ASSERT_TRUE(computed_macs->GetString("b", &mac_2));
63
64 EXPECT_EQ(2U, computed_macs->size());
65
66 base::StringValue string_1("string1");
67 base::StringValue string_2("string2");
68 EXPECT_EQ(pref_hash_store.ComputeMac("foo.bar.a", &string_1), mac_1);
69 EXPECT_EQ(pref_hash_store.ComputeMac("foo.bar.b", &string_2), mac_2);
70 }
71
33 TEST_F(PrefHashStoreImplTest, AtomicHashStoreAndCheck) { 72 TEST_F(PrefHashStoreImplTest, AtomicHashStoreAndCheck) {
34 base::StringValue string_1("string1"); 73 base::StringValue string_1("string1");
35 base::StringValue string_2("string2"); 74 base::StringValue string_2("string2");
36 75
37 { 76 {
38 // 32 NULL bytes is the seed that was used to generate the legacy hash. 77 // 32 NULL bytes is the seed that was used to generate the legacy hash.
39 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); 78 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true);
40 std::unique_ptr<PrefHashStoreTransaction> transaction( 79 std::unique_ptr<PrefHashStoreTransaction> transaction(
41 pref_hash_store.BeginTransaction(GetHashStoreContents())); 80 pref_hash_store.BeginTransaction(GetHashStoreContents()));
42 81
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 // Load a new |pref_hash_store2| in which the hashes dictionary is trusted. 509 // Load a new |pref_hash_store2| in which the hashes dictionary is trusted.
471 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); 510 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true);
472 std::unique_ptr<PrefHashStoreTransaction> transaction( 511 std::unique_ptr<PrefHashStoreTransaction> transaction(
473 pref_hash_store2.BeginTransaction(GetHashStoreContents())); 512 pref_hash_store2.BeginTransaction(GetHashStoreContents()));
474 std::vector<std::string> invalid_keys; 513 std::vector<std::string> invalid_keys;
475 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, 514 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE,
476 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); 515 transaction->CheckSplitValue("path1", &dict, &invalid_keys));
477 EXPECT_TRUE(invalid_keys.empty()); 516 EXPECT_TRUE(invalid_keys.empty());
478 } 517 }
479 } 518 }
OLDNEW
« no previous file with comments | « components/user_prefs/tracked/pref_hash_store_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698