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

Side by Side Diff: chrome/browser/policy/policy_loader_win_unittest.cc

Issue 56623005: Policy providers all get a SchemaRegistry to work with. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-9-purge-with-callback
Patch Set: Fixed mac tests Created 7 years, 1 month 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 "chrome/browser/policy/policy_loader_win.h" 5 #include "chrome/browser/policy/policy_loader_win.h"
6 6
7 #include <userenv.h> 7 #include <userenv.h>
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 class RegistryTestHarness : public PolicyProviderTestHarness, 245 class RegistryTestHarness : public PolicyProviderTestHarness,
246 public AppliedGPOListProvider { 246 public AppliedGPOListProvider {
247 public: 247 public:
248 RegistryTestHarness(HKEY hive, PolicyScope scope); 248 RegistryTestHarness(HKEY hive, PolicyScope scope);
249 virtual ~RegistryTestHarness(); 249 virtual ~RegistryTestHarness();
250 250
251 // PolicyProviderTestHarness: 251 // PolicyProviderTestHarness:
252 virtual void SetUp() OVERRIDE; 252 virtual void SetUp() OVERRIDE;
253 253
254 virtual ConfigurationPolicyProvider* CreateProvider( 254 virtual ConfigurationPolicyProvider* CreateProvider(
255 SchemaRegistry* registry,
255 scoped_refptr<base::SequencedTaskRunner> task_runner, 256 scoped_refptr<base::SequencedTaskRunner> task_runner,
256 const PolicyDefinitionList* policy_list) OVERRIDE; 257 const PolicyDefinitionList* policy_list) OVERRIDE;
257 258
258 virtual void InstallEmptyPolicy() OVERRIDE; 259 virtual void InstallEmptyPolicy() OVERRIDE;
259 virtual void InstallStringPolicy(const std::string& policy_name, 260 virtual void InstallStringPolicy(const std::string& policy_name,
260 const std::string& policy_value) OVERRIDE; 261 const std::string& policy_value) OVERRIDE;
261 virtual void InstallIntegerPolicy(const std::string& policy_name, 262 virtual void InstallIntegerPolicy(const std::string& policy_name,
262 int policy_value) OVERRIDE; 263 int policy_value) OVERRIDE;
263 virtual void InstallBooleanPolicy(const std::string& policy_name, 264 virtual void InstallBooleanPolicy(const std::string& policy_name,
264 bool policy_value) OVERRIDE; 265 bool policy_value) OVERRIDE;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 class PRegTestHarness : public PolicyProviderTestHarness, 297 class PRegTestHarness : public PolicyProviderTestHarness,
297 public AppliedGPOListProvider { 298 public AppliedGPOListProvider {
298 public: 299 public:
299 PRegTestHarness(); 300 PRegTestHarness();
300 virtual ~PRegTestHarness(); 301 virtual ~PRegTestHarness();
301 302
302 // PolicyProviderTestHarness: 303 // PolicyProviderTestHarness:
303 virtual void SetUp() OVERRIDE; 304 virtual void SetUp() OVERRIDE;
304 305
305 virtual ConfigurationPolicyProvider* CreateProvider( 306 virtual ConfigurationPolicyProvider* CreateProvider(
307 SchemaRegistry* registry,
306 scoped_refptr<base::SequencedTaskRunner> task_runner, 308 scoped_refptr<base::SequencedTaskRunner> task_runner,
307 const PolicyDefinitionList* policy_list) OVERRIDE; 309 const PolicyDefinitionList* policy_list) OVERRIDE;
308 310
309 virtual void InstallEmptyPolicy() OVERRIDE; 311 virtual void InstallEmptyPolicy() OVERRIDE;
310 virtual void InstallStringPolicy(const std::string& policy_name, 312 virtual void InstallStringPolicy(const std::string& policy_name,
311 const std::string& policy_value) OVERRIDE; 313 const std::string& policy_value) OVERRIDE;
312 virtual void InstallIntegerPolicy(const std::string& policy_name, 314 virtual void InstallIntegerPolicy(const std::string& policy_name,
313 int policy_value) OVERRIDE; 315 int policy_value) OVERRIDE;
314 virtual void InstallBooleanPolicy(const std::string& policy_name, 316 virtual void InstallBooleanPolicy(const std::string& policy_name,
315 bool policy_value) OVERRIDE; 317 bool policy_value) OVERRIDE;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 } 415 }
414 416
415 RegistryTestHarness::RegistryTestHarness(HKEY hive, PolicyScope scope) 417 RegistryTestHarness::RegistryTestHarness(HKEY hive, PolicyScope scope)
416 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {} 418 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {}
417 419
418 RegistryTestHarness::~RegistryTestHarness() {} 420 RegistryTestHarness::~RegistryTestHarness() {}
419 421
420 void RegistryTestHarness::SetUp() {} 422 void RegistryTestHarness::SetUp() {}
421 423
422 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider( 424 ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider(
425 SchemaRegistry* registry,
423 scoped_refptr<base::SequencedTaskRunner> task_runner, 426 scoped_refptr<base::SequencedTaskRunner> task_runner,
424 const PolicyDefinitionList* policy_list) { 427 const PolicyDefinitionList* policy_list) {
425 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin( 428 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(
426 task_runner, policy_list, kRegistryChromePolicyKey, this)); 429 task_runner, policy_list, kRegistryChromePolicyKey, this));
427 return new AsyncPolicyProvider(loader.Pass()); 430 return new AsyncPolicyProvider(registry, loader.Pass());
428 } 431 }
429 432
430 void RegistryTestHarness::InstallEmptyPolicy() {} 433 void RegistryTestHarness::InstallEmptyPolicy() {}
431 434
432 void RegistryTestHarness::InstallStringPolicy( 435 void RegistryTestHarness::InstallStringPolicy(
433 const std::string& policy_name, 436 const std::string& policy_name,
434 const std::string& policy_value) { 437 const std::string& policy_value) {
435 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS); 438 RegKey key(hive_, kRegistryChromePolicyKey, KEY_ALL_ACCESS);
436 ASSERT_TRUE(key.Valid()); 439 ASSERT_TRUE(key.Valid());
437 ASSERT_HRESULT_SUCCEEDED(key.WriteValue(UTF8ToUTF16(policy_name).c_str(), 440 ASSERT_HRESULT_SUCCEEDED(key.WriteValue(UTF8ToUTF16(policy_name).c_str(),
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 preg_file_path_ = temp_dir_.path().Append(PolicyLoaderWin::kPRegFileName); 548 preg_file_path_ = temp_dir_.path().Append(PolicyLoaderWin::kPRegFileName);
546 ASSERT_TRUE(file_util::WriteFile(preg_file_path_, 549 ASSERT_TRUE(file_util::WriteFile(preg_file_path_,
547 preg_parser::kPRegFileHeader, 550 preg_parser::kPRegFileHeader,
548 arraysize(preg_parser::kPRegFileHeader))); 551 arraysize(preg_parser::kPRegFileHeader)));
549 552
550 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT)); 553 memset(&gpo_, 0, sizeof(GROUP_POLICY_OBJECT));
551 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str()); 554 gpo_.lpFileSysPath = const_cast<wchar_t*>(temp_dir_.path().value().c_str());
552 } 555 }
553 556
554 ConfigurationPolicyProvider* PRegTestHarness::CreateProvider( 557 ConfigurationPolicyProvider* PRegTestHarness::CreateProvider(
558 SchemaRegistry* registry,
555 scoped_refptr<base::SequencedTaskRunner> task_runner, 559 scoped_refptr<base::SequencedTaskRunner> task_runner,
556 const PolicyDefinitionList* policy_list) { 560 const PolicyDefinitionList* policy_list) {
557 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin( 561 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(
558 task_runner, policy_list, kRegistryChromePolicyKey, this)); 562 task_runner, policy_list, kRegistryChromePolicyKey, this));
559 return new AsyncPolicyProvider(loader.Pass()); 563 return new AsyncPolicyProvider(registry, loader.Pass());
560 } 564 }
561 565
562 void PRegTestHarness::InstallEmptyPolicy() {} 566 void PRegTestHarness::InstallEmptyPolicy() {}
563 567
564 void PRegTestHarness::InstallStringPolicy(const std::string& policy_name, 568 void PRegTestHarness::InstallStringPolicy(const std::string& policy_name,
565 const std::string& policy_value) { 569 const std::string& policy_value) {
566 AppendStringToPRegFile(kRegistryChromePolicyKey, policy_name, policy_value); 570 AppendStringToPRegFile(kRegistryChromePolicyKey, policy_name, policy_value);
567 } 571 }
568 572
569 void PRegTestHarness::InstallIntegerPolicy(const std::string& policy_name, 573 void PRegTestHarness::InstallIntegerPolicy(const std::string& policy_name,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 // The policy key this tests places data under. This must match the data 786 // The policy key this tests places data under. This must match the data
783 // files in chrome/test/data/policy/gpo. 787 // files in chrome/test/data/policy/gpo.
784 static const char16 kTestPolicyKey[]; 788 static const char16 kTestPolicyKey[];
785 789
786 PolicyLoaderWinTest() 790 PolicyLoaderWinTest()
787 : gpo_list_(NULL), 791 : gpo_list_(NULL),
788 gpo_list_status_(ERROR_ACCESS_DENIED) {} 792 gpo_list_status_(ERROR_ACCESS_DENIED) {}
789 virtual ~PolicyLoaderWinTest() {} 793 virtual ~PolicyLoaderWinTest() {}
790 794
791 virtual void SetUp() OVERRIDE { 795 virtual void SetUp() OVERRIDE {
796 PolicyTestBase::SetUp();
797
792 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_)); 798 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_));
793 test_data_dir_ = test_data_dir_.AppendASCII("chrome") 799 test_data_dir_ = test_data_dir_.AppendASCII("chrome")
794 .AppendASCII("test") 800 .AppendASCII("test")
795 .AppendASCII("data") 801 .AppendASCII("data")
796 .AppendASCII("policy") 802 .AppendASCII("policy")
797 .AppendASCII("gpo"); 803 .AppendASCII("gpo");
798 } 804 }
799 805
800 // AppliedGPOListProvider: 806 // AppliedGPOListProvider:
801 virtual DWORD GetAppliedGPOList(DWORD flags, 807 virtual DWORD GetAppliedGPOList(DWORD flags,
(...skipping 17 matching lines...) Expand all
819 gpo->dwOptions = options; 825 gpo->dwOptions = options;
820 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); 826 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str());
821 gpo->pNext = next; 827 gpo->pNext = next;
822 gpo->pPrev = prev; 828 gpo->pPrev = prev;
823 } 829 }
824 830
825 bool Matches(const PolicyBundle& expected) { 831 bool Matches(const PolicyBundle& expected) {
826 PolicyLoaderWin loader(loop_.message_loop_proxy(), 832 PolicyLoaderWin loader(loop_.message_loop_proxy(),
827 &test_policy_definitions::kList, kTestPolicyKey, 833 &test_policy_definitions::kList, kTestPolicyKey,
828 this); 834 this);
829 scoped_ptr<PolicyBundle> loaded(loader.Load()); 835 scoped_ptr<PolicyBundle> loaded(
836 loader.InitialLoad(schema_registry_.schema_map()));
830 return loaded->Equals(expected); 837 return loaded->Equals(expected);
831 } 838 }
832 839
833 void InstallRegistrySentinel() { 840 void InstallRegistrySentinel() {
834 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); 841 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS);
835 ASSERT_TRUE(hklm_key.Valid()); 842 ASSERT_TRUE(hklm_key.Valid());
836 hklm_key.WriteValue( 843 hklm_key.WriteValue(
837 UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), 844 UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(),
838 UTF8ToUTF16("registry").c_str()); 845 UTF8ToUTF16("registry").c_str());
839 } 846 }
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); 1204 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE);
1198 base::DictionaryValue expected_b; 1205 base::DictionaryValue expected_b;
1199 expected_b.SetInteger("policy 1", 2); 1206 expected_b.SetInteger("policy 1", 2);
1200 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 1207 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
1201 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) 1208 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
1202 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); 1209 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE);
1203 EXPECT_TRUE(Matches(expected)); 1210 EXPECT_TRUE(Matches(expected));
1204 } 1211 }
1205 1212
1206 } // namespace policy 1213 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698