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 "components/policy/core/common/schema_map.h" | 5 #include "components/policy/core/common/schema_map.h" |
6 | 6 |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "components/policy/core/common/external_data_fetcher.h" | 9 #include "components/policy/core/common/external_data_fetcher.h" |
10 #include "components/policy/core/common/external_data_manager.h" | 10 #include "components/policy/core/common/external_data_manager.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 PolicyBundle bundle; | 233 PolicyBundle bundle; |
234 | 234 |
235 // Known components with schemas are filtered. | 235 // Known components with schemas are filtered. |
236 PolicyNamespace extension_ns(POLICY_DOMAIN_EXTENSIONS, "with-schema"); | 236 PolicyNamespace extension_ns(POLICY_DOMAIN_EXTENSIONS, "with-schema"); |
237 bundle.Get(extension_ns).Set("String", | 237 bundle.Get(extension_ns).Set("String", |
238 POLICY_LEVEL_MANDATORY, | 238 POLICY_LEVEL_MANDATORY, |
239 POLICY_SCOPE_USER, | 239 POLICY_SCOPE_USER, |
240 base::Value::CreateStringValue("value 1"), | 240 base::Value::CreateStringValue("value 1"), |
241 NULL); | 241 NULL); |
242 | 242 |
243 // Known components without a schema are not filtered. | |
244 PolicyNamespace without_schema_ns(POLICY_DOMAIN_EXTENSIONS, "without-schema"); | |
245 bundle.Get(without_schema_ns).Set("Schemaless", | |
246 POLICY_LEVEL_MANDATORY, | |
247 POLICY_SCOPE_USER, | |
248 base::Value::CreateStringValue("value 2"), | |
249 NULL); | |
250 | |
251 // The Chrome namespace isn't filtered. | 243 // The Chrome namespace isn't filtered. |
252 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, ""); | 244 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, ""); |
253 bundle.Get(chrome_ns).Set("ChromePolicy", | 245 bundle.Get(chrome_ns).Set("ChromePolicy", |
254 POLICY_LEVEL_MANDATORY, | 246 POLICY_LEVEL_MANDATORY, |
255 POLICY_SCOPE_USER, | 247 POLICY_SCOPE_USER, |
256 base::Value::CreateStringValue("value 3"), | 248 base::Value::CreateStringValue("value 3"), |
257 NULL); | 249 NULL); |
258 | 250 |
259 PolicyBundle expected_bundle; | 251 PolicyBundle expected_bundle; |
260 expected_bundle.MergeFrom(bundle); | 252 expected_bundle.MergeFrom(bundle); |
261 | 253 |
| 254 // Known components without a schema are filtered out completely. |
| 255 PolicyNamespace without_schema_ns(POLICY_DOMAIN_EXTENSIONS, "without-schema"); |
| 256 bundle.Get(without_schema_ns).Set("Schemaless", |
| 257 POLICY_LEVEL_MANDATORY, |
| 258 POLICY_SCOPE_USER, |
| 259 base::Value::CreateStringValue("value 2"), |
| 260 NULL); |
| 261 |
262 // Unknown policies of known components with a schema are removed. | 262 // Unknown policies of known components with a schema are removed. |
263 bundle.Get(extension_ns).Set("Surprise", | 263 bundle.Get(extension_ns).Set("Surprise", |
264 POLICY_LEVEL_MANDATORY, | 264 POLICY_LEVEL_MANDATORY, |
265 POLICY_SCOPE_USER, | 265 POLICY_SCOPE_USER, |
266 base::Value::CreateStringValue("value 4"), | 266 base::Value::CreateStringValue("value 4"), |
267 NULL); | 267 NULL); |
268 | 268 |
269 // Unknown components are removed. | 269 // Unknown components are removed. |
270 PolicyNamespace unknown_ns(POLICY_DOMAIN_EXTENSIONS, "unknown"); | 270 PolicyNamespace unknown_ns(POLICY_DOMAIN_EXTENSIONS, "unknown"); |
271 bundle.Get(unknown_ns).Set("Surprise", | 271 bundle.Get(unknown_ns).Set("Surprise", |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 newer = new SchemaMap(map); | 304 newer = new SchemaMap(map); |
305 newer->GetChanges(older, &removed, &added); | 305 newer->GetChanges(older, &removed, &added); |
306 ASSERT_EQ(2u, removed.size()); | 306 ASSERT_EQ(2u, removed.size()); |
307 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_CHROME, ""), removed[0]); | 307 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_CHROME, ""), removed[0]); |
308 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "xyz"), removed[1]); | 308 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "xyz"), removed[1]); |
309 ASSERT_EQ(1u, added.size()); | 309 ASSERT_EQ(1u, added.size()); |
310 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "abc"), added[0]); | 310 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "abc"), added[0]); |
311 } | 311 } |
312 | 312 |
313 } // namespace policy | 313 } // namespace policy |
OLD | NEW |