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 "chrome/browser/policy/preg_parser_win.h" | 5 #include "chrome/browser/policy/preg_parser_win.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/policy/policy_load_status.h" |
12 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace policy { | 16 namespace policy { |
16 namespace preg_parser { | 17 namespace preg_parser { |
17 | 18 |
18 TEST(PRegParserWinTest, TestParseFile) { | 19 TEST(PRegParserWinTest, TestParseFile) { |
19 base::FilePath test_data_dir; | 20 base::FilePath test_data_dir; |
20 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); | 21 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); |
21 | 22 |
22 // Prepare the test dictionary with some data so the test can check that the | 23 // Prepare the test dictionary with some data so the test can check that the |
23 // PReg action triggers work, i.e. remove these items. | 24 // PReg action triggers work, i.e. remove these items. |
24 base::DictionaryValue dict; | 25 base::DictionaryValue dict; |
25 dict.SetInteger("DeleteValuesTest1", 1); | 26 dict.SetInteger("DeleteValuesTest1", 1); |
26 dict.SetString("DeleteValuesTest2", "2"); | 27 dict.SetString("DeleteValuesTest2", "2"); |
27 dict.SetInteger("DeleteKeysTest1", 1); | 28 dict.SetInteger("DeleteKeysTest1", 1); |
28 dict.SetString("DeleteKeysTest2", "2"); | 29 dict.SetString("DeleteKeysTest2", "2"); |
29 dict.SetInteger("DelTest", 1); | 30 dict.SetInteger("DelTest", 1); |
30 base::DictionaryValue* subdict = new base::DictionaryValue(); | 31 base::DictionaryValue* subdict = new base::DictionaryValue(); |
31 subdict->SetInteger("DelValsTest1", 1); | 32 subdict->SetInteger("DelValsTest1", 1); |
32 subdict->SetString("DelValsTest2", "2"); | 33 subdict->SetString("DelValsTest2", "2"); |
33 subdict->Set("DelValsTest3", new base::DictionaryValue()); | 34 subdict->Set("DelValsTest3", new base::DictionaryValue()); |
34 dict.Set("DelValsTest", subdict); | 35 dict.Set("DelValsTest", subdict); |
35 | 36 |
36 // Run the parser. | 37 // Run the parser. |
37 base::FilePath test_file(test_data_dir.AppendASCII("policy/registry.pol")); | 38 base::FilePath test_file(test_data_dir.AppendASCII("policy/registry.pol")); |
| 39 PolicyLoadStatusSample status; |
38 ASSERT_TRUE(preg_parser::ReadFile( | 40 ASSERT_TRUE(preg_parser::ReadFile( |
39 test_file, L"SOFTWARE\\Policies\\Chromium", &dict)); | 41 test_file, L"SOFTWARE\\Policies\\Chromium", &dict, &status)); |
40 | 42 |
41 // Build the expected output dictionary. | 43 // Build the expected output dictionary. |
42 base::DictionaryValue expected; | 44 base::DictionaryValue expected; |
43 base::DictionaryValue* del_vals_dict = new base::DictionaryValue(); | 45 base::DictionaryValue* del_vals_dict = new base::DictionaryValue(); |
44 del_vals_dict->Set("DelValsTest3", new base::DictionaryValue()); | 46 del_vals_dict->Set("DelValsTest3", new base::DictionaryValue()); |
45 expected.Set("DelValsTest", del_vals_dict); | 47 expected.Set("DelValsTest", del_vals_dict); |
46 expected.SetInteger("HomepageIsNewTabPage", 1); | 48 expected.SetInteger("HomepageIsNewTabPage", 1); |
47 expected.SetString("HomepageLocation", "http://www.example.com"); | 49 expected.SetString("HomepageLocation", "http://www.example.com"); |
48 expected.SetInteger("RestoreOnStartup", 4); | 50 expected.SetInteger("RestoreOnStartup", 4); |
49 base::DictionaryValue* startup_urls = new DictionaryValue(); | 51 base::DictionaryValue* startup_urls = new DictionaryValue(); |
50 startup_urls->SetString("1", "http://www.chromium.org"); | 52 startup_urls->SetString("1", "http://www.chromium.org"); |
51 startup_urls->SetString("2", "http://www.example.com"); | 53 startup_urls->SetString("2", "http://www.example.com"); |
52 expected.Set("RestoreOnStartupURLs", startup_urls); | 54 expected.Set("RestoreOnStartupURLs", startup_urls); |
53 expected.SetInteger("ShowHomeButton", 1); | 55 expected.SetInteger("ShowHomeButton", 1); |
54 expected.SetString("Snowman", "\xE2\x98\x83"); | 56 expected.SetString("Snowman", "\xE2\x98\x83"); |
55 | 57 |
56 EXPECT_TRUE(base::Value::Equals(&expected, &dict)); | 58 EXPECT_TRUE(base::Value::Equals(&expected, &dict)); |
57 } | 59 } |
58 | 60 |
59 } // namespace policy | 61 } // namespace policy |
60 } // namespace preg_parser | 62 } // namespace preg_parser |
OLD | NEW |