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

Side by Side Diff: components/policy/core/common/preg_parser_win_unittest.cc

Issue 1902633006: Convert //components/policy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and use namespace alias 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/policy/core/common/preg_parser_win.h" 5 #include "components/policy/core/common/preg_parser_win.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/path_service.h" 14 #include "base/path_service.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "components/policy/core/common/policy_load_status.h" 16 #include "components/policy/core/common/policy_load_status.h"
16 #include "components/policy/core/common/registry_dict_win.h" 17 #include "components/policy/core/common/registry_dict_win.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace policy { 20 namespace policy {
20 namespace preg_parser { 21 namespace preg_parser {
21 namespace { 22 namespace {
22 23
(...skipping 28 matching lines...) Expand all
51 } 52 }
52 } 53 }
53 54
54 return testing::AssertionSuccess(); 55 return testing::AssertionSuccess();
55 } 56 }
56 57
57 void SetInteger(RegistryDict* dict, 58 void SetInteger(RegistryDict* dict,
58 const std::string& name, 59 const std::string& name,
59 int value) { 60 int value) {
60 dict->SetValue( 61 dict->SetValue(
61 name, 62 name, base::WrapUnique<base::Value>(new base::FundamentalValue(value)));
62 make_scoped_ptr<base::Value>(new base::FundamentalValue(value)));
63 } 63 }
64 64
65 void SetString(RegistryDict* dict, 65 void SetString(RegistryDict* dict,
66 const std::string& name, 66 const std::string& name,
67 const std::string& value) { 67 const std::string& value) {
68 dict->SetValue( 68 dict->SetValue(name,
69 name, 69 base::WrapUnique<base::Value>(new base::StringValue(value)));
70 make_scoped_ptr<base::Value>(new base::StringValue(value)));
71 } 70 }
72 71
73 TEST(PRegParserWinTest, TestParseFile) { 72 TEST(PRegParserWinTest, TestParseFile) {
74 base::FilePath test_data_dir; 73 base::FilePath test_data_dir;
75 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir)); 74 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir));
76 75
77 // Prepare the test dictionary with some data so the test can check that the 76 // Prepare the test dictionary with some data so the test can check that the
78 // PReg action triggers work, i.e. remove these items. 77 // PReg action triggers work, i.e. remove these items.
79 RegistryDict dict; 78 RegistryDict dict;
80 SetInteger(&dict, "DeleteValuesTest1", 1); 79 SetInteger(&dict, "DeleteValuesTest1", 1);
81 SetString(&dict, "DeleteValuesTest2", "2"); 80 SetString(&dict, "DeleteValuesTest2", "2");
82 dict.SetKey("DeleteKeysTest1", make_scoped_ptr(new RegistryDict())); 81 dict.SetKey("DeleteKeysTest1", base::WrapUnique(new RegistryDict()));
83 scoped_ptr<RegistryDict> delete_keys_test(new RegistryDict()); 82 std::unique_ptr<RegistryDict> delete_keys_test(new RegistryDict());
84 SetInteger(delete_keys_test.get(), "DeleteKeysTest2Entry", 1); 83 SetInteger(delete_keys_test.get(), "DeleteKeysTest2Entry", 1);
85 dict.SetKey("DeleteKeysTest2", std::move(delete_keys_test)); 84 dict.SetKey("DeleteKeysTest2", std::move(delete_keys_test));
86 SetInteger(&dict, "DelTest", 1); 85 SetInteger(&dict, "DelTest", 1);
87 scoped_ptr<RegistryDict> subdict(new RegistryDict()); 86 std::unique_ptr<RegistryDict> subdict(new RegistryDict());
88 SetInteger(subdict.get(), "DelValsTest1", 1); 87 SetInteger(subdict.get(), "DelValsTest1", 1);
89 SetString(subdict.get(), "DelValsTest2", "2"); 88 SetString(subdict.get(), "DelValsTest2", "2");
90 subdict->SetKey("DelValsTest3", make_scoped_ptr(new RegistryDict())); 89 subdict->SetKey("DelValsTest3", base::WrapUnique(new RegistryDict()));
91 dict.SetKey("DelValsTest", std::move(subdict)); 90 dict.SetKey("DelValsTest", std::move(subdict));
92 91
93 // Run the parser. 92 // Run the parser.
94 base::FilePath test_file( 93 base::FilePath test_file(
95 test_data_dir.AppendASCII("chrome/test/data/policy/registry.pol")); 94 test_data_dir.AppendASCII("chrome/test/data/policy/registry.pol"));
96 PolicyLoadStatusSample status; 95 PolicyLoadStatusSample status;
97 ASSERT_TRUE(preg_parser::ReadFile( 96 ASSERT_TRUE(preg_parser::ReadFile(
98 test_file, L"SOFTWARE\\Policies\\Chromium", &dict, &status)); 97 test_file, L"SOFTWARE\\Policies\\Chromium", &dict, &status));
99 98
100 // Build the expected output dictionary. 99 // Build the expected output dictionary.
101 RegistryDict expected; 100 RegistryDict expected;
102 scoped_ptr<RegistryDict> del_vals_dict(new RegistryDict()); 101 std::unique_ptr<RegistryDict> del_vals_dict(new RegistryDict());
103 del_vals_dict->SetKey("DelValsTest3", make_scoped_ptr(new RegistryDict())); 102 del_vals_dict->SetKey("DelValsTest3", base::WrapUnique(new RegistryDict()));
104 expected.SetKey("DelValsTest", std::move(del_vals_dict)); 103 expected.SetKey("DelValsTest", std::move(del_vals_dict));
105 SetInteger(&expected, "HomepageIsNewTabPage", 1); 104 SetInteger(&expected, "HomepageIsNewTabPage", 1);
106 SetString(&expected, "HomepageLocation", "http://www.example.com"); 105 SetString(&expected, "HomepageLocation", "http://www.example.com");
107 SetInteger(&expected, "RestoreOnStartup", 4); 106 SetInteger(&expected, "RestoreOnStartup", 4);
108 scoped_ptr<RegistryDict> startup_urls(new RegistryDict()); 107 std::unique_ptr<RegistryDict> startup_urls(new RegistryDict());
109 SetString(startup_urls.get(), "1", "http://www.chromium.org"); 108 SetString(startup_urls.get(), "1", "http://www.chromium.org");
110 SetString(startup_urls.get(), "2", "http://www.example.com"); 109 SetString(startup_urls.get(), "2", "http://www.example.com");
111 expected.SetKey("RestoreOnStartupURLs", std::move(startup_urls)); 110 expected.SetKey("RestoreOnStartupURLs", std::move(startup_urls));
112 SetInteger(&expected, "ShowHomeButton", 1); 111 SetInteger(&expected, "ShowHomeButton", 1);
113 SetString(&expected, "Snowman", "\xE2\x98\x83"); 112 SetString(&expected, "Snowman", "\xE2\x98\x83");
114 SetString(&expected, "Empty", ""); 113 SetString(&expected, "Empty", "");
115 114
116 EXPECT_TRUE(RegistryDictEquals(dict, expected)); 115 EXPECT_TRUE(RegistryDictEquals(dict, expected));
117 } 116 }
118 117
119 } // namespace 118 } // namespace
120 } // namespace preg_parser 119 } // namespace preg_parser
121 } // namespace policy 120 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/preg_parser_win.cc ('k') | components/policy/core/common/proxy_policy_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698