OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 8 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 10 #include "chrome/browser/prefs/proxy_prefs.h" |
10 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
12 | 13 |
13 namespace policy { | 14 namespace policy { |
14 | 15 |
15 // Holds a set of test parameters, consisting of pref name and policy type. | 16 // Holds a set of test parameters, consisting of pref name and policy type. |
16 class TypeAndName { | 17 class TypeAndName { |
17 public: | 18 public: |
18 TypeAndName(ConfigurationPolicyType type, const char* pref_name) | 19 TypeAndName(ConfigurationPolicyType type, const char* pref_name) |
19 : type_(type), | 20 : type_(type), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 testing::TestWithParam<TypeAndName> > { | 90 testing::TestWithParam<TypeAndName> > { |
90 }; | 91 }; |
91 | 92 |
92 TEST_P(ConfigurationPolicyPrefStoreStringTest, GetDefault) { | 93 TEST_P(ConfigurationPolicyPrefStoreStringTest, GetDefault) { |
93 std::string result; | 94 std::string result; |
94 EXPECT_FALSE(store_.prefs()->GetString(GetParam().pref_name(), &result)); | 95 EXPECT_FALSE(store_.prefs()->GetString(GetParam().pref_name(), &result)); |
95 } | 96 } |
96 | 97 |
97 TEST_P(ConfigurationPolicyPrefStoreStringTest, SetValue) { | 98 TEST_P(ConfigurationPolicyPrefStoreStringTest, SetValue) { |
98 store_.Apply(GetParam().type(), | 99 store_.Apply(GetParam().type(), |
99 Value::CreateStringValue("http://chromium.org")); | 100 Value::CreateStringValue("http://chromium.org")); |
| 101 store_.Completed(); |
100 std::string result; | 102 std::string result; |
101 EXPECT_TRUE(store_.prefs()->GetString(GetParam().pref_name(), &result)); | 103 EXPECT_TRUE(store_.prefs()->GetString(GetParam().pref_name(), &result)); |
102 EXPECT_EQ(result, "http://chromium.org"); | 104 EXPECT_EQ(result, "http://chromium.org"); |
103 } | 105 } |
104 | 106 |
105 INSTANTIATE_TEST_CASE_P( | 107 INSTANTIATE_TEST_CASE_P( |
106 ConfigurationPolicyPrefStoreStringTestInstance, | 108 ConfigurationPolicyPrefStoreStringTestInstance, |
107 ConfigurationPolicyPrefStoreStringTest, | 109 ConfigurationPolicyPrefStoreStringTest, |
108 testing::Values( | 110 testing::Values( |
109 TypeAndName(kPolicyHomePage, | 111 TypeAndName(kPolicyHomePage, |
110 prefs::kHomePage), | 112 prefs::kHomePage), |
111 TypeAndName(kPolicyProxyServer, | |
112 prefs::kProxyServer), | |
113 TypeAndName(kPolicyProxyPacUrl, | |
114 prefs::kProxyPacUrl), | |
115 TypeAndName(kPolicyProxyBypassList, | |
116 prefs::kProxyBypassList), | |
117 TypeAndName(kPolicyApplicationLocale, | 113 TypeAndName(kPolicyApplicationLocale, |
118 prefs::kApplicationLocale), | 114 prefs::kApplicationLocale), |
119 TypeAndName(kPolicyApplicationLocale, | 115 TypeAndName(kPolicyApplicationLocale, |
120 prefs::kApplicationLocale), | 116 prefs::kApplicationLocale), |
121 TypeAndName(kPolicyAuthSchemes, | 117 TypeAndName(kPolicyAuthSchemes, |
122 prefs::kAuthSchemes), | 118 prefs::kAuthSchemes), |
123 TypeAndName(kPolicyAuthServerWhitelist, | 119 TypeAndName(kPolicyAuthServerWhitelist, |
124 prefs::kAuthServerWhitelist), | 120 prefs::kAuthServerWhitelist), |
125 TypeAndName(kPolicyAuthNegotiateDelegateWhitelist, | 121 TypeAndName(kPolicyAuthNegotiateDelegateWhitelist, |
126 prefs::kAuthNegotiateDelegateWhitelist), | 122 prefs::kAuthNegotiateDelegateWhitelist), |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 212 |
217 INSTANTIATE_TEST_CASE_P( | 213 INSTANTIATE_TEST_CASE_P( |
218 ConfigurationPolicyPrefStoreIntegerTestInstance, | 214 ConfigurationPolicyPrefStoreIntegerTestInstance, |
219 ConfigurationPolicyPrefStoreIntegerTest, | 215 ConfigurationPolicyPrefStoreIntegerTest, |
220 testing::Values( | 216 testing::Values( |
221 TypeAndName(kPolicyRestoreOnStartup, | 217 TypeAndName(kPolicyRestoreOnStartup, |
222 prefs::kRestoreOnStartup))); | 218 prefs::kRestoreOnStartup))); |
223 | 219 |
224 // Test cases for the proxy policy settings. | 220 // Test cases for the proxy policy settings. |
225 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test { | 221 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test { |
| 222 protected: |
| 223 // Verify that all the proxy prefs are set to the specified expected values. |
| 224 static void VerifyProxyPrefs( |
| 225 const ConfigurationPolicyPrefStore& store, |
| 226 const std::string& expected_proxy_server, |
| 227 const std::string& expected_proxy_pac_url, |
| 228 const std::string& expected_proxy_bypass_list, |
| 229 const ProxyPrefs::ProxyMode& expected_proxy_mode) { |
| 230 std::string string_result; |
| 231 |
| 232 if (expected_proxy_server.empty()) { |
| 233 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, |
| 234 &string_result)); |
| 235 } else { |
| 236 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, |
| 237 &string_result)); |
| 238 EXPECT_EQ(expected_proxy_server, string_result); |
| 239 } |
| 240 if (expected_proxy_pac_url.empty()) { |
| 241 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, |
| 242 &string_result)); |
| 243 } else { |
| 244 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyPacUrl, |
| 245 &string_result)); |
| 246 EXPECT_EQ(expected_proxy_pac_url, string_result); |
| 247 } |
| 248 if (expected_proxy_bypass_list.empty()) { |
| 249 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, |
| 250 &string_result)); |
| 251 } else { |
| 252 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList, |
| 253 &string_result)); |
| 254 EXPECT_EQ(expected_proxy_bypass_list, string_result); |
| 255 } |
| 256 int int_result = -1; |
| 257 EXPECT_TRUE(store.prefs()->GetInteger(prefs::kProxyMode, &int_result)); |
| 258 EXPECT_EQ(expected_proxy_mode, int_result); |
| 259 } |
226 }; | 260 }; |
227 | 261 |
228 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) { | 262 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) { |
229 scoped_ptr<MockConfigurationPolicyProvider> provider( | 263 scoped_ptr<MockConfigurationPolicyProvider> provider( |
230 new MockConfigurationPolicyProvider()); | 264 new MockConfigurationPolicyProvider()); |
231 provider->AddPolicy(kPolicyProxyBypassList, | 265 provider->AddPolicy(kPolicyProxyBypassList, |
232 Value::CreateStringValue("http://chromium.org/override")); | 266 Value::CreateStringValue("http://chromium.org/override")); |
233 provider->AddPolicy(kPolicyProxyPacUrl, | |
234 Value::CreateStringValue("http://short.org/proxy.pac")); | |
235 provider->AddPolicy(kPolicyProxyServer, | 267 provider->AddPolicy(kPolicyProxyServer, |
236 Value::CreateStringValue("chromium.org")); | 268 Value::CreateStringValue("chromium.org")); |
237 provider->AddPolicy(kPolicyProxyServerMode, | 269 provider->AddPolicy(kPolicyProxyMode, |
238 Value::CreateIntegerValue( | 270 Value::CreateIntegerValue( |
239 kPolicyManuallyConfiguredProxyMode)); | 271 kPolicyManuallyConfiguredProxyMode)); |
240 | 272 |
241 ConfigurationPolicyPrefStore store(provider.get()); | 273 ConfigurationPolicyPrefStore store(provider.get()); |
| 274 VerifyProxyPrefs( |
| 275 store, "chromium.org", "", "http://chromium.org/override", |
| 276 ProxyPrefs::FIXED_SERVERS); |
| 277 } |
242 | 278 |
243 std::string string_result; | 279 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptionsReversedApplyOrder) { |
244 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList, | 280 scoped_ptr<MockConfigurationPolicyProvider> provider( |
245 &string_result)); | 281 new MockConfigurationPolicyProvider()); |
246 EXPECT_EQ("http://chromium.org/override", string_result); | 282 provider->AddPolicy(kPolicyProxyMode, |
247 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); | 283 Value::CreateIntegerValue( |
248 EXPECT_EQ("http://short.org/proxy.pac", string_result); | 284 kPolicyManuallyConfiguredProxyMode)); |
249 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); | 285 provider->AddPolicy(kPolicyProxyBypassList, |
250 EXPECT_EQ("chromium.org", string_result); | 286 Value::CreateStringValue("http://chromium.org/override")); |
251 bool bool_result; | 287 provider->AddPolicy(kPolicyProxyServer, |
252 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); | 288 Value::CreateStringValue("chromium.org")); |
253 EXPECT_FALSE(bool_result); | 289 |
254 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); | 290 ConfigurationPolicyPrefStore store(provider.get()); |
255 EXPECT_FALSE(bool_result); | 291 VerifyProxyPrefs( |
| 292 store, "chromium.org", "", "http://chromium.org/override", |
| 293 ProxyPrefs::FIXED_SERVERS); |
256 } | 294 } |
257 | 295 |
258 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) { | 296 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) { |
259 scoped_ptr<MockConfigurationPolicyProvider> provider( | 297 scoped_ptr<MockConfigurationPolicyProvider> provider( |
260 new MockConfigurationPolicyProvider()); | 298 new MockConfigurationPolicyProvider()); |
261 provider->AddPolicy(kPolicyProxyBypassList, | 299 provider->AddPolicy(kPolicyProxyMode, |
262 Value::CreateStringValue("http://chromium.org/override")); | 300 Value::CreateIntegerValue(kPolicyNoProxyServerMode)); |
263 provider->AddPolicy(kPolicyProxyServerMode, | |
264 Value::CreateIntegerValue( | |
265 kPolicyNoProxyServerMode)); | |
266 | 301 |
267 ConfigurationPolicyPrefStore store(provider.get()); | 302 ConfigurationPolicyPrefStore store(provider.get()); |
268 | 303 VerifyProxyPrefs(store, "", "", "", ProxyPrefs::DISABLED); |
269 std::string string_result; | |
270 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, | |
271 &string_result)); | |
272 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); | |
273 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); | |
274 bool bool_result; | |
275 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); | |
276 EXPECT_TRUE(bool_result); | |
277 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); | |
278 EXPECT_FALSE(bool_result); | |
279 } | |
280 | |
281 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyReversedApplyOrder) { | |
282 scoped_ptr<MockConfigurationPolicyProvider> provider( | |
283 new MockConfigurationPolicyProvider()); | |
284 provider->AddPolicy(kPolicyProxyServerMode, | |
285 Value::CreateIntegerValue( | |
286 kPolicyNoProxyServerMode)); | |
287 provider->AddPolicy(kPolicyProxyBypassList, | |
288 Value::CreateStringValue("http://chromium.org/override")); | |
289 | |
290 ConfigurationPolicyPrefStore store(provider.get()); | |
291 | |
292 std::string string_result; | |
293 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, | |
294 &string_result)); | |
295 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); | |
296 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); | |
297 bool bool_result; | |
298 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); | |
299 EXPECT_TRUE(bool_result); | |
300 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); | |
301 EXPECT_FALSE(bool_result); | |
302 } | 304 } |
303 | 305 |
304 TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetect) { | 306 TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetect) { |
305 scoped_ptr<MockConfigurationPolicyProvider> provider( | 307 scoped_ptr<MockConfigurationPolicyProvider> provider( |
306 new MockConfigurationPolicyProvider()); | 308 new MockConfigurationPolicyProvider()); |
307 provider->AddPolicy(kPolicyProxyServerMode, | 309 provider->AddPolicy(kPolicyProxyMode, |
308 Value::CreateIntegerValue( | 310 Value::CreateIntegerValue(kPolicyAutoDetectProxyMode)); |
309 kPolicyAutoDetectProxyMode)); | |
310 | 311 |
311 ConfigurationPolicyPrefStore store(provider.get()); | 312 ConfigurationPolicyPrefStore store(provider.get()); |
| 313 VerifyProxyPrefs(store, "", "", "", ProxyPrefs::AUTO_DETECT); |
| 314 } |
312 | 315 |
313 std::string string_result; | 316 TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetectPac) { |
314 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, | 317 scoped_ptr<MockConfigurationPolicyProvider> provider( |
315 &string_result)); | 318 new MockConfigurationPolicyProvider()); |
316 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); | 319 provider->AddPolicy(kPolicyProxyPacUrl, |
317 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); | 320 Value::CreateStringValue("http://short.org/proxy.pac")); |
318 bool bool_result; | 321 provider->AddPolicy(kPolicyProxyMode, |
319 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); | 322 Value::CreateIntegerValue(kPolicyAutoDetectProxyMode)); |
320 EXPECT_FALSE(bool_result); | 323 |
321 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); | 324 ConfigurationPolicyPrefStore store(provider.get()); |
322 EXPECT_TRUE(bool_result); | 325 VerifyProxyPrefs( |
| 326 store, "", "http://short.org/proxy.pac", "", ProxyPrefs::PAC_SCRIPT); |
323 } | 327 } |
324 | 328 |
325 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) { | 329 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) { |
326 scoped_ptr<MockConfigurationPolicyProvider> provider( | 330 scoped_ptr<MockConfigurationPolicyProvider> provider( |
327 new MockConfigurationPolicyProvider()); | 331 new MockConfigurationPolicyProvider()); |
328 provider->AddPolicy(kPolicyProxyBypassList, | 332 provider->AddPolicy(kPolicyProxyMode, |
329 Value::CreateStringValue("http://chromium.org/override")); | 333 Value::CreateIntegerValue(kPolicyUseSystemProxyMode)); |
330 provider->AddPolicy(kPolicyProxyServerMode, | |
331 Value::CreateIntegerValue( | |
332 kPolicyUseSystemProxyMode)); | |
333 | 334 |
334 ConfigurationPolicyPrefStore store(provider.get()); | 335 ConfigurationPolicyPrefStore store(provider.get()); |
335 | 336 VerifyProxyPrefs(store, "", "", "", ProxyPrefs::SYSTEM); |
336 std::string string_result; | |
337 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, | |
338 &string_result)); | |
339 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); | |
340 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); | |
341 bool bool_result; | |
342 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); | |
343 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, | |
344 &bool_result)); | |
345 } | 337 } |
346 | 338 |
347 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemReversedApplyOrder) { | 339 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ProxyInvalid) { |
348 scoped_ptr<MockConfigurationPolicyProvider> provider( | 340 for (int i = 0; i < NUM_PROXY_MODES; ++i) { |
349 new MockConfigurationPolicyProvider()); | 341 scoped_ptr<MockConfigurationPolicyProvider> provider( |
350 provider->AddPolicy(kPolicyProxyServerMode, | 342 new MockConfigurationPolicyProvider()); |
351 Value::CreateIntegerValue( | 343 provider->AddPolicy(kPolicyProxyMode, Value::CreateIntegerValue(i)); |
352 kPolicyUseSystemProxyMode)); | 344 // No mode expects all three parameters being set. |
353 provider->AddPolicy(kPolicyProxyBypassList, | 345 provider->AddPolicy(kPolicyProxyPacUrl, |
354 Value::CreateStringValue("http://chromium.org/override")); | 346 Value::CreateStringValue("http://short.org/proxy.pac")); |
| 347 provider->AddPolicy(kPolicyProxyBypassList, |
| 348 Value::CreateStringValue( |
| 349 "http://chromium.org/override")); |
| 350 provider->AddPolicy(kPolicyProxyServer, |
| 351 Value::CreateStringValue("chromium.org")); |
355 | 352 |
356 ConfigurationPolicyPrefStore store(provider.get()); | 353 ConfigurationPolicyPrefStore store(provider.get()); |
357 | 354 EXPECT_FALSE(store.prefs()->HasKey(prefs::kProxyMode)); |
358 std::string string_result; | 355 } |
359 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, | |
360 &string_result)); | |
361 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); | |
362 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); | |
363 bool bool_result; | |
364 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); | |
365 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, | |
366 &bool_result)); | |
367 } | 356 } |
368 | 357 |
369 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test { | 358 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test { |
370 }; | 359 }; |
371 | 360 |
372 // Checks that if the policy for default search is valid, i.e. there's a | 361 // Checks that if the policy for default search is valid, i.e. there's a |
373 // search URL, that all the elements have been given proper defaults. | 362 // search URL, that all the elements have been given proper defaults. |
374 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) { | 363 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) { |
375 const char* const search_url = "http://test.com/search?t={searchTerms}"; | 364 const char* const search_url = "http://test.com/search?t={searchTerms}"; |
376 scoped_ptr<MockConfigurationPolicyProvider> provider( | 365 scoped_ptr<MockConfigurationPolicyProvider> provider( |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 | 611 |
623 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Disabled) { | 612 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Disabled) { |
624 store_.Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(false)); | 613 store_.Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(false)); |
625 // Disabling AutoFill should switch the pref to managed. | 614 // Disabling AutoFill should switch the pref to managed. |
626 bool result = true; | 615 bool result = true; |
627 EXPECT_TRUE(store_.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result)); | 616 EXPECT_TRUE(store_.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result)); |
628 EXPECT_FALSE(result); | 617 EXPECT_FALSE(result); |
629 } | 618 } |
630 | 619 |
631 } // namespace policy | 620 } // namespace policy |
OLD | NEW |