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

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

Issue 10491013: Implement the windows policy provider based on the AsyncPolicyLoader. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed comment Created 8 years, 6 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
« no previous file with comments | « chrome/browser/policy/policy_loader_win.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <gtest/gtest.h> 5 #include "chrome/browser/policy/policy_loader_win.h"
6
6 #include <windows.h> 7 #include <windows.h>
7 8
8 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
9 #include "base/string16.h" 10 #include "base/string16.h"
10 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "base/win/registry.h" 13 #include "base/win/registry.h"
13 #include "chrome/browser/policy/asynchronous_policy_test_base.h" 14 #include "chrome/browser/policy/async_policy_provider.h"
14 #include "chrome/browser/policy/configuration_policy_provider_test.h" 15 #include "chrome/browser/policy/configuration_policy_provider_test.h"
15 #include "chrome/browser/policy/configuration_policy_provider_win.h"
16 #include "chrome/browser/policy/policy_bundle.h" 16 #include "chrome/browser/policy/policy_bundle.h"
17 #include "chrome/browser/policy/policy_map.h" 17 #include "chrome/browser/policy/policy_map.h"
18 #include "policy/policy_constants.h" 18 #include "policy/policy_constants.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 using base::win::RegKey; 21 using base::win::RegKey;
22 22
23 namespace policy { 23 namespace policy {
24 24
25 namespace { 25 namespace {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 133 }
134 134
135 TestHarness::TestHarness(HKEY hive, PolicyScope scope) 135 TestHarness::TestHarness(HKEY hive, PolicyScope scope)
136 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {} 136 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {}
137 137
138 TestHarness::~TestHarness() {} 138 TestHarness::~TestHarness() {}
139 139
140 void TestHarness::SetUp() {} 140 void TestHarness::SetUp() {}
141 141
142 ConfigurationPolicyProvider* TestHarness::CreateProvider( 142 ConfigurationPolicyProvider* TestHarness::CreateProvider(
143 const PolicyDefinitionList* policy_definition_list) { 143 const PolicyDefinitionList* policy_list) {
144 return new ConfigurationPolicyProviderWin(policy_definition_list); 144 scoped_ptr<AsyncPolicyLoader> loader(new PolicyLoaderWin(policy_list));
145 return new AsyncPolicyProvider(policy_list, loader.Pass());
145 } 146 }
146 147
147 void TestHarness::InstallEmptyPolicy() {} 148 void TestHarness::InstallEmptyPolicy() {}
148 149
149 void TestHarness::InstallStringPolicy(const std::string& policy_name, 150 void TestHarness::InstallStringPolicy(const std::string& policy_name,
150 const std::string& policy_value) { 151 const std::string& policy_value) {
151 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS); 152 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS);
152 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), 153 key.WriteValue(UTF8ToUTF16(policy_name).c_str(),
153 UTF8ToUTF16(policy_value).c_str()); 154 UTF8ToUTF16(policy_value).c_str());
154 } 155 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 204
204 // static 205 // static
205 PolicyProviderTestHarness* TestHarness::CreateHKLM() { 206 PolicyProviderTestHarness* TestHarness::CreateHKLM() {
206 return new TestHarness(HKEY_LOCAL_MACHINE, POLICY_SCOPE_MACHINE); 207 return new TestHarness(HKEY_LOCAL_MACHINE, POLICY_SCOPE_MACHINE);
207 } 208 }
208 209
209 } // namespace 210 } // namespace
210 211
211 // Instantiate abstract test case for basic policy reading tests. 212 // Instantiate abstract test case for basic policy reading tests.
212 INSTANTIATE_TEST_CASE_P( 213 INSTANTIATE_TEST_CASE_P(
213 ConfigurationPolicyProviderWinTest, 214 PolicyProviderWinTest,
214 ConfigurationPolicyProviderTest, 215 ConfigurationPolicyProviderTest,
215 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM)); 216 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM));
216 217
217 // Test cases for windows policy provider specific functionality. 218 // Test cases for windows policy provider specific functionality.
218 class ConfigurationPolicyProviderWinTest : public AsynchronousPolicyTestBase { 219 class PolicyLoaderWinTest : public PolicyTestBase {
219 protected: 220 protected:
220 ConfigurationPolicyProviderWinTest() 221 PolicyLoaderWinTest() {}
221 : provider_(&test_policy_definitions::kList) {} 222 virtual ~PolicyLoaderWinTest() {}
222 virtual ~ConfigurationPolicyProviderWinTest() {}
223 223
224 ScopedGroupPolicyRegistrySandbox registry_sandbox_; 224 ScopedGroupPolicyRegistrySandbox registry_sandbox_;
225 ConfigurationPolicyProviderWin provider_;
226 }; 225 };
227 226
228 TEST_F(ConfigurationPolicyProviderWinTest, HKLMOverHKCU) { 227 TEST_F(PolicyLoaderWinTest, HKLMOverHKCU) {
229 RegKey hklm_key(HKEY_LOCAL_MACHINE, 228 RegKey hklm_key(HKEY_LOCAL_MACHINE,
230 policy::kRegistryMandatorySubKey, 229 policy::kRegistryMandatorySubKey,
231 KEY_ALL_ACCESS); 230 KEY_ALL_ACCESS);
232 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), 231 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(),
233 UTF8ToUTF16("hklm").c_str()); 232 UTF8ToUTF16("hklm").c_str());
234 RegKey hkcu_key(HKEY_CURRENT_USER, 233 RegKey hkcu_key(HKEY_CURRENT_USER,
235 policy::kRegistryMandatorySubKey, 234 policy::kRegistryMandatorySubKey,
236 KEY_ALL_ACCESS); 235 KEY_ALL_ACCESS);
237 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), 236 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(),
238 UTF8ToUTF16("hkcu").c_str()); 237 UTF8ToUTF16("hkcu").c_str());
239 238
240 provider_.RefreshPolicies(); 239 PolicyLoaderWin loader(&test_policy_definitions::kList);
241 loop_.RunAllPending(); 240 scoped_ptr<PolicyBundle> bundle(loader.Load());
242 241
243 PolicyBundle expected_bundle; 242 PolicyBundle expected_bundle;
244 expected_bundle.Get(POLICY_DOMAIN_CHROME, "") 243 expected_bundle.Get(POLICY_DOMAIN_CHROME, "")
245 .Set(test_policy_definitions::kKeyString, 244 .Set(test_policy_definitions::kKeyString,
246 POLICY_LEVEL_MANDATORY, 245 POLICY_LEVEL_MANDATORY,
247 POLICY_SCOPE_MACHINE, 246 POLICY_SCOPE_MACHINE,
248 base::Value::CreateStringValue("hklm")); 247 base::Value::CreateStringValue("hklm"));
249 EXPECT_TRUE(provider_.policies().Equals(expected_bundle)); 248 EXPECT_TRUE(bundle->Equals(expected_bundle));
250 } 249 }
251 250
252 } // namespace policy 251 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_loader_win.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698