| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
| 6 #include <windows.h> | 6 #include <windows.h> |
| 7 | 7 |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 TestHarness::TestHarness(HKEY hive) | 129 TestHarness::TestHarness(HKEY hive) |
| 130 : hive_(hive) {} | 130 : hive_(hive) {} |
| 131 | 131 |
| 132 TestHarness::~TestHarness() {} | 132 TestHarness::~TestHarness() {} |
| 133 | 133 |
| 134 void TestHarness::SetUp() {} | 134 void TestHarness::SetUp() {} |
| 135 | 135 |
| 136 AsynchronousPolicyProvider* TestHarness::CreateProvider( | 136 AsynchronousPolicyProvider* TestHarness::CreateProvider( |
| 137 const PolicyDefinitionList* policy_definition_list) { | 137 const PolicyDefinitionList* policy_definition_list) { |
| 138 return new ConfigurationPolicyProviderWin(policy_definition_list, | 138 return new ConfigurationPolicyProviderWin(policy_definition_list, |
| 139 policy::kRegistryMandatorySubKey); | 139 policy::kRegistryMandatorySubKey, |
| 140 POLICY_LEVEL_MANDATORY); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void TestHarness::InstallEmptyPolicy() {} | 143 void TestHarness::InstallEmptyPolicy() {} |
| 143 | 144 |
| 144 void TestHarness::InstallStringPolicy(const std::string& policy_name, | 145 void TestHarness::InstallStringPolicy(const std::string& policy_name, |
| 145 const std::string& policy_value) { | 146 const std::string& policy_value) { |
| 146 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS); | 147 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS); |
| 147 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), | 148 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), |
| 148 UTF8ToUTF16(policy_value).c_str()); | 149 UTF8ToUTF16(policy_value).c_str()); |
| 149 } | 150 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 INSTANTIATE_TEST_CASE_P( | 198 INSTANTIATE_TEST_CASE_P( |
| 198 ConfigurationPolicyProviderWinTest, | 199 ConfigurationPolicyProviderWinTest, |
| 199 ConfigurationPolicyProviderTest, | 200 ConfigurationPolicyProviderTest, |
| 200 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM)); | 201 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM)); |
| 201 | 202 |
| 202 // Test cases for windows policy provider specific functionality. | 203 // Test cases for windows policy provider specific functionality. |
| 203 class ConfigurationPolicyProviderWinTest : public AsynchronousPolicyTestBase { | 204 class ConfigurationPolicyProviderWinTest : public AsynchronousPolicyTestBase { |
| 204 protected: | 205 protected: |
| 205 ConfigurationPolicyProviderWinTest() | 206 ConfigurationPolicyProviderWinTest() |
| 206 : provider_(&test_policy_definitions::kList, | 207 : provider_(&test_policy_definitions::kList, |
| 207 policy::kRegistryMandatorySubKey) {} | 208 policy::kRegistryMandatorySubKey, |
| 209 POLICY_LEVEL_MANDATORY) {} |
| 208 virtual ~ConfigurationPolicyProviderWinTest() {} | 210 virtual ~ConfigurationPolicyProviderWinTest() {} |
| 209 | 211 |
| 210 ScopedGroupPolicyRegistrySandbox registry_sandbox_; | 212 ScopedGroupPolicyRegistrySandbox registry_sandbox_; |
| 211 ConfigurationPolicyProviderWin provider_; | 213 ConfigurationPolicyProviderWin provider_; |
| 212 }; | 214 }; |
| 213 | 215 |
| 214 TEST_F(ConfigurationPolicyProviderWinTest, HKLMOverHKCU) { | 216 TEST_F(ConfigurationPolicyProviderWinTest, HKLMOverHKCU) { |
| 215 RegKey hklm_key(HKEY_LOCAL_MACHINE, | 217 RegKey hklm_key(HKEY_LOCAL_MACHINE, |
| 216 policy::kRegistryMandatorySubKey, | 218 policy::kRegistryMandatorySubKey, |
| 217 KEY_ALL_ACCESS); | 219 KEY_ALL_ACCESS); |
| 218 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 220 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), |
| 219 UTF8ToUTF16("hklm").c_str()); | 221 UTF8ToUTF16("hklm").c_str()); |
| 220 RegKey hkcu_key(HKEY_CURRENT_USER, | 222 RegKey hkcu_key(HKEY_CURRENT_USER, |
| 221 policy::kRegistryMandatorySubKey, | 223 policy::kRegistryMandatorySubKey, |
| 222 KEY_ALL_ACCESS); | 224 KEY_ALL_ACCESS); |
| 223 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), | 225 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), |
| 224 UTF8ToUTF16("hkcu").c_str()); | 226 UTF8ToUTF16("hkcu").c_str()); |
| 225 | 227 |
| 226 provider_.RefreshPolicies(); | 228 provider_.RefreshPolicies(); |
| 227 loop_.RunAllPending(); | 229 loop_.RunAllPending(); |
| 228 | 230 |
| 229 PolicyMap policy_map; | 231 PolicyMap policy_map; |
| 230 provider_.Provide(&policy_map); | 232 provider_.Provide(&policy_map); |
| 231 const Value* value = policy_map.Get(test_policy_definitions::kPolicyString); | 233 const Value* value = policy_map.GetValue(test_policy_definitions::kKeyString); |
| 232 EXPECT_TRUE(StringValue("hklm").Equals(value)); | 234 EXPECT_TRUE(StringValue("hklm").Equals(value)); |
| 233 } | 235 } |
| 234 | 236 |
| 235 } // namespace policy | 237 } // namespace policy |
| OLD | NEW |