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/memory/scoped_ptr.h" | 8 #include "base/string16.h" |
9 #include "base/message_loop.h" | |
10 #include "base/stl_util.h" | |
11 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
12 #include "base/string_piece.h" | |
13 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
14 #include "base/win/registry.h" | 11 #include "base/win/registry.h" |
15 #include "chrome/browser/policy/asynchronous_policy_loader.h" | 12 #include "chrome/browser/policy/asynchronous_policy_test_base.h" |
16 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 13 #include "chrome/browser/policy/configuration_policy_provider_test.h" |
17 #include "chrome/browser/policy/configuration_policy_provider_win.h" | 14 #include "chrome/browser/policy/configuration_policy_provider_win.h" |
18 #include "chrome/browser/policy/policy_map.h" | 15 #include "chrome/browser/policy/policy_map.h" |
19 #include "chrome/common/pref_names.h" | |
20 #include "content/test/test_browser_thread.h" | |
21 #include "policy/policy_constants.h" | 16 #include "policy/policy_constants.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
23 | 18 |
24 using base::win::RegKey; | 19 using base::win::RegKey; |
25 using content::BrowserThread; | |
26 | 20 |
27 namespace policy { | 21 namespace policy { |
28 | 22 |
29 namespace { | 23 namespace { |
30 | 24 |
31 const wchar_t kUnitTestRegistrySubKey[] = L"SOFTWARE\\Chromium Unit Tests"; | 25 const wchar_t kUnitTestRegistrySubKey[] = L"SOFTWARE\\Chromium Unit Tests"; |
32 const wchar_t kUnitTestMachineOverrideSubKey[] = | 26 const wchar_t kUnitTestMachineOverrideSubKey[] = |
33 L"SOFTWARE\\Chromium Unit Tests\\HKLM Override"; | 27 L"SOFTWARE\\Chromium Unit Tests\\HKLM Override"; |
34 const wchar_t kUnitTestUserOverrideSubKey[] = | 28 const wchar_t kUnitTestUserOverrideSubKey[] = |
35 L"SOFTWARE\\Chromium Unit Tests\\HKCU Override"; | 29 L"SOFTWARE\\Chromium Unit Tests\\HKCU Override"; |
36 | 30 |
37 // Holds policy type, corresponding policy name string and a valid value for use | 31 // This class provides sandboxing and mocking for the parts of the Windows |
38 // in parametrized value tests. | 32 // Registry implementing Group Policy. It prepares two temporary sandbox keys |
39 class PolicyTestParams { | 33 // in |kUnitTestRegistrySubKey|, one for HKLM and one for HKCU. A test's calls |
| 34 // to the registry are redirected by Windows to these sandboxes, allowing the |
| 35 // tests to manipulate and access policy as if it were active, but without |
| 36 // actually changing the parts of the Registry that are managed by Group |
| 37 // Policy. |
| 38 class ScopedGroupPolicyRegistrySandbox { |
40 public: | 39 public: |
41 // Assumes ownership of |hklm_value| and |hkcu_value|. | 40 ScopedGroupPolicyRegistrySandbox(); |
42 PolicyTestParams(ConfigurationPolicyType type, | 41 ~ScopedGroupPolicyRegistrySandbox(); |
43 const char* policy_name, | |
44 Value* hklm_value, | |
45 Value* hkcu_value) | |
46 : type_(type), | |
47 policy_name_(policy_name), | |
48 hklm_value_(hklm_value), | |
49 hkcu_value_(hkcu_value) {} | |
50 | |
51 // testing::TestWithParam does copy the parameters, so provide copy | |
52 // constructor and assignment operator. | |
53 PolicyTestParams(const PolicyTestParams& other) | |
54 : type_(other.type_), | |
55 policy_name_(other.policy_name_), | |
56 hklm_value_(other.hklm_value_->DeepCopy()), | |
57 hkcu_value_(other.hkcu_value_->DeepCopy()) {} | |
58 | |
59 const PolicyTestParams& operator=(PolicyTestParams other) { | |
60 swap(other); | |
61 return *this; | |
62 } | |
63 | |
64 void swap(PolicyTestParams& other) { | |
65 std::swap(type_, other.type_); | |
66 std::swap(policy_name_, other.policy_name_); | |
67 hklm_value_.swap(other.hklm_value_); | |
68 hkcu_value_.swap(other.hkcu_value_); | |
69 } | |
70 | |
71 ConfigurationPolicyType type() const { return type_; } | |
72 const char* policy_name() const { return policy_name_; } | |
73 const Value* hklm_value() const { return hklm_value_.get(); } | |
74 const Value* hkcu_value() const { return hkcu_value_.get(); } | |
75 | |
76 // Factory methods for different value types. | |
77 static PolicyTestParams ForStringPolicy( | |
78 ConfigurationPolicyType type, | |
79 const char* policy_name) { | |
80 return PolicyTestParams(type, | |
81 policy_name, | |
82 Value::CreateStringValue("string_a"), | |
83 Value::CreateStringValue("string_b")); | |
84 } | |
85 static PolicyTestParams ForBooleanPolicy( | |
86 ConfigurationPolicyType type, | |
87 const char* policy_name) { | |
88 return PolicyTestParams(type, | |
89 policy_name, | |
90 Value::CreateBooleanValue(true), | |
91 Value::CreateBooleanValue(false)); | |
92 } | |
93 static PolicyTestParams ForIntegerPolicy( | |
94 ConfigurationPolicyType type, | |
95 const char* policy_name) { | |
96 return PolicyTestParams(type, | |
97 policy_name, | |
98 Value::CreateIntegerValue(42), | |
99 Value::CreateIntegerValue(17)); | |
100 } | |
101 static PolicyTestParams ForListPolicy( | |
102 ConfigurationPolicyType type, | |
103 const char* policy_name) { | |
104 ListValue* hklm_value = new ListValue; | |
105 hklm_value->Set(0U, Value::CreateStringValue("It's a plane!")); | |
106 ListValue* hkcu_value = new ListValue; | |
107 hkcu_value->Set(0U, Value::CreateStringValue("It's a bird!")); | |
108 hkcu_value->Set(0U, Value::CreateStringValue("It's a flying carpet!")); | |
109 return PolicyTestParams(type, policy_name, hklm_value, hkcu_value); | |
110 } | |
111 | 42 |
112 private: | 43 private: |
113 ConfigurationPolicyType type_; | 44 void ActivateOverrides(); |
114 const char* policy_name_; | 45 void RemoveOverrides(); |
115 scoped_ptr<Value> hklm_value_; | |
116 scoped_ptr<Value> hkcu_value_; | |
117 }; | |
118 | 46 |
119 } // namespace | 47 // Deletes the sandbox keys. |
120 | 48 void DeleteKeys(); |
121 // This test class provides sandboxing and mocking for the parts of the | |
122 // Windows Registry implementing Group Policy. The |SetUp| method prepares | |
123 // two temporary sandbox keys in |kUnitTestRegistrySubKey|, one for HKLM and one | |
124 // for HKCU. A test's calls to the registry are redirected by Windows to these | |
125 // sandboxes, allowing the tests to manipulate and access policy as if it | |
126 // were active, but without actually changing the parts of the Registry that | |
127 // are managed by Group Policy. | |
128 class ConfigurationPolicyProviderWinTest | |
129 : public testing::TestWithParam<PolicyTestParams> { | |
130 public: | |
131 ConfigurationPolicyProviderWinTest(); | |
132 | |
133 // testing::Test method overrides: | |
134 virtual void SetUp(); | |
135 virtual void TearDown(); | |
136 | |
137 void ActivateOverrides(); | |
138 void DeactivateOverrides(); | |
139 | |
140 // Deletes the registry key created during the tests. | |
141 void DeleteRegistrySandbox(); | |
142 | |
143 // Write a string value to the registry. | |
144 void WriteString(HKEY hive, const char* name, const wchar_t* value); | |
145 // Write a DWORD value to the registry. | |
146 void WriteDWORD(HKEY hive, const char* name, DWORD value); | |
147 | |
148 // Write the given value to the registry. | |
149 void WriteValue(HKEY hive, const char* name, const Value* value); | |
150 // Write a value that is not compatible with the given |value|. | |
151 void WriteInvalidValue(HKEY hive, const char* name, const Value* value); | |
152 | |
153 protected: | |
154 scoped_ptr<ConfigurationPolicyProviderWin> provider_; | |
155 | |
156 // A message loop must be declared and instantiated for these tests, | |
157 // because Windows policy provider create WaitableEvents and | |
158 // ObjectWatchers that require the tests to have a MessageLoop associated | |
159 // with the thread executing the tests. | |
160 MessageLoop loop_; | |
161 | |
162 private: | |
163 content::TestBrowserThread ui_thread_; | |
164 content::TestBrowserThread file_thread_; | |
165 | 49 |
166 // Keys are created for the lifetime of a test to contain | 50 // Keys are created for the lifetime of a test to contain |
167 // the sandboxed HKCU and HKLM hives, respectively. | 51 // the sandboxed HKCU and HKLM hives, respectively. |
168 RegKey temp_hkcu_hive_key_; | 52 RegKey temp_hkcu_hive_key_; |
169 RegKey temp_hklm_hive_key_; | 53 RegKey temp_hklm_hive_key_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(ScopedGroupPolicyRegistrySandbox); |
170 }; | 56 }; |
171 | 57 |
172 ConfigurationPolicyProviderWinTest::ConfigurationPolicyProviderWinTest() | 58 class TestHarness : public PolicyProviderTestHarness { |
173 : ui_thread_(BrowserThread::UI, &loop_), | 59 public: |
174 file_thread_(BrowserThread::FILE, &loop_), | 60 explicit TestHarness(HKEY hive); |
175 temp_hklm_hive_key_(HKEY_CURRENT_USER, kUnitTestMachineOverrideSubKey, | 61 virtual ~TestHarness(); |
176 KEY_READ), | |
177 temp_hkcu_hive_key_(HKEY_CURRENT_USER, kUnitTestUserOverrideSubKey, | |
178 KEY_READ) { | |
179 } | |
180 | 62 |
181 void ConfigurationPolicyProviderWinTest::SetUp() { | 63 virtual void SetUp() OVERRIDE; |
| 64 |
| 65 virtual AsynchronousPolicyProvider* CreateProvider( |
| 66 const PolicyDefinitionList* policy_definition_list) OVERRIDE; |
| 67 |
| 68 virtual void InstallEmptyPolicy() OVERRIDE; |
| 69 virtual void InstallStringPolicy(const std::string& policy_name, |
| 70 const std::string& policy_value) OVERRIDE; |
| 71 virtual void InstallIntegerPolicy(const std::string& policy_name, |
| 72 int policy_value) OVERRIDE; |
| 73 virtual void InstallBooleanPolicy(const std::string& policy_name, |
| 74 bool policy_value) OVERRIDE; |
| 75 virtual void InstallStringListPolicy(const std::string& policy_name, |
| 76 const ListValue* policy_value) OVERRIDE; |
| 77 |
| 78 // Creates a harness instance that will install policy in HKCU or HKLM, |
| 79 // respectively. |
| 80 static PolicyProviderTestHarness* CreateHKCU(); |
| 81 static PolicyProviderTestHarness* CreateHKLM(); |
| 82 |
| 83 private: |
| 84 HKEY hive_; |
| 85 |
| 86 ScopedGroupPolicyRegistrySandbox registry_sandbox_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(TestHarness); |
| 89 }; |
| 90 |
| 91 ScopedGroupPolicyRegistrySandbox::ScopedGroupPolicyRegistrySandbox() { |
182 // Cleanup any remnants of previous tests. | 92 // Cleanup any remnants of previous tests. |
183 DeleteRegistrySandbox(); | 93 DeleteKeys(); |
184 | 94 |
185 // Create the subkeys to hold the overridden HKLM and HKCU | 95 // Create the subkeys to hold the overridden HKLM and HKCU |
186 // policy settings. | 96 // policy settings. |
187 temp_hklm_hive_key_.Create(HKEY_CURRENT_USER, | 97 temp_hklm_hive_key_.Create(HKEY_CURRENT_USER, |
188 kUnitTestMachineOverrideSubKey, | 98 kUnitTestMachineOverrideSubKey, |
189 KEY_ALL_ACCESS); | 99 KEY_ALL_ACCESS); |
190 temp_hkcu_hive_key_.Create(HKEY_CURRENT_USER, | 100 temp_hkcu_hive_key_.Create(HKEY_CURRENT_USER, |
191 kUnitTestUserOverrideSubKey, | 101 kUnitTestUserOverrideSubKey, |
192 KEY_ALL_ACCESS); | 102 KEY_ALL_ACCESS); |
193 | 103 |
194 ActivateOverrides(); | 104 ActivateOverrides(); |
195 | |
196 provider_.reset(new ConfigurationPolicyProviderWin( | |
197 GetChromePolicyDefinitionList())); | |
198 } | 105 } |
199 | 106 |
200 void ConfigurationPolicyProviderWinTest::TearDown() { | 107 ScopedGroupPolicyRegistrySandbox::~ScopedGroupPolicyRegistrySandbox() { |
201 DeactivateOverrides(); | 108 RemoveOverrides(); |
202 DeleteRegistrySandbox(); | 109 DeleteKeys(); |
203 loop_.RunAllPending(); | |
204 } | 110 } |
205 | 111 |
206 void ConfigurationPolicyProviderWinTest::ActivateOverrides() { | 112 void ScopedGroupPolicyRegistrySandbox::ActivateOverrides() { |
207 HRESULT result = RegOverridePredefKey(HKEY_LOCAL_MACHINE, | 113 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_LOCAL_MACHINE, |
208 temp_hklm_hive_key_.Handle()); | 114 temp_hklm_hive_key_.Handle())); |
209 EXPECT_EQ(ERROR_SUCCESS, result); | 115 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_CURRENT_USER, |
210 result = RegOverridePredefKey(HKEY_CURRENT_USER, | 116 temp_hkcu_hive_key_.Handle())); |
211 temp_hkcu_hive_key_.Handle()); | |
212 EXPECT_EQ(ERROR_SUCCESS, result); | |
213 } | 117 } |
214 | 118 |
215 void ConfigurationPolicyProviderWinTest::DeactivateOverrides() { | 119 void ScopedGroupPolicyRegistrySandbox::RemoveOverrides() { |
216 uint32 result = RegOverridePredefKey(HKEY_LOCAL_MACHINE, 0); | 120 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_LOCAL_MACHINE, 0)); |
217 EXPECT_EQ(ERROR_SUCCESS, result); | 121 ASSERT_HRESULT_SUCCEEDED(RegOverridePredefKey(HKEY_CURRENT_USER, 0)); |
218 result = RegOverridePredefKey(HKEY_CURRENT_USER, 0); | |
219 EXPECT_EQ(ERROR_SUCCESS, result); | |
220 } | 122 } |
221 | 123 |
222 void ConfigurationPolicyProviderWinTest::DeleteRegistrySandbox() { | 124 void ScopedGroupPolicyRegistrySandbox::DeleteKeys() { |
223 temp_hklm_hive_key_.Close(); | |
224 temp_hkcu_hive_key_.Close(); | |
225 RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, KEY_ALL_ACCESS); | 125 RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, KEY_ALL_ACCESS); |
226 key.DeleteKey(L""); | 126 key.DeleteKey(L""); |
227 } | 127 } |
228 | 128 |
229 void ConfigurationPolicyProviderWinTest::WriteString(HKEY hive, | 129 TestHarness::TestHarness(HKEY hive) |
230 const char* name, | 130 : hive_(hive) {} |
231 const wchar_t* value) { | 131 |
232 RegKey key(hive, policy::kRegistrySubKey, KEY_ALL_ACCESS); | 132 TestHarness::~TestHarness() {} |
233 key.WriteValue(UTF8ToUTF16(name).c_str(), value); | 133 |
| 134 void TestHarness::SetUp() {} |
| 135 |
| 136 AsynchronousPolicyProvider* TestHarness::CreateProvider( |
| 137 const PolicyDefinitionList* policy_definition_list) { |
| 138 return new ConfigurationPolicyProviderWin(policy_definition_list); |
234 } | 139 } |
235 | 140 |
236 void ConfigurationPolicyProviderWinTest::WriteDWORD(HKEY hive, | 141 void TestHarness::InstallEmptyPolicy() {} |
237 const char* name, | 142 |
238 DWORD value) { | 143 void TestHarness::InstallStringPolicy(const std::string& policy_name, |
239 RegKey key(hive, policy::kRegistrySubKey, KEY_ALL_ACCESS); | 144 const std::string& policy_value) { |
240 key.WriteValue(UTF8ToUTF16(name).c_str(), value); | 145 RegKey key(hive_, policy::kRegistrySubKey, KEY_ALL_ACCESS); |
| 146 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), |
| 147 UTF8ToUTF16(policy_value).c_str()); |
241 } | 148 } |
242 | 149 |
243 void ConfigurationPolicyProviderWinTest::WriteValue(HKEY hive, | 150 void TestHarness::InstallIntegerPolicy(const std::string& policy_name, |
244 const char* name, | 151 int policy_value) { |
245 const Value* value) { | 152 RegKey key(hive_, policy::kRegistrySubKey, KEY_ALL_ACCESS); |
246 switch (value->GetType()) { | 153 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), |
247 case Value::TYPE_BOOLEAN: { | 154 static_cast<DWORD>(policy_value)); |
248 bool v; | 155 } |
249 ASSERT_TRUE(value->GetAsBoolean(&v)); | 156 |
250 WriteDWORD(hive, name, v); | 157 void TestHarness::InstallBooleanPolicy(const std::string& policy_name, |
251 break; | 158 bool policy_value) { |
252 } | 159 RegKey key(hive_, policy::kRegistrySubKey, KEY_ALL_ACCESS); |
253 case Value::TYPE_INTEGER: { | 160 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), |
254 int v; | 161 static_cast<DWORD>(policy_value)); |
255 ASSERT_TRUE(value->GetAsInteger(&v)); | 162 } |
256 WriteDWORD(hive, name, v); | 163 |
257 break; | 164 void TestHarness::InstallStringListPolicy(const std::string& policy_name, |
258 } | 165 const ListValue* policy_value) { |
259 case Value::TYPE_STRING: { | 166 RegKey key(hive_, |
260 std::string v; | 167 (string16(policy::kRegistrySubKey) + ASCIIToUTF16("\\") + |
261 ASSERT_TRUE(value->GetAsString(&v)); | 168 UTF8ToUTF16(policy_name)).c_str(), |
262 WriteString(hive, name, UTF8ToUTF16(v).c_str()); | 169 KEY_ALL_ACCESS); |
263 break; | 170 int index = 1; |
264 } | 171 for (ListValue::const_iterator element(policy_value->begin()); |
265 case Value::TYPE_LIST: { | 172 element != policy_value->end(); |
266 const ListValue* list = static_cast<const ListValue*>(value); | 173 ++element) { |
267 RegKey key(hive, | 174 std::string element_value; |
268 (string16(policy::kRegistrySubKey) + ASCIIToUTF16("\\") + | 175 if (!(*element)->GetAsString(&element_value)) |
269 UTF8ToUTF16(name)).c_str(), | 176 continue; |
270 KEY_ALL_ACCESS); | 177 std::string name(base::IntToString(index++)); |
271 int index = 1; | 178 key.WriteValue(UTF8ToUTF16(name).c_str(), |
272 for (ListValue::const_iterator element(list->begin()); | 179 UTF8ToUTF16(element_value).c_str()); |
273 element != list->end(); ++element) { | |
274 ASSERT_TRUE((*element)->IsType(Value::TYPE_STRING)); | |
275 std::string element_value; | |
276 ASSERT_TRUE((*element)->GetAsString(&element_value)); | |
277 key.WriteValue(base::IntToString16(index++).c_str(), | |
278 UTF8ToUTF16(element_value).c_str()); | |
279 } | |
280 break; | |
281 } | |
282 default: | |
283 FAIL() << "Unsupported value type " << value->GetType(); | |
284 break; | |
285 } | 180 } |
286 } | 181 } |
287 | 182 |
288 void ConfigurationPolicyProviderWinTest::WriteInvalidValue(HKEY hive, | 183 // static |
289 const char* name, | 184 PolicyProviderTestHarness* TestHarness::CreateHKCU() { |
290 const Value* value) { | 185 return new TestHarness(HKEY_CURRENT_USER); |
291 if (value->IsType(Value::TYPE_STRING)) | |
292 WriteDWORD(hive, name, -1); | |
293 else | |
294 WriteString(hive, name, L"bad value"); | |
295 } | 186 } |
296 | 187 |
297 TEST_P(ConfigurationPolicyProviderWinTest, Default) { | 188 // static |
298 PolicyMap policy_map; | 189 PolicyProviderTestHarness* TestHarness::CreateHKLM() { |
299 provider_->Provide(&policy_map); | 190 return new TestHarness(HKEY_LOCAL_MACHINE); |
300 EXPECT_TRUE(policy_map.empty()); | |
301 } | 191 } |
302 | 192 |
303 TEST_P(ConfigurationPolicyProviderWinTest, InvalidValue) { | 193 } // namespace |
304 WriteInvalidValue(HKEY_LOCAL_MACHINE, | 194 |
305 GetParam().policy_name(), | 195 // Instantiate abstract test case for basic policy reading tests. |
306 GetParam().hklm_value()); | 196 INSTANTIATE_TEST_CASE_P( |
307 WriteInvalidValue(HKEY_CURRENT_USER, | 197 ConfigurationPolicyProviderWinTest, |
308 GetParam().policy_name(), | 198 ConfigurationPolicyProviderTest, |
309 GetParam().hkcu_value()); | 199 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM)); |
310 provider_->loader()->Reload(); | 200 |
| 201 // Test cases for windows policy provider specific functionality. |
| 202 class ConfigurationPolicyProviderWinTest : public AsynchronousPolicyTestBase { |
| 203 protected: |
| 204 ConfigurationPolicyProviderWinTest() |
| 205 : provider_(&test_policy_definitions::kList) {} |
| 206 virtual ~ConfigurationPolicyProviderWinTest() {} |
| 207 |
| 208 ScopedGroupPolicyRegistrySandbox registry_sandbox_; |
| 209 ConfigurationPolicyProviderWin provider_; |
| 210 }; |
| 211 |
| 212 TEST_F(ConfigurationPolicyProviderWinTest, HKLMOverHKCU) { |
| 213 RegKey hklm_key(HKEY_LOCAL_MACHINE, policy::kRegistrySubKey, KEY_ALL_ACCESS); |
| 214 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), |
| 215 UTF8ToUTF16("hklm").c_str()); |
| 216 RegKey hkcu_key(HKEY_CURRENT_USER, policy::kRegistrySubKey, KEY_ALL_ACCESS); |
| 217 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(), |
| 218 UTF8ToUTF16("hkcu").c_str()); |
| 219 |
| 220 provider_.ForceReload(); |
311 loop_.RunAllPending(); | 221 loop_.RunAllPending(); |
| 222 |
312 PolicyMap policy_map; | 223 PolicyMap policy_map; |
313 provider_->Provide(&policy_map); | 224 provider_.Provide(&policy_map); |
314 EXPECT_TRUE(policy_map.empty()); | 225 const Value* value = policy_map.Get(test_policy_definitions::kPolicyString); |
| 226 EXPECT_TRUE(StringValue("hklm").Equals(value)); |
315 } | 227 } |
316 | 228 |
317 TEST_P(ConfigurationPolicyProviderWinTest, HKLM) { | |
318 WriteValue(HKEY_LOCAL_MACHINE, | |
319 GetParam().policy_name(), | |
320 GetParam().hklm_value()); | |
321 provider_->loader()->Reload(); | |
322 loop_.RunAllPending(); | |
323 PolicyMap policy_map; | |
324 provider_->Provide(&policy_map); | |
325 const Value* value = policy_map.Get(GetParam().type()); | |
326 ASSERT_TRUE(value); | |
327 EXPECT_TRUE(value->Equals(GetParam().hklm_value())); | |
328 } | |
329 | |
330 TEST_P(ConfigurationPolicyProviderWinTest, HKCU) { | |
331 WriteValue(HKEY_CURRENT_USER, | |
332 GetParam().policy_name(), | |
333 GetParam().hkcu_value()); | |
334 provider_->loader()->Reload(); | |
335 loop_.RunAllPending(); | |
336 PolicyMap policy_map; | |
337 provider_->Provide(&policy_map); | |
338 const Value* value = policy_map.Get(GetParam().type()); | |
339 ASSERT_TRUE(value); | |
340 EXPECT_TRUE(value->Equals(GetParam().hkcu_value())); | |
341 } | |
342 | |
343 TEST_P(ConfigurationPolicyProviderWinTest, HKLMOverHKCU) { | |
344 WriteValue(HKEY_LOCAL_MACHINE, | |
345 GetParam().policy_name(), | |
346 GetParam().hklm_value()); | |
347 WriteValue(HKEY_CURRENT_USER, | |
348 GetParam().policy_name(), | |
349 GetParam().hkcu_value()); | |
350 provider_->loader()->Reload(); | |
351 loop_.RunAllPending(); | |
352 PolicyMap policy_map; | |
353 provider_->Provide(&policy_map); | |
354 const Value* value = policy_map.Get(GetParam().type()); | |
355 ASSERT_TRUE(value); | |
356 EXPECT_TRUE(value->Equals(GetParam().hklm_value())); | |
357 } | |
358 | |
359 // Test parameters for all supported policies. testing::Values() has a limit of | |
360 // 50 parameters which is reached in this instantiation; new policies should go | |
361 // in the next instantiation after this one. | |
362 INSTANTIATE_TEST_CASE_P( | |
363 ConfigurationPolicyProviderWinTestInstance, | |
364 ConfigurationPolicyProviderWinTest, | |
365 testing::Values( | |
366 PolicyTestParams::ForStringPolicy( | |
367 kPolicyHomepageLocation, | |
368 key::kHomepageLocation), | |
369 PolicyTestParams::ForBooleanPolicy( | |
370 kPolicyHomepageIsNewTabPage, | |
371 key::kHomepageIsNewTabPage), | |
372 PolicyTestParams::ForIntegerPolicy( | |
373 kPolicyRestoreOnStartup, | |
374 key::kRestoreOnStartup), | |
375 PolicyTestParams::ForListPolicy( | |
376 kPolicyRestoreOnStartupURLs, | |
377 key::kRestoreOnStartupURLs), | |
378 PolicyTestParams::ForBooleanPolicy( | |
379 kPolicyDefaultSearchProviderEnabled, | |
380 key::kDefaultSearchProviderEnabled), | |
381 PolicyTestParams::ForStringPolicy( | |
382 kPolicyDefaultSearchProviderName, | |
383 key::kDefaultSearchProviderName), | |
384 PolicyTestParams::ForStringPolicy( | |
385 kPolicyDefaultSearchProviderKeyword, | |
386 key::kDefaultSearchProviderKeyword), | |
387 PolicyTestParams::ForStringPolicy( | |
388 kPolicyDefaultSearchProviderSearchURL, | |
389 key::kDefaultSearchProviderSearchURL), | |
390 PolicyTestParams::ForStringPolicy( | |
391 kPolicyDefaultSearchProviderSuggestURL, | |
392 key::kDefaultSearchProviderSuggestURL), | |
393 PolicyTestParams::ForStringPolicy( | |
394 kPolicyDefaultSearchProviderInstantURL, | |
395 key::kDefaultSearchProviderInstantURL), | |
396 PolicyTestParams::ForStringPolicy( | |
397 kPolicyDefaultSearchProviderIconURL, | |
398 key::kDefaultSearchProviderIconURL), | |
399 PolicyTestParams::ForListPolicy( | |
400 kPolicyDefaultSearchProviderEncodings, | |
401 key::kDefaultSearchProviderEncodings), | |
402 PolicyTestParams::ForStringPolicy( | |
403 kPolicyProxyMode, | |
404 key::kProxyMode), | |
405 PolicyTestParams::ForIntegerPolicy( | |
406 kPolicyProxyServerMode, | |
407 key::kProxyServerMode), | |
408 PolicyTestParams::ForStringPolicy( | |
409 kPolicyProxyServer, | |
410 key::kProxyServer), | |
411 PolicyTestParams::ForStringPolicy( | |
412 kPolicyProxyPacUrl, | |
413 key::kProxyPacUrl), | |
414 PolicyTestParams::ForStringPolicy( | |
415 kPolicyProxyBypassList, | |
416 key::kProxyBypassList), | |
417 PolicyTestParams::ForBooleanPolicy( | |
418 kPolicyAlternateErrorPagesEnabled, | |
419 key::kAlternateErrorPagesEnabled), | |
420 PolicyTestParams::ForBooleanPolicy( | |
421 kPolicySearchSuggestEnabled, | |
422 key::kSearchSuggestEnabled), | |
423 PolicyTestParams::ForBooleanPolicy( | |
424 kPolicyDnsPrefetchingEnabled, | |
425 key::kDnsPrefetchingEnabled), | |
426 PolicyTestParams::ForBooleanPolicy( | |
427 kPolicySafeBrowsingEnabled, | |
428 key::kSafeBrowsingEnabled), | |
429 PolicyTestParams::ForBooleanPolicy( | |
430 kPolicyMetricsReportingEnabled, | |
431 key::kMetricsReportingEnabled), | |
432 PolicyTestParams::ForBooleanPolicy( | |
433 kPolicyPasswordManagerEnabled, | |
434 key::kPasswordManagerEnabled), | |
435 PolicyTestParams::ForListPolicy( | |
436 kPolicyDisabledPlugins, | |
437 key::kDisabledPlugins), | |
438 PolicyTestParams::ForListPolicy( | |
439 kPolicyDisabledPluginsExceptions, | |
440 key::kDisabledPluginsExceptions), | |
441 PolicyTestParams::ForListPolicy( | |
442 kPolicyEnabledPlugins, | |
443 key::kEnabledPlugins), | |
444 PolicyTestParams::ForBooleanPolicy( | |
445 kPolicyAutoFillEnabled, | |
446 key::kAutoFillEnabled), | |
447 PolicyTestParams::ForBooleanPolicy( | |
448 kPolicySyncDisabled, | |
449 key::kSyncDisabled), | |
450 PolicyTestParams::ForStringPolicy( | |
451 kPolicyApplicationLocaleValue, | |
452 key::kApplicationLocaleValue), | |
453 PolicyTestParams::ForListPolicy( | |
454 kPolicyExtensionInstallWhitelist, | |
455 key::kExtensionInstallWhitelist), | |
456 PolicyTestParams::ForListPolicy( | |
457 kPolicyExtensionInstallBlacklist, | |
458 key::kExtensionInstallBlacklist), | |
459 PolicyTestParams::ForBooleanPolicy( | |
460 kPolicyShowHomeButton, | |
461 key::kShowHomeButton), | |
462 PolicyTestParams::ForBooleanPolicy( | |
463 kPolicyPrintingEnabled, | |
464 key::kPrintingEnabled), | |
465 PolicyTestParams::ForBooleanPolicy( | |
466 kPolicyInstantEnabled, | |
467 key::kInstantEnabled), | |
468 PolicyTestParams::ForIntegerPolicy( | |
469 kPolicyIncognitoModeAvailability, | |
470 key::kIncognitoModeAvailability), | |
471 PolicyTestParams::ForBooleanPolicy( | |
472 kPolicyDisablePluginFinder, | |
473 key::kDisablePluginFinder), | |
474 PolicyTestParams::ForBooleanPolicy( | |
475 kPolicyClearSiteDataOnExit, | |
476 key::kClearSiteDataOnExit), | |
477 PolicyTestParams::ForStringPolicy( | |
478 kPolicyDownloadDirectory, | |
479 key::kDownloadDirectory), | |
480 PolicyTestParams::ForBooleanPolicy( | |
481 kPolicyDefaultBrowserSettingEnabled, | |
482 key::kDefaultBrowserSettingEnabled), | |
483 PolicyTestParams::ForBooleanPolicy( | |
484 kPolicyCloudPrintProxyEnabled, | |
485 key::kCloudPrintProxyEnabled), | |
486 PolicyTestParams::ForBooleanPolicy( | |
487 kPolicyTranslateEnabled, | |
488 key::kTranslateEnabled), | |
489 PolicyTestParams::ForBooleanPolicy( | |
490 kPolicyAllowOutdatedPlugins, | |
491 key::kAllowOutdatedPlugins), | |
492 PolicyTestParams::ForBooleanPolicy( | |
493 kPolicyAlwaysAuthorizePlugins, | |
494 key::kAlwaysAuthorizePlugins), | |
495 PolicyTestParams::ForBooleanPolicy( | |
496 kPolicyBookmarkBarEnabled, | |
497 key::kBookmarkBarEnabled), | |
498 PolicyTestParams::ForBooleanPolicy( | |
499 kPolicyEditBookmarksEnabled, | |
500 key::kEditBookmarksEnabled), | |
501 PolicyTestParams::ForBooleanPolicy( | |
502 kPolicyAllowFileSelectionDialogs, | |
503 key::kAllowFileSelectionDialogs), | |
504 PolicyTestParams::ForListPolicy( | |
505 kPolicyDisabledSchemes, | |
506 key::kDisabledSchemes), | |
507 PolicyTestParams::ForStringPolicy( | |
508 kPolicyDiskCacheDir, | |
509 key::kDiskCacheDir), | |
510 PolicyTestParams::ForIntegerPolicy( | |
511 kPolicyMaxConnectionsPerProxy, | |
512 key::kMaxConnectionsPerProxy), | |
513 PolicyTestParams::ForListPolicy( | |
514 kPolicyURLBlacklist, | |
515 key::kURLBlacklist))); | |
516 | |
517 // testing::Values has a limit of 50 test templates, which is reached by the | |
518 // instantiations above. Add tests for new policies here: | |
519 INSTANTIATE_TEST_CASE_P( | |
520 ConfigurationPolicyProviderWinTestInstance2, | |
521 ConfigurationPolicyProviderWinTest, | |
522 testing::Values( | |
523 PolicyTestParams::ForListPolicy( | |
524 kPolicyURLWhitelist, | |
525 key::kURLWhitelist), | |
526 PolicyTestParams::ForBooleanPolicy( | |
527 kPolicyCloudPrintSubmitEnabled, | |
528 key::kCloudPrintSubmitEnabled))); | |
529 | |
530 } // namespace policy | 229 } // namespace policy |
OLD | NEW |