| OLD | NEW |
| 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.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/memory/ptr_util.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "components/policy/core/common/policy_load_status.h" | 17 #include "components/policy/core/common/policy_load_status.h" |
| 17 #include "components/policy/core/common/registry_dict_win.h" | 18 #include "components/policy/core/common/registry_dict.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace policy { | 21 namespace policy { |
| 21 namespace preg_parser { | 22 namespace preg_parser { |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // Check whether two RegistryDicts equal each other. | 25 // Check whether two RegistryDicts equal each other. |
| 25 testing::AssertionResult RegistryDictEquals(const RegistryDict& a, | 26 testing::AssertionResult RegistryDictEquals(const RegistryDict& a, |
| 26 const RegistryDict& b) { | 27 const RegistryDict& b) { |
| 27 auto iter_key_a = a.keys().begin(); | 28 auto iter_key_a = a.keys().begin(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 name, base::WrapUnique<base::Value>(new base::FundamentalValue(value))); | 64 name, base::WrapUnique<base::Value>(new base::FundamentalValue(value))); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void SetString(RegistryDict* dict, | 67 void SetString(RegistryDict* dict, |
| 67 const std::string& name, | 68 const std::string& name, |
| 68 const std::string& value) { | 69 const std::string& value) { |
| 69 dict->SetValue(name, | 70 dict->SetValue(name, |
| 70 base::WrapUnique<base::Value>(new base::StringValue(value))); | 71 base::WrapUnique<base::Value>(new base::StringValue(value))); |
| 71 } | 72 } |
| 72 | 73 |
| 73 TEST(PRegParserWinTest, TestParseFile) { | 74 TEST(PRegParserTest, TestParseFile) { |
| 74 base::FilePath test_data_dir; | 75 base::FilePath test_data_dir; |
| 75 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir)); | 76 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir)); |
| 76 | 77 |
| 77 // Prepare the test dictionary with some data so the test can check that the | 78 // Prepare the test dictionary with some data so the test can check that the |
| 78 // PReg action triggers work, i.e. remove these items. | 79 // PReg action triggers work, i.e. remove these items. |
| 79 RegistryDict dict; | 80 RegistryDict dict; |
| 80 SetInteger(&dict, "DeleteValuesTest1", 1); | 81 SetInteger(&dict, "DeleteValuesTest1", 1); |
| 81 SetString(&dict, "DeleteValuesTest2", "2"); | 82 SetString(&dict, "DeleteValuesTest2", "2"); |
| 82 dict.SetKey("DeleteKeysTest1", base::MakeUnique<RegistryDict>()); | 83 dict.SetKey("DeleteKeysTest1", base::MakeUnique<RegistryDict>()); |
| 83 std::unique_ptr<RegistryDict> delete_keys_test(new RegistryDict()); | 84 std::unique_ptr<RegistryDict> delete_keys_test(new RegistryDict()); |
| 84 SetInteger(delete_keys_test.get(), "DeleteKeysTest2Entry", 1); | 85 SetInteger(delete_keys_test.get(), "DeleteKeysTest2Entry", 1); |
| 85 dict.SetKey("DeleteKeysTest2", std::move(delete_keys_test)); | 86 dict.SetKey("DeleteKeysTest2", std::move(delete_keys_test)); |
| 86 SetInteger(&dict, "DelTest", 1); | 87 SetInteger(&dict, "DelTest", 1); |
| 87 std::unique_ptr<RegistryDict> subdict(new RegistryDict()); | 88 std::unique_ptr<RegistryDict> subdict(new RegistryDict()); |
| 88 SetInteger(subdict.get(), "DelValsTest1", 1); | 89 SetInteger(subdict.get(), "DelValsTest1", 1); |
| 89 SetString(subdict.get(), "DelValsTest2", "2"); | 90 SetString(subdict.get(), "DelValsTest2", "2"); |
| 90 subdict->SetKey("DelValsTest3", base::MakeUnique<RegistryDict>()); | 91 subdict->SetKey("DelValsTest3", base::MakeUnique<RegistryDict>()); |
| 91 dict.SetKey("DelValsTest", std::move(subdict)); | 92 dict.SetKey("DelValsTest", std::move(subdict)); |
| 92 | 93 |
| 93 // Run the parser. | 94 // Run the parser. |
| 94 base::FilePath test_file( | 95 base::FilePath test_file( |
| 95 test_data_dir.AppendASCII("chrome/test/data/policy/registry.pol")); | 96 test_data_dir.AppendASCII("chrome/test/data/policy/registry.pol")); |
| 96 PolicyLoadStatusSample status; | 97 PolicyLoadStatusSample status; |
| 97 ASSERT_TRUE(preg_parser::ReadFile( | 98 ASSERT_TRUE(preg_parser::ReadFile( |
| 98 test_file, L"SOFTWARE\\Policies\\Chromium", &dict, &status)); | 99 test_file, base::ASCIIToUTF16("SOFTWARE\\Policies\\Chromium"), |
| 100 &dict, &status)); |
| 99 | 101 |
| 100 // Build the expected output dictionary. | 102 // Build the expected output dictionary. |
| 101 RegistryDict expected; | 103 RegistryDict expected; |
| 102 std::unique_ptr<RegistryDict> del_vals_dict(new RegistryDict()); | 104 std::unique_ptr<RegistryDict> del_vals_dict(new RegistryDict()); |
| 103 del_vals_dict->SetKey("DelValsTest3", base::MakeUnique<RegistryDict>()); | 105 del_vals_dict->SetKey("DelValsTest3", base::MakeUnique<RegistryDict>()); |
| 104 expected.SetKey("DelValsTest", std::move(del_vals_dict)); | 106 expected.SetKey("DelValsTest", std::move(del_vals_dict)); |
| 105 SetInteger(&expected, "HomepageIsNewTabPage", 1); | 107 SetInteger(&expected, "HomepageIsNewTabPage", 1); |
| 106 SetString(&expected, "HomepageLocation", "http://www.example.com"); | 108 SetString(&expected, "HomepageLocation", "http://www.example.com"); |
| 107 SetInteger(&expected, "RestoreOnStartup", 4); | 109 SetInteger(&expected, "RestoreOnStartup", 4); |
| 108 std::unique_ptr<RegistryDict> startup_urls(new RegistryDict()); | 110 std::unique_ptr<RegistryDict> startup_urls(new RegistryDict()); |
| 109 SetString(startup_urls.get(), "1", "http://www.chromium.org"); | 111 SetString(startup_urls.get(), "1", "http://www.chromium.org"); |
| 110 SetString(startup_urls.get(), "2", "http://www.example.com"); | 112 SetString(startup_urls.get(), "2", "http://www.example.com"); |
| 111 expected.SetKey("RestoreOnStartupURLs", std::move(startup_urls)); | 113 expected.SetKey("RestoreOnStartupURLs", std::move(startup_urls)); |
| 112 SetInteger(&expected, "ShowHomeButton", 1); | 114 SetInteger(&expected, "ShowHomeButton", 1); |
| 113 SetString(&expected, "Snowman", "\xE2\x98\x83"); | 115 SetString(&expected, "Snowman", "\xE2\x98\x83"); |
| 114 SetString(&expected, "Empty", ""); | 116 SetString(&expected, "Empty", ""); |
| 115 | 117 |
| 116 EXPECT_TRUE(RegistryDictEquals(dict, expected)); | 118 EXPECT_TRUE(RegistryDictEquals(dict, expected)); |
| 117 } | 119 } |
| 118 | 120 |
| 119 } // namespace | 121 } // namespace |
| 120 } // namespace preg_parser | 122 } // namespace preg_parser |
| 121 } // namespace policy | 123 } // namespace policy |
| OLD | NEW |