OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
6 #include "base/prefs/pref_value_map.h" | 6 #include "base/prefs/pref_value_map.h" |
7 #include "chrome/browser/extensions/external_policy_loader.h" | 7 #include "chrome/browser/extensions/external_policy_loader.h" |
8 #include "chrome/browser/extensions/policy_handlers.h" | 8 #include "chrome/browser/extensions/policy_handlers.h" |
9 #include "components/policy/core/browser/policy_error_map.h" | 9 #include "components/policy/core/browser/policy_error_map.h" |
10 #include "components/policy/core/common/policy_map.h" | 10 #include "components/policy/core/common/policy_map.h" |
| 11 #include "components/policy/core/common/policy_types.h" |
11 #include "components/policy/core/common/schema.h" | 12 #include "components/policy/core/common/schema.h" |
12 #include "extensions/browser/pref_names.h" | 13 #include "extensions/browser/pref_names.h" |
13 #include "policy/policy_constants.h" | 14 #include "policy/policy_constants.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace extensions { | 17 namespace extensions { |
17 | 18 |
18 const char kTestPref[] = "unit_test.test_pref"; | 19 const char kTestPref[] = "unit_test.test_pref"; |
19 const char kTestManagementPolicy1[] = | 20 const char kTestManagementPolicy1[] = |
20 "{" | 21 "{" |
(...skipping 15 matching lines...) Expand all Loading... |
36 TEST(ExtensionListPolicyHandlerTest, CheckPolicySettings) { | 37 TEST(ExtensionListPolicyHandlerTest, CheckPolicySettings) { |
37 base::ListValue list; | 38 base::ListValue list; |
38 policy::PolicyMap policy_map; | 39 policy::PolicyMap policy_map; |
39 policy::PolicyErrorMap errors; | 40 policy::PolicyErrorMap errors; |
40 ExtensionListPolicyHandler handler( | 41 ExtensionListPolicyHandler handler( |
41 policy::key::kExtensionInstallBlacklist, kTestPref, true); | 42 policy::key::kExtensionInstallBlacklist, kTestPref, true); |
42 | 43 |
43 policy_map.Set(policy::key::kExtensionInstallBlacklist, | 44 policy_map.Set(policy::key::kExtensionInstallBlacklist, |
44 policy::POLICY_LEVEL_MANDATORY, | 45 policy::POLICY_LEVEL_MANDATORY, |
45 policy::POLICY_SCOPE_USER, | 46 policy::POLICY_SCOPE_USER, |
| 47 policy::POLICY_SOURCE_CLOUD, |
46 list.DeepCopy(), | 48 list.DeepCopy(), |
47 NULL); | 49 NULL); |
48 errors.Clear(); | 50 errors.Clear(); |
49 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 51 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
50 EXPECT_TRUE(errors.empty()); | 52 EXPECT_TRUE(errors.empty()); |
51 | 53 |
52 list.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop")); | 54 list.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop")); |
53 policy_map.Set(policy::key::kExtensionInstallBlacklist, | 55 policy_map.Set(policy::key::kExtensionInstallBlacklist, |
54 policy::POLICY_LEVEL_MANDATORY, | 56 policy::POLICY_LEVEL_MANDATORY, |
55 policy::POLICY_SCOPE_USER, | 57 policy::POLICY_SCOPE_USER, |
| 58 policy::POLICY_SOURCE_CLOUD, |
56 list.DeepCopy(), | 59 list.DeepCopy(), |
57 NULL); | 60 NULL); |
58 errors.Clear(); | 61 errors.Clear(); |
59 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 62 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
60 EXPECT_TRUE(errors.empty()); | 63 EXPECT_TRUE(errors.empty()); |
61 | 64 |
62 list.Append(new base::StringValue("*")); | 65 list.Append(new base::StringValue("*")); |
63 policy_map.Set(policy::key::kExtensionInstallBlacklist, | 66 policy_map.Set(policy::key::kExtensionInstallBlacklist, |
64 policy::POLICY_LEVEL_MANDATORY, | 67 policy::POLICY_LEVEL_MANDATORY, |
65 policy::POLICY_SCOPE_USER, | 68 policy::POLICY_SCOPE_USER, |
| 69 policy::POLICY_SOURCE_CLOUD, |
66 list.DeepCopy(), | 70 list.DeepCopy(), |
67 NULL); | 71 NULL); |
68 errors.Clear(); | 72 errors.Clear(); |
69 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 73 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
70 EXPECT_TRUE(errors.empty()); | 74 EXPECT_TRUE(errors.empty()); |
71 | 75 |
72 list.Append(new base::StringValue("invalid")); | 76 list.Append(new base::StringValue("invalid")); |
73 policy_map.Set(policy::key::kExtensionInstallBlacklist, | 77 policy_map.Set(policy::key::kExtensionInstallBlacklist, |
74 policy::POLICY_LEVEL_MANDATORY, | 78 policy::POLICY_LEVEL_MANDATORY, |
75 policy::POLICY_SCOPE_USER, | 79 policy::POLICY_SCOPE_USER, |
| 80 policy::POLICY_SOURCE_CLOUD, |
76 list.DeepCopy(), | 81 list.DeepCopy(), |
77 NULL); | 82 NULL); |
78 errors.Clear(); | 83 errors.Clear(); |
79 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 84 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
80 EXPECT_FALSE(errors.empty()); | 85 EXPECT_FALSE(errors.empty()); |
81 EXPECT_FALSE( | 86 EXPECT_FALSE( |
82 errors.GetErrors(policy::key::kExtensionInstallBlacklist).empty()); | 87 errors.GetErrors(policy::key::kExtensionInstallBlacklist).empty()); |
83 } | 88 } |
84 | 89 |
85 TEST(ExtensionListPolicyHandlerTest, ApplyPolicySettings) { | 90 TEST(ExtensionListPolicyHandlerTest, ApplyPolicySettings) { |
86 base::ListValue policy; | 91 base::ListValue policy; |
87 base::ListValue expected; | 92 base::ListValue expected; |
88 policy::PolicyMap policy_map; | 93 policy::PolicyMap policy_map; |
89 PrefValueMap prefs; | 94 PrefValueMap prefs; |
90 base::Value* value = NULL; | 95 base::Value* value = NULL; |
91 ExtensionListPolicyHandler handler( | 96 ExtensionListPolicyHandler handler( |
92 policy::key::kExtensionInstallBlacklist, kTestPref, false); | 97 policy::key::kExtensionInstallBlacklist, kTestPref, false); |
93 | 98 |
94 policy.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop")); | 99 policy.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop")); |
95 expected.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop")); | 100 expected.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop")); |
96 | 101 |
97 policy_map.Set(policy::key::kExtensionInstallBlacklist, | 102 policy_map.Set(policy::key::kExtensionInstallBlacklist, |
98 policy::POLICY_LEVEL_MANDATORY, | 103 policy::POLICY_LEVEL_MANDATORY, |
99 policy::POLICY_SCOPE_USER, | 104 policy::POLICY_SCOPE_USER, |
| 105 policy::POLICY_SOURCE_CLOUD, |
100 policy.DeepCopy(), | 106 policy.DeepCopy(), |
101 NULL); | 107 NULL); |
102 handler.ApplyPolicySettings(policy_map, &prefs); | 108 handler.ApplyPolicySettings(policy_map, &prefs); |
103 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 109 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
104 EXPECT_TRUE(base::Value::Equals(&expected, value)); | 110 EXPECT_TRUE(base::Value::Equals(&expected, value)); |
105 | 111 |
106 policy.Append(new base::StringValue("invalid")); | 112 policy.Append(new base::StringValue("invalid")); |
107 policy_map.Set(policy::key::kExtensionInstallBlacklist, | 113 policy_map.Set(policy::key::kExtensionInstallBlacklist, |
108 policy::POLICY_LEVEL_MANDATORY, | 114 policy::POLICY_LEVEL_MANDATORY, |
109 policy::POLICY_SCOPE_USER, | 115 policy::POLICY_SCOPE_USER, |
| 116 policy::POLICY_SOURCE_CLOUD, |
110 policy.DeepCopy(), | 117 policy.DeepCopy(), |
111 NULL); | 118 NULL); |
112 handler.ApplyPolicySettings(policy_map, &prefs); | 119 handler.ApplyPolicySettings(policy_map, &prefs); |
113 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 120 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
114 EXPECT_TRUE(base::Value::Equals(&expected, value)); | 121 EXPECT_TRUE(base::Value::Equals(&expected, value)); |
115 } | 122 } |
116 | 123 |
117 TEST(ExtensionInstallForcelistPolicyHandlerTest, CheckPolicySettings) { | 124 TEST(ExtensionInstallForcelistPolicyHandlerTest, CheckPolicySettings) { |
118 base::ListValue list; | 125 base::ListValue list; |
119 policy::PolicyMap policy_map; | 126 policy::PolicyMap policy_map; |
120 policy::PolicyErrorMap errors; | 127 policy::PolicyErrorMap errors; |
121 ExtensionInstallForcelistPolicyHandler handler; | 128 ExtensionInstallForcelistPolicyHandler handler; |
122 | 129 |
123 policy_map.Set(policy::key::kExtensionInstallForcelist, | 130 policy_map.Set(policy::key::kExtensionInstallForcelist, |
124 policy::POLICY_LEVEL_MANDATORY, | 131 policy::POLICY_LEVEL_MANDATORY, |
125 policy::POLICY_SCOPE_USER, | 132 policy::POLICY_SCOPE_USER, |
| 133 policy::POLICY_SOURCE_CLOUD, |
126 list.DeepCopy(), | 134 list.DeepCopy(), |
127 NULL); | 135 NULL); |
128 errors.Clear(); | 136 errors.Clear(); |
129 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 137 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
130 EXPECT_TRUE(errors.empty()); | 138 EXPECT_TRUE(errors.empty()); |
131 | 139 |
132 list.AppendString("abcdefghijklmnopabcdefghijklmnop;http://example.com"); | 140 list.AppendString("abcdefghijklmnopabcdefghijklmnop;http://example.com"); |
133 policy_map.Set(policy::key::kExtensionInstallForcelist, | 141 policy_map.Set(policy::key::kExtensionInstallForcelist, |
134 policy::POLICY_LEVEL_MANDATORY, | 142 policy::POLICY_LEVEL_MANDATORY, |
135 policy::POLICY_SCOPE_USER, | 143 policy::POLICY_SCOPE_USER, |
| 144 policy::POLICY_SOURCE_CLOUD, |
136 list.DeepCopy(), | 145 list.DeepCopy(), |
137 NULL); | 146 NULL); |
138 errors.Clear(); | 147 errors.Clear(); |
139 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 148 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
140 EXPECT_TRUE(errors.empty()); | 149 EXPECT_TRUE(errors.empty()); |
141 | 150 |
142 // Add an erroneous entry. This should generate an error, but the good | 151 // Add an erroneous entry. This should generate an error, but the good |
143 // entry should still be translated successfully. | 152 // entry should still be translated successfully. |
144 list.AppendString("adfasdf;http://example.com"); | 153 list.AppendString("adfasdf;http://example.com"); |
145 policy_map.Set(policy::key::kExtensionInstallForcelist, | 154 policy_map.Set(policy::key::kExtensionInstallForcelist, |
146 policy::POLICY_LEVEL_MANDATORY, | 155 policy::POLICY_LEVEL_MANDATORY, |
147 policy::POLICY_SCOPE_USER, | 156 policy::POLICY_SCOPE_USER, |
| 157 policy::POLICY_SOURCE_CLOUD, |
148 list.DeepCopy(), | 158 list.DeepCopy(), |
149 NULL); | 159 NULL); |
150 errors.Clear(); | 160 errors.Clear(); |
151 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 161 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
152 EXPECT_EQ(1U, errors.size()); | 162 EXPECT_EQ(1U, errors.size()); |
153 | 163 |
154 // Add an entry with bad URL, which should generate another error. | 164 // Add an entry with bad URL, which should generate another error. |
155 list.AppendString("abcdefghijklmnopabcdefghijklmnop;nourl"); | 165 list.AppendString("abcdefghijklmnopabcdefghijklmnop;nourl"); |
156 policy_map.Set(policy::key::kExtensionInstallForcelist, | 166 policy_map.Set(policy::key::kExtensionInstallForcelist, |
157 policy::POLICY_LEVEL_MANDATORY, | 167 policy::POLICY_LEVEL_MANDATORY, |
158 policy::POLICY_SCOPE_USER, | 168 policy::POLICY_SCOPE_USER, |
| 169 policy::POLICY_SOURCE_CLOUD, |
159 list.DeepCopy(), | 170 list.DeepCopy(), |
160 NULL); | 171 NULL); |
161 errors.Clear(); | 172 errors.Clear(); |
162 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 173 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
163 EXPECT_EQ(2U, errors.size()); | 174 EXPECT_EQ(2U, errors.size()); |
164 | 175 |
165 // Just an extension ID should also generate an error. | 176 // Just an extension ID should also generate an error. |
166 list.AppendString("abcdefghijklmnopabcdefghijklmnop"); | 177 list.AppendString("abcdefghijklmnopabcdefghijklmnop"); |
167 policy_map.Set(policy::key::kExtensionInstallForcelist, | 178 policy_map.Set(policy::key::kExtensionInstallForcelist, |
168 policy::POLICY_LEVEL_MANDATORY, | 179 policy::POLICY_LEVEL_MANDATORY, |
169 policy::POLICY_SCOPE_USER, | 180 policy::POLICY_SCOPE_USER, |
| 181 policy::POLICY_SOURCE_CLOUD, |
170 list.DeepCopy(), | 182 list.DeepCopy(), |
171 NULL); | 183 NULL); |
172 errors.Clear(); | 184 errors.Clear(); |
173 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 185 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
174 EXPECT_EQ(3U, errors.size()); | 186 EXPECT_EQ(3U, errors.size()); |
175 } | 187 } |
176 | 188 |
177 TEST(ExtensionInstallForcelistPolicyHandlerTest, ApplyPolicySettings) { | 189 TEST(ExtensionInstallForcelistPolicyHandlerTest, ApplyPolicySettings) { |
178 base::ListValue policy; | 190 base::ListValue policy; |
179 base::DictionaryValue expected; | 191 base::DictionaryValue expected; |
180 policy::PolicyMap policy_map; | 192 policy::PolicyMap policy_map; |
181 PrefValueMap prefs; | 193 PrefValueMap prefs; |
182 base::Value* value = NULL; | 194 base::Value* value = NULL; |
183 ExtensionInstallForcelistPolicyHandler handler; | 195 ExtensionInstallForcelistPolicyHandler handler; |
184 | 196 |
185 handler.ApplyPolicySettings(policy_map, &prefs); | 197 handler.ApplyPolicySettings(policy_map, &prefs); |
186 EXPECT_FALSE(prefs.GetValue(pref_names::kInstallForceList, &value)); | 198 EXPECT_FALSE(prefs.GetValue(pref_names::kInstallForceList, &value)); |
187 EXPECT_FALSE(value); | 199 EXPECT_FALSE(value); |
188 | 200 |
189 policy_map.Set(policy::key::kExtensionInstallForcelist, | 201 policy_map.Set(policy::key::kExtensionInstallForcelist, |
190 policy::POLICY_LEVEL_MANDATORY, | 202 policy::POLICY_LEVEL_MANDATORY, |
191 policy::POLICY_SCOPE_USER, | 203 policy::POLICY_SCOPE_USER, |
| 204 policy::POLICY_SOURCE_CLOUD, |
192 policy.DeepCopy(), | 205 policy.DeepCopy(), |
193 NULL); | 206 NULL); |
194 handler.ApplyPolicySettings(policy_map, &prefs); | 207 handler.ApplyPolicySettings(policy_map, &prefs); |
195 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value)); | 208 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value)); |
196 EXPECT_TRUE(base::Value::Equals(&expected, value)); | 209 EXPECT_TRUE(base::Value::Equals(&expected, value)); |
197 | 210 |
198 policy.AppendString("abcdefghijklmnopabcdefghijklmnop;http://example.com"); | 211 policy.AppendString("abcdefghijklmnopabcdefghijklmnop;http://example.com"); |
199 extensions::ExternalPolicyLoader::AddExtension( | 212 extensions::ExternalPolicyLoader::AddExtension( |
200 &expected, "abcdefghijklmnopabcdefghijklmnop", "http://example.com"); | 213 &expected, "abcdefghijklmnopabcdefghijklmnop", "http://example.com"); |
201 policy_map.Set(policy::key::kExtensionInstallForcelist, | 214 policy_map.Set(policy::key::kExtensionInstallForcelist, |
202 policy::POLICY_LEVEL_MANDATORY, | 215 policy::POLICY_LEVEL_MANDATORY, |
203 policy::POLICY_SCOPE_USER, | 216 policy::POLICY_SCOPE_USER, |
| 217 policy::POLICY_SOURCE_CLOUD, |
204 policy.DeepCopy(), | 218 policy.DeepCopy(), |
205 NULL); | 219 NULL); |
206 handler.ApplyPolicySettings(policy_map, &prefs); | 220 handler.ApplyPolicySettings(policy_map, &prefs); |
207 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value)); | 221 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value)); |
208 EXPECT_TRUE(base::Value::Equals(&expected, value)); | 222 EXPECT_TRUE(base::Value::Equals(&expected, value)); |
209 | 223 |
210 policy.AppendString("invalid"); | 224 policy.AppendString("invalid"); |
211 policy_map.Set(policy::key::kExtensionInstallForcelist, | 225 policy_map.Set(policy::key::kExtensionInstallForcelist, |
212 policy::POLICY_LEVEL_MANDATORY, | 226 policy::POLICY_LEVEL_MANDATORY, |
213 policy::POLICY_SCOPE_USER, | 227 policy::POLICY_SCOPE_USER, |
| 228 policy::POLICY_SOURCE_CLOUD, |
214 policy.DeepCopy(), | 229 policy.DeepCopy(), |
215 NULL); | 230 NULL); |
216 handler.ApplyPolicySettings(policy_map, &prefs); | 231 handler.ApplyPolicySettings(policy_map, &prefs); |
217 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value)); | 232 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value)); |
218 EXPECT_TRUE(base::Value::Equals(&expected, value)); | 233 EXPECT_TRUE(base::Value::Equals(&expected, value)); |
219 } | 234 } |
220 | 235 |
221 TEST(ExtensionURLPatternListPolicyHandlerTest, CheckPolicySettings) { | 236 TEST(ExtensionURLPatternListPolicyHandlerTest, CheckPolicySettings) { |
222 base::ListValue list; | 237 base::ListValue list; |
223 policy::PolicyMap policy_map; | 238 policy::PolicyMap policy_map; |
224 policy::PolicyErrorMap errors; | 239 policy::PolicyErrorMap errors; |
225 ExtensionURLPatternListPolicyHandler handler( | 240 ExtensionURLPatternListPolicyHandler handler( |
226 policy::key::kExtensionInstallSources, kTestPref); | 241 policy::key::kExtensionInstallSources, kTestPref); |
227 | 242 |
228 policy_map.Set(policy::key::kExtensionInstallSources, | 243 policy_map.Set(policy::key::kExtensionInstallSources, |
229 policy::POLICY_LEVEL_MANDATORY, | 244 policy::POLICY_LEVEL_MANDATORY, |
230 policy::POLICY_SCOPE_USER, | 245 policy::POLICY_SCOPE_USER, |
| 246 policy::POLICY_SOURCE_CLOUD, |
231 list.DeepCopy(), | 247 list.DeepCopy(), |
232 NULL); | 248 NULL); |
233 errors.Clear(); | 249 errors.Clear(); |
234 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 250 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
235 EXPECT_TRUE(errors.empty()); | 251 EXPECT_TRUE(errors.empty()); |
236 | 252 |
237 list.Append(new base::StringValue("http://*.google.com/*")); | 253 list.Append(new base::StringValue("http://*.google.com/*")); |
238 policy_map.Set(policy::key::kExtensionInstallSources, | 254 policy_map.Set(policy::key::kExtensionInstallSources, |
239 policy::POLICY_LEVEL_MANDATORY, | 255 policy::POLICY_LEVEL_MANDATORY, |
240 policy::POLICY_SCOPE_USER, | 256 policy::POLICY_SCOPE_USER, |
| 257 policy::POLICY_SOURCE_CLOUD, |
241 list.DeepCopy(), | 258 list.DeepCopy(), |
242 NULL); | 259 NULL); |
243 errors.Clear(); | 260 errors.Clear(); |
244 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 261 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
245 EXPECT_TRUE(errors.empty()); | 262 EXPECT_TRUE(errors.empty()); |
246 | 263 |
247 list.Append(new base::StringValue("<all_urls>")); | 264 list.Append(new base::StringValue("<all_urls>")); |
248 policy_map.Set(policy::key::kExtensionInstallSources, | 265 policy_map.Set(policy::key::kExtensionInstallSources, |
249 policy::POLICY_LEVEL_MANDATORY, | 266 policy::POLICY_LEVEL_MANDATORY, |
250 policy::POLICY_SCOPE_USER, | 267 policy::POLICY_SCOPE_USER, |
| 268 policy::POLICY_SOURCE_CLOUD, |
251 list.DeepCopy(), | 269 list.DeepCopy(), |
252 NULL); | 270 NULL); |
253 errors.Clear(); | 271 errors.Clear(); |
254 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 272 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
255 EXPECT_TRUE(errors.empty()); | 273 EXPECT_TRUE(errors.empty()); |
256 | 274 |
257 list.Append(new base::StringValue("invalid")); | 275 list.Append(new base::StringValue("invalid")); |
258 policy_map.Set(policy::key::kExtensionInstallSources, | 276 policy_map.Set(policy::key::kExtensionInstallSources, |
259 policy::POLICY_LEVEL_MANDATORY, | 277 policy::POLICY_LEVEL_MANDATORY, |
260 policy::POLICY_SCOPE_USER, | 278 policy::POLICY_SCOPE_USER, |
| 279 policy::POLICY_SOURCE_CLOUD, |
261 list.DeepCopy(), | 280 list.DeepCopy(), |
262 NULL); | 281 NULL); |
263 errors.Clear(); | 282 errors.Clear(); |
264 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 283 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
265 EXPECT_FALSE(errors.empty()); | 284 EXPECT_FALSE(errors.empty()); |
266 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty()); | 285 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty()); |
267 | 286 |
268 // URLPattern syntax has a different way to express 'all urls'. Though '*' | 287 // URLPattern syntax has a different way to express 'all urls'. Though '*' |
269 // would be compatible today, it would be brittle, so we disallow. | 288 // would be compatible today, it would be brittle, so we disallow. |
270 list.Append(new base::StringValue("*")); | 289 list.Append(new base::StringValue("*")); |
271 policy_map.Set(policy::key::kExtensionInstallSources, | 290 policy_map.Set(policy::key::kExtensionInstallSources, |
272 policy::POLICY_LEVEL_MANDATORY, | 291 policy::POLICY_LEVEL_MANDATORY, |
273 policy::POLICY_SCOPE_USER, | 292 policy::POLICY_SCOPE_USER, |
| 293 policy::POLICY_SOURCE_CLOUD, |
274 list.DeepCopy(), | 294 list.DeepCopy(), |
275 NULL); | 295 NULL); |
276 errors.Clear(); | 296 errors.Clear(); |
277 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 297 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
278 EXPECT_FALSE(errors.empty()); | 298 EXPECT_FALSE(errors.empty()); |
279 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty()); | 299 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty()); |
280 } | 300 } |
281 | 301 |
282 TEST(ExtensionURLPatternListPolicyHandlerTest, ApplyPolicySettings) { | 302 TEST(ExtensionURLPatternListPolicyHandlerTest, ApplyPolicySettings) { |
283 base::ListValue list; | 303 base::ListValue list; |
284 policy::PolicyMap policy_map; | 304 policy::PolicyMap policy_map; |
285 PrefValueMap prefs; | 305 PrefValueMap prefs; |
286 base::Value* value = NULL; | 306 base::Value* value = NULL; |
287 ExtensionURLPatternListPolicyHandler handler( | 307 ExtensionURLPatternListPolicyHandler handler( |
288 policy::key::kExtensionInstallSources, kTestPref); | 308 policy::key::kExtensionInstallSources, kTestPref); |
289 | 309 |
290 list.Append(new base::StringValue("https://corp.monkey.net/*")); | 310 list.Append(new base::StringValue("https://corp.monkey.net/*")); |
291 policy_map.Set(policy::key::kExtensionInstallSources, | 311 policy_map.Set(policy::key::kExtensionInstallSources, |
292 policy::POLICY_LEVEL_MANDATORY, | 312 policy::POLICY_LEVEL_MANDATORY, |
293 policy::POLICY_SCOPE_USER, | 313 policy::POLICY_SCOPE_USER, |
| 314 policy::POLICY_SOURCE_CLOUD, |
294 list.DeepCopy(), | 315 list.DeepCopy(), |
295 NULL); | 316 NULL); |
296 handler.ApplyPolicySettings(policy_map, &prefs); | 317 handler.ApplyPolicySettings(policy_map, &prefs); |
297 ASSERT_TRUE(prefs.GetValue(kTestPref, &value)); | 318 ASSERT_TRUE(prefs.GetValue(kTestPref, &value)); |
298 EXPECT_TRUE(base::Value::Equals(&list, value)); | 319 EXPECT_TRUE(base::Value::Equals(&list, value)); |
299 } | 320 } |
300 | 321 |
301 TEST(ExtensionSettingsPolicyHandlerTest, CheckPolicySettings) { | 322 TEST(ExtensionSettingsPolicyHandlerTest, CheckPolicySettings) { |
302 std::string error; | 323 std::string error; |
303 scoped_ptr<base::Value> policy_value = base::JSONReader::ReadAndReturnError( | 324 scoped_ptr<base::Value> policy_value = base::JSONReader::ReadAndReturnError( |
304 kTestManagementPolicy1, | 325 kTestManagementPolicy1, |
305 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error); | 326 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error); |
306 ASSERT_TRUE(policy_value.get()) << error; | 327 ASSERT_TRUE(policy_value.get()) << error; |
307 | 328 |
308 policy::Schema chrome_schema = | 329 policy::Schema chrome_schema = |
309 policy::Schema::Wrap(policy::GetChromeSchemaData()); | 330 policy::Schema::Wrap(policy::GetChromeSchemaData()); |
310 policy::PolicyMap policy_map; | 331 policy::PolicyMap policy_map; |
311 policy::PolicyErrorMap errors; | 332 policy::PolicyErrorMap errors; |
312 ExtensionSettingsPolicyHandler handler(chrome_schema); | 333 ExtensionSettingsPolicyHandler handler(chrome_schema); |
313 | 334 |
314 policy_map.Set(policy::key::kExtensionSettings, | 335 policy_map.Set(policy::key::kExtensionSettings, |
315 policy::POLICY_LEVEL_MANDATORY, | 336 policy::POLICY_LEVEL_MANDATORY, |
316 policy::POLICY_SCOPE_USER, | 337 policy::POLICY_SCOPE_USER, |
| 338 policy::POLICY_SOURCE_CLOUD, |
317 policy_value.release(), | 339 policy_value.release(), |
318 NULL); | 340 NULL); |
319 // CheckPolicySettings() fails due to missing update URL. | 341 // CheckPolicySettings() fails due to missing update URL. |
320 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 342 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
321 EXPECT_FALSE(errors.empty()); | 343 EXPECT_FALSE(errors.empty()); |
322 } | 344 } |
323 | 345 |
324 TEST(ExtensionSettingsPolicyHandlerTest, ApplyPolicySettings) { | 346 TEST(ExtensionSettingsPolicyHandlerTest, ApplyPolicySettings) { |
325 std::string error; | 347 std::string error; |
326 scoped_ptr<base::Value> policy_value = base::JSONReader::ReadAndReturnError( | 348 scoped_ptr<base::Value> policy_value = base::JSONReader::ReadAndReturnError( |
327 kTestManagementPolicy2, | 349 kTestManagementPolicy2, |
328 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error); | 350 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error); |
329 ASSERT_TRUE(policy_value.get()) << error; | 351 ASSERT_TRUE(policy_value.get()) << error; |
330 | 352 |
331 policy::Schema chrome_schema = | 353 policy::Schema chrome_schema = |
332 policy::Schema::Wrap(policy::GetChromeSchemaData()); | 354 policy::Schema::Wrap(policy::GetChromeSchemaData()); |
333 policy::PolicyMap policy_map; | 355 policy::PolicyMap policy_map; |
334 policy::PolicyErrorMap errors; | 356 policy::PolicyErrorMap errors; |
335 PrefValueMap prefs; | 357 PrefValueMap prefs; |
336 ExtensionSettingsPolicyHandler handler(chrome_schema); | 358 ExtensionSettingsPolicyHandler handler(chrome_schema); |
337 | 359 |
338 policy_map.Set(policy::key::kExtensionSettings, | 360 policy_map.Set(policy::key::kExtensionSettings, |
339 policy::POLICY_LEVEL_MANDATORY, | 361 policy::POLICY_LEVEL_MANDATORY, |
340 policy::POLICY_SCOPE_USER, | 362 policy::POLICY_SCOPE_USER, |
| 363 policy::POLICY_SOURCE_CLOUD, |
341 policy_value->DeepCopy(), | 364 policy_value->DeepCopy(), |
342 NULL); | 365 NULL); |
343 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 366 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
344 handler.ApplyPolicySettings(policy_map, &prefs); | 367 handler.ApplyPolicySettings(policy_map, &prefs); |
345 base::Value* value = NULL; | 368 base::Value* value = NULL; |
346 ASSERT_TRUE(prefs.GetValue(pref_names::kExtensionManagement, &value)); | 369 ASSERT_TRUE(prefs.GetValue(pref_names::kExtensionManagement, &value)); |
347 EXPECT_TRUE(base::Value::Equals(policy_value.get(), value)); | 370 EXPECT_TRUE(base::Value::Equals(policy_value.get(), value)); |
348 } | 371 } |
349 | 372 |
350 } // namespace extensions | 373 } // namespace extensions |
OLD | NEW |