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

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

Issue 10384145: Removed ConfigurationPolicyProvider::Provide(). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased Created 8 years, 7 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 <gtest/gtest.h>
6 #include <windows.h> 6 #include <windows.h>
7 7
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "base/win/registry.h" 12 #include "base/win/registry.h"
13 #include "chrome/browser/policy/asynchronous_policy_test_base.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" 15 #include "chrome/browser/policy/configuration_policy_provider_win.h"
16 #include "chrome/browser/policy/policy_bundle.h"
16 #include "chrome/browser/policy/policy_map.h" 17 #include "chrome/browser/policy/policy_map.h"
17 #include "policy/policy_constants.h" 18 #include "policy/policy_constants.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 using base::win::RegKey; 21 using base::win::RegKey;
21 22
22 namespace policy { 23 namespace policy {
23 24
24 namespace { 25 namespace {
25 26
(...skipping 25 matching lines...) Expand all
51 // Keys are created for the lifetime of a test to contain 52 // Keys are created for the lifetime of a test to contain
52 // the sandboxed HKCU and HKLM hives, respectively. 53 // the sandboxed HKCU and HKLM hives, respectively.
53 RegKey temp_hkcu_hive_key_; 54 RegKey temp_hkcu_hive_key_;
54 RegKey temp_hklm_hive_key_; 55 RegKey temp_hklm_hive_key_;
55 56
56 DISALLOW_COPY_AND_ASSIGN(ScopedGroupPolicyRegistrySandbox); 57 DISALLOW_COPY_AND_ASSIGN(ScopedGroupPolicyRegistrySandbox);
57 }; 58 };
58 59
59 class TestHarness : public PolicyProviderTestHarness { 60 class TestHarness : public PolicyProviderTestHarness {
60 public: 61 public:
61 explicit TestHarness(HKEY hive); 62 explicit TestHarness(HKEY hive, PolicyScope scope);
62 virtual ~TestHarness(); 63 virtual ~TestHarness();
63 64
64 virtual void SetUp() OVERRIDE; 65 virtual void SetUp() OVERRIDE;
65 66
66 virtual AsynchronousPolicyProvider* CreateProvider( 67 virtual AsynchronousPolicyProvider* CreateProvider(
67 const PolicyDefinitionList* policy_definition_list) OVERRIDE; 68 const PolicyDefinitionList* policy_definition_list) OVERRIDE;
68 69
69 virtual void InstallEmptyPolicy() OVERRIDE; 70 virtual void InstallEmptyPolicy() OVERRIDE;
70 virtual void InstallStringPolicy(const std::string& policy_name, 71 virtual void InstallStringPolicy(const std::string& policy_name,
71 const std::string& policy_value) OVERRIDE; 72 const std::string& policy_value) OVERRIDE;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 void ScopedGroupPolicyRegistrySandbox::RemoveOverrides() { 125 void ScopedGroupPolicyRegistrySandbox::RemoveOverrides() {
125 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_LOCAL_MACHINE, 0)); 126 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_LOCAL_MACHINE, 0));
126 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_CURRENT_USER, 0)); 127 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_CURRENT_USER, 0));
127 } 128 }
128 129
129 void ScopedGroupPolicyRegistrySandbox::DeleteKeys() { 130 void ScopedGroupPolicyRegistrySandbox::DeleteKeys() {
130 RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, KEY_ALL_ACCESS); 131 RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, KEY_ALL_ACCESS);
131 key.DeleteKey(L""); 132 key.DeleteKey(L"");
132 } 133 }
133 134
134 TestHarness::TestHarness(HKEY hive) 135 TestHarness::TestHarness(HKEY hive, PolicyScope scope)
135 : hive_(hive) {} 136 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, scope), hive_(hive) {}
136 137
137 TestHarness::~TestHarness() {} 138 TestHarness::~TestHarness() {}
138 139
139 void TestHarness::SetUp() {} 140 void TestHarness::SetUp() {}
140 141
141 AsynchronousPolicyProvider* TestHarness::CreateProvider( 142 AsynchronousPolicyProvider* TestHarness::CreateProvider(
142 const PolicyDefinitionList* policy_definition_list) { 143 const PolicyDefinitionList* policy_definition_list) {
143 return new ConfigurationPolicyProviderWin(policy_definition_list, 144 return new ConfigurationPolicyProviderWin(policy_definition_list,
144 policy::kRegistryMandatorySubKey, 145 policy::kRegistryMandatorySubKey,
145 POLICY_LEVEL_MANDATORY); 146 POLICY_LEVEL_MANDATORY);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 const base::DictionaryValue* policy_value) { 193 const base::DictionaryValue* policy_value) {
193 std::string json; 194 std::string json;
194 base::JSONWriter::Write(policy_value, &json); 195 base::JSONWriter::Write(policy_value, &json);
195 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS); 196 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS);
196 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), 197 key.WriteValue(UTF8ToUTF16(policy_name).c_str(),
197 UTF8ToUTF16(json).c_str()); 198 UTF8ToUTF16(json).c_str());
198 } 199 }
199 200
200 // static 201 // static
201 PolicyProviderTestHarness* TestHarness::CreateHKCU() { 202 PolicyProviderTestHarness* TestHarness::CreateHKCU() {
202 return new TestHarness(HKEY_CURRENT_USER); 203 return new TestHarness(HKEY_CURRENT_USER, POLICY_SCOPE_USER);
203 } 204 }
204 205
205 // static 206 // static
206 PolicyProviderTestHarness* TestHarness::CreateHKLM() { 207 PolicyProviderTestHarness* TestHarness::CreateHKLM() {
207 return new TestHarness(HKEY_LOCAL_MACHINE); 208 return new TestHarness(HKEY_LOCAL_MACHINE, POLICY_SCOPE_MACHINE);
208 } 209 }
209 210
210 } // namespace 211 } // namespace
211 212
212 // Instantiate abstract test case for basic policy reading tests. 213 // Instantiate abstract test case for basic policy reading tests.
213 INSTANTIATE_TEST_CASE_P( 214 INSTANTIATE_TEST_CASE_P(
214 ConfigurationPolicyProviderWinTest, 215 ConfigurationPolicyProviderWinTest,
215 ConfigurationPolicyProviderTest, 216 ConfigurationPolicyProviderTest,
216 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM)); 217 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM));
217 218
(...skipping 18 matching lines...) Expand all
236 UTF8ToUTF16("hklm").c_str()); 237 UTF8ToUTF16("hklm").c_str());
237 RegKey hkcu_key(HKEY_CURRENT_USER, 238 RegKey hkcu_key(HKEY_CURRENT_USER,
238 policy::kRegistryMandatorySubKey, 239 policy::kRegistryMandatorySubKey,
239 KEY_ALL_ACCESS); 240 KEY_ALL_ACCESS);
240 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), 241 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(),
241 UTF8ToUTF16("hkcu").c_str()); 242 UTF8ToUTF16("hkcu").c_str());
242 243
243 provider_.RefreshPolicies(); 244 provider_.RefreshPolicies();
244 loop_.RunAllPending(); 245 loop_.RunAllPending();
245 246
246 PolicyMap policy_map; 247 PolicyBundle expected_bundle;
247 provider_.Provide(&policy_map); 248 expected_bundle.Get(POLICY_DOMAIN_CHROME, "")
248 const base::Value* value = 249 .Set(test_policy_definitions::kKeyString,
249 policy_map.GetValue(test_policy_definitions::kKeyString); 250 POLICY_LEVEL_MANDATORY,
250 EXPECT_TRUE(base::StringValue("hklm").Equals(value)); 251 POLICY_SCOPE_MACHINE,
252 base::Value::CreateStringValue("hklm"));
253 EXPECT_TRUE(provider_.policies().Equals(expected_bundle));
251 } 254 }
252 255
253 } // namespace policy 256 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_provider_test.cc ('k') | chrome/browser/policy/file_based_policy_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698