OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/policy/policy_loader_win.h" | 5 #include "chrome/browser/policy/policy_loader_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/process.h" | 10 #include "base/process.h" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 ConfigurationPolicyProvider* TestHarness::CreateProvider( | 313 ConfigurationPolicyProvider* TestHarness::CreateProvider( |
314 const PolicyDefinitionList* policy_list) { | 314 const PolicyDefinitionList* policy_list) { |
315 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); | 315 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list)); |
316 return new AsyncPolicyProvider(loader.Pass()); | 316 return new AsyncPolicyProvider(loader.Pass()); |
317 } | 317 } |
318 | 318 |
319 void TestHarness::InstallEmptyPolicy() {} | 319 void TestHarness::InstallEmptyPolicy() {} |
320 | 320 |
321 void TestHarness::InstallStringPolicy(const std::string& policy_name, | 321 void TestHarness::InstallStringPolicy(const std::string& policy_name, |
322 const std::string& policy_value) { | 322 const std::string& policy_value) { |
323 RegKey key(hive_, kRegistryMandatorySubKey, KEY_ALL_ACCESS); | 323 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS); |
324 ASSERT_TRUE(key.Valid()); | 324 ASSERT_TRUE(key.Valid()); |
325 ASSERT_HRESULT_SUCCEEDED(key.WriteValue(UTF8ToUTF16(policy_name).c_str(), | 325 ASSERT_HRESULT_SUCCEEDED(key.WriteValue(UTF8ToUTF16(policy_name).c_str(), |
326 UTF8ToUTF16(policy_value).c_str())); | 326 UTF8ToUTF16(policy_value).c_str())); |
327 } | 327 } |
328 | 328 |
329 void TestHarness::InstallIntegerPolicy(const std::string& policy_name, | 329 void TestHarness::InstallIntegerPolicy(const std::string& policy_name, |
330 int policy_value) { | 330 int policy_value) { |
331 RegKey key(hive_, kRegistryMandatorySubKey, KEY_ALL_ACCESS); | 331 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS); |
332 ASSERT_TRUE(key.Valid()); | 332 ASSERT_TRUE(key.Valid()); |
333 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), | 333 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), |
334 static_cast<DWORD>(policy_value)); | 334 static_cast<DWORD>(policy_value)); |
335 } | 335 } |
336 | 336 |
337 void TestHarness::InstallBooleanPolicy(const std::string& policy_name, | 337 void TestHarness::InstallBooleanPolicy(const std::string& policy_name, |
338 bool policy_value) { | 338 bool policy_value) { |
339 RegKey key(hive_, kRegistryMandatorySubKey, KEY_ALL_ACCESS); | 339 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS); |
340 ASSERT_TRUE(key.Valid()); | 340 ASSERT_TRUE(key.Valid()); |
341 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), | 341 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), |
342 static_cast<DWORD>(policy_value)); | 342 static_cast<DWORD>(policy_value)); |
343 } | 343 } |
344 | 344 |
345 void TestHarness::InstallStringListPolicy(const std::string& policy_name, | 345 void TestHarness::InstallStringListPolicy(const std::string& policy_name, |
346 const base::ListValue* policy_value) { | 346 const base::ListValue* policy_value) { |
347 RegKey key(hive_, | 347 RegKey key(hive_, |
348 (string16(kRegistryMandatorySubKey) + ASCIIToUTF16("\\") + | 348 (string16(kRegistryChromePolicyKey) + ASCIIToUTF16("\\") + |
349 UTF8ToUTF16(policy_name)).c_str(), | 349 UTF8ToUTF16(policy_name)).c_str(), |
350 KEY_ALL_ACCESS); | 350 KEY_ALL_ACCESS); |
351 ASSERT_TRUE(key.Valid()); | 351 ASSERT_TRUE(key.Valid()); |
352 int index = 1; | 352 int index = 1; |
353 for (base::ListValue::const_iterator element(policy_value->begin()); | 353 for (base::ListValue::const_iterator element(policy_value->begin()); |
354 element != policy_value->end(); | 354 element != policy_value->end(); |
355 ++element) { | 355 ++element) { |
356 std::string element_value; | 356 std::string element_value; |
357 if (!(*element)->GetAsString(&element_value)) | 357 if (!(*element)->GetAsString(&element_value)) |
358 continue; | 358 continue; |
359 std::string name(base::IntToString(index++)); | 359 std::string name(base::IntToString(index++)); |
360 key.WriteValue(UTF8ToUTF16(name).c_str(), | 360 key.WriteValue(UTF8ToUTF16(name).c_str(), |
361 UTF8ToUTF16(element_value).c_str()); | 361 UTF8ToUTF16(element_value).c_str()); |
362 } | 362 } |
363 } | 363 } |
364 | 364 |
365 void TestHarness::InstallDictionaryPolicy( | 365 void TestHarness::InstallDictionaryPolicy( |
366 const std::string& policy_name, | 366 const std::string& policy_name, |
367 const base::DictionaryValue* policy_value) { | 367 const base::DictionaryValue* policy_value) { |
368 std::string json; | 368 std::string json; |
369 base::JSONWriter::Write(policy_value, &json); | 369 base::JSONWriter::Write(policy_value, &json); |
370 RegKey key(hive_, kRegistryMandatorySubKey, KEY_ALL_ACCESS); | 370 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS); |
371 ASSERT_TRUE(key.Valid()); | 371 ASSERT_TRUE(key.Valid()); |
372 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), | 372 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), |
373 UTF8ToUTF16(json).c_str()); | 373 UTF8ToUTF16(json).c_str()); |
374 } | 374 } |
375 | 375 |
376 void TestHarness::Install3rdPartyPolicy(const base::DictionaryValue* policies) { | 376 void TestHarness::Install3rdPartyPolicy(const base::DictionaryValue* policies) { |
377 // The first level entries are domains, and the second level entries map | 377 // The first level entries are domains, and the second level entries map |
378 // components to their policy. | 378 // components to their policy. |
379 const string16 kPathPrefix = string16(kRegistryMandatorySubKey) + kPathSep + | 379 const string16 kPathPrefix = string16(kRegistryChromePolicyKey) + kPathSep + |
380 kThirdParty + kPathSep; | 380 kThirdParty + kPathSep; |
381 for (base::DictionaryValue::Iterator domain(*policies); | 381 for (base::DictionaryValue::Iterator domain(*policies); |
382 domain.HasNext(); domain.Advance()) { | 382 domain.HasNext(); domain.Advance()) { |
383 const base::DictionaryValue* components = NULL; | 383 const base::DictionaryValue* components = NULL; |
384 if (!domain.value().GetAsDictionary(&components)) { | 384 if (!domain.value().GetAsDictionary(&components)) { |
385 ADD_FAILURE(); | 385 ADD_FAILURE(); |
386 continue; | 386 continue; |
387 } | 387 } |
388 for (base::DictionaryValue::Iterator component(*components); | 388 for (base::DictionaryValue::Iterator component(*components); |
389 component.HasNext(); component.Advance()) { | 389 component.HasNext(); component.Advance()) { |
390 const string16 path = string16(kRegistryMandatorySubKey) + kPathSep + | 390 const string16 path = string16(kRegistryChromePolicyKey) + kPathSep + |
391 kThirdParty + kPathSep + | 391 kThirdParty + kPathSep + |
392 UTF8ToUTF16(domain.key()) + kPathSep + | 392 UTF8ToUTF16(domain.key()) + kPathSep + |
393 UTF8ToUTF16(component.key()); | 393 UTF8ToUTF16(component.key()); |
394 InstallValue(component.value(), hive_, path, kMandatory); | 394 InstallValue(component.value(), hive_, path, kMandatory); |
395 EXPECT_TRUE(InstallSchema(component.value(), hive_, path, kSchema)); | 395 EXPECT_TRUE(InstallSchema(component.value(), hive_, path, kSchema)); |
396 } | 396 } |
397 } | 397 } |
398 } | 398 } |
399 | 399 |
400 // static | 400 // static |
(...skipping 29 matching lines...) Expand all Loading... |
430 bool Matches(const PolicyBundle& expected) { | 430 bool Matches(const PolicyBundle& expected) { |
431 PolicyLoaderWin loader(&test_policy_definitions::kList); | 431 PolicyLoaderWin loader(&test_policy_definitions::kList); |
432 scoped_ptr<PolicyBundle> loaded(loader.Load()); | 432 scoped_ptr<PolicyBundle> loaded(loader.Load()); |
433 return loaded->Equals(expected); | 433 return loaded->Equals(expected); |
434 } | 434 } |
435 | 435 |
436 ScopedGroupPolicyRegistrySandbox registry_sandbox_; | 436 ScopedGroupPolicyRegistrySandbox registry_sandbox_; |
437 }; | 437 }; |
438 | 438 |
439 TEST_F(PolicyLoaderWinTest, HKLMOverHKCU) { | 439 TEST_F(PolicyLoaderWinTest, HKLMOverHKCU) { |
440 RegKey hklm_key(HKEY_LOCAL_MACHINE, kRegistryMandatorySubKey, KEY_ALL_ACCESS); | 440 RegKey hklm_key(HKEY_LOCAL_MACHINE, kRegistryChromePolicyKey, KEY_ALL_ACCESS); |
441 ASSERT_TRUE(hklm_key.Valid()); | 441 ASSERT_TRUE(hklm_key.Valid()); |
442 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 442 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), |
443 UTF8ToUTF16("hklm").c_str()); | 443 UTF8ToUTF16("hklm").c_str()); |
444 RegKey hkcu_key(HKEY_CURRENT_USER, kRegistryMandatorySubKey, KEY_ALL_ACCESS); | 444 RegKey hkcu_key(HKEY_CURRENT_USER, kRegistryChromePolicyKey, KEY_ALL_ACCESS); |
445 ASSERT_TRUE(hkcu_key.Valid()); | 445 ASSERT_TRUE(hkcu_key.Valid()); |
446 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 446 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), |
447 UTF8ToUTF16("hkcu").c_str()); | 447 UTF8ToUTF16("hkcu").c_str()); |
448 | 448 |
449 PolicyBundle expected; | 449 PolicyBundle expected; |
450 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 450 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
451 .Set(test_policy_definitions::kKeyString, | 451 .Set(test_policy_definitions::kKeyString, |
452 POLICY_LEVEL_MANDATORY, | 452 POLICY_LEVEL_MANDATORY, |
453 POLICY_SCOPE_MACHINE, | 453 POLICY_SCOPE_MACHINE, |
454 base::Value::CreateStringValue("hklm")); | 454 base::Value::CreateStringValue("hklm")); |
455 EXPECT_TRUE(Matches(expected)); | 455 EXPECT_TRUE(Matches(expected)); |
456 } | 456 } |
457 | 457 |
458 TEST_F(PolicyLoaderWinTest, Load3rdPartyWithoutSchema) { | 458 TEST_F(PolicyLoaderWinTest, Load3rdPartyWithoutSchema) { |
459 base::DictionaryValue dict; | 459 base::DictionaryValue dict; |
460 dict.SetString("str", "string value"); | 460 dict.SetString("str", "string value"); |
461 dict.SetInteger("int", 123); | 461 dict.SetInteger("int", 123); |
462 dict.Set("subdict", dict.DeepCopy()); | 462 dict.Set("subdict", dict.DeepCopy()); |
463 dict.Set("subsubdict", dict.DeepCopy()); | 463 dict.Set("subsubdict", dict.DeepCopy()); |
464 dict.Set("subsubsubdict", dict.DeepCopy()); | 464 dict.Set("subsubsubdict", dict.DeepCopy()); |
465 | 465 |
466 base::DictionaryValue policy_dict; | 466 base::DictionaryValue policy_dict; |
467 policy_dict.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.policy", | 467 policy_dict.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.policy", |
468 dict.DeepCopy()); | 468 dict.DeepCopy()); |
469 policy_dict.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.policy", | 469 policy_dict.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.policy", |
470 dict.DeepCopy()); | 470 dict.DeepCopy()); |
471 EXPECT_TRUE(InstallValue(policy_dict, HKEY_LOCAL_MACHINE, | 471 EXPECT_TRUE(InstallValue(policy_dict, HKEY_LOCAL_MACHINE, |
472 kRegistryMandatorySubKey, kThirdParty)); | 472 kRegistryChromePolicyKey, kThirdParty)); |
473 | 473 |
474 PolicyBundle expected; | 474 PolicyBundle expected; |
475 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 475 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
476 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) | 476 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) |
477 .LoadFrom(&dict, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); | 477 .LoadFrom(&dict, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
478 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 478 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
479 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 479 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
480 .LoadFrom(&dict, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); | 480 .LoadFrom(&dict, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
481 EXPECT_TRUE(Matches(expected)); | 481 EXPECT_TRUE(Matches(expected)); |
482 } | 482 } |
483 | 483 |
484 TEST_F(PolicyLoaderWinTest, Merge3rdPartyPolicies) { | 484 TEST_F(PolicyLoaderWinTest, Merge3rdPartyPolicies) { |
485 // Policy for the same extension will be provided at the 4 level/scope | 485 // Policy for the same extension will be provided at the 4 level/scope |
486 // combinations, to verify that they overlap as expected. | 486 // combinations, to verify that they overlap as expected. |
487 | 487 |
488 const string16 kPathSuffix = | 488 const string16 kPathSuffix = |
489 kRegistryMandatorySubKey + ASCIIToUTF16("\\3rdparty\\extensions\\merge"); | 489 kRegistryChromePolicyKey + ASCIIToUTF16("\\3rdparty\\extensions\\merge"); |
490 | 490 |
491 const char kUserMandatory[] = "user-mandatory"; | 491 const char kUserMandatory[] = "user-mandatory"; |
492 const char kUserRecommended[] = "user-recommended"; | 492 const char kUserRecommended[] = "user-recommended"; |
493 const char kMachineMandatory[] = "machine-mandatory"; | 493 const char kMachineMandatory[] = "machine-mandatory"; |
494 const char kMachineRecommended[] = "machine-recommended"; | 494 const char kMachineRecommended[] = "machine-recommended"; |
495 | 495 |
496 base::DictionaryValue policy; | 496 base::DictionaryValue policy; |
497 policy.SetString("a", kMachineMandatory); | 497 policy.SetString("a", kMachineMandatory); |
498 EXPECT_TRUE(InstallValue(policy, HKEY_LOCAL_MACHINE, | 498 EXPECT_TRUE(InstallValue(policy, HKEY_LOCAL_MACHINE, |
499 kPathSuffix, kMandatory)); | 499 kPathSuffix, kMandatory)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 ASSERT_FALSE(encoded_list.empty()); | 551 ASSERT_FALSE(encoded_list.empty()); |
552 base::DictionaryValue encoded_policy; | 552 base::DictionaryValue encoded_policy; |
553 encoded_policy.SetString("null", ""); | 553 encoded_policy.SetString("null", ""); |
554 encoded_policy.SetString("bool", "1"); | 554 encoded_policy.SetString("bool", "1"); |
555 encoded_policy.SetString("int", "-123"); | 555 encoded_policy.SetString("int", "-123"); |
556 encoded_policy.SetString("double", "456.78e9"); | 556 encoded_policy.SetString("double", "456.78e9"); |
557 encoded_policy.SetString("list", encoded_list); | 557 encoded_policy.SetString("list", encoded_list); |
558 encoded_policy.SetString("dict", encoded_dict); | 558 encoded_policy.SetString("dict", encoded_dict); |
559 | 559 |
560 const string16 kPathSuffix = | 560 const string16 kPathSuffix = |
561 kRegistryMandatorySubKey + ASCIIToUTF16("\\3rdparty\\extensions\\string"); | 561 kRegistryChromePolicyKey + ASCIIToUTF16("\\3rdparty\\extensions\\string"); |
562 EXPECT_TRUE(InstallSchema(policy, HKEY_CURRENT_USER, kPathSuffix, kSchema)); | 562 EXPECT_TRUE(InstallSchema(policy, HKEY_CURRENT_USER, kPathSuffix, kSchema)); |
563 EXPECT_TRUE( | 563 EXPECT_TRUE( |
564 InstallValue(encoded_policy, HKEY_CURRENT_USER, kPathSuffix, kMandatory)); | 564 InstallValue(encoded_policy, HKEY_CURRENT_USER, kPathSuffix, kMandatory)); |
565 | 565 |
566 PolicyBundle expected; | 566 PolicyBundle expected; |
567 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "string")) | 567 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "string")) |
568 .LoadFrom(&policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); | 568 .LoadFrom(&policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); |
569 EXPECT_TRUE(Matches(expected)); | 569 EXPECT_TRUE(Matches(expected)); |
570 } | 570 } |
571 | 571 |
572 TEST_F(PolicyLoaderWinTest, LoadIntegerEncodedValues) { | 572 TEST_F(PolicyLoaderWinTest, LoadIntegerEncodedValues) { |
573 base::DictionaryValue policy; | 573 base::DictionaryValue policy; |
574 policy.SetBoolean("bool", true); | 574 policy.SetBoolean("bool", true); |
575 policy.SetInteger("int", 123); | 575 policy.SetInteger("int", 123); |
576 policy.SetDouble("double", 456.0); | 576 policy.SetDouble("double", 456.0); |
577 | 577 |
578 base::DictionaryValue encoded_policy; | 578 base::DictionaryValue encoded_policy; |
579 encoded_policy.SetInteger("bool", 1); | 579 encoded_policy.SetInteger("bool", 1); |
580 encoded_policy.SetInteger("int", 123); | 580 encoded_policy.SetInteger("int", 123); |
581 encoded_policy.SetInteger("double", 456); | 581 encoded_policy.SetInteger("double", 456); |
582 | 582 |
583 const string16 kPathSuffix = | 583 const string16 kPathSuffix = |
584 kRegistryMandatorySubKey + ASCIIToUTF16("\\3rdparty\\extensions\\int"); | 584 kRegistryChromePolicyKey + ASCIIToUTF16("\\3rdparty\\extensions\\int"); |
585 EXPECT_TRUE(InstallSchema(policy, HKEY_CURRENT_USER, kPathSuffix, kSchema)); | 585 EXPECT_TRUE(InstallSchema(policy, HKEY_CURRENT_USER, kPathSuffix, kSchema)); |
586 EXPECT_TRUE( | 586 EXPECT_TRUE( |
587 InstallValue(encoded_policy, HKEY_CURRENT_USER, kPathSuffix, kMandatory)); | 587 InstallValue(encoded_policy, HKEY_CURRENT_USER, kPathSuffix, kMandatory)); |
588 | 588 |
589 PolicyBundle expected; | 589 PolicyBundle expected; |
590 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "int")) | 590 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "int")) |
591 .LoadFrom(&policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); | 591 .LoadFrom(&policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); |
592 EXPECT_TRUE(Matches(expected)); | 592 EXPECT_TRUE(Matches(expected)); |
593 } | 593 } |
594 | 594 |
595 TEST_F(PolicyLoaderWinTest, DefaultPropertySchemaType) { | 595 TEST_F(PolicyLoaderWinTest, DefaultPropertySchemaType) { |
596 // Build a schema for an "object" with a default schema for its properties. | 596 // Build a schema for an "object" with a default schema for its properties. |
597 base::DictionaryValue default_schema; | 597 base::DictionaryValue default_schema; |
598 default_schema.SetString(schema::kType, "number"); | 598 default_schema.SetString(schema::kType, "number"); |
599 base::DictionaryValue integer_schema; | 599 base::DictionaryValue integer_schema; |
600 integer_schema.SetString(schema::kType, "integer"); | 600 integer_schema.SetString(schema::kType, "integer"); |
601 base::DictionaryValue properties; | 601 base::DictionaryValue properties; |
602 properties.Set("special-int1", integer_schema.DeepCopy()); | 602 properties.Set("special-int1", integer_schema.DeepCopy()); |
603 properties.Set("special-int2", integer_schema.DeepCopy()); | 603 properties.Set("special-int2", integer_schema.DeepCopy()); |
604 base::DictionaryValue schema; | 604 base::DictionaryValue schema; |
605 schema.SetString(schema::kType, "object"); | 605 schema.SetString(schema::kType, "object"); |
606 schema.Set(schema::kProperties, properties.DeepCopy()); | 606 schema.Set(schema::kProperties, properties.DeepCopy()); |
607 schema.Set(schema::kAdditionalProperties, default_schema.DeepCopy()); | 607 schema.Set(schema::kAdditionalProperties, default_schema.DeepCopy()); |
608 | 608 |
609 const string16 kPathSuffix = | 609 const string16 kPathSuffix = |
610 kRegistryMandatorySubKey + ASCIIToUTF16("\\3rdparty\\extensions\\test"); | 610 kRegistryChromePolicyKey + ASCIIToUTF16("\\3rdparty\\extensions\\test"); |
611 EXPECT_TRUE(WriteSchema(schema, HKEY_CURRENT_USER, kPathSuffix, kSchema)); | 611 EXPECT_TRUE(WriteSchema(schema, HKEY_CURRENT_USER, kPathSuffix, kSchema)); |
612 | 612 |
613 // Write some test values. | 613 // Write some test values. |
614 base::DictionaryValue policy; | 614 base::DictionaryValue policy; |
615 // These special values have a specific schema for them. | 615 // These special values have a specific schema for them. |
616 policy.SetInteger("special-int1", 123); | 616 policy.SetInteger("special-int1", 123); |
617 policy.SetString("special-int2", "-456"); | 617 policy.SetString("special-int2", "-456"); |
618 // Other values default to be loaded as doubles. | 618 // Other values default to be loaded as doubles. |
619 policy.SetInteger("double1", 789.0); | 619 policy.SetInteger("double1", 789.0); |
620 policy.SetString("double2", "123.456e7"); | 620 policy.SetString("double2", "123.456e7"); |
621 policy.SetString("invalid", "omg"); | 621 policy.SetString("invalid", "omg"); |
622 EXPECT_TRUE(InstallValue(policy, HKEY_CURRENT_USER, kPathSuffix, kMandatory)); | 622 EXPECT_TRUE(InstallValue(policy, HKEY_CURRENT_USER, kPathSuffix, kMandatory)); |
623 | 623 |
624 base::DictionaryValue expected_policy; | 624 base::DictionaryValue expected_policy; |
625 expected_policy.SetInteger("special-int1", 123); | 625 expected_policy.SetInteger("special-int1", 123); |
626 expected_policy.SetInteger("special-int2", -456); | 626 expected_policy.SetInteger("special-int2", -456); |
627 expected_policy.SetDouble("double1", 789.0); | 627 expected_policy.SetDouble("double1", 789.0); |
628 expected_policy.SetDouble("double2", 123.456e7); | 628 expected_policy.SetDouble("double2", 123.456e7); |
| 629 expected_policy.Set("invalid", base::Value::CreateNullValue()); |
629 PolicyBundle expected; | 630 PolicyBundle expected; |
630 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "test")) | 631 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "test")) |
631 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); | 632 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); |
632 EXPECT_TRUE(Matches(expected)); | 633 EXPECT_TRUE(Matches(expected)); |
633 } | 634 } |
634 | 635 |
635 } // namespace policy | 636 } // namespace policy |
OLD | NEW |