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