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

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