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

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

Issue 8467011: Include only policy definitions that apply to the platfrom in the policy definition list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjust all policy provider tests to use shared testing code. Net-negative line counts! Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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/configuration_policy_provider_test.h"
16 #include "chrome/browser/policy/configuration_policy_pref_store.h"
17 #include "chrome/browser/policy/configuration_policy_provider_win.h" 13 #include "chrome/browser/policy/configuration_policy_provider_win.h"
18 #include "chrome/browser/policy/policy_map.h" 14 #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" 15 #include "policy/policy_constants.h"
22 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
23 17
24 using base::win::RegKey; 18 using base::win::RegKey;
25 using content::BrowserThread; 19 using content::BrowserThread;
Joao da Silva 2011/11/09 15:37:47 Nit: not needed
Mattias Nissler (ping if slow) 2011/11/09 17:04:11 Done.
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 // Deletes the sandbox keys.
114 const char* policy_name_; 45 void DeleteKeys();
115 scoped_ptr<Value> hklm_value_; 46
116 scoped_ptr<Value> hkcu_value_; 47 // Keys are created for the lifetime of a test to contain
48 // the sandboxed HKCU and HKLM hives, respectively.
49 RegKey temp_hkcu_hive_key_;
50 RegKey temp_hklm_hive_key_;
51
52 DISALLOW_COPY_AND_ASSIGN(ScopedGroupPolicyRegistrySandbox);
117 }; 53 };
118 54
119 } // namespace 55 class TestHarness : public PolicyProviderTestHarness {
56 public:
57 explicit TestHarness(HKEY hive);
58 virtual ~TestHarness();
120 59
121 // This test class provides sandboxing and mocking for the parts of the 60 virtual void SetUp() OVERRIDE;
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 61
133 // testing::Test method overrides: 62 virtual AsynchronousPolicyProvider* CreateProvider(
134 virtual void SetUp(); 63 const PolicyDefinitionList* policy_definition_list) OVERRIDE;
135 virtual void TearDown();
136 64
65 virtual void InstallEmptyPolicy() OVERRIDE;
66 virtual void InstallStringPolicy(const std::string& policy_name,
67 const std::string& policy_value) OVERRIDE;
68 virtual void InstallIntegerPolicy(const std::string& policy_name,
69 int policy_value) OVERRIDE;
70 virtual void InstallBooleanPolicy(const std::string& policy_name,
71 bool policy_value) OVERRIDE;
72 virtual void InstallStringListPolicy(const std::string& policy_name,
73 const ListValue* policy_value) OVERRIDE;
74
75 // Creates a harness instance that will install policy in HKCU or HKLM,
76 // respectively.
77 static PolicyProviderTestHarness* CreateHKCU();
78 static PolicyProviderTestHarness* CreateHKLM();
79
80 private:
81 // Activates/Deactivates registry key redirection.
137 void ActivateOverrides(); 82 void ActivateOverrides();
138 void DeactivateOverrides(); 83 void DeactivateOverrides();
139 84
140 // Deletes the registry key created during the tests. 85 // Deletes the registry key created during the tests.
141 void DeleteRegistrySandbox(); 86 void DeleteRegistrySandbox();
142 87
143 // Write a string value to the registry. 88 HKEY hive_;
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 89
148 // Write the given value to the registry. 90 ScopedGroupPolicyRegistrySandbox registry_sandbox_;
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 91
153 protected: 92 DISALLOW_COPY_AND_ASSIGN(TestHarness);
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
166 // Keys are created for the lifetime of a test to contain
167 // the sandboxed HKCU and HKLM hives, respectively.
168 RegKey temp_hkcu_hive_key_;
169 RegKey temp_hklm_hive_key_;
170 }; 93 };
171 94
172 ConfigurationPolicyProviderWinTest::ConfigurationPolicyProviderWinTest() 95 ScopedGroupPolicyRegistrySandbox::ScopedGroupPolicyRegistrySandbox() {
173 : ui_thread_(BrowserThread::UI, &loop_),
174 file_thread_(BrowserThread::FILE, &loop_),
175 temp_hklm_hive_key_(HKEY_CURRENT_USER, kUnitTestMachineOverrideSubKey,
176 KEY_READ),
177 temp_hkcu_hive_key_(HKEY_CURRENT_USER, kUnitTestUserOverrideSubKey,
178 KEY_READ) {
179 }
180
181 void ConfigurationPolicyProviderWinTest::SetUp() {
182 // Cleanup any remnants of previous tests. 96 // Cleanup any remnants of previous tests.
183 DeleteRegistrySandbox(); 97 DeleteKeys();
184 98
185 // Create the subkeys to hold the overridden HKLM and HKCU 99 // Create the subkeys to hold the overridden HKLM and HKCU
186 // policy settings. 100 // policy settings.
187 temp_hklm_hive_key_.Create(HKEY_CURRENT_USER, 101 temp_hklm_hive_key_.Create(HKEY_CURRENT_USER,
188 kUnitTestMachineOverrideSubKey, 102 kUnitTestMachineOverrideSubKey,
189 KEY_ALL_ACCESS); 103 KEY_ALL_ACCESS);
190 temp_hkcu_hive_key_.Create(HKEY_CURRENT_USER, 104 temp_hkcu_hive_key_.Create(HKEY_CURRENT_USER,
191 kUnitTestUserOverrideSubKey, 105 kUnitTestUserOverrideSubKey,
192 KEY_ALL_ACCESS); 106 KEY_ALL_ACCESS);
193 107
194 ActivateOverrides(); 108 // Activate the overrides.
195 109 HRESULT result = RegOverridePredefKey(HKEY_LOCAL_MACHINE,
196 provider_.reset(new ConfigurationPolicyProviderWin( 110 temp_hklm_hive_key_.Handle());
197 GetChromePolicyDefinitionList())); 111 CHECK_EQ(ERROR_SUCCESS, result);
Joao da Silva 2011/11/09 15:37:47 CHECK failure will crash the unit_test process. It
Mattias Nissler (ping if slow) 2011/11/09 17:04:11 I figured out something that works :)
112 result = RegOverridePredefKey(HKEY_CURRENT_USER,
113 temp_hkcu_hive_key_.Handle());
114 CHECK_EQ(ERROR_SUCCESS, result);
198 } 115 }
199 116
200 void ConfigurationPolicyProviderWinTest::TearDown() { 117 ScopedGroupPolicyRegistrySandbox::~ScopedGroupPolicyRegistrySandbox() {
201 DeactivateOverrides(); 118 HRESULT result = RegOverridePredefKey(HKEY_LOCAL_MACHINE, 0);
202 DeleteRegistrySandbox(); 119 CHECK_EQ(ERROR_SUCCESS, result);
203 loop_.RunAllPending(); 120 result = RegOverridePredefKey(HKEY_CURRENT_USER, 0);
121 CHECK_EQ(ERROR_SUCCESS, result);
122
123 DeleteKeys();
204 } 124 }
205 125
206 void ConfigurationPolicyProviderWinTest::ActivateOverrides() { 126 void ScopedGroupPolicyRegistrySandbox::DeleteKeys() {
207 HRESULT result = RegOverridePredefKey(HKEY_LOCAL_MACHINE,
208 temp_hklm_hive_key_.Handle());
209 EXPECT_EQ(ERROR_SUCCESS, result);
210 result = RegOverridePredefKey(HKEY_CURRENT_USER,
211 temp_hkcu_hive_key_.Handle());
212 EXPECT_EQ(ERROR_SUCCESS, result);
213 }
214
215 void ConfigurationPolicyProviderWinTest::DeactivateOverrides() {
216 uint32 result = RegOverridePredefKey(HKEY_LOCAL_MACHINE, 0);
217 EXPECT_EQ(ERROR_SUCCESS, result);
218 result = RegOverridePredefKey(HKEY_CURRENT_USER, 0);
219 EXPECT_EQ(ERROR_SUCCESS, result);
220 }
221
222 void ConfigurationPolicyProviderWinTest::DeleteRegistrySandbox() {
223 temp_hklm_hive_key_.Close();
224 temp_hkcu_hive_key_.Close();
225 RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, KEY_ALL_ACCESS); 127 RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, KEY_ALL_ACCESS);
226 key.DeleteKey(L""); 128 key.DeleteKey(L"");
227 } 129 }
228 130
229 void ConfigurationPolicyProviderWinTest::WriteString(HKEY hive, 131 TestHarness::TestHarness(HKEY hive)
230 const char* name, 132 : hive_(hive) {}
231 const wchar_t* value) { 133
232 RegKey key(hive, policy::kRegistrySubKey, KEY_ALL_ACCESS); 134 TestHarness::~TestHarness() {}
233 key.WriteValue(UTF8ToUTF16(name).c_str(), value); 135
136 void TestHarness::SetUp() {}
137
138 AsynchronousPolicyProvider* TestHarness::CreateProvider(
139 const PolicyDefinitionList* policy_definition_list) {
140 return new ConfigurationPolicyProviderWin(policy_definition_list);
234 } 141 }
235 142
236 void ConfigurationPolicyProviderWinTest::WriteDWORD(HKEY hive, 143 void TestHarness::InstallEmptyPolicy() {}
237 const char* name, 144
238 DWORD value) { 145 void TestHarness::InstallStringPolicy(const std::string& policy_name,
239 RegKey key(hive, policy::kRegistrySubKey, KEY_ALL_ACCESS); 146 const std::string& policy_value) {
240 key.WriteValue(UTF8ToUTF16(name).c_str(), value); 147 RegKey key(hive_, policy::kRegistrySubKey, KEY_ALL_ACCESS);
148 key.WriteValue(UTF8ToUTF16(policy_name).c_str(),
149 UTF8ToUTF16(policy_value).c_str());
241 } 150 }
242 151
243 void ConfigurationPolicyProviderWinTest::WriteValue(HKEY hive, 152 void TestHarness::InstallIntegerPolicy(const std::string& policy_name,
244 const char* name, 153 int policy_value) {
245 const Value* value) { 154 RegKey key(hive_, policy::kRegistrySubKey, KEY_ALL_ACCESS);
246 switch (value->GetType()) { 155 key.WriteValue(UTF8ToUTF16(policy_name).c_str(),
247 case Value::TYPE_BOOLEAN: { 156 static_cast<DWORD>(policy_value));
248 bool v; 157 }
249 ASSERT_TRUE(value->GetAsBoolean(&v)); 158
250 WriteDWORD(hive, name, v); 159 void TestHarness::InstallBooleanPolicy(const std::string& policy_name,
251 break; 160 bool policy_value) {
252 } 161 RegKey key(hive_, policy::kRegistrySubKey, KEY_ALL_ACCESS);
253 case Value::TYPE_INTEGER: { 162 key.WriteValue(UTF8ToUTF16(policy_name).c_str(),
254 int v; 163 static_cast<DWORD>(policy_value));
255 ASSERT_TRUE(value->GetAsInteger(&v)); 164 }
256 WriteDWORD(hive, name, v); 165
257 break; 166 void TestHarness::InstallStringListPolicy(const std::string& policy_name,
258 } 167 const ListValue* policy_value) {
259 case Value::TYPE_STRING: { 168 RegKey key(hive_,
260 std::string v; 169 (string16(policy::kRegistrySubKey) + ASCIIToUTF16("\\") +
261 ASSERT_TRUE(value->GetAsString(&v)); 170 UTF8ToUTF16(policy_name)).c_str(),
262 WriteString(hive, name, UTF8ToUTF16(v).c_str()); 171 KEY_ALL_ACCESS);
263 break; 172 int index = 1;
264 } 173 for (ListValue::const_iterator element(policy_value->begin());
265 case Value::TYPE_LIST: { 174 element != policy_value->end();
266 const ListValue* list = static_cast<const ListValue*>(value); 175 ++element) {
267 RegKey key(hive, 176 std::string element_value;
268 (string16(policy::kRegistrySubKey) + ASCIIToUTF16("\\") + 177 if (!(*element)->GetAsString(&element_value))
269 UTF8ToUTF16(name)).c_str(), 178 continue;
270 KEY_ALL_ACCESS); 179 std::string name(base::IntToString(index++));
271 int index = 1; 180 key.WriteValue(UTF8ToUTF16(name).c_str(),
272 for (ListValue::const_iterator element(list->begin()); 181 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 } 182 }
286 } 183 }
287 184
288 void ConfigurationPolicyProviderWinTest::WriteInvalidValue(HKEY hive, 185 // static
289 const char* name, 186 PolicyProviderTestHarness* TestHarness::CreateHKCU() {
290 const Value* value) { 187 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 } 188 }
296 189
297 TEST_P(ConfigurationPolicyProviderWinTest, Default) { 190 // static
298 PolicyMap policy_map; 191 PolicyProviderTestHarness* TestHarness::CreateHKLM() {
299 provider_->Provide(&policy_map); 192 return new TestHarness(HKEY_LOCAL_MACHINE);
300 EXPECT_TRUE(policy_map.empty());
301 } 193 }
302 194
303 TEST_P(ConfigurationPolicyProviderWinTest, InvalidValue) { 195 } // namespace
304 WriteInvalidValue(HKEY_LOCAL_MACHINE, 196
305 GetParam().policy_name(), 197 // Instantiate abstract test case for basic policy reading tests.
306 GetParam().hklm_value()); 198 INSTANTIATE_TEST_CASE_P(
307 WriteInvalidValue(HKEY_CURRENT_USER, 199 ConfigurationPolicyProviderWinTest,
308 GetParam().policy_name(), 200 ConfigurationPolicyProviderTest,
309 GetParam().hkcu_value()); 201 testing::Values(TestHarness::CreateHKCU, TestHarness::CreateHKLM));
310 provider_->loader()->Reload(); 202
203 // Test cases for windows policy provider specific functionality.
204 class ConfigurationPolicyProviderWinTest : public testing::Test {
205 protected:
206 ConfigurationPolicyProviderWinTest()
207 : ui_thread_(content::BrowserThread::UI, &loop_),
208 file_thread_(content::BrowserThread::FILE, &loop_),
209 provider_(&test_policy_definitions::kList) {}
210
211 // Set up threads so the provider can do stuff on the FILE thread.
212 MessageLoopForIO loop_;
213 content::TestBrowserThread ui_thread_;
214 content::TestBrowserThread file_thread_;
215
216 ScopedGroupPolicyRegistrySandbox registry_sandbox_;
217 ConfigurationPolicyProviderWin provider_;
218 };
219
220 TEST_F(ConfigurationPolicyProviderWinTest, HKLMOverHKCU) {
221 RegKey hklm_key(HKEY_LOCAL_MACHINE, policy::kRegistrySubKey, KEY_ALL_ACCESS);
222 hklm_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(),
223 UTF8ToUTF16("hklm").c_str());
224 RegKey hkcu_key(HKEY_CURRENT_USER, policy::kRegistrySubKey, KEY_ALL_ACCESS);
225 hkcu_key.WriteValue(UTF8ToUTF16(test_policy_definitions::kKeyString).c_str(),
226 UTF8ToUTF16("hkcu").c_str());
227
228 provider_.ForceReload();
311 loop_.RunAllPending(); 229 loop_.RunAllPending();
230
312 PolicyMap policy_map; 231 PolicyMap policy_map;
313 provider_->Provide(&policy_map); 232 provider_.Provide(&policy_map);
314 EXPECT_TRUE(policy_map.empty()); 233 const Value* value = policy_map.Get(test_policy_definitions::kPolicyString);
234 EXPECT_TRUE(StringValue("hklm").Equals(value));
315 } 235 }
316 236
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 237 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698