Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: chrome/browser/policy/policy_domain_descriptor_unittest.cc

Issue 15061007: Added a PolicyDomainDescriptor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/policy_domain_descriptor.h"
6
7 #include "base/values.h"
8 #include "chrome/browser/policy/policy_bundle.h"
9 #include "chrome/browser/policy/policy_map.h"
10 #include "chrome/browser/policy/policy_schema.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace policy {
14
15 TEST(PolicyDomainDescriptor, FilterBundle) {
16 scoped_refptr<PolicyDomainDescriptor> descriptor =
17 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS);
18 EXPECT_EQ(POLICY_DOMAIN_EXTENSIONS, descriptor->domain());
19 EXPECT_TRUE(descriptor->components().empty());
20
21 std::string error;
22 scoped_ptr<PolicySchema> schema = PolicySchema::Parse(
23 "{"
24 " \"$schema\":\"http://json-schema.org/draft-03/schema#\","
25 " \"type\":\"object\","
26 " \"properties\": {"
27 " \"Array\": {"
28 " \"type\": \"array\","
29 " \"items\": { \"type\": \"string\" }"
30 " },"
31 " \"Boolean\": { \"type\": \"boolean\" },"
32 " \"Integer\": { \"type\": \"integer\" },"
33 " \"Null\": { \"type\": \"null\" },"
34 " \"Number\": { \"type\": \"number\" },"
35 " \"Object\": {"
36 " \"type\": \"object\","
37 " \"properties\": {"
38 " \"a\": { \"type\": \"string\" },"
39 " \"b\": { \"type\": \"integer\" }"
40 " }"
41 " },"
42 " \"String\": { \"type\": \"string\" }"
43 " }"
44 "}", &error);
45 ASSERT_TRUE(schema) << error;
46
47 descriptor->RegisterComponent("abc", schema.Pass());
48
49 EXPECT_EQ(1u, descriptor->components().size());
50 EXPECT_NE(descriptor->components().end(),
51 descriptor->components().find("abc"));
52
53 PolicyBundle bundle;
54 descriptor->FilterBundle(&bundle);
55 const PolicyBundle empty_bundle;
56 EXPECT_TRUE(bundle.Equals(empty_bundle));
57
58 // Other namespaces aren't filtered.
59 PolicyBundle expected_bundle;
60 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, "");
61 expected_bundle.Get(chrome_ns).Set("ChromePolicy",
62 POLICY_LEVEL_MANDATORY,
63 POLICY_SCOPE_USER,
64 base::Value::CreateStringValue("value"));
65 bundle.CopyFrom(expected_bundle);
66 // Unknown components of the domain are filtered out.
67 PolicyNamespace another_extension_ns(POLICY_DOMAIN_EXTENSIONS, "xyz");
68 bundle.Get(another_extension_ns).Set(
69 "AnotherExtensionPolicy",
70 POLICY_LEVEL_MANDATORY,
71 POLICY_SCOPE_USER,
72 base::Value::CreateStringValue("value"));
73 descriptor->FilterBundle(&bundle);
74 EXPECT_TRUE(bundle.Equals(expected_bundle));
75
76 PolicyNamespace extension_ns(POLICY_DOMAIN_EXTENSIONS, "abc");
77 PolicyMap& map = expected_bundle.Get(extension_ns);
78 base::ListValue list;
79 list.AppendString("a");
80 list.AppendString("b");
81 map.Set("Array", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
82 list.DeepCopy());
83 map.Set("Boolean", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
84 base::Value::CreateBooleanValue(true));
85 map.Set("Integer", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
86 base::Value::CreateIntegerValue(1));
87 map.Set("Null", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
88 base::Value::CreateNullValue());
89 map.Set("Number", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
90 base::Value::CreateDoubleValue(1.2));
91 base::DictionaryValue dict;
92 dict.SetString("a", "b");
93 dict.SetInteger("b", 2);
94 map.Set("Object", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, dict.DeepCopy());
95 map.Set("String", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
96 base::Value::CreateStringValue("value"));
97
98 bundle.MergeFrom(expected_bundle);
99 bundle.Get(extension_ns).Set("Unexpected",
100 POLICY_LEVEL_MANDATORY,
101 POLICY_SCOPE_USER,
102 base::Value::CreateStringValue("to-be-removed"));
103
104 descriptor->FilterBundle(&bundle);
105 EXPECT_TRUE(bundle.Equals(expected_bundle));
106
107 // Mismatched types are also removed.
108 bundle.Clear();
109 PolicyMap& badmap = bundle.Get(extension_ns);
110 badmap.Set("Array", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
111 base::Value::CreateBooleanValue(false));
112 badmap.Set("Boolean", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
113 base::Value::CreateIntegerValue(0));
114 badmap.Set("Integer", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
115 base::Value::CreateBooleanValue(false));
116 badmap.Set("Null", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
117 base::Value::CreateBooleanValue(false));
118 badmap.Set("Number", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
119 base::Value::CreateBooleanValue(false));
120 badmap.Set("Object", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
121 base::Value::CreateBooleanValue(false));
122 badmap.Set("String", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
123 base::Value::CreateBooleanValue(false));
124
125 descriptor->FilterBundle(&bundle);
126 EXPECT_TRUE(bundle.Equals(empty_bundle));
127 }
128
129 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_domain_descriptor.cc ('k') | chrome/browser/policy/policy_prefs_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698