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 <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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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"); |
804 | |
805 // Unknown components will be filtered out. Register their names with an | |
806 // invalid schema to avoid that. | |
807 ComponentMap components; | |
bartfab (slow)
2013/11/08 13:50:17
Nit: #include "chrome/browser/policy/schema_map.h"
Joao da Silva
2013/11/08 14:18:46
Done.
| |
808 components["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] = Schema(); | |
809 components["bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"] = Schema(); | |
810 components["int"] = Schema(); | |
811 components["merge"] = Schema(); | |
812 components["string"] = Schema(); | |
813 components["test"] = Schema(); | |
814 schema_registry_.RegisterComponents(POLICY_DOMAIN_EXTENSIONS, components); | |
798 } | 815 } |
799 | 816 |
800 // AppliedGPOListProvider: | 817 // AppliedGPOListProvider: |
801 virtual DWORD GetAppliedGPOList(DWORD flags, | 818 virtual DWORD GetAppliedGPOList(DWORD flags, |
802 LPCTSTR machine_name, | 819 LPCTSTR machine_name, |
803 PSID sid_user, | 820 PSID sid_user, |
804 GUID* extension_guid, | 821 GUID* extension_guid, |
805 PGROUP_POLICY_OBJECT* gpo_list) OVERRIDE { | 822 PGROUP_POLICY_OBJECT* gpo_list) OVERRIDE { |
806 *gpo_list = gpo_list_; | 823 *gpo_list = gpo_list_; |
807 return gpo_list_status_; | 824 return gpo_list_status_; |
(...skipping 11 matching lines...) Expand all Loading... | |
819 gpo->dwOptions = options; | 836 gpo->dwOptions = options; |
820 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); | 837 gpo->lpFileSysPath = const_cast<wchar_t*>(path.value().c_str()); |
821 gpo->pNext = next; | 838 gpo->pNext = next; |
822 gpo->pPrev = prev; | 839 gpo->pPrev = prev; |
823 } | 840 } |
824 | 841 |
825 bool Matches(const PolicyBundle& expected) { | 842 bool Matches(const PolicyBundle& expected) { |
826 PolicyLoaderWin loader(loop_.message_loop_proxy(), | 843 PolicyLoaderWin loader(loop_.message_loop_proxy(), |
827 &test_policy_definitions::kList, kTestPolicyKey, | 844 &test_policy_definitions::kList, kTestPolicyKey, |
828 this); | 845 this); |
829 scoped_ptr<PolicyBundle> loaded(loader.Load()); | 846 scoped_ptr<PolicyBundle> loaded( |
847 loader.InitialLoad(schema_registry_.schema_map())); | |
830 return loaded->Equals(expected); | 848 return loaded->Equals(expected); |
831 } | 849 } |
832 | 850 |
833 void InstallRegistrySentinel() { | 851 void InstallRegistrySentinel() { |
834 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); | 852 RegKey hklm_key(HKEY_CURRENT_USER, kTestPolicyKey, KEY_ALL_ACCESS); |
835 ASSERT_TRUE(hklm_key.Valid()); | 853 ASSERT_TRUE(hklm_key.Valid()); |
836 hklm_key.WriteValue( | 854 hklm_key.WriteValue( |
837 UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 855 UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), |
838 UTF8ToUTF16("registry").c_str()); | 856 UTF8ToUTF16("registry").c_str()); |
839 } | 857 } |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1197 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); | 1215 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
1198 base::DictionaryValue expected_b; | 1216 base::DictionaryValue expected_b; |
1199 expected_b.SetInteger("policy 1", 2); | 1217 expected_b.SetInteger("policy 1", 2); |
1200 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 1218 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
1201 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 1219 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
1202 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); | 1220 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
1203 EXPECT_TRUE(Matches(expected)); | 1221 EXPECT_TRUE(Matches(expected)); |
1204 } | 1222 } |
1205 | 1223 |
1206 } // namespace policy | 1224 } // namespace policy |
OLD | NEW |