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

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: Fix win build 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
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/configuration_policy_provider_test.h" 14 #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" 15 #include "chrome/browser/policy/policy_bundle.h"
17 #include "chrome/browser/policy/policy_map.h" 16 #include "chrome/browser/policy/policy_map.h"
18 #include "policy/policy_constants.h" 17 #include "policy/policy_constants.h"
19 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
20 19
21 using base::win::RegKey; 20 using base::win::RegKey;
22 21
23 namespace policy { 22 namespace policy {
24 23
25 namespace { 24 namespace {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 133
135 TestHarness::TestHarness(HKEY hive, PolicyScope scope) 134 TestHarness::TestHarness(HKEY hive, PolicyScope scope)
136 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {} 135 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {}
137 136
138 TestHarness::~TestHarness() {} 137 TestHarness::~TestHarness() {}
139 138
140 void TestHarness::SetUp() {} 139 void TestHarness::SetUp() {}
141 140
142 ConfigurationPolicyProvider* TestHarness::CreateProvider( 141 ConfigurationPolicyProvider* TestHarness::CreateProvider(
143 const PolicyDefinitionList* policy_definition_list) { 142 const PolicyDefinitionList* policy_definition_list) {
144 return new ConfigurationPolicyProviderWin(policy_definition_list); 143 return WinPolicyLoader::CreateProvider(policy_definition_list);
145 } 144 }
146 145
147 void TestHarness::InstallEmptyPolicy() {} 146 void TestHarness::InstallEmptyPolicy() {}
148 147
149 void TestHarness::InstallStringPolicy(const std::string& policy_name, 148 void TestHarness::InstallStringPolicy(const std::string& policy_name,
150 const std::string& policy_value) { 149 const std::string& policy_value) {
151 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS); 150 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS);
152 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), 151 key.WriteValue(UTF8ToUTF16(policy_name).c_str(),
153 UTF8ToUTF16(policy_value).c_str()); 152 UTF8ToUTF16(policy_value).c_str());
154 } 153 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 202
204 // static 203 // static
205 PolicyProviderTestHarness* TestHarness::CreateHKLM() { 204 PolicyProviderTestHarness* TestHarness::CreateHKLM() {
206 return new TestHarness(HKEY_LOCAL_MACHINE, POLICY_SCOPE_MACHINE); 205 return new TestHarness(HKEY_LOCAL_MACHINE, POLICY_SCOPE_MACHINE);
207 } 206 }
208 207
209 } // namespace 208 } // namespace
210 209
211 // Instantiate abstract test case for basic policy reading tests. 210 // Instantiate abstract test case for basic policy reading tests.
212 INSTANTIATE_TEST_CASE_P( 211 INSTANTIATE_TEST_CASE_P(
213 ConfigurationPolicyProviderWinTest, 212 WinPolicyLoaderTest,
214 ConfigurationPolicyProviderTest, 213 ConfigurationPolicyProviderTest,
215 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM)); 214 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM));
216 215
217 // Test cases for windows policy provider specific functionality. 216 // Test cases for windows policy provider specific functionality.
218 class ConfigurationPolicyProviderWinTest : public AsynchronousPolicyTestBase { 217 class WinPolicyLoaderTest : public PolicyTestBase {
Mattias Nissler (ping if slow) 2012/06/04 09:29:41 same comment as for mac regarding clashing test na
Joao da Silva 2012/06/06 13:05:24 Done.
219 protected: 218 protected:
220 ConfigurationPolicyProviderWinTest() 219 WinPolicyLoaderTest() {}
221 : provider_(&test_policy_definitions::kList) {} 220 virtual ~WinPolicyLoaderTest() {}
222 virtual ~ConfigurationPolicyProviderWinTest() {}
223 221
224 ScopedGroupPolicyRegistrySandbox registry_sandbox_; 222 ScopedGroupPolicyRegistrySandbox registry_sandbox_;
225 ConfigurationPolicyProviderWin provider_;
226 }; 223 };
227 224
228 TEST_F(ConfigurationPolicyProviderWinTest, HKLMOverHKCU) { 225 TEST_F(WinPolicyLoaderTest, HKLMOverHKCU) {
229 RegKey hklm_key(HKEY_LOCAL_MACHINE, 226 RegKey hklm_key(HKEY_LOCAL_MACHINE,
230 policy::kRegistryMandatorySubKey, 227 policy::kRegistryMandatorySubKey,
231 KEY_ALL_ACCESS); 228 KEY_ALL_ACCESS);
232 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), 229 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(),
233 UTF8ToUTF16("hklm").c_str()); 230 UTF8ToUTF16("hklm").c_str());
234 RegKey hkcu_key(HKEY_CURRENT_USER, 231 RegKey hkcu_key(HKEY_CURRENT_USER,
235 policy::kRegistryMandatorySubKey, 232 policy::kRegistryMandatorySubKey,
236 KEY_ALL_ACCESS); 233 KEY_ALL_ACCESS);
237 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), 234 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(),
238 UTF8ToUTF16("hkcu").c_str()); 235 UTF8ToUTF16("hkcu").c_str());
239 236
240 provider_.RefreshPolicies(); 237 scoped_ptr<AsyncPolicyProvider> provider_(
238 WinPolicyLoader::CreateProvider(&test_policy_definitions::kList));
239 provider_->RefreshPolicies();
241 loop_.RunAllPending(); 240 loop_.RunAllPending();
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(provider_->policies().Equals(expected_bundle));
250 } 249 }
251 250
252 } // namespace policy 251 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698