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

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

Issue 1908143002: Convert //components/user_prefs from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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_calculator.h" 5 #include "components/user_prefs/tracked/pref_hash_calculator.h"
6 6
7 #include <memory>
7 #include <string> 8 #include <string>
8 9
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 TEST(PrefHashCalculatorTest, TestCurrentAlgorithm) { 15 TEST(PrefHashCalculatorTest, TestCurrentAlgorithm) {
16 base::StringValue string_value_1("string value 1"); 16 base::StringValue string_value_1("string value 1");
17 base::StringValue string_value_2("string value 2"); 17 base::StringValue string_value_2("string value 2");
18 base::DictionaryValue dictionary_value_1; 18 base::DictionaryValue dictionary_value_1;
19 dictionary_value_1.SetInteger("int value", 1); 19 dictionary_value_1.SetInteger("int value", 1);
20 dictionary_value_1.Set("nested empty map", new base::DictionaryValue); 20 dictionary_value_1.Set("nested empty map", new base::DictionaryValue);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 ASSERT_FALSE(calc1.Calculate("pref_path", NULL).empty()); 68 ASSERT_FALSE(calc1.Calculate("pref_path", NULL).empty());
69 } 69 }
70 70
71 // Tests the output against a known value to catch unexpected algorithm changes. 71 // Tests the output against a known value to catch unexpected algorithm changes.
72 // The test hashes below must NEVER be updated, the serialization algorithm used 72 // The test hashes below must NEVER be updated, the serialization algorithm used
73 // must always be able to generate data that will produce these exact hashes. 73 // must always be able to generate data that will produce these exact hashes.
74 TEST(PrefHashCalculatorTest, CatchHashChanges) { 74 TEST(PrefHashCalculatorTest, CatchHashChanges) {
75 static const char kSeed[] = "0123456789ABCDEF0123456789ABCDEF"; 75 static const char kSeed[] = "0123456789ABCDEF0123456789ABCDEF";
76 static const char kDeviceId[] = "test_device_id1"; 76 static const char kDeviceId[] = "test_device_id1";
77 77
78 scoped_ptr<base::Value> null_value = base::Value::CreateNullValue(); 78 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue();
79 scoped_ptr<base::Value> bool_value(new base::FundamentalValue(false)); 79 std::unique_ptr<base::Value> bool_value(new base::FundamentalValue(false));
80 scoped_ptr<base::Value> int_value(new base::FundamentalValue(1234567890)); 80 std::unique_ptr<base::Value> int_value(
81 scoped_ptr<base::Value> double_value( 81 new base::FundamentalValue(1234567890));
82 std::unique_ptr<base::Value> double_value(
82 new base::FundamentalValue(123.0987654321)); 83 new base::FundamentalValue(123.0987654321));
83 scoped_ptr<base::Value> string_value( 84 std::unique_ptr<base::Value> string_value(
84 new base::StringValue("testing with special chars:\n<>{}:^^@#$\\/")); 85 new base::StringValue("testing with special chars:\n<>{}:^^@#$\\/"));
85 86
86 // For legacy reasons, we have to support pruning of empty lists/dictionaries 87 // For legacy reasons, we have to support pruning of empty lists/dictionaries
87 // and nested empty ists/dicts in the hash generation algorithm. 88 // and nested empty ists/dicts in the hash generation algorithm.
88 scoped_ptr<base::DictionaryValue> nested_empty_dict( 89 std::unique_ptr<base::DictionaryValue> nested_empty_dict(
89 new base::DictionaryValue); 90 new base::DictionaryValue);
90 nested_empty_dict->Set("a", new base::DictionaryValue); 91 nested_empty_dict->Set("a", new base::DictionaryValue);
91 nested_empty_dict->Set("b", new base::ListValue); 92 nested_empty_dict->Set("b", new base::ListValue);
92 scoped_ptr<base::ListValue> nested_empty_list(new base::ListValue); 93 std::unique_ptr<base::ListValue> nested_empty_list(new base::ListValue);
93 nested_empty_list->Append(new base::DictionaryValue); 94 nested_empty_list->Append(new base::DictionaryValue);
94 nested_empty_list->Append(new base::ListValue); 95 nested_empty_list->Append(new base::ListValue);
95 nested_empty_list->Append(nested_empty_dict->DeepCopy()); 96 nested_empty_list->Append(nested_empty_dict->DeepCopy());
96 97
97 // A dictionary with an empty dictionary, an empty list, and nested empty 98 // A dictionary with an empty dictionary, an empty list, and nested empty
98 // dictionaries/lists in it. 99 // dictionaries/lists in it.
99 scoped_ptr<base::DictionaryValue> dict_value(new base::DictionaryValue); 100 std::unique_ptr<base::DictionaryValue> dict_value(new base::DictionaryValue);
100 dict_value->Set("a", new base::StringValue("foo")); 101 dict_value->Set("a", new base::StringValue("foo"));
101 dict_value->Set("d", new base::ListValue); 102 dict_value->Set("d", new base::ListValue);
102 dict_value->Set("b", new base::DictionaryValue); 103 dict_value->Set("b", new base::DictionaryValue);
103 dict_value->Set("c", new base::StringValue("baz")); 104 dict_value->Set("c", new base::StringValue("baz"));
104 dict_value->Set("e", nested_empty_dict.release()); 105 dict_value->Set("e", nested_empty_dict.release());
105 dict_value->Set("f", nested_empty_list.release()); 106 dict_value->Set("f", nested_empty_list.release());
106 107
107 scoped_ptr<base::ListValue> list_value(new base::ListValue); 108 std::unique_ptr<base::ListValue> list_value(new base::ListValue);
108 list_value->AppendBoolean(true); 109 list_value->AppendBoolean(true);
109 list_value->AppendInteger(100); 110 list_value->AppendInteger(100);
110 list_value->AppendDouble(1.0); 111 list_value->AppendDouble(1.0);
111 112
112 ASSERT_EQ(base::Value::TYPE_NULL, null_value->GetType()); 113 ASSERT_EQ(base::Value::TYPE_NULL, null_value->GetType());
113 ASSERT_EQ(base::Value::TYPE_BOOLEAN, bool_value->GetType()); 114 ASSERT_EQ(base::Value::TYPE_BOOLEAN, bool_value->GetType());
114 ASSERT_EQ(base::Value::TYPE_INTEGER, int_value->GetType()); 115 ASSERT_EQ(base::Value::TYPE_INTEGER, int_value->GetType());
115 ASSERT_EQ(base::Value::TYPE_DOUBLE, double_value->GetType()); 116 ASSERT_EQ(base::Value::TYPE_DOUBLE, double_value->GetType());
116 ASSERT_EQ(base::Value::TYPE_STRING, string_value->GetType()); 117 ASSERT_EQ(base::Value::TYPE_STRING, string_value->GetType());
117 ASSERT_EQ(base::Value::TYPE_DICTIONARY, dict_value->GetType()); 118 ASSERT_EQ(base::Value::TYPE_DICTIONARY, dict_value->GetType());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 "845EF34663FF8D32BE6707F40258FBA531C2BFC532E3B014AFB3476115C2A9DE"; 195 "845EF34663FF8D32BE6707F40258FBA531C2BFC532E3B014AFB3476115C2A9DE";
195 196
196 base::ListValue startup_urls; 197 base::ListValue startup_urls;
197 startup_urls.Set(0, new base::StringValue("http://www.chromium.org/")); 198 startup_urls.Set(0, new base::StringValue("http://www.chromium.org/"));
198 199
199 EXPECT_EQ( 200 EXPECT_EQ(
200 PrefHashCalculator::VALID_SECURE_LEGACY, 201 PrefHashCalculator::VALID_SECURE_LEGACY,
201 PrefHashCalculator(std::string(kSeed, arraysize(kSeed)), kDeviceId) 202 PrefHashCalculator(std::string(kSeed, arraysize(kSeed)), kDeviceId)
202 .Validate("session.startup_urls", &startup_urls, kExpectedValue)); 203 .Validate("session.startup_urls", &startup_urls, kExpectedValue));
203 } 204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698