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

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

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

Powered by Google App Engine
This is Rietveld 408576698