OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/policy/policy_domain_descriptor.h" | 5 #include "chrome/browser/policy/policy_domain_descriptor.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 std::string())); | 29 std::string())); |
30 } | 30 } |
31 | 31 |
32 TEST_F(PolicyDomainDescriptorTest, FilterBundle) { | 32 TEST_F(PolicyDomainDescriptorTest, FilterBundle) { |
33 scoped_refptr<PolicyDomainDescriptor> descriptor = | 33 scoped_refptr<PolicyDomainDescriptor> descriptor = |
34 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS); | 34 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS); |
35 EXPECT_EQ(POLICY_DOMAIN_EXTENSIONS, descriptor->domain()); | 35 EXPECT_EQ(POLICY_DOMAIN_EXTENSIONS, descriptor->domain()); |
36 EXPECT_TRUE(descriptor->components().empty()); | 36 EXPECT_TRUE(descriptor->components().empty()); |
37 | 37 |
38 std::string error; | 38 std::string error; |
39 scoped_ptr<SchemaOwner> schema = SchemaOwner::Parse( | 39 Schema schema = Schema::Parse( |
40 "{" | 40 "{" |
41 " \"type\":\"object\"," | 41 " \"type\":\"object\"," |
42 " \"properties\": {" | 42 " \"properties\": {" |
43 " \"Array\": {" | 43 " \"Array\": {" |
44 " \"type\": \"array\"," | 44 " \"type\": \"array\"," |
45 " \"items\": { \"type\": \"string\" }" | 45 " \"items\": { \"type\": \"string\" }" |
46 " }," | 46 " }," |
47 " \"Boolean\": { \"type\": \"boolean\" }," | 47 " \"Boolean\": { \"type\": \"boolean\" }," |
48 " \"Integer\": { \"type\": \"integer\" }," | 48 " \"Integer\": { \"type\": \"integer\" }," |
49 " \"Null\": { \"type\": \"null\" }," | 49 " \"Null\": { \"type\": \"null\" }," |
50 " \"Number\": { \"type\": \"number\" }," | 50 " \"Number\": { \"type\": \"number\" }," |
51 " \"Object\": {" | 51 " \"Object\": {" |
52 " \"type\": \"object\"," | 52 " \"type\": \"object\"," |
53 " \"properties\": {" | 53 " \"properties\": {" |
54 " \"a\": { \"type\": \"string\" }," | 54 " \"a\": { \"type\": \"string\" }," |
55 " \"b\": { \"type\": \"integer\" }" | 55 " \"b\": { \"type\": \"integer\" }" |
56 " }" | 56 " }" |
57 " }," | 57 " }," |
58 " \"String\": { \"type\": \"string\" }" | 58 " \"String\": { \"type\": \"string\" }" |
59 " }" | 59 " }" |
60 "}", &error); | 60 "}", &error); |
61 ASSERT_TRUE(schema) << error; | 61 ASSERT_TRUE(schema.valid()) << error; |
62 | 62 |
63 descriptor->RegisterComponent("abc", schema.Pass()); | 63 descriptor->RegisterComponent("abc", schema); |
64 | 64 |
65 EXPECT_EQ(1u, descriptor->components().size()); | 65 EXPECT_EQ(1u, descriptor->components().size()); |
66 EXPECT_EQ(1u, descriptor->components().count("abc")); | 66 EXPECT_EQ(1u, descriptor->components().count("abc")); |
67 | 67 |
68 PolicyBundle bundle; | 68 PolicyBundle bundle; |
69 descriptor->FilterBundle(&bundle); | 69 descriptor->FilterBundle(&bundle); |
70 const PolicyBundle empty_bundle; | 70 const PolicyBundle empty_bundle; |
71 EXPECT_TRUE(bundle.Equals(empty_bundle)); | 71 EXPECT_TRUE(bundle.Equals(empty_bundle)); |
72 | 72 |
73 // Other namespaces aren't filtered. | 73 // Other namespaces aren't filtered. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 EXPECT_TRUE(bundle.Equals(empty_bundle)); | 145 EXPECT_TRUE(bundle.Equals(empty_bundle)); |
146 } | 146 } |
147 | 147 |
148 TEST_F(PolicyDomainDescriptorTest, LegacyComponents) { | 148 TEST_F(PolicyDomainDescriptorTest, LegacyComponents) { |
149 scoped_refptr<PolicyDomainDescriptor> descriptor = | 149 scoped_refptr<PolicyDomainDescriptor> descriptor = |
150 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS); | 150 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS); |
151 EXPECT_EQ(POLICY_DOMAIN_EXTENSIONS, descriptor->domain()); | 151 EXPECT_EQ(POLICY_DOMAIN_EXTENSIONS, descriptor->domain()); |
152 EXPECT_TRUE(descriptor->components().empty()); | 152 EXPECT_TRUE(descriptor->components().empty()); |
153 | 153 |
154 std::string error; | 154 std::string error; |
155 scoped_ptr<SchemaOwner> schema = SchemaOwner::Parse( | 155 Schema schema = Schema::Parse( |
156 "{" | 156 "{" |
157 " \"type\":\"object\"," | 157 " \"type\":\"object\"," |
158 " \"properties\": {" | 158 " \"properties\": {" |
159 " \"String\": { \"type\": \"string\" }" | 159 " \"String\": { \"type\": \"string\" }" |
160 " }" | 160 " }" |
161 "}", &error); | 161 "}", &error); |
162 ASSERT_TRUE(schema) << error; | 162 ASSERT_TRUE(schema.valid()) << error; |
163 | 163 |
164 descriptor->RegisterComponent("with-schema", schema.Pass()); | 164 descriptor->RegisterComponent("with-schema", schema); |
165 descriptor->RegisterComponent("without-schema", scoped_ptr<SchemaOwner>()); | 165 descriptor->RegisterComponent("without-schema", Schema()); |
166 | 166 |
167 EXPECT_EQ(2u, descriptor->components().size()); | 167 EXPECT_EQ(2u, descriptor->components().size()); |
168 | 168 |
169 // |bundle| contains policies loaded by a policy provider. | 169 // |bundle| contains policies loaded by a policy provider. |
170 PolicyBundle bundle; | 170 PolicyBundle bundle; |
171 | 171 |
172 // Known components with schemas are filtered. | 172 // Known components with schemas are filtered. |
173 PolicyNamespace extension_ns(POLICY_DOMAIN_EXTENSIONS, "with-schema"); | 173 PolicyNamespace extension_ns(POLICY_DOMAIN_EXTENSIONS, "with-schema"); |
174 bundle.Get(extension_ns).Set("String", | 174 bundle.Get(extension_ns).Set("String", |
175 POLICY_LEVEL_MANDATORY, | 175 POLICY_LEVEL_MANDATORY, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 POLICY_LEVEL_MANDATORY, | 209 POLICY_LEVEL_MANDATORY, |
210 POLICY_SCOPE_USER, | 210 POLICY_SCOPE_USER, |
211 base::Value::CreateStringValue("value 5"), | 211 base::Value::CreateStringValue("value 5"), |
212 NULL); | 212 NULL); |
213 | 213 |
214 descriptor->FilterBundle(&bundle); | 214 descriptor->FilterBundle(&bundle); |
215 EXPECT_TRUE(bundle.Equals(expected_bundle)); | 215 EXPECT_TRUE(bundle.Equals(expected_bundle)); |
216 } | 216 } |
217 | 217 |
218 } // namespace policy | 218 } // namespace policy |
OLD | NEW |