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

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

Issue 1304843004: Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed another test. 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/policy_map.h" 5 #include "components/policy/core/common/policy_map.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "components/policy/core/common/external_data_manager.h" 9 #include "components/policy/core/common/external_data_manager.h"
10 #include "components/policy/core/common/policy_types.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace policy { 13 namespace policy {
13 14
14 namespace { 15 namespace {
15 16
16 // Dummy policy names. 17 // Dummy policy names.
17 const char kTestPolicyName1[] = "policy.test.1"; 18 const char kTestPolicyName1[] = "policy.test.1";
18 const char kTestPolicyName2[] = "policy.test.2"; 19 const char kTestPolicyName2[] = "policy.test.2";
19 const char kTestPolicyName3[] = "policy.test.3"; 20 const char kTestPolicyName3[] = "policy.test.3";
20 const char kTestPolicyName4[] = "policy.test.4"; 21 const char kTestPolicyName4[] = "policy.test.4";
21 const char kTestPolicyName5[] = "policy.test.5"; 22 const char kTestPolicyName5[] = "policy.test.5";
22 const char kTestPolicyName6[] = "policy.test.6"; 23 const char kTestPolicyName6[] = "policy.test.6";
23 const char kTestPolicyName7[] = "policy.test.7"; 24 const char kTestPolicyName7[] = "policy.test.7";
24 const char kTestPolicyName8[] = "policy.test.8"; 25 const char kTestPolicyName8[] = "policy.test.8";
25 26
26 // Utility functions for the tests. 27 // Utility functions for the tests.
27 void SetPolicy(PolicyMap* map, const char* name, base::Value* value) { 28 void SetPolicy(PolicyMap* map, const char* name, base::Value* value) {
28 map->Set(name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, value, NULL); 29 map->Set(name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
30 value, nullptr);
29 } 31 }
30 32
31 void SetPolicy(PolicyMap* map, 33 void SetPolicy(PolicyMap* map,
32 const char* name, 34 const char* name,
33 ExternalDataFetcher* external_data_fetcher) { 35 ExternalDataFetcher* external_data_fetcher) {
34 map->Set(name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 36 map->Set(name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
35 NULL, external_data_fetcher); 37 NULL, external_data_fetcher);
36 } 38 }
37 39
38 } // namespace 40 } // namespace
39 41
40 class PolicyMapTest : public testing::Test { 42 class PolicyMapTest : public testing::Test {
41 protected: 43 protected:
42 scoped_ptr<ExternalDataFetcher> CreateExternalDataFetcher( 44 scoped_ptr<ExternalDataFetcher> CreateExternalDataFetcher(
43 const std::string& policy) const; 45 const std::string& policy) const;
44 }; 46 };
(...skipping 12 matching lines...) Expand all
57 SetPolicy(&map, kTestPolicyName1, new base::StringValue("bbb")); 59 SetPolicy(&map, kTestPolicyName1, new base::StringValue("bbb"));
58 base::StringValue expected_b("bbb"); 60 base::StringValue expected_b("bbb");
59 EXPECT_TRUE(expected_b.Equals(map.GetValue(kTestPolicyName1))); 61 EXPECT_TRUE(expected_b.Equals(map.GetValue(kTestPolicyName1)));
60 SetPolicy(&map, kTestPolicyName1, 62 SetPolicy(&map, kTestPolicyName1,
61 CreateExternalDataFetcher("dummy").release()); 63 CreateExternalDataFetcher("dummy").release());
62 EXPECT_FALSE(map.GetValue(kTestPolicyName1)); 64 EXPECT_FALSE(map.GetValue(kTestPolicyName1));
63 const PolicyMap::Entry* entry = map.Get(kTestPolicyName1); 65 const PolicyMap::Entry* entry = map.Get(kTestPolicyName1);
64 ASSERT_TRUE(entry != NULL); 66 ASSERT_TRUE(entry != NULL);
65 EXPECT_EQ(POLICY_LEVEL_MANDATORY, entry->level); 67 EXPECT_EQ(POLICY_LEVEL_MANDATORY, entry->level);
66 EXPECT_EQ(POLICY_SCOPE_USER, entry->scope); 68 EXPECT_EQ(POLICY_SCOPE_USER, entry->scope);
69 EXPECT_EQ(POLICY_SOURCE_CLOUD, entry->source);
67 EXPECT_TRUE(ExternalDataFetcher::Equals( 70 EXPECT_TRUE(ExternalDataFetcher::Equals(
68 entry->external_data_fetcher, CreateExternalDataFetcher("dummy").get())); 71 entry->external_data_fetcher, CreateExternalDataFetcher("dummy").get()));
69 map.Set(kTestPolicyName1, POLICY_LEVEL_RECOMMENDED, 72 map.Set(kTestPolicyName1, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE,
70 POLICY_SCOPE_MACHINE, NULL, NULL); 73 POLICY_SOURCE_ENTERPRISE_DEFAULT, nullptr, nullptr);
71 EXPECT_FALSE(map.GetValue(kTestPolicyName1)); 74 EXPECT_FALSE(map.GetValue(kTestPolicyName1));
72 entry = map.Get(kTestPolicyName1); 75 entry = map.Get(kTestPolicyName1);
73 ASSERT_TRUE(entry != NULL); 76 ASSERT_TRUE(entry != NULL);
74 EXPECT_EQ(POLICY_LEVEL_RECOMMENDED, entry->level); 77 EXPECT_EQ(POLICY_LEVEL_RECOMMENDED, entry->level);
75 EXPECT_EQ(POLICY_SCOPE_MACHINE, entry->scope); 78 EXPECT_EQ(POLICY_SCOPE_MACHINE, entry->scope);
79 EXPECT_EQ(POLICY_SOURCE_ENTERPRISE_DEFAULT, entry->source);
76 EXPECT_FALSE(entry->external_data_fetcher); 80 EXPECT_FALSE(entry->external_data_fetcher);
77 } 81 }
78 82
79 TEST_F(PolicyMapTest, Equals) { 83 TEST_F(PolicyMapTest, Equals) {
80 PolicyMap a; 84 PolicyMap a;
81 SetPolicy(&a, kTestPolicyName1, new base::StringValue("aaa")); 85 SetPolicy(&a, kTestPolicyName1, new base::StringValue("aaa"));
82 PolicyMap a2; 86 PolicyMap a2;
83 SetPolicy(&a2, kTestPolicyName1, new base::StringValue("aaa")); 87 SetPolicy(&a2, kTestPolicyName1, new base::StringValue("aaa"));
84 PolicyMap b; 88 PolicyMap b;
85 SetPolicy(&b, kTestPolicyName1, new base::StringValue("bbb")); 89 SetPolicy(&b, kTestPolicyName1, new base::StringValue("bbb"));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 PolicyMap empty; 161 PolicyMap empty;
158 EXPECT_TRUE(a.Equals(empty)); 162 EXPECT_TRUE(a.Equals(empty));
159 EXPECT_FALSE(b.Equals(empty)); 163 EXPECT_FALSE(b.Equals(empty));
160 } 164 }
161 165
162 TEST_F(PolicyMapTest, MergeFrom) { 166 TEST_F(PolicyMapTest, MergeFrom) {
163 PolicyMap a; 167 PolicyMap a;
164 a.Set(kTestPolicyName1, 168 a.Set(kTestPolicyName1,
165 POLICY_LEVEL_MANDATORY, 169 POLICY_LEVEL_MANDATORY,
166 POLICY_SCOPE_USER, 170 POLICY_SCOPE_USER,
171 POLICY_SOURCE_CLOUD,
167 new base::StringValue("google.com"), 172 new base::StringValue("google.com"),
168 NULL); 173 NULL);
169 a.Set(kTestPolicyName2, 174 a.Set(kTestPolicyName2,
170 POLICY_LEVEL_MANDATORY, 175 POLICY_LEVEL_MANDATORY,
171 POLICY_SCOPE_MACHINE, 176 POLICY_SCOPE_MACHINE,
177 POLICY_SOURCE_CLOUD,
172 new base::FundamentalValue(true), 178 new base::FundamentalValue(true),
173 NULL); 179 NULL);
174 a.Set(kTestPolicyName3, 180 a.Set(kTestPolicyName3,
175 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 181 POLICY_LEVEL_MANDATORY,
182 POLICY_SCOPE_MACHINE,
183 POLICY_SOURCE_ENTERPRISE_DEFAULT,
176 NULL, CreateExternalDataFetcher("a").release()); 184 NULL, CreateExternalDataFetcher("a").release());
177 a.Set(kTestPolicyName4, 185 a.Set(kTestPolicyName4,
178 POLICY_LEVEL_RECOMMENDED, 186 POLICY_LEVEL_RECOMMENDED,
179 POLICY_SCOPE_USER, 187 POLICY_SCOPE_USER,
188 POLICY_SOURCE_CLOUD,
180 new base::FundamentalValue(false), 189 new base::FundamentalValue(false),
181 NULL); 190 NULL);
182 a.Set(kTestPolicyName5, 191 a.Set(kTestPolicyName5,
183 POLICY_LEVEL_RECOMMENDED, 192 POLICY_LEVEL_RECOMMENDED,
184 POLICY_SCOPE_MACHINE, 193 POLICY_SCOPE_MACHINE,
194 POLICY_SOURCE_CLOUD,
185 new base::StringValue("google.com/q={x}"), 195 new base::StringValue("google.com/q={x}"),
186 NULL); 196 NULL);
187 197
188 PolicyMap b; 198 PolicyMap b;
189 b.Set(kTestPolicyName1, 199 b.Set(kTestPolicyName1,
190 POLICY_LEVEL_MANDATORY, 200 POLICY_LEVEL_MANDATORY,
191 POLICY_SCOPE_MACHINE, 201 POLICY_SCOPE_MACHINE,
202 POLICY_SOURCE_CLOUD,
192 new base::StringValue("chromium.org"), 203 new base::StringValue("chromium.org"),
193 NULL); 204 NULL);
194 b.Set(kTestPolicyName2, 205 b.Set(kTestPolicyName2,
195 POLICY_LEVEL_MANDATORY, 206 POLICY_LEVEL_MANDATORY,
196 POLICY_SCOPE_MACHINE, 207 POLICY_SCOPE_MACHINE,
208 POLICY_SOURCE_CLOUD,
197 new base::FundamentalValue(false), 209 new base::FundamentalValue(false),
198 NULL); 210 NULL);
199 b.Set(kTestPolicyName3, 211 b.Set(kTestPolicyName3,
200 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 212 POLICY_LEVEL_MANDATORY,
213 POLICY_SCOPE_MACHINE,
214 POLICY_SOURCE_CLOUD,
201 NULL, CreateExternalDataFetcher("b").release()); 215 NULL, CreateExternalDataFetcher("b").release());
202 b.Set(kTestPolicyName4, 216 b.Set(kTestPolicyName4,
203 POLICY_LEVEL_RECOMMENDED, 217 POLICY_LEVEL_RECOMMENDED,
204 POLICY_SCOPE_MACHINE, 218 POLICY_SCOPE_MACHINE,
219 POLICY_SOURCE_ENTERPRISE_OVERRIDE,
205 new base::FundamentalValue(true), 220 new base::FundamentalValue(true),
206 NULL); 221 NULL);
207 b.Set(kTestPolicyName5, 222 b.Set(kTestPolicyName5,
208 POLICY_LEVEL_MANDATORY, 223 POLICY_LEVEL_MANDATORY,
209 POLICY_SCOPE_MACHINE, 224 POLICY_SCOPE_MACHINE,
225 POLICY_SOURCE_PLATFORM,
210 new base::StringValue(std::string()), 226 new base::StringValue(std::string()),
211 NULL); 227 NULL);
212 b.Set(kTestPolicyName6, 228 b.Set(kTestPolicyName6,
213 POLICY_LEVEL_RECOMMENDED, 229 POLICY_LEVEL_RECOMMENDED,
214 POLICY_SCOPE_USER, 230 POLICY_SCOPE_USER,
231 POLICY_SOURCE_CLOUD,
215 new base::FundamentalValue(true), 232 new base::FundamentalValue(true),
216 NULL); 233 NULL);
217 234
218 a.MergeFrom(b); 235 a.MergeFrom(b);
219 236
220 PolicyMap c; 237 PolicyMap c;
221 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER. 238 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER.
222 c.Set(kTestPolicyName1, 239 c.Set(kTestPolicyName1,
223 POLICY_LEVEL_MANDATORY, 240 POLICY_LEVEL_MANDATORY,
224 POLICY_SCOPE_MACHINE, 241 POLICY_SCOPE_MACHINE,
242 POLICY_SOURCE_CLOUD,
225 new base::StringValue("chromium.org"), 243 new base::StringValue("chromium.org"),
226 NULL); 244 NULL);
227 // |a| has precedence over |b|. 245 // |a| has precedence over |b|.
228 c.Set(kTestPolicyName2, 246 c.Set(kTestPolicyName2,
229 POLICY_LEVEL_MANDATORY, 247 POLICY_LEVEL_MANDATORY,
230 POLICY_SCOPE_MACHINE, 248 POLICY_SCOPE_MACHINE,
249 POLICY_SOURCE_CLOUD,
231 new base::FundamentalValue(true), 250 new base::FundamentalValue(true),
232 NULL); 251 NULL);
233 c.Set(kTestPolicyName3, 252 c.Set(kTestPolicyName3,
234 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 253 POLICY_LEVEL_MANDATORY,
254 POLICY_SCOPE_MACHINE,
255 POLICY_SOURCE_ENTERPRISE_DEFAULT,
235 NULL, CreateExternalDataFetcher("a").release()); 256 NULL, CreateExternalDataFetcher("a").release());
236 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER for POLICY_LEVEL_RECOMMENDED. 257 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER for POLICY_LEVEL_RECOMMENDED.
237 c.Set(kTestPolicyName4, 258 c.Set(kTestPolicyName4,
238 POLICY_LEVEL_RECOMMENDED, 259 POLICY_LEVEL_RECOMMENDED,
239 POLICY_SCOPE_MACHINE, 260 POLICY_SCOPE_MACHINE,
261 POLICY_SOURCE_ENTERPRISE_OVERRIDE,
240 new base::FundamentalValue(true), 262 new base::FundamentalValue(true),
241 NULL); 263 NULL);
242 // POLICY_LEVEL_MANDATORY over POLICY_LEVEL_RECOMMENDED. 264 // POLICY_LEVEL_MANDATORY over POLICY_LEVEL_RECOMMENDED.
243 c.Set(kTestPolicyName5, 265 c.Set(kTestPolicyName5,
244 POLICY_LEVEL_MANDATORY, 266 POLICY_LEVEL_MANDATORY,
245 POLICY_SCOPE_MACHINE, 267 POLICY_SCOPE_MACHINE,
268 POLICY_SOURCE_PLATFORM,
246 new base::StringValue(std::string()), 269 new base::StringValue(std::string()),
247 NULL); 270 NULL);
248 // Merge new ones. 271 // Merge new ones.
249 c.Set(kTestPolicyName6, 272 c.Set(kTestPolicyName6,
250 POLICY_LEVEL_RECOMMENDED, 273 POLICY_LEVEL_RECOMMENDED,
251 POLICY_SCOPE_USER, 274 POLICY_SCOPE_USER,
275 POLICY_SOURCE_CLOUD,
252 new base::FundamentalValue(true), 276 new base::FundamentalValue(true),
253 NULL); 277 NULL);
254 278
255 EXPECT_TRUE(a.Equals(c)); 279 EXPECT_TRUE(a.Equals(c));
256 } 280 }
257 281
258 TEST_F(PolicyMapTest, GetDifferingKeys) { 282 TEST_F(PolicyMapTest, GetDifferingKeys) {
259 PolicyMap a; 283 PolicyMap a;
260 a.Set(kTestPolicyName1, 284 a.Set(kTestPolicyName1,
261 POLICY_LEVEL_MANDATORY, 285 POLICY_LEVEL_MANDATORY,
262 POLICY_SCOPE_USER, 286 POLICY_SCOPE_USER,
287 POLICY_SOURCE_CLOUD,
263 new base::StringValue("google.com"), 288 new base::StringValue("google.com"),
264 NULL); 289 NULL);
265 a.Set(kTestPolicyName2, 290 a.Set(kTestPolicyName2,
266 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 291 POLICY_LEVEL_MANDATORY,
292 POLICY_SCOPE_MACHINE,
293 POLICY_SOURCE_CLOUD,
267 NULL, CreateExternalDataFetcher("dummy").release()); 294 NULL, CreateExternalDataFetcher("dummy").release());
268 a.Set(kTestPolicyName3, 295 a.Set(kTestPolicyName3,
269 POLICY_LEVEL_MANDATORY, 296 POLICY_LEVEL_MANDATORY,
270 POLICY_SCOPE_MACHINE, 297 POLICY_SCOPE_MACHINE,
298 POLICY_SOURCE_CLOUD,
271 new base::FundamentalValue(true), 299 new base::FundamentalValue(true),
272 NULL); 300 NULL);
273 a.Set(kTestPolicyName4, 301 a.Set(kTestPolicyName4,
274 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 302 POLICY_LEVEL_MANDATORY,
303 POLICY_SCOPE_MACHINE,
304 POLICY_SOURCE_CLOUD,
275 NULL, CreateExternalDataFetcher("a").release()); 305 NULL, CreateExternalDataFetcher("a").release());
276 a.Set(kTestPolicyName5, 306 a.Set(kTestPolicyName5,
277 POLICY_LEVEL_RECOMMENDED, 307 POLICY_LEVEL_RECOMMENDED,
278 POLICY_SCOPE_USER, 308 POLICY_SCOPE_USER,
309 POLICY_SOURCE_CLOUD,
279 new base::FundamentalValue(false), 310 new base::FundamentalValue(false),
280 NULL); 311 NULL);
281 a.Set(kTestPolicyName6, 312 a.Set(kTestPolicyName6,
282 POLICY_LEVEL_RECOMMENDED, 313 POLICY_LEVEL_RECOMMENDED,
283 POLICY_SCOPE_MACHINE, 314 POLICY_SCOPE_MACHINE,
315 POLICY_SOURCE_CLOUD,
284 new base::StringValue("google.com/q={x}"), 316 new base::StringValue("google.com/q={x}"),
285 NULL); 317 NULL);
286 a.Set(kTestPolicyName7, 318 a.Set(kTestPolicyName7,
287 POLICY_LEVEL_MANDATORY, 319 POLICY_LEVEL_MANDATORY,
288 POLICY_SCOPE_USER, 320 POLICY_SCOPE_USER,
321 POLICY_SOURCE_CLOUD,
289 new base::FundamentalValue(true), 322 new base::FundamentalValue(true),
290 NULL); 323 NULL);
291 324
292 PolicyMap b; 325 PolicyMap b;
293 b.Set(kTestPolicyName1, 326 b.Set(kTestPolicyName1,
294 POLICY_LEVEL_MANDATORY, 327 POLICY_LEVEL_MANDATORY,
295 POLICY_SCOPE_USER, 328 POLICY_SCOPE_USER,
329 POLICY_SOURCE_CLOUD,
296 new base::StringValue("google.com"), 330 new base::StringValue("google.com"),
297 NULL); 331 NULL);
298 b.Set(kTestPolicyName2, 332 b.Set(kTestPolicyName2,
299 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 333 POLICY_LEVEL_MANDATORY,
334 POLICY_SCOPE_MACHINE,
335 POLICY_SOURCE_CLOUD,
300 NULL, CreateExternalDataFetcher("dummy").release()); 336 NULL, CreateExternalDataFetcher("dummy").release());
301 b.Set(kTestPolicyName3, 337 b.Set(kTestPolicyName3,
302 POLICY_LEVEL_MANDATORY, 338 POLICY_LEVEL_MANDATORY,
303 POLICY_SCOPE_MACHINE, 339 POLICY_SCOPE_MACHINE,
340 POLICY_SOURCE_CLOUD,
304 new base::FundamentalValue(false), 341 new base::FundamentalValue(false),
305 NULL); 342 NULL);
306 b.Set(kTestPolicyName4, 343 b.Set(kTestPolicyName4,
307 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 344 POLICY_LEVEL_MANDATORY,
345 POLICY_SCOPE_MACHINE,
346 POLICY_SOURCE_CLOUD,
308 NULL, CreateExternalDataFetcher("b").release()); 347 NULL, CreateExternalDataFetcher("b").release());
309 b.Set(kTestPolicyName5, 348 b.Set(kTestPolicyName5,
310 POLICY_LEVEL_MANDATORY, 349 POLICY_LEVEL_MANDATORY,
311 POLICY_SCOPE_USER, 350 POLICY_SCOPE_USER,
351 POLICY_SOURCE_CLOUD,
312 new base::FundamentalValue(false), 352 new base::FundamentalValue(false),
313 NULL); 353 NULL);
314 b.Set(kTestPolicyName6, 354 b.Set(kTestPolicyName6,
315 POLICY_LEVEL_RECOMMENDED, 355 POLICY_LEVEL_RECOMMENDED,
316 POLICY_SCOPE_USER, 356 POLICY_SCOPE_USER,
357 POLICY_SOURCE_CLOUD,
317 new base::StringValue("google.com/q={x}"), 358 new base::StringValue("google.com/q={x}"),
318 NULL); 359 NULL);
319 b.Set(kTestPolicyName8, 360 b.Set(kTestPolicyName8,
320 POLICY_LEVEL_RECOMMENDED, 361 POLICY_LEVEL_RECOMMENDED,
321 POLICY_SCOPE_USER, 362 POLICY_SCOPE_USER,
363 POLICY_SOURCE_CLOUD,
322 new base::FundamentalValue(true), 364 new base::FundamentalValue(true),
323 NULL); 365 NULL);
324 366
325 std::set<std::string> diff; 367 std::set<std::string> diff;
326 std::set<std::string> diff2; 368 std::set<std::string> diff2;
327 a.GetDifferingKeys(b, &diff); 369 a.GetDifferingKeys(b, &diff);
328 b.GetDifferingKeys(a, &diff2); 370 b.GetDifferingKeys(a, &diff2);
329 // Order shouldn't matter. 371 // Order shouldn't matter.
330 EXPECT_EQ(diff, diff2); 372 EXPECT_EQ(diff, diff2);
331 // No change. 373 // No change.
332 EXPECT_TRUE(diff.find(kTestPolicyName1) == diff.end()); 374 EXPECT_TRUE(diff.find(kTestPolicyName1) == diff.end());
333 EXPECT_TRUE(diff.find(kTestPolicyName2) == diff.end()); 375 EXPECT_TRUE(diff.find(kTestPolicyName2) == diff.end());
334 // Different values. 376 // Different values.
335 EXPECT_TRUE(diff.find(kTestPolicyName3) != diff.end()); 377 EXPECT_TRUE(diff.find(kTestPolicyName3) != diff.end());
336 // Different external data references. 378 // Different external data references.
337 EXPECT_TRUE(diff.find(kTestPolicyName4) != diff.end()); 379 EXPECT_TRUE(diff.find(kTestPolicyName4) != diff.end());
338 // Different levels. 380 // Different levels.
339 EXPECT_TRUE(diff.find(kTestPolicyName5) != diff.end()); 381 EXPECT_TRUE(diff.find(kTestPolicyName5) != diff.end());
340 // Different scopes. 382 // Different scopes.
341 EXPECT_TRUE(diff.find(kTestPolicyName6) != diff.end()); 383 EXPECT_TRUE(diff.find(kTestPolicyName6) != diff.end());
342 // Not in |a|. 384 // Not in |a|.
343 EXPECT_TRUE(diff.find(kTestPolicyName8) != diff.end()); 385 EXPECT_TRUE(diff.find(kTestPolicyName8) != diff.end());
344 // Not in |b|. 386 // Not in |b|.
345 EXPECT_TRUE(diff.find(kTestPolicyName7) != diff.end()); 387 EXPECT_TRUE(diff.find(kTestPolicyName7) != diff.end());
346 // No surprises. 388 // No surprises.
347 EXPECT_EQ(6u, diff.size()); 389 EXPECT_EQ(6u, diff.size());
348 } 390 }
349 391
392 TEST_F(PolicyMapTest, LoadFromSetsLevelScopeAndSource) {
393 base::DictionaryValue policies;
394 policies.SetString("TestPolicy1", "google.com");
395 policies.SetBoolean("TestPolicy2", true);
396 policies.SetInteger("TestPolicy3", -12321);
397
398 PolicyMap loaded;
399 loaded.LoadFrom(&policies,
400 POLICY_LEVEL_MANDATORY,
401 POLICY_SCOPE_USER,
402 POLICY_SOURCE_PLATFORM);
403
404 PolicyMap expected;
405 expected.Set("TestPolicy1",
406 POLICY_LEVEL_MANDATORY,
407 POLICY_SCOPE_USER,
408 POLICY_SOURCE_PLATFORM,
409 new base::StringValue("google.com"),
410 nullptr);
411 expected.Set("TestPolicy2",
412 POLICY_LEVEL_MANDATORY,
413 POLICY_SCOPE_USER,
414 POLICY_SOURCE_PLATFORM,
415 new base::FundamentalValue(true),
416 nullptr);
417 expected.Set("TestPolicy3",
418 POLICY_LEVEL_MANDATORY,
419 POLICY_SCOPE_USER,
420 POLICY_SOURCE_PLATFORM,
421 new base::FundamentalValue(-12321),
422 nullptr);
423 EXPECT_TRUE(loaded.Equals(expected));
424 }
425
350 } // namespace policy 426 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/policy_map.cc ('k') | components/policy/core/common/policy_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698