| OLD | NEW |
| 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 "chrome/browser/prefs/pref_hash_calculator.h" | 5 #include "chrome/browser/prefs/pref_hash_calculator.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 TEST(PrefHashCalculatorTest, TestCurrentAlgorithm) { | 12 TEST(PrefHashCalculatorTest, TestCurrentAlgorithm) { |
| 13 base::StringValue string_value_1("string value 1"); | 13 base::StringValue string_value_1("string value 1"); |
| 14 base::StringValue string_value_2("string value 2"); | 14 base::StringValue string_value_2("string value 2"); |
| 15 base::DictionaryValue dictionary_value_1; | 15 base::DictionaryValue dictionary_value_1; |
| 16 dictionary_value_1.SetInteger("int value", 1); | 16 dictionary_value_1.SetInteger("int value", 1); |
| 17 dictionary_value_1.Set("nested empty map", new DictionaryValue); | 17 dictionary_value_1.Set("nested empty map", new base::DictionaryValue); |
| 18 base::DictionaryValue dictionary_value_1_equivalent; | 18 base::DictionaryValue dictionary_value_1_equivalent; |
| 19 dictionary_value_1_equivalent.SetInteger("int value", 1); | 19 dictionary_value_1_equivalent.SetInteger("int value", 1); |
| 20 base::DictionaryValue dictionary_value_2; | 20 base::DictionaryValue dictionary_value_2; |
| 21 dictionary_value_2.SetInteger("int value", 2); | 21 dictionary_value_2.SetInteger("int value", 2); |
| 22 | 22 |
| 23 PrefHashCalculator calc1("seed1", "deviceid"); | 23 PrefHashCalculator calc1("seed1", "deviceid"); |
| 24 PrefHashCalculator calc1_dup("seed1", "deviceid"); | 24 PrefHashCalculator calc1_dup("seed1", "deviceid"); |
| 25 PrefHashCalculator calc2("seed2", "deviceid"); | 25 PrefHashCalculator calc2("seed2", "deviceid"); |
| 26 PrefHashCalculator calc3("seed1", "deviceid2"); | 26 PrefHashCalculator calc3("seed1", "deviceid2"); |
| 27 | 27 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // 32 NULL bytes is the seed that was used to generate the hash in old | 84 // 32 NULL bytes is the seed that was used to generate the hash in old |
| 85 // tests. Use it again to ensure that we haven't altered the algorithm. | 85 // tests. Use it again to ensure that we haven't altered the algorithm. |
| 86 EXPECT_EQ(PrefHashCalculator::VALID, | 86 EXPECT_EQ(PrefHashCalculator::VALID, |
| 87 PrefHashCalculator(std::string(32u, 0), kDeviceId).Validate( | 87 PrefHashCalculator(std::string(32u, 0), kDeviceId).Validate( |
| 88 "pref.path2", &list, kExpectedValue)); | 88 "pref.path2", &list, kExpectedValue)); |
| 89 } | 89 } |
| 90 { | 90 { |
| 91 static const char kExpectedValue[] = | 91 static const char kExpectedValue[] = |
| 92 "A50FE7EB31BFBC32B8A27E71730AF15421178A9B5815644ACE174B18966735B9"; | 92 "A50FE7EB31BFBC32B8A27E71730AF15421178A9B5815644ACE174B18966735B9"; |
| 93 | 93 |
| 94 DictionaryValue dict; | 94 base::DictionaryValue dict; |
| 95 dict.Set("a", new StringValue("foo")); | 95 dict.Set("a", new base::StringValue("foo")); |
| 96 dict.Set("d", new StringValue("bad")); | 96 dict.Set("d", new base::StringValue("bad")); |
| 97 dict.Set("b", new StringValue("bar")); | 97 dict.Set("b", new base::StringValue("bar")); |
| 98 dict.Set("c", new StringValue("baz")); | 98 dict.Set("c", new base::StringValue("baz")); |
| 99 | 99 |
| 100 // 32 NULL bytes is the seed that was used to generate the hash in old | 100 // 32 NULL bytes is the seed that was used to generate the hash in old |
| 101 // tests. Use it again to ensure that we haven't altered the algorithm. | 101 // tests. Use it again to ensure that we haven't altered the algorithm. |
| 102 EXPECT_EQ(PrefHashCalculator::VALID, | 102 EXPECT_EQ(PrefHashCalculator::VALID, |
| 103 PrefHashCalculator(std::string(32u, 0), kDeviceId).Validate( | 103 PrefHashCalculator(std::string(32u, 0), kDeviceId).Validate( |
| 104 "pref.path1", &dict, kExpectedValue)); | 104 "pref.path1", &dict, kExpectedValue)); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 TEST(PrefHashCalculatorTest, TestLegacyAlgorithm) { | 108 TEST(PrefHashCalculatorTest, TestLegacyAlgorithm) { |
| 109 const char* kExpectedValue = | 109 const char* kExpectedValue = |
| 110 "C503FB7C65EEFD5C07185F616A0AA67923C069909933F362022B1F187E73E9A2"; | 110 "C503FB7C65EEFD5C07185F616A0AA67923C069909933F362022B1F187E73E9A2"; |
| 111 const char* kDeviceId = "deviceid"; | 111 const char* kDeviceId = "deviceid"; |
| 112 | 112 |
| 113 DictionaryValue dict; | 113 base::DictionaryValue dict; |
| 114 dict.Set("a", new StringValue("foo")); | 114 dict.Set("a", new base::StringValue("foo")); |
| 115 dict.Set("d", new StringValue("bad")); | 115 dict.Set("d", new base::StringValue("bad")); |
| 116 dict.Set("b", new StringValue("bar")); | 116 dict.Set("b", new base::StringValue("bar")); |
| 117 dict.Set("c", new StringValue("baz")); | 117 dict.Set("c", new base::StringValue("baz")); |
| 118 | 118 |
| 119 // 32 NULL bytes is the seed that was used to generate the legacy hash. | 119 // 32 NULL bytes is the seed that was used to generate the legacy hash. |
| 120 EXPECT_EQ(PrefHashCalculator::VALID_LEGACY, | 120 EXPECT_EQ(PrefHashCalculator::VALID_LEGACY, |
| 121 PrefHashCalculator(std::string(32u, 0), kDeviceId).Validate( | 121 PrefHashCalculator(std::string(32u, 0), kDeviceId).Validate( |
| 122 "pref.path1", &dict, kExpectedValue)); | 122 "pref.path1", &dict, kExpectedValue)); |
| 123 | 123 |
| 124 } | 124 } |
| OLD | NEW |