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

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

Issue 1902633006: Convert //components/policy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and use namespace alias Created 4 years, 8 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 (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 "components/policy/core/common/policy_loader_win.h" 5 #include "components/policy/core/common/policy_loader_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <userenv.h> 10 #include <userenv.h>
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 344 }
345 345
346 RegistryTestHarness::~RegistryTestHarness() {} 346 RegistryTestHarness::~RegistryTestHarness() {}
347 347
348 void RegistryTestHarness::SetUp() {} 348 void RegistryTestHarness::SetUp() {}
349 349
350 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider( 350 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider(
351 SchemaRegistry* registry, 351 SchemaRegistry* registry,
352 scoped_refptr<base::SequencedTaskRunner> task_runner) { 352 scoped_refptr<base::SequencedTaskRunner> task_runner) {
353 base::win::SetDomainStateForTesting(true); 353 base::win::SetDomainStateForTesting(true);
354 scoped_ptr<AsyncPolicyLoader> loader( 354 std::unique_ptr<AsyncPolicyLoader> loader(
355 new PolicyLoaderWin(task_runner, kTestPolicyKey, this)); 355 new PolicyLoaderWin(task_runner, kTestPolicyKey, this));
356 return new AsyncPolicyProvider(registry, std::move(loader)); 356 return new AsyncPolicyProvider(registry, std::move(loader));
357 } 357 }
358 358
359 void RegistryTestHarness::InstallEmptyPolicy() {} 359 void RegistryTestHarness::InstallEmptyPolicy() {}
360 360
361 void RegistryTestHarness::InstallStringPolicy( 361 void RegistryTestHarness::InstallStringPolicy(
362 const std::string& policy_name, 362 const std::string& policy_name,
363 const std::string& policy_value) { 363 const std::string& policy_value) {
364 RegKey key(hive_, kTestPolicyKey, KEY_ALL_ACCESS); 364 RegKey key(hive_, kTestPolicyKey, KEY_ALL_ACCESS);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 preg_parser::kPRegFileHeader, 477 preg_parser::kPRegFileHeader,
478 arraysize(preg_parser::kPRegFileHeader))); 478 arraysize(preg_parser::kPRegFileHeader)));
479 479
480 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT)); 480 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT));
481 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str()); 481 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str());
482 } 482 }
483 483
484 ConfigurationPolicyProvider* PRegTestHarness::CreateProvider( 484 ConfigurationPolicyProvider* PRegTestHarness::CreateProvider(
485 SchemaRegistry* registry, 485 SchemaRegistry* registry,
486 scoped_refptr<base::SequencedTaskRunner> task_runner) { 486 scoped_refptr<base::SequencedTaskRunner> task_runner) {
487 scoped_ptr<AsyncPolicyLoader> loader( 487 std::unique_ptr<AsyncPolicyLoader> loader(
488 new PolicyLoaderWin(task_runner, kTestPolicyKey, this)); 488 new PolicyLoaderWin(task_runner, kTestPolicyKey, this));
489 return new AsyncPolicyProvider(registry, std::move(loader)); 489 return new AsyncPolicyProvider(registry, std::move(loader));
490 } 490 }
491 491
492 void PRegTestHarness::InstallEmptyPolicy() {} 492 void PRegTestHarness::InstallEmptyPolicy() {}
493 493
494 void PRegTestHarness::InstallStringPolicy(const std::string& policy_name, 494 void PRegTestHarness::InstallStringPolicy(const std::string& policy_name,
495 const std::string& policy_value) { 495 const std::string& policy_value) {
496 AppendStringToPRegFile(kTestPolicyKey, policy_name, policy_value); 496 AppendStringToPRegFile(kTestPolicyKey, policy_name, policy_value);
497 } 497 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 memset(gpo, 0, sizeof(GROUP_POLICY_OBJECT)); 742 memset(gpo, 0, sizeof(GROUP_POLICY_OBJECT));
743 gpo->dwOptions = options; 743 gpo->dwOptions = options;
744 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); 744 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str());
745 gpo->pNext = next; 745 gpo->pNext = next;
746 gpo->pPrev = prev; 746 gpo->pPrev = prev;
747 } 747 }
748 748
749 bool Matches(const PolicyBundle& expected) { 749 bool Matches(const PolicyBundle& expected) {
750 PolicyLoaderWin loader(loop_.task_runner(), kTestPolicyKey, 750 PolicyLoaderWin loader(loop_.task_runner(), kTestPolicyKey,
751 gpo_list_provider_); 751 gpo_list_provider_);
752 scoped_ptr<PolicyBundle> loaded( 752 std::unique_ptr<PolicyBundle> loaded(
753 loader.InitialLoad(schema_registry_.schema_map())); 753 loader.InitialLoad(schema_registry_.schema_map()));
754 return loaded->Equals(expected); 754 return loaded->Equals(expected);
755 } 755 }
756 756
757 void InstallRegistrySentinel() { 757 void InstallRegistrySentinel() {
758 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); 758 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS);
759 ASSERT_TRUE(hklm_key.Valid()); 759 ASSERT_TRUE(hklm_key.Valid());
760 hklm_key.WriteValue( 760 hklm_key.WriteValue(
761 UTF8ToUTF16(test_keys::kKeyString).c_str(), 761 UTF8ToUTF16(test_keys::kKeyString).c_str(),
762 UTF8ToUTF16("registry").c_str()); 762 UTF8ToUTF16("registry").c_str());
763 } 763 }
764 764
765 bool MatchesRegistrySentinel() { 765 bool MatchesRegistrySentinel() {
766 base::DictionaryValue expected_policy; 766 base::DictionaryValue expected_policy;
767 expected_policy.SetString(test_keys::kKeyString, "registry"); 767 expected_policy.SetString(test_keys::kKeyString, "registry");
768 PolicyBundle expected; 768 PolicyBundle expected;
769 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 769 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
770 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 770 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
771 POLICY_SOURCE_PLATFORM); 771 POLICY_SOURCE_PLATFORM);
772 return Matches(expected); 772 return Matches(expected);
773 } 773 }
774 774
775 bool MatchesTestBundle() { 775 bool MatchesTestBundle() {
776 base::DictionaryValue expected_policy; 776 base::DictionaryValue expected_policy;
777 expected_policy.SetBoolean(test_keys::kKeyBoolean, true); 777 expected_policy.SetBoolean(test_keys::kKeyBoolean, true);
778 expected_policy.SetString(test_keys::kKeyString, "GPO"); 778 expected_policy.SetString(test_keys::kKeyString, "GPO");
779 expected_policy.SetInteger(test_keys::kKeyInteger, 42); 779 expected_policy.SetInteger(test_keys::kKeyInteger, 42);
780 scoped_ptr<base::ListValue> list(new base::ListValue()); 780 std::unique_ptr<base::ListValue> list(new base::ListValue());
781 list->AppendString("GPO 1"); 781 list->AppendString("GPO 1");
782 list->AppendString("GPO 2"); 782 list->AppendString("GPO 2");
783 expected_policy.Set(test_keys::kKeyStringList, list.release()); 783 expected_policy.Set(test_keys::kKeyStringList, list.release());
784 PolicyBundle expected; 784 PolicyBundle expected;
785 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 785 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
786 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, 786 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY,
787 POLICY_SCOPE_MACHINE, POLICY_SOURCE_PLATFORM); 787 POLICY_SCOPE_MACHINE, POLICY_SOURCE_PLATFORM);
788 return Matches(expected); 788 return Matches(expected);
789 } 789 }
790 790
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 expected_policy.Set("alternative_browser_path", 1237 expected_policy.Set("alternative_browser_path",
1238 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 1238 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
1239 POLICY_SOURCE_PLATFORM, 1239 POLICY_SOURCE_PLATFORM,
1240 new base::StringValue("c:\\legacy\\browser.exe"), NULL); 1240 new base::StringValue("c:\\legacy\\browser.exe"), NULL);
1241 expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 1241 expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
1242 POLICY_SOURCE_PLATFORM, list.DeepCopy(), nullptr); 1242 POLICY_SOURCE_PLATFORM, list.DeepCopy(), nullptr);
1243 EXPECT_TRUE(Matches(expected)); 1243 EXPECT_TRUE(Matches(expected));
1244 } 1244 }
1245 1245
1246 } // namespace policy 1246 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/policy_loader_win.cc ('k') | components/policy/core/common/policy_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698