summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy/preg_parser_win_unittest.cc
blob: efe32c6efbb59d6fc9e067fed7926a63f37a5b1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/policy/preg_parser_win.h"

#include "base/files/file_path.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/values.h"
#include "chrome/browser/policy/policy_load_status.h"
#include "chrome/common/chrome_paths.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace policy {
namespace preg_parser {

TEST(PRegParserWinTest, TestParseFile) {
  base::FilePath test_data_dir;
  ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));

  // Prepare the test dictionary with some data so the test can check that the
  // PReg action triggers work, i.e. remove these items.
  base::DictionaryValue dict;
  dict.SetInteger("DeleteValuesTest1", 1);
  dict.SetString("DeleteValuesTest2", "2");
  dict.SetInteger("DeleteKeysTest1", 1);
  dict.SetString("DeleteKeysTest2", "2");
  dict.SetInteger("DelTest", 1);
  base::DictionaryValue* subdict = new base::DictionaryValue();
  subdict->SetInteger("DelValsTest1", 1);
  subdict->SetString("DelValsTest2", "2");
  subdict->Set("DelValsTest3", new base::DictionaryValue());
  dict.Set("DelValsTest", subdict);

  // Run the parser.
  base::FilePath test_file(test_data_dir.AppendASCII("policy/registry.pol"));
  PolicyLoadStatusSample status;
  ASSERT_TRUE(preg_parser::ReadFile(
      test_file, L"SOFTWARE\\Policies\\Chromium", &dict, &status));

  // Build the expected output dictionary.
  base::DictionaryValue expected;
  base::DictionaryValue* del_vals_dict = new base::DictionaryValue();
  del_vals_dict->Set("DelValsTest3", new base::DictionaryValue());
  expected.Set("DelValsTest", del_vals_dict);
  expected.SetInteger("HomepageIsNewTabPage", 1);
  expected.SetString("HomepageLocation", "http://www.example.com");
  expected.SetInteger("RestoreOnStartup", 4);
  base::DictionaryValue* startup_urls = new DictionaryValue();
  startup_urls->SetString("1", "http://www.chromium.org");
  startup_urls->SetString("2", "http://www.example.com");
  expected.Set("RestoreOnStartupURLs", startup_urls);
  expected.SetInteger("ShowHomeButton", 1);
  expected.SetString("Snowman", "\xE2\x98\x83");

  EXPECT_TRUE(base::Value::Equals(&expected, &dict));
}

}  // namespace policy
}  // namespace preg_parser