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 <cstring> | 5 #include <cstring> |
6 #include <memory> | 6 #include <memory> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
25 // Checks if two schemas are the same or not. Note that this function doesn't | 25 // Checks if two schemas are the same or not. Note that this function doesn't |
26 // consider restrictions on integers and strings nor pattern properties. | 26 // consider restrictions on integers and strings nor pattern properties. |
27 bool IsSameSchema(Schema a, Schema b) { | 27 bool IsSameSchema(Schema a, Schema b) { |
28 if (a.valid() != b.valid()) | 28 if (a.valid() != b.valid()) |
29 return false; | 29 return false; |
30 if (!a.valid()) | 30 if (!a.valid()) |
31 return true; | 31 return true; |
32 if (a.type() != b.type()) | 32 if (a.type() != b.type()) |
33 return false; | 33 return false; |
34 if (a.type() == base::Value::TYPE_LIST) | 34 if (a.type() == base::Value::Type::LIST) |
35 return IsSameSchema(a.GetItems(), b.GetItems()); | 35 return IsSameSchema(a.GetItems(), b.GetItems()); |
36 if (a.type() != base::Value::TYPE_DICTIONARY) | 36 if (a.type() != base::Value::Type::DICTIONARY) |
37 return true; | 37 return true; |
38 Schema::Iterator a_it = a.GetPropertiesIterator(); | 38 Schema::Iterator a_it = a.GetPropertiesIterator(); |
39 Schema::Iterator b_it = b.GetPropertiesIterator(); | 39 Schema::Iterator b_it = b.GetPropertiesIterator(); |
40 while (!a_it.IsAtEnd()) { | 40 while (!a_it.IsAtEnd()) { |
41 if (b_it.IsAtEnd()) | 41 if (b_it.IsAtEnd()) |
42 return false; | 42 return false; |
43 if (strcmp(a_it.key(), b_it.key()) != 0) | 43 if (strcmp(a_it.key(), b_it.key()) != 0) |
44 return false; | 44 return false; |
45 if (!IsSameSchema(a_it.schema(), b_it.schema())) | 45 if (!IsSameSchema(a_it.schema(), b_it.schema())) |
46 return false; | 46 return false; |
47 a_it.Advance(); | 47 a_it.Advance(); |
48 b_it.Advance(); | 48 b_it.Advance(); |
49 } | 49 } |
50 if (!b_it.IsAtEnd()) | 50 if (!b_it.IsAtEnd()) |
51 return false; | 51 return false; |
52 return IsSameSchema(a.GetAdditionalProperties(), b.GetAdditionalProperties()); | 52 return IsSameSchema(a.GetAdditionalProperties(), b.GetAdditionalProperties()); |
53 } | 53 } |
54 #endif | 54 #endif |
55 | 55 |
56 } // namespace | 56 } // namespace |
57 | 57 |
58 TEST(GeneratePolicySource, ChromeSchemaData) { | 58 TEST(GeneratePolicySource, ChromeSchemaData) { |
59 Schema schema = Schema::Wrap(GetChromeSchemaData()); | 59 Schema schema = Schema::Wrap(GetChromeSchemaData()); |
60 ASSERT_TRUE(schema.valid()); | 60 ASSERT_TRUE(schema.valid()); |
61 EXPECT_EQ(base::Value::TYPE_DICTIONARY, schema.type()); | 61 EXPECT_EQ(base::Value::Type::DICTIONARY, schema.type()); |
62 | 62 |
63 Schema subschema = schema.GetAdditionalProperties(); | 63 Schema subschema = schema.GetAdditionalProperties(); |
64 EXPECT_FALSE(subschema.valid()); | 64 EXPECT_FALSE(subschema.valid()); |
65 | 65 |
66 subschema = schema.GetProperty("no such policy exists"); | 66 subschema = schema.GetProperty("no such policy exists"); |
67 EXPECT_FALSE(subschema.valid()); | 67 EXPECT_FALSE(subschema.valid()); |
68 | 68 |
69 subschema = schema.GetProperty(key::kSearchSuggestEnabled); | 69 subschema = schema.GetProperty(key::kSearchSuggestEnabled); |
70 ASSERT_TRUE(subschema.valid()); | 70 ASSERT_TRUE(subschema.valid()); |
71 EXPECT_EQ(base::Value::TYPE_BOOLEAN, subschema.type()); | 71 EXPECT_EQ(base::Value::Type::BOOLEAN, subschema.type()); |
72 | 72 |
73 subschema = schema.GetProperty(key::kDefaultCookiesSetting); | 73 subschema = schema.GetProperty(key::kDefaultCookiesSetting); |
74 ASSERT_TRUE(subschema.valid()); | 74 ASSERT_TRUE(subschema.valid()); |
75 EXPECT_EQ(base::Value::TYPE_INTEGER, subschema.type()); | 75 EXPECT_EQ(base::Value::Type::INTEGER, subschema.type()); |
76 | 76 |
77 subschema = schema.GetProperty(key::kProxyMode); | 77 subschema = schema.GetProperty(key::kProxyMode); |
78 ASSERT_TRUE(subschema.valid()); | 78 ASSERT_TRUE(subschema.valid()); |
79 EXPECT_EQ(base::Value::TYPE_STRING, subschema.type()); | 79 EXPECT_EQ(base::Value::Type::STRING, subschema.type()); |
80 | 80 |
81 subschema = schema.GetProperty(key::kURLBlacklist); | 81 subschema = schema.GetProperty(key::kURLBlacklist); |
82 ASSERT_TRUE(subschema.valid()); | 82 ASSERT_TRUE(subschema.valid()); |
83 EXPECT_EQ(base::Value::TYPE_LIST, subschema.type()); | 83 EXPECT_EQ(base::Value::Type::LIST, subschema.type()); |
84 ASSERT_TRUE(subschema.GetItems().valid()); | 84 ASSERT_TRUE(subschema.GetItems().valid()); |
85 EXPECT_EQ(base::Value::TYPE_STRING, subschema.GetItems().type()); | 85 EXPECT_EQ(base::Value::Type::STRING, subschema.GetItems().type()); |
86 | 86 |
87 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 87 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
88 subschema = schema.GetProperty(key::kExtensionSettings); | 88 subschema = schema.GetProperty(key::kExtensionSettings); |
89 ASSERT_TRUE(subschema.valid()); | 89 ASSERT_TRUE(subschema.valid()); |
90 ASSERT_EQ(base::Value::TYPE_DICTIONARY, subschema.type()); | 90 ASSERT_EQ(base::Value::Type::DICTIONARY, subschema.type()); |
91 EXPECT_FALSE(subschema.GetAdditionalProperties().valid()); | 91 EXPECT_FALSE(subschema.GetAdditionalProperties().valid()); |
92 EXPECT_FALSE(subschema.GetProperty("no such extension id exists").valid()); | 92 EXPECT_FALSE(subschema.GetProperty("no such extension id exists").valid()); |
93 EXPECT_TRUE(subschema.GetPatternProperties("*").empty()); | 93 EXPECT_TRUE(subschema.GetPatternProperties("*").empty()); |
94 EXPECT_TRUE(subschema.GetPatternProperties("no such extension id").empty()); | 94 EXPECT_TRUE(subschema.GetPatternProperties("no such extension id").empty()); |
95 EXPECT_TRUE(subschema.GetPatternProperties("^[a-p]{32}$").empty()); | 95 EXPECT_TRUE(subschema.GetPatternProperties("^[a-p]{32}$").empty()); |
96 EXPECT_TRUE(subschema.GetPatternProperties( | 96 EXPECT_TRUE(subschema.GetPatternProperties( |
97 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").empty()); | 97 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").empty()); |
98 EXPECT_TRUE(subschema.GetPatternProperties( | 98 EXPECT_TRUE(subschema.GetPatternProperties( |
99 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").empty()); | 99 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").empty()); |
100 SchemaList schema_list = | 100 SchemaList schema_list = |
101 subschema.GetPatternProperties("abcdefghijklmnopabcdefghijklmnop"); | 101 subschema.GetPatternProperties("abcdefghijklmnopabcdefghijklmnop"); |
102 ASSERT_EQ(1u, schema_list.size()); | 102 ASSERT_EQ(1u, schema_list.size()); |
103 subschema = schema_list[0]; | 103 subschema = schema_list[0]; |
104 ASSERT_TRUE(subschema.valid()); | 104 ASSERT_TRUE(subschema.valid()); |
105 ASSERT_EQ(base::Value::TYPE_DICTIONARY, subschema.type()); | 105 ASSERT_EQ(base::Value::Type::DICTIONARY, subschema.type()); |
106 subschema = subschema.GetProperty("installation_mode"); | 106 subschema = subschema.GetProperty("installation_mode"); |
107 ASSERT_TRUE(subschema.valid()); | 107 ASSERT_TRUE(subschema.valid()); |
108 ASSERT_EQ(base::Value::TYPE_STRING, subschema.type()); | 108 ASSERT_EQ(base::Value::Type::STRING, subschema.type()); |
109 | 109 |
110 subschema = schema.GetProperty(key::kExtensionSettings).GetProperty("*"); | 110 subschema = schema.GetProperty(key::kExtensionSettings).GetProperty("*"); |
111 ASSERT_TRUE(subschema.valid()); | 111 ASSERT_TRUE(subschema.valid()); |
112 ASSERT_EQ(base::Value::TYPE_DICTIONARY, subschema.type()); | 112 ASSERT_EQ(base::Value::Type::DICTIONARY, subschema.type()); |
113 subschema = subschema.GetProperty("installation_mode"); | 113 subschema = subschema.GetProperty("installation_mode"); |
114 ASSERT_TRUE(subschema.valid()); | 114 ASSERT_TRUE(subschema.valid()); |
115 ASSERT_EQ(base::Value::TYPE_STRING, subschema.type()); | 115 ASSERT_EQ(base::Value::Type::STRING, subschema.type()); |
116 #endif | 116 #endif |
117 | 117 |
118 subschema = schema.GetProperty(key::kProxySettings); | 118 subschema = schema.GetProperty(key::kProxySettings); |
119 ASSERT_TRUE(subschema.valid()); | 119 ASSERT_TRUE(subschema.valid()); |
120 EXPECT_EQ(base::Value::TYPE_DICTIONARY, subschema.type()); | 120 EXPECT_EQ(base::Value::Type::DICTIONARY, subschema.type()); |
121 EXPECT_FALSE(subschema.GetAdditionalProperties().valid()); | 121 EXPECT_FALSE(subschema.GetAdditionalProperties().valid()); |
122 EXPECT_FALSE(subschema.GetProperty("no such proxy key exists").valid()); | 122 EXPECT_FALSE(subschema.GetProperty("no such proxy key exists").valid()); |
123 ASSERT_TRUE(subschema.GetProperty(key::kProxyMode).valid()); | 123 ASSERT_TRUE(subschema.GetProperty(key::kProxyMode).valid()); |
124 ASSERT_TRUE(subschema.GetProperty(key::kProxyServer).valid()); | 124 ASSERT_TRUE(subschema.GetProperty(key::kProxyServer).valid()); |
125 ASSERT_TRUE(subschema.GetProperty(key::kProxyServerMode).valid()); | 125 ASSERT_TRUE(subschema.GetProperty(key::kProxyServerMode).valid()); |
126 ASSERT_TRUE(subschema.GetProperty(key::kProxyPacUrl).valid()); | 126 ASSERT_TRUE(subschema.GetProperty(key::kProxyPacUrl).valid()); |
127 ASSERT_TRUE(subschema.GetProperty(key::kProxyBypassList).valid()); | 127 ASSERT_TRUE(subschema.GetProperty(key::kProxyBypassList).valid()); |
128 | 128 |
129 // Verify that all the Chrome policies are there. | 129 // Verify that all the Chrome policies are there. |
130 for (Schema::Iterator it = schema.GetPropertiesIterator(); | 130 for (Schema::Iterator it = schema.GetPropertiesIterator(); |
(...skipping 11 matching lines...) Expand all Loading... |
142 key::kProxyServer, | 142 key::kProxyServer, |
143 key::kProxyServerMode, | 143 key::kProxyServerMode, |
144 NULL, | 144 NULL, |
145 }; | 145 }; |
146 const char** next = kExpectedProperties; | 146 const char** next = kExpectedProperties; |
147 for (Schema::Iterator it(subschema.GetPropertiesIterator()); | 147 for (Schema::Iterator it(subschema.GetPropertiesIterator()); |
148 !it.IsAtEnd(); it.Advance(), ++next) { | 148 !it.IsAtEnd(); it.Advance(), ++next) { |
149 ASSERT_TRUE(*next != NULL); | 149 ASSERT_TRUE(*next != NULL); |
150 EXPECT_STREQ(*next, it.key()); | 150 EXPECT_STREQ(*next, it.key()); |
151 ASSERT_TRUE(it.schema().valid()); | 151 ASSERT_TRUE(it.schema().valid()); |
152 EXPECT_EQ(base::Value::TYPE_STRING, it.schema().type()); | 152 EXPECT_EQ(base::Value::Type::STRING, it.schema().type()); |
153 } | 153 } |
154 EXPECT_TRUE(*next == NULL); | 154 EXPECT_TRUE(*next == NULL); |
155 | 155 |
156 #if defined(OS_CHROMEOS) | 156 #if defined(OS_CHROMEOS) |
157 subschema = schema.GetKnownProperty(key::kPowerManagementIdleSettings); | 157 subschema = schema.GetKnownProperty(key::kPowerManagementIdleSettings); |
158 ASSERT_TRUE(subschema.valid()); | 158 ASSERT_TRUE(subschema.valid()); |
159 | 159 |
160 EXPECT_TRUE(IsSameSchema(subschema.GetKnownProperty("AC"), | 160 EXPECT_TRUE(IsSameSchema(subschema.GetKnownProperty("AC"), |
161 subschema.GetKnownProperty("Battery"))); | 161 subschema.GetKnownProperty("Battery"))); |
162 | 162 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 base::MakeUnique<base::StringValue>("test_value"), nullptr); | 223 base::MakeUnique<base::StringValue>("test_value"), nullptr); |
224 SetEnterpriseUsersDefaults(&policy_map); | 224 SetEnterpriseUsersDefaults(&policy_map); |
225 multiprof_behavior = | 225 multiprof_behavior = |
226 policy_map.GetValue(key::kChromeOsMultiProfileUserBehavior); | 226 policy_map.GetValue(key::kChromeOsMultiProfileUserBehavior); |
227 expected = base::StringValue("test_value"); | 227 expected = base::StringValue("test_value"); |
228 EXPECT_TRUE(expected.Equals(multiprof_behavior)); | 228 EXPECT_TRUE(expected.Equals(multiprof_behavior)); |
229 } | 229 } |
230 #endif | 230 #endif |
231 | 231 |
232 } // namespace policy | 232 } // namespace policy |
OLD | NEW |