OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/config_dir_policy_loader.h" | 5 #include "components/policy/core/common/config_dir_policy_loader.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/json/json_string_value_serializer.h" | 12 #include "base/json/json_string_value_serializer.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "components/policy/core/common/async_policy_provider.h" | 18 #include "components/policy/core/common/async_policy_provider.h" |
19 #include "components/policy/core/common/configuration_policy_provider_test.h" | 19 #include "components/policy/core/common/configuration_policy_provider_test.h" |
20 #include "components/policy/core/common/policy_bundle.h" | 20 #include "components/policy/core/common/policy_bundle.h" |
21 #include "components/policy/core/common/policy_map.h" | 21 #include "components/policy/core/common/policy_map.h" |
22 #include "components/policy/core/common/policy_types.h" | 22 #include "components/policy/core/common/policy_types.h" |
23 | 23 |
24 // Use real existing policies as samples because ConfigDirPolicyLoader does | |
25 // basic verification at load time. These constants are specific to | |
26 // ConfigDirPolicyLoader and thus are hidden in an anonymous namespace. (They | |
27 // cannot be applied generally because Windows tests depend on reading GPO | |
28 // sample files containing hard-coded policy names.) | |
29 namespace { | |
30 | |
31 const char kKeyString[] = "HomepageLocation"; | |
32 const char kKeyBoolean[] = "HomepageIsNewTabPage"; | |
33 const char kKeyInteger[] = "NetworkPredictionOptions"; | |
34 const char kKeyStringList[] = "DisabledSchemes"; | |
35 const char kKeyDictionary[] = "ProxySettings"; | |
36 | |
37 const char kTestChromeSchema[] = | |
38 "{" | |
39 " \"type\": \"object\"," | |
40 " \"properties\": {" | |
41 " \"HomepageLocation\": { \"type\": \"string\" }," | |
42 " \"HomepageIsNewTabPage\": { \"type\": \"boolean\" }," | |
43 " \"NetworkPredictionOptions\": { \"type\": \"integer\" }," | |
44 " \"DisabledSchemes\": {" | |
45 " \"type\": \"array\"," | |
46 " \"items\": { \"type\": \"string\" }" | |
47 " }," | |
48 " \"ProxySettings\": {" | |
49 " \"type\": \"object\"," | |
50 " \"properties\": {" | |
51 " \"bool\": { \"type\": \"boolean\" }," | |
52 " \"double\": { \"type\": \"number\" }," | |
53 " \"int\": { \"type\": \"integer\" }," | |
54 " \"string\": { \"type\": \"string\" }," | |
55 " \"array\": {" | |
56 " \"type\": \"array\"," | |
57 " \"items\": { \"type\": \"string\" }" | |
58 " }," | |
59 " \"dictionary\": {" | |
60 " \"type\": \"object\"," | |
61 " \"properties\": {" | |
62 " \"sub\": { \"type\": \"string\" }," | |
63 " \"sublist\": {" | |
64 " \"type\": \"array\"," | |
65 " \"items\": {" | |
66 " \"type\": \"object\"," | |
67 " \"properties\": {" | |
68 " \"aaa\": { \"type\": \"integer\" }," | |
69 " \"bbb\": { \"type\": \"integer\" }," | |
70 " \"ccc\": { \"type\": \"string\" }," | |
71 " \"ddd\": { \"type\": \"string\" }" | |
72 " }" | |
73 " }" | |
74 " }" | |
75 " }" | |
76 " }," | |
77 " \"list\": {" | |
78 " \"type\": \"array\"," | |
79 " \"items\": {" | |
80 " \"type\": \"object\"," | |
81 " \"properties\": {" | |
82 " \"subdictindex\": { \"type\": \"integer\" }," | |
83 " \"subdict\": {" | |
84 " \"type\": \"object\"," | |
85 " \"properties\": {" | |
86 " \"bool\": { \"type\": \"boolean\" }," | |
87 " \"double\": { \"type\": \"number\" }," | |
88 " \"int\": { \"type\": \"integer\" }," | |
89 " \"string\": { \"type\": \"string\" }" | |
90 " }" | |
91 " }" | |
92 " }" | |
93 " }" | |
94 " }," | |
95 " \"dict\": {" | |
96 " \"type\": \"object\"," | |
97 " \"properties\": {" | |
98 " \"bool\": { \"type\": \"boolean\" }," | |
99 " \"double\": { \"type\": \"number\" }," | |
100 " \"int\": { \"type\": \"integer\" }," | |
101 " \"string\": { \"type\": \"string\" }," | |
102 " \"list\": {" | |
103 " \"type\": \"array\"," | |
104 " \"items\": {" | |
105 " \"type\": \"object\"," | |
106 " \"properties\": {" | |
107 " \"subdictindex\": { \"type\": \"integer\" }," | |
108 " \"subdict\": {" | |
109 " \"type\": \"object\"," | |
110 " \"properties\": {" | |
111 " \"bool\": { \"type\": \"boolean\" }," | |
112 " \"double\": { \"type\": \"number\" }," | |
113 " \"int\": { \"type\": \"integer\" }," | |
114 " \"string\": { \"type\": \"string\" }" | |
115 " }" | |
116 " }" | |
117 " }" | |
118 " }" | |
119 " }" | |
120 " }" | |
121 " }" | |
122 " }" | |
123 " }" | |
124 " }" | |
125 "}"; | |
126 | |
127 } // anonymous namespace | |
128 | |
129 namespace policy { | 24 namespace policy { |
130 | 25 |
131 namespace { | 26 namespace { |
132 | 27 |
133 // Subdirectory of the config dir that contains mandatory policies. | 28 // Subdirectory of the config dir that contains mandatory policies. |
134 const base::FilePath::CharType kMandatoryPath[] = FILE_PATH_LITERAL("managed"); | 29 const base::FilePath::CharType kMandatoryPath[] = FILE_PATH_LITERAL("managed"); |
135 | 30 |
136 class TestHarness : public PolicyProviderTestHarness { | 31 class TestHarness : public PolicyProviderTestHarness { |
137 public: | 32 public: |
138 TestHarness(); | 33 TestHarness(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 base::ScopedTempDir test_dir_; | 69 base::ScopedTempDir test_dir_; |
175 int next_policy_file_index_; | 70 int next_policy_file_index_; |
176 | 71 |
177 DISALLOW_COPY_AND_ASSIGN(TestHarness); | 72 DISALLOW_COPY_AND_ASSIGN(TestHarness); |
178 }; | 73 }; |
179 | 74 |
180 TestHarness::TestHarness() | 75 TestHarness::TestHarness() |
181 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, | 76 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, |
182 POLICY_SCOPE_MACHINE, | 77 POLICY_SCOPE_MACHINE, |
183 POLICY_SOURCE_PLATFORM), | 78 POLICY_SOURCE_PLATFORM), |
184 next_policy_file_index_(100) { | 79 next_policy_file_index_(100) {} |
185 key_string_ = kKeyString; | |
186 key_boolean_ = kKeyBoolean; | |
187 key_integer_ = kKeyInteger; | |
188 key_stringlist_ = kKeyStringList; | |
189 key_dictionary_ = kKeyDictionary; | |
190 test_schema_ = kTestChromeSchema; | |
191 } | |
192 | 80 |
193 TestHarness::~TestHarness() {} | 81 TestHarness::~TestHarness() {} |
194 | 82 |
195 void TestHarness::SetUp() { | 83 void TestHarness::SetUp() { |
196 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 84 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
197 } | 85 } |
198 | 86 |
199 ConfigurationPolicyProvider* TestHarness::CreateProvider( | 87 ConfigurationPolicyProvider* TestHarness::CreateProvider( |
200 SchemaRegistry* registry, | 88 SchemaRegistry* registry, |
201 scoped_refptr<base::SequencedTaskRunner> task_runner) { | 89 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 std::unique_ptr<PolicyBundle> bundle(loader.Load()); | 231 std::unique_ptr<PolicyBundle> bundle(loader.Load()); |
344 ASSERT_TRUE(bundle.get()); | 232 ASSERT_TRUE(bundle.get()); |
345 PolicyBundle expected_bundle; | 233 PolicyBundle expected_bundle; |
346 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 234 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
347 .LoadFrom(&test_dict_foo, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 235 .LoadFrom(&test_dict_foo, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
348 POLICY_SOURCE_PLATFORM); | 236 POLICY_SOURCE_PLATFORM); |
349 EXPECT_TRUE(bundle->Equals(expected_bundle)); | 237 EXPECT_TRUE(bundle->Equals(expected_bundle)); |
350 } | 238 } |
351 | 239 |
352 } // namespace policy | 240 } // namespace policy |
OLD | NEW |