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

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
70 virtual PolicyLevel GetPolicyLevel() const OVERRIDE;
71 virtual PolicyScope GetPolicyScope() const OVERRIDE;
72
69 virtual void InstallEmptyPolicy() OVERRIDE; 73 virtual void InstallEmptyPolicy() OVERRIDE;
70 virtual void InstallStringPolicy(const std::string& policy_name, 74 virtual void InstallStringPolicy(const std::string& policy_name,
71 const std::string& policy_value) OVERRIDE; 75 const std::string& policy_value) OVERRIDE;
72 virtual void InstallIntegerPolicy(const std::string& policy_name, 76 virtual void InstallIntegerPolicy(const std::string& policy_name,
73 int policy_value) OVERRIDE; 77 int policy_value) OVERRIDE;
74 virtual void InstallBooleanPolicy(const std::string& policy_name, 78 virtual void InstallBooleanPolicy(const std::string& policy_name,
75 bool policy_value) OVERRIDE; 79 bool policy_value) OVERRIDE;
76 virtual void InstallStringListPolicy( 80 virtual void InstallStringListPolicy(
77 const std::string& policy_name, 81 const std::string& policy_name,
78 const base::ListValue* policy_value) OVERRIDE; 82 const base::ListValue* policy_value) OVERRIDE;
79 virtual void InstallDictionaryPolicy( 83 virtual void InstallDictionaryPolicy(
80 const std::string& policy_name, 84 const std::string& policy_name,
81 const base::DictionaryValue* policy_value) OVERRIDE; 85 const base::DictionaryValue* policy_value) OVERRIDE;
82 86
83 // Creates a harness instance that will install policy in HKCU or HKLM, 87 // Creates a harness instance that will install policy in HKCU or HKLM,
84 // respectively. 88 // respectively.
85 static PolicyProviderTestHarness* CreateHKCU(); 89 static PolicyProviderTestHarness* CreateHKCU();
86 static PolicyProviderTestHarness* CreateHKLM(); 90 static PolicyProviderTestHarness* CreateHKLM();
87 91
88 private: 92 private:
89 HKEY hive_; 93 HKEY hive_;
94 PolicyScope policy_scope_;
90 95
91 ScopedGroupPolicyRegistrySandbox registry_sandbox_; 96 ScopedGroupPolicyRegistrySandbox registry_sandbox_;
92 97
93 DISALLOW_COPY_AND_ASSIGN(TestHarness); 98 DISALLOW_COPY_AND_ASSIGN(TestHarness);
94 }; 99 };
95 100
96 ScopedGroupPolicyRegistrySandbox::ScopedGroupPolicyRegistrySandbox() { 101 ScopedGroupPolicyRegistrySandbox::ScopedGroupPolicyRegistrySandbox() {
97 // Cleanup any remnants of previous tests. 102 // Cleanup any remnants of previous tests.
98 DeleteKeys(); 103 DeleteKeys();
99 104
(...skipping 24 matching lines...) Expand all
124 void ScopedGroupPolicyRegistrySandbox::RemoveOverrides() { 129 void ScopedGroupPolicyRegistrySandbox::RemoveOverrides() {
125 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_LOCAL_MACHINE, 0)); 130 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_LOCAL_MACHINE, 0));
126 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_CURRENT_USER, 0)); 131 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_CURRENT_USER, 0));
127 } 132 }
128 133
129 void ScopedGroupPolicyRegistrySandbox::DeleteKeys() { 134 void ScopedGroupPolicyRegistrySandbox::DeleteKeys() {
130 RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, KEY_ALL_ACCESS); 135 RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, KEY_ALL_ACCESS);
131 key.DeleteKey(L""); 136 key.DeleteKey(L"");
132 } 137 }
133 138
134 TestHarness::TestHarness(HKEY hive) 139 TestHarness::TestHarness(HKEY hive, PolicyScope scope)
135 : hive_(hive) {} 140 : hive_(hive), policy_scope_(scope) {}
136 141
137 TestHarness::~TestHarness() {} 142 TestHarness::~TestHarness() {}
138 143
139 void TestHarness::SetUp() {} 144 void TestHarness::SetUp() {}
140 145
141 AsynchronousPolicyProvider* TestHarness::CreateProvider( 146 AsynchronousPolicyProvider* TestHarness::CreateProvider(
142 const PolicyDefinitionList* policy_definition_list) { 147 const PolicyDefinitionList* policy_definition_list) {
143 return new ConfigurationPolicyProviderWin(policy_definition_list, 148 return new ConfigurationPolicyProviderWin(policy_definition_list,
144 policy::kRegistryMandatorySubKey, 149 policy::kRegistryMandatorySubKey,
145 POLICY_LEVEL_MANDATORY); 150 POLICY_LEVEL_MANDATORY);
146 } 151 }
147 152
153 PolicyLevel TestHarness::GetPolicyLevel() const {
154 return POLICY_LEVEL_MANDATORY;
155 }
156
157 PolicyScope TestHarness::GetPolicyScope() const {
158 return policy_scope_;
159 }
160
148 void TestHarness::InstallEmptyPolicy() {} 161 void TestHarness::InstallEmptyPolicy() {}
149 162
150 void TestHarness::InstallStringPolicy(const std::string& policy_name, 163 void TestHarness::InstallStringPolicy(const std::string& policy_name,
151 const std::string& policy_value) { 164 const std::string& policy_value) {
152 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS); 165 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS);
153 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), 166 key.WriteValue(UTF8ToUTF16(policy_name).c_str(),
154 UTF8ToUTF16(policy_value).c_str()); 167 UTF8ToUTF16(policy_value).c_str());
155 } 168 }
156 169
157 void TestHarness::InstallIntegerPolicy(const std::string& policy_name, 170 void TestHarness::InstallIntegerPolicy(const std::string& policy_name,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 const base::DictionaryValue* policy_value) { 205 const base::DictionaryValue* policy_value) {
193 std::string json; 206 std::string json;
194 base::JSONWriter::Write(policy_value, &json); 207 base::JSONWriter::Write(policy_value, &json);
195 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS); 208 RegKey key(hive_, policy::kRegistryMandatorySubKey, KEY_ALL_ACCESS);
196 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), 209 key.WriteValue(UTF8ToUTF16(policy_name).c_str(),
197 UTF8ToUTF16(json).c_str()); 210 UTF8ToUTF16(json).c_str());
198 } 211 }
199 212
200 // static 213 // static
201 PolicyProviderTestHarness* TestHarness::CreateHKCU() { 214 PolicyProviderTestHarness* TestHarness::CreateHKCU() {
202 return new TestHarness(HKEY_CURRENT_USER); 215 return new TestHarness(HKEY_CURRENT_USER, POLICY_SCOPE_USER);
203 } 216 }
204 217
205 // static 218 // static
206 PolicyProviderTestHarness* TestHarness::CreateHKLM() { 219 PolicyProviderTestHarness* TestHarness::CreateHKLM() {
207 return new TestHarness(HKEY_LOCAL_MACHINE); 220 return new TestHarness(HKEY_LOCAL_MACHINE, POLICY_SCOPE_MACHINE);
208 } 221 }
209 222
210 } // namespace 223 } // namespace
211 224
212 // Instantiate abstract test case for basic policy reading tests. 225 // Instantiate abstract test case for basic policy reading tests.
213 INSTANTIATE_TEST_CASE_P( 226 INSTANTIATE_TEST_CASE_P(
214 ConfigurationPolicyProviderWinTest, 227 ConfigurationPolicyProviderWinTest,
215 ConfigurationPolicyProviderTest, 228 ConfigurationPolicyProviderTest,
216 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM)); 229 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM));
217 230
(...skipping 18 matching lines...) Expand all
236 UTF8ToUTF16("hklm").c_str()); 249 UTF8ToUTF16("hklm").c_str());
237 RegKey hkcu_key(HKEY_CURRENT_USER, 250 RegKey hkcu_key(HKEY_CURRENT_USER,
238 policy::kRegistryMandatorySubKey, 251 policy::kRegistryMandatorySubKey,
239 KEY_ALL_ACCESS); 252 KEY_ALL_ACCESS);
240 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), 253 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(),
241 UTF8ToUTF16("hkcu").c_str()); 254 UTF8ToUTF16("hkcu").c_str());
242 255
243 provider_.RefreshPolicies(); 256 provider_.RefreshPolicies();
244 loop_.RunAllPending(); 257 loop_.RunAllPending();
245 258
246 PolicyMap policy_map; 259 PolicyBundle expected_bundle;
247 provider_.Provide(&policy_map); 260 expected_bundle.Get(POLICY_DOMAIN_CHROME, "")
248 const base::Value* value = 261 .Set(test_policy_definitions::kKeyString,
249 policy_map.GetValue(test_policy_definitions::kKeyString); 262 POLICY_LEVEL_MANDATORY,
250 EXPECT_TRUE(base::StringValue("hklm").Equals(value)); 263 POLICY_SCOPE_MACHINE,
264 base::Value::CreateStringValue("hklm"));
265 EXPECT_TRUE(provider_.policies().Equals(expected_bundle));
251 } 266 }
252 267
253 } // namespace policy 268 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698