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

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

Issue 2287733002: Switch //components away from base::ListValue::Append(Value*) overload. (Closed)
Patch Set: rebase 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
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 <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 TEST(PrefHashCalculatorTest, TestCurrentAlgorithm) { 16 TEST(PrefHashCalculatorTest, TestCurrentAlgorithm) {
16 base::StringValue string_value_1("string value 1"); 17 base::StringValue string_value_1("string value 1");
17 base::StringValue string_value_2("string value 2"); 18 base::StringValue string_value_2("string value 2");
18 base::DictionaryValue dictionary_value_1; 19 base::DictionaryValue dictionary_value_1;
19 dictionary_value_1.SetInteger("int value", 1); 20 dictionary_value_1.SetInteger("int value", 1);
20 dictionary_value_1.Set("nested empty map", new base::DictionaryValue); 21 dictionary_value_1.Set("nested empty map", new base::DictionaryValue);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 std::unique_ptr<base::Value> string_value( 85 std::unique_ptr<base::Value> string_value(
85 new base::StringValue("testing with special chars:\n<>{}:^^@#$\\/")); 86 new base::StringValue("testing with special chars:\n<>{}:^^@#$\\/"));
86 87
87 // For legacy reasons, we have to support pruning of empty lists/dictionaries 88 // For legacy reasons, we have to support pruning of empty lists/dictionaries
88 // and nested empty ists/dicts in the hash generation algorithm. 89 // and nested empty ists/dicts in the hash generation algorithm.
89 std::unique_ptr<base::DictionaryValue> nested_empty_dict( 90 std::unique_ptr<base::DictionaryValue> nested_empty_dict(
90 new base::DictionaryValue); 91 new base::DictionaryValue);
91 nested_empty_dict->Set("a", new base::DictionaryValue); 92 nested_empty_dict->Set("a", new base::DictionaryValue);
92 nested_empty_dict->Set("b", new base::ListValue); 93 nested_empty_dict->Set("b", new base::ListValue);
93 std::unique_ptr<base::ListValue> nested_empty_list(new base::ListValue); 94 std::unique_ptr<base::ListValue> nested_empty_list(new base::ListValue);
94 nested_empty_list->Append(new base::DictionaryValue); 95 nested_empty_list->Append(base::MakeUnique<base::DictionaryValue>());
95 nested_empty_list->Append(new base::ListValue); 96 nested_empty_list->Append(base::MakeUnique<base::ListValue>());
96 nested_empty_list->Append(nested_empty_dict->DeepCopy()); 97 nested_empty_list->Append(nested_empty_dict->CreateDeepCopy());
97 98
98 // A dictionary with an empty dictionary, an empty list, and nested empty 99 // A dictionary with an empty dictionary, an empty list, and nested empty
99 // dictionaries/lists in it. 100 // dictionaries/lists in it.
100 std::unique_ptr<base::DictionaryValue> dict_value(new base::DictionaryValue); 101 std::unique_ptr<base::DictionaryValue> dict_value(new base::DictionaryValue);
101 dict_value->Set("a", new base::StringValue("foo")); 102 dict_value->Set("a", new base::StringValue("foo"));
102 dict_value->Set("d", new base::ListValue); 103 dict_value->Set("d", new base::ListValue);
103 dict_value->Set("b", new base::DictionaryValue); 104 dict_value->Set("b", new base::DictionaryValue);
104 dict_value->Set("c", new base::StringValue("baz")); 105 dict_value->Set("c", new base::StringValue("baz"));
105 dict_value->Set("e", nested_empty_dict.release()); 106 dict_value->Set("e", nested_empty_dict.release());
106 dict_value->Set("f", nested_empty_list.release()); 107 dict_value->Set("f", nested_empty_list.release());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 "845EF34663FF8D32BE6707F40258FBA531C2BFC532E3B014AFB3476115C2A9DE"; 196 "845EF34663FF8D32BE6707F40258FBA531C2BFC532E3B014AFB3476115C2A9DE";
196 197
197 base::ListValue startup_urls; 198 base::ListValue startup_urls;
198 startup_urls.Set(0, new base::StringValue("http://www.chromium.org/")); 199 startup_urls.Set(0, new base::StringValue("http://www.chromium.org/"));
199 200
200 EXPECT_EQ( 201 EXPECT_EQ(
201 PrefHashCalculator::VALID_SECURE_LEGACY, 202 PrefHashCalculator::VALID_SECURE_LEGACY,
202 PrefHashCalculator(std::string(kSeed, arraysize(kSeed)), kDeviceId) 203 PrefHashCalculator(std::string(kSeed, arraysize(kSeed)), kDeviceId)
203 .Validate("session.startup_urls", &startup_urls, kExpectedValue)); 204 .Validate("session.startup_urls", &startup_urls, kExpectedValue));
204 } 205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698