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

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: addressed comments, rebase on new PolicySchema 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 "chrome/browser/policy/policy_bundle.h"
8 #include "chrome/browser/policy/policy_schema.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace policy {
12
13 TEST(PolicyDomainDescriptor, FilterBundle) {
14 scoped_refptr<PolicyDomainDescriptor> descriptor =
15 new PolicyDomainDescriptor(POLICY_DOMAIN_EXTENSIONS);
16 EXPECT_EQ(POLICY_DOMAIN_EXTENSIONS, descriptor->domain());
17 EXPECT_TRUE(descriptor->components().empty());
18
19 std::string error;
20 scoped_ptr<PolicySchema> schema = PolicySchema::Parse(
21 "{"
22 " \"$schema\":\"http://json-schema.org/draft-03/schema#\","
23 " \"type\":\"object\","
24 " \"properties\": {"
25 " \"Array\": {"
26 " \"type\": \"array\","
27 " \"items\": { \"type\": \"string\" }"
28 " },"
29 " \"Boolean\": { \"type\": \"boolean\" },"
30 " \"Integer\": { \"type\": \"integer\" },"
31 " \"Null\": { \"type\": \"null\" },"
32 " \"Number\": { \"type\": \"number\" },"
33 " \"Object\": {"
34 " \"type\": \"object\","
35 " \"properties\": {"
36 " \"a\": { \"type\": \"string\" },"
37 " \"b\": { \"type\": \"integer\" }"
38 " }"
39 " },"
40 " \"String\": { \"type\": \"string\" }"
41 " }"
42 "}", &error);
43 ASSERT_TRUE(schema) << error;
44
45 descriptor->SetComponent("abc", schema.Pass());
46
47 EXPECT_EQ(1u, descriptor->components().size());
48 EXPECT_NE(descriptor->components().end(),
49 descriptor->components().find("abc"));
50
51 PolicyBundle bundle;
52 descriptor->FilterBundle(&bundle);
53 const PolicyBundle empty_bundle;
54 EXPECT_TRUE(bundle.Equals(empty_bundle));
55
56 // Other namespace aren't filtered.
bartfab (slow) 2013/05/21 12:10:56 Nit: This part of the test only verifies that POLI
Joao da Silva 2013/05/21 17:50:14 Ah, but it's not left alone :-) Undeclared compone
57 PolicyBundle expected_bundle;
58 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, "");
59 expected_bundle.Get(chrome_ns).Set("ChromePolicy",
60 POLICY_LEVEL_MANDATORY,
61 POLICY_SCOPE_USER,
62 base::Value::CreateStringValue("value"));
bartfab (slow) 2013/05/21 12:10:56 #include "base/values.h"
Joao da Silva 2013/05/21 17:50:14 Done.
63 bundle.CopyFrom(expected_bundle);
64 descriptor->FilterBundle(&bundle);
65 EXPECT_TRUE(bundle.Equals(expected_bundle));
66
67 PolicyNamespace extension_ns(POLICY_DOMAIN_EXTENSIONS, "abc");
68 PolicyMap& map = expected_bundle.Get(extension_ns);
bartfab (slow) 2013/05/21 12:10:56 #include "chrome/browser/policy/policy_map.h"
Joao da Silva 2013/05/21 17:50:14 Done.
69 base::ListValue list;
70 list.AppendString("a");
71 list.AppendString("b");
72 map.Set("Array", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
73 list.DeepCopy());
74 map.Set("Boolean", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
75 base::Value::CreateBooleanValue(true));
76 map.Set("Integer", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
77 base::Value::CreateIntegerValue(1));
78 map.Set("Null", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
79 base::Value::CreateNullValue());
80 map.Set("Number", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
81 base::Value::CreateDoubleValue(1.2));
82 base::DictionaryValue dict;
83 dict.SetString("a", "b");
84 dict.SetInteger("b", 2);
85 map.Set("Object", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, dict.DeepCopy());
86 map.Set("String", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
87 base::Value::CreateStringValue("value"));
88
89 bundle.MergeFrom(expected_bundle);
90 bundle.Get(extension_ns).Set("Unexpected",
91 POLICY_LEVEL_MANDATORY,
92 POLICY_SCOPE_USER,
93 base::Value::CreateStringValue("to-be-removed"));
94
95 descriptor->FilterBundle(&bundle);
96 EXPECT_TRUE(bundle.Equals(expected_bundle));
97
98 // Mismatched types are also removed.
99 bundle.Clear();
100 PolicyMap& badmap = bundle.Get(extension_ns);
101 badmap.Set("Array", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
102 base::Value::CreateBooleanValue(false));
103 badmap.Set("Boolean", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
104 base::Value::CreateIntegerValue(0));
105 badmap.Set("Integer", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
106 base::Value::CreateBooleanValue(false));
107 badmap.Set("Null", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
108 base::Value::CreateBooleanValue(false));
109 badmap.Set("Number", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
110 base::Value::CreateBooleanValue(false));
111 badmap.Set("Object", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
112 base::Value::CreateBooleanValue(false));
113 badmap.Set("String", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
114 base::Value::CreateBooleanValue(false));
115
116 descriptor->FilterBundle(&bundle);
117 EXPECT_TRUE(bundle.Equals(empty_bundle));
118 }
119
120 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698