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

Side by Side Diff: components/policy/core/common/schema_map_unittest.cc

Issue 1350913006: Revert of Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
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"
11 #include "components/policy/core/common/policy_bundle.h" 11 #include "components/policy/core/common/policy_bundle.h"
12 #include "components/policy/core/common/policy_map.h" 12 #include "components/policy/core/common/policy_map.h"
13 #include "components/policy/core/common/policy_types.h"
14 #include "components/policy/core/common/schema.h" 13 #include "components/policy/core/common/schema.h"
15 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
16 15
17 namespace policy { 16 namespace policy {
18 17
19 namespace { 18 namespace {
20 19
21 const char kTestSchema[] = 20 const char kTestSchema[] =
22 "{" 21 "{"
23 " \"type\": \"object\"," 22 " \"type\": \"object\","
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 schema_map->FilterBundle(&bundle); 134 schema_map->FilterBundle(&bundle);
136 const PolicyBundle empty_bundle; 135 const PolicyBundle empty_bundle;
137 EXPECT_TRUE(bundle.Equals(empty_bundle)); 136 EXPECT_TRUE(bundle.Equals(empty_bundle));
138 137
139 // The Chrome namespace isn't filtered. 138 // The Chrome namespace isn't filtered.
140 PolicyBundle expected_bundle; 139 PolicyBundle expected_bundle;
141 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, ""); 140 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, "");
142 expected_bundle.Get(chrome_ns).Set("ChromePolicy", 141 expected_bundle.Get(chrome_ns).Set("ChromePolicy",
143 POLICY_LEVEL_MANDATORY, 142 POLICY_LEVEL_MANDATORY,
144 POLICY_SCOPE_USER, 143 POLICY_SCOPE_USER,
145 POLICY_SOURCE_CLOUD,
146 new base::StringValue("value"), 144 new base::StringValue("value"),
147 NULL); 145 NULL);
148 bundle.CopyFrom(expected_bundle); 146 bundle.CopyFrom(expected_bundle);
149 147
150 // Unknown components are filtered out. 148 // Unknown components are filtered out.
151 PolicyNamespace another_extension_ns(POLICY_DOMAIN_EXTENSIONS, "xyz"); 149 PolicyNamespace another_extension_ns(POLICY_DOMAIN_EXTENSIONS, "xyz");
152 bundle.Get(another_extension_ns).Set("AnotherExtensionPolicy", 150 bundle.Get(another_extension_ns).Set("AnotherExtensionPolicy",
153 POLICY_LEVEL_MANDATORY, 151 POLICY_LEVEL_MANDATORY,
154 POLICY_SCOPE_USER, 152 POLICY_SCOPE_USER,
155 POLICY_SOURCE_CLOUD,
156 new base::StringValue("value"), 153 new base::StringValue("value"),
157 NULL); 154 NULL);
158 schema_map->FilterBundle(&bundle); 155 schema_map->FilterBundle(&bundle);
159 EXPECT_TRUE(bundle.Equals(expected_bundle)); 156 EXPECT_TRUE(bundle.Equals(expected_bundle));
160 157
161 PolicyNamespace extension_ns(POLICY_DOMAIN_EXTENSIONS, "abc"); 158 PolicyNamespace extension_ns(POLICY_DOMAIN_EXTENSIONS, "abc");
162 PolicyMap& map = expected_bundle.Get(extension_ns); 159 PolicyMap& map = expected_bundle.Get(extension_ns);
163 base::ListValue list; 160 base::ListValue list;
164 list.AppendString("a"); 161 list.AppendString("a");
165 list.AppendString("b"); 162 list.AppendString("b");
166 map.Set("list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 163 map.Set("list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
167 POLICY_SOURCE_CLOUD, list.DeepCopy(), nullptr); 164 list.DeepCopy(), NULL);
168 map.Set("boolean", 165 map.Set("boolean",
169 POLICY_LEVEL_MANDATORY, 166 POLICY_LEVEL_MANDATORY,
170 POLICY_SCOPE_USER, 167 POLICY_SCOPE_USER,
171 POLICY_SOURCE_CLOUD,
172 new base::FundamentalValue(true), 168 new base::FundamentalValue(true),
173 NULL); 169 NULL);
174 map.Set("integer", 170 map.Set("integer",
175 POLICY_LEVEL_MANDATORY, 171 POLICY_LEVEL_MANDATORY,
176 POLICY_SCOPE_USER, 172 POLICY_SCOPE_USER,
177 POLICY_SOURCE_CLOUD,
178 new base::FundamentalValue(1), 173 new base::FundamentalValue(1),
179 NULL); 174 NULL);
180 map.Set("null", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 175 map.Set("null", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
181 POLICY_SOURCE_CLOUD, base::Value::CreateNullValue().release(), 176 base::Value::CreateNullValue().release(), NULL);
182 nullptr);
183 map.Set("double", 177 map.Set("double",
184 POLICY_LEVEL_MANDATORY, 178 POLICY_LEVEL_MANDATORY,
185 POLICY_SCOPE_USER, 179 POLICY_SCOPE_USER,
186 POLICY_SOURCE_CLOUD,
187 new base::FundamentalValue(1.2), 180 new base::FundamentalValue(1.2),
188 NULL); 181 NULL);
189 base::DictionaryValue dict; 182 base::DictionaryValue dict;
190 dict.SetString("a", "b"); 183 dict.SetString("a", "b");
191 dict.SetInteger("b", 2); 184 dict.SetInteger("b", 2);
192 map.Set("object", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 185 map.Set("object", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
193 POLICY_SOURCE_CLOUD, dict.DeepCopy(), nullptr); 186 dict.DeepCopy(), NULL);
194 map.Set("string", 187 map.Set("string",
195 POLICY_LEVEL_MANDATORY, 188 POLICY_LEVEL_MANDATORY,
196 POLICY_SCOPE_USER, 189 POLICY_SCOPE_USER,
197 POLICY_SOURCE_CLOUD,
198 new base::StringValue("value"), 190 new base::StringValue("value"),
199 NULL); 191 NULL);
200 192
201 bundle.MergeFrom(expected_bundle); 193 bundle.MergeFrom(expected_bundle);
202 bundle.Get(extension_ns).Set("Unexpected", 194 bundle.Get(extension_ns).Set("Unexpected",
203 POLICY_LEVEL_MANDATORY, 195 POLICY_LEVEL_MANDATORY,
204 POLICY_SCOPE_USER, 196 POLICY_SCOPE_USER,
205 POLICY_SOURCE_CLOUD,
206 new base::StringValue("to-be-removed"), 197 new base::StringValue("to-be-removed"),
207 NULL); 198 NULL);
208 199
209 schema_map->FilterBundle(&bundle); 200 schema_map->FilterBundle(&bundle);
210 EXPECT_TRUE(bundle.Equals(expected_bundle)); 201 EXPECT_TRUE(bundle.Equals(expected_bundle));
211 202
212 // Mismatched types are also removed. 203 // Mismatched types are also removed.
213 bundle.Clear(); 204 bundle.Clear();
214 PolicyMap& badmap = bundle.Get(extension_ns); 205 PolicyMap& badmap = bundle.Get(extension_ns);
215 badmap.Set("list", 206 badmap.Set("list",
216 POLICY_LEVEL_MANDATORY, 207 POLICY_LEVEL_MANDATORY,
217 POLICY_SCOPE_USER, 208 POLICY_SCOPE_USER,
218 POLICY_SOURCE_CLOUD,
219 new base::FundamentalValue(false), 209 new base::FundamentalValue(false),
220 NULL); 210 NULL);
221 badmap.Set("boolean", 211 badmap.Set("boolean",
222 POLICY_LEVEL_MANDATORY, 212 POLICY_LEVEL_MANDATORY,
223 POLICY_SCOPE_USER, 213 POLICY_SCOPE_USER,
224 POLICY_SOURCE_CLOUD,
225 new base::FundamentalValue(0), 214 new base::FundamentalValue(0),
226 NULL); 215 NULL);
227 badmap.Set("integer", 216 badmap.Set("integer",
228 POLICY_LEVEL_MANDATORY, 217 POLICY_LEVEL_MANDATORY,
229 POLICY_SCOPE_USER, 218 POLICY_SCOPE_USER,
230 POLICY_SOURCE_CLOUD,
231 new base::FundamentalValue(false), 219 new base::FundamentalValue(false),
232 NULL); 220 NULL);
233 badmap.Set("null", 221 badmap.Set("null",
234 POLICY_LEVEL_MANDATORY, 222 POLICY_LEVEL_MANDATORY,
235 POLICY_SCOPE_USER, 223 POLICY_SCOPE_USER,
236 POLICY_SOURCE_CLOUD,
237 new base::FundamentalValue(false), 224 new base::FundamentalValue(false),
238 NULL); 225 NULL);
239 badmap.Set("double", 226 badmap.Set("double",
240 POLICY_LEVEL_MANDATORY, 227 POLICY_LEVEL_MANDATORY,
241 POLICY_SCOPE_USER, 228 POLICY_SCOPE_USER,
242 POLICY_SOURCE_CLOUD,
243 new base::FundamentalValue(false), 229 new base::FundamentalValue(false),
244 NULL); 230 NULL);
245 badmap.Set("object", 231 badmap.Set("object",
246 POLICY_LEVEL_MANDATORY, 232 POLICY_LEVEL_MANDATORY,
247 POLICY_SCOPE_USER, 233 POLICY_SCOPE_USER,
248 POLICY_SOURCE_CLOUD,
249 new base::FundamentalValue(false), 234 new base::FundamentalValue(false),
250 NULL); 235 NULL);
251 badmap.Set("string", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 236 badmap.Set("string", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
252 POLICY_SOURCE_CLOUD, nullptr, 237 NULL,
253 new ExternalDataFetcher(base::WeakPtr<ExternalDataManager>(), 238 new ExternalDataFetcher(base::WeakPtr<ExternalDataManager>(),
254 std::string())); 239 std::string()));
255 240
256 schema_map->FilterBundle(&bundle); 241 schema_map->FilterBundle(&bundle);
257 EXPECT_TRUE(bundle.Equals(empty_bundle)); 242 EXPECT_TRUE(bundle.Equals(empty_bundle));
258 } 243 }
259 244
260 TEST_F(SchemaMapTest, LegacyComponents) { 245 TEST_F(SchemaMapTest, LegacyComponents) {
261 std::string error; 246 std::string error;
262 Schema schema = Schema::Parse( 247 Schema schema = Schema::Parse(
(...skipping 11 matching lines...) Expand all
274 scoped_refptr<SchemaMap> schema_map = new SchemaMap(domain_map); 259 scoped_refptr<SchemaMap> schema_map = new SchemaMap(domain_map);
275 260
276 // |bundle| contains policies loaded by a policy provider. 261 // |bundle| contains policies loaded by a policy provider.
277 PolicyBundle bundle; 262 PolicyBundle bundle;
278 263
279 // Known components with schemas are filtered. 264 // Known components with schemas are filtered.
280 PolicyNamespace extension_ns(POLICY_DOMAIN_EXTENSIONS, "with-schema"); 265 PolicyNamespace extension_ns(POLICY_DOMAIN_EXTENSIONS, "with-schema");
281 bundle.Get(extension_ns).Set("String", 266 bundle.Get(extension_ns).Set("String",
282 POLICY_LEVEL_MANDATORY, 267 POLICY_LEVEL_MANDATORY,
283 POLICY_SCOPE_USER, 268 POLICY_SCOPE_USER,
284 POLICY_SOURCE_CLOUD,
285 new base::StringValue("value 1"), 269 new base::StringValue("value 1"),
286 NULL); 270 NULL);
287 271
288 // The Chrome namespace isn't filtered. 272 // The Chrome namespace isn't filtered.
289 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, ""); 273 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, "");
290 bundle.Get(chrome_ns).Set("ChromePolicy", 274 bundle.Get(chrome_ns).Set("ChromePolicy",
291 POLICY_LEVEL_MANDATORY, 275 POLICY_LEVEL_MANDATORY,
292 POLICY_SCOPE_USER, 276 POLICY_SCOPE_USER,
293 POLICY_SOURCE_CLOUD,
294 new base::StringValue("value 3"), 277 new base::StringValue("value 3"),
295 NULL); 278 NULL);
296 279
297 PolicyBundle expected_bundle; 280 PolicyBundle expected_bundle;
298 expected_bundle.MergeFrom(bundle); 281 expected_bundle.MergeFrom(bundle);
299 282
300 // Known components without a schema are filtered out completely. 283 // Known components without a schema are filtered out completely.
301 PolicyNamespace without_schema_ns(POLICY_DOMAIN_EXTENSIONS, "without-schema"); 284 PolicyNamespace without_schema_ns(POLICY_DOMAIN_EXTENSIONS, "without-schema");
302 bundle.Get(without_schema_ns).Set("Schemaless", 285 bundle.Get(without_schema_ns).Set("Schemaless",
303 POLICY_LEVEL_MANDATORY, 286 POLICY_LEVEL_MANDATORY,
304 POLICY_SCOPE_USER, 287 POLICY_SCOPE_USER,
305 POLICY_SOURCE_CLOUD,
306 new base::StringValue("value 2"), 288 new base::StringValue("value 2"),
307 NULL); 289 NULL);
308 290
309 // Unknown policies of known components with a schema are removed. 291 // Unknown policies of known components with a schema are removed.
310 bundle.Get(extension_ns).Set("Surprise", 292 bundle.Get(extension_ns).Set("Surprise",
311 POLICY_LEVEL_MANDATORY, 293 POLICY_LEVEL_MANDATORY,
312 POLICY_SCOPE_USER, 294 POLICY_SCOPE_USER,
313 POLICY_SOURCE_CLOUD,
314 new base::StringValue("value 4"), 295 new base::StringValue("value 4"),
315 NULL); 296 NULL);
316 297
317 // Unknown components are removed. 298 // Unknown components are removed.
318 PolicyNamespace unknown_ns(POLICY_DOMAIN_EXTENSIONS, "unknown"); 299 PolicyNamespace unknown_ns(POLICY_DOMAIN_EXTENSIONS, "unknown");
319 bundle.Get(unknown_ns).Set("Surprise", 300 bundle.Get(unknown_ns).Set("Surprise",
320 POLICY_LEVEL_MANDATORY, 301 POLICY_LEVEL_MANDATORY,
321 POLICY_SCOPE_USER, 302 POLICY_SCOPE_USER,
322 POLICY_SOURCE_CLOUD,
323 new base::StringValue("value 5"), 303 new base::StringValue("value 5"),
324 NULL); 304 NULL);
325 305
326 schema_map->FilterBundle(&bundle); 306 schema_map->FilterBundle(&bundle);
327 EXPECT_TRUE(bundle.Equals(expected_bundle)); 307 EXPECT_TRUE(bundle.Equals(expected_bundle));
328 } 308 }
329 309
330 TEST_F(SchemaMapTest, GetChanges) { 310 TEST_F(SchemaMapTest, GetChanges) {
331 DomainMap map; 311 DomainMap map;
332 map[POLICY_DOMAIN_CHROME][""] = Schema(); 312 map[POLICY_DOMAIN_CHROME][""] = Schema();
(...skipping 20 matching lines...) Expand all
353 newer = new SchemaMap(map); 333 newer = new SchemaMap(map);
354 newer->GetChanges(older, &removed, &added); 334 newer->GetChanges(older, &removed, &added);
355 ASSERT_EQ(2u, removed.size()); 335 ASSERT_EQ(2u, removed.size());
356 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_CHROME, ""), removed[0]); 336 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_CHROME, ""), removed[0]);
357 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "xyz"), removed[1]); 337 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "xyz"), removed[1]);
358 ASSERT_EQ(1u, added.size()); 338 ASSERT_EQ(1u, added.size());
359 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "abc"), added[0]); 339 EXPECT_EQ(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "abc"), added[0]);
360 } 340 }
361 341
362 } // namespace policy 342 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698