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 "services/preferences/tracked/pref_hash_calculator.h" | 5 #include "services/preferences/tracked/pref_hash_calculator.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 ASSERT_FALSE(calc1.Calculate("pref_path", NULL).empty()); | 69 ASSERT_FALSE(calc1.Calculate("pref_path", NULL).empty()); |
70 } | 70 } |
71 | 71 |
72 // Tests the output against a known value to catch unexpected algorithm changes. | 72 // Tests the output against a known value to catch unexpected algorithm changes. |
73 // The test hashes below must NEVER be updated, the serialization algorithm used | 73 // The test hashes below must NEVER be updated, the serialization algorithm used |
74 // must always be able to generate data that will produce these exact hashes. | 74 // must always be able to generate data that will produce these exact hashes. |
75 TEST(PrefHashCalculatorTest, CatchHashChanges) { | 75 TEST(PrefHashCalculatorTest, CatchHashChanges) { |
76 static const char kSeed[] = "0123456789ABCDEF0123456789ABCDEF"; | 76 static const char kSeed[] = "0123456789ABCDEF0123456789ABCDEF"; |
77 static const char kDeviceId[] = "test_device_id1"; | 77 static const char kDeviceId[] = "test_device_id1"; |
78 | 78 |
79 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); | 79 auto null_value = base::MakeUnique<base::Value>(); |
80 std::unique_ptr<base::Value> bool_value(new base::Value(false)); | 80 std::unique_ptr<base::Value> bool_value(new base::Value(false)); |
81 std::unique_ptr<base::Value> int_value(new base::Value(1234567890)); | 81 std::unique_ptr<base::Value> int_value(new base::Value(1234567890)); |
82 std::unique_ptr<base::Value> double_value(new base::Value(123.0987654321)); | 82 std::unique_ptr<base::Value> double_value(new base::Value(123.0987654321)); |
83 std::unique_ptr<base::Value> string_value( | 83 std::unique_ptr<base::Value> string_value( |
84 new base::Value("testing with special chars:\n<>{}:^^@#$\\/")); | 84 new base::Value("testing with special chars:\n<>{}:^^@#$\\/")); |
85 | 85 |
86 // For legacy reasons, we have to support pruning of empty lists/dictionaries | 86 // For legacy reasons, we have to support pruning of empty lists/dictionaries |
87 // and nested empty ists/dicts in the hash generation algorithm. | 87 // and nested empty ists/dicts in the hash generation algorithm. |
88 std::unique_ptr<base::DictionaryValue> nested_empty_dict( | 88 std::unique_ptr<base::DictionaryValue> nested_empty_dict( |
89 new base::DictionaryValue); | 89 new base::DictionaryValue); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 187 |
188 // As in PrefHashCalculatorTest.CatchHashChanges. | 188 // As in PrefHashCalculatorTest.CatchHashChanges. |
189 const base::Value string_value("testing with special chars:\n<>{}:^^@#$\\/"); | 189 const base::Value string_value("testing with special chars:\n<>{}:^^@#$\\/"); |
190 static const char kExpectedValue[] = | 190 static const char kExpectedValue[] = |
191 "05ACCBD3B05C45C36CD06190F63EC577112311929D8380E26E5F13182EB68318"; | 191 "05ACCBD3B05C45C36CD06190F63EC577112311929D8380E26E5F13182EB68318"; |
192 | 192 |
193 EXPECT_EQ(PrefHashCalculator::VALID_SECURE_LEGACY, | 193 EXPECT_EQ(PrefHashCalculator::VALID_SECURE_LEGACY, |
194 PrefHashCalculator(kSeed, kNewDeviceId, kLegacyDeviceId) | 194 PrefHashCalculator(kSeed, kNewDeviceId, kLegacyDeviceId) |
195 .Validate("pref.path", &string_value, kExpectedValue)); | 195 .Validate("pref.path", &string_value, kExpectedValue)); |
196 } | 196 } |
OLD | NEW |