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

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

Issue 6240013: Make proxy settings one atomic dictionary in the PrefStores such that modifications are atomic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/out/Debug
Patch Set: Updated to ToT and addressed Matt's comments in base-CL Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | 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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/ref_counted.h" 6 #include "base/ref_counted.h"
7 #include "chrome/browser/policy/configuration_policy_pref_store.h" 7 #include "chrome/browser/policy/configuration_policy_pref_store.h"
8 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 8 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
9 #include "chrome/browser/prefs/proxy_prefs.h" 9 #include "chrome/browser/prefs/proxy_prefs.h"
10 #include "chrome/common/notification_service.h" 10 #include "chrome/common/notification_service.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test { 231 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test {
232 protected: 232 protected:
233 // Verify that all the proxy prefs are set to the specified expected values. 233 // Verify that all the proxy prefs are set to the specified expected values.
234 static void VerifyProxyPrefs( 234 static void VerifyProxyPrefs(
235 const ConfigurationPolicyPrefStore& store, 235 const ConfigurationPolicyPrefStore& store,
236 const std::string& expected_proxy_server, 236 const std::string& expected_proxy_server,
237 const std::string& expected_proxy_pac_url, 237 const std::string& expected_proxy_pac_url,
238 const std::string& expected_proxy_bypass_list, 238 const std::string& expected_proxy_bypass_list,
239 const ProxyPrefs::ProxyMode& expected_proxy_mode) { 239 const ProxyPrefs::ProxyMode& expected_proxy_mode) {
240 Value* value = NULL; 240 Value* value = NULL;
241 241 ASSERT_EQ(PrefStore::READ_OK,
242 store.GetValue(prefs::kProxy, &value));
243 ASSERT_EQ(Value::TYPE_DICTIONARY, value->GetType());
244 ProxyPrefsDictionary dict(static_cast<DictionaryValue*>(value));
245 std::string s;
242 if (expected_proxy_server.empty()) { 246 if (expected_proxy_server.empty()) {
243 EXPECT_EQ(PrefStore::READ_USE_DEFAULT, 247 EXPECT_FALSE(dict.GetProxyServer(&s));
244 store.GetValue(prefs::kProxyServer, NULL));
245 } else { 248 } else {
246 EXPECT_EQ(PrefStore::READ_OK, 249 ASSERT_TRUE(dict.GetProxyServer(&s));
247 store.GetValue(prefs::kProxyServer, &value)); 250 EXPECT_EQ(expected_proxy_server, s);
248 EXPECT_TRUE(StringValue(expected_proxy_server).Equals(value));
249 } 251 }
250 if (expected_proxy_pac_url.empty()) { 252 if (expected_proxy_pac_url.empty()) {
251 EXPECT_EQ(PrefStore::READ_USE_DEFAULT, 253 EXPECT_FALSE(dict.GetPacUrl(&s));
252 store.GetValue(prefs::kProxyPacUrl, NULL));
253 } else { 254 } else {
254 EXPECT_EQ(PrefStore::READ_OK, 255 ASSERT_TRUE(dict.GetPacUrl(&s));
255 store.GetValue(prefs::kProxyPacUrl, &value)); 256 EXPECT_EQ(expected_proxy_pac_url, s);
256 EXPECT_TRUE(StringValue(expected_proxy_pac_url).Equals(value));
257 } 257 }
258 if (expected_proxy_bypass_list.empty()) { 258 if (expected_proxy_bypass_list.empty()) {
259 EXPECT_EQ(PrefStore::READ_USE_DEFAULT, 259 EXPECT_FALSE(dict.GetBypassList(&s));
260 store.GetValue(prefs::kProxyBypassList, NULL));
261 } else { 260 } else {
262 EXPECT_EQ(PrefStore::READ_OK, 261 ASSERT_TRUE(dict.GetBypassList(&s));
263 store.GetValue(prefs::kProxyBypassList, &value)); 262 EXPECT_EQ(expected_proxy_bypass_list, s);
264 EXPECT_TRUE(StringValue(expected_proxy_bypass_list).Equals(value));
265 } 263 }
266 EXPECT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kProxyMode, &value)); 264 ProxyPrefs::ProxyMode mode;
267 EXPECT_TRUE(FundamentalValue(expected_proxy_mode).Equals(value)); 265 ASSERT_TRUE(dict.GetMode(&mode));
266 EXPECT_EQ(expected_proxy_mode, mode);
268 } 267 }
269 }; 268 };
270 269
271 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) { 270 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) {
272 MockConfigurationPolicyProvider provider; 271 MockConfigurationPolicyProvider provider;
273 provider.AddPolicy(kPolicyProxyBypassList, 272 provider.AddPolicy(kPolicyProxyBypassList,
274 Value::CreateStringValue("http://chromium.org/override")); 273 Value::CreateStringValue("http://chromium.org/override"));
275 provider.AddPolicy(kPolicyProxyServer, 274 provider.AddPolicy(kPolicyProxyServer,
276 Value::CreateStringValue("chromium.org")); 275 Value::CreateStringValue("chromium.org"));
277 provider.AddPolicy(kPolicyProxyServerMode, 276 provider.AddPolicy(kPolicyProxyServerMode,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 provider.AddPolicy(kPolicyProxyPacUrl, 401 provider.AddPolicy(kPolicyProxyPacUrl,
403 Value::CreateStringValue("http://short.org/proxy.pac")); 402 Value::CreateStringValue("http://short.org/proxy.pac"));
404 provider.AddPolicy(kPolicyProxyBypassList, 403 provider.AddPolicy(kPolicyProxyBypassList,
405 Value::CreateStringValue( 404 Value::CreateStringValue(
406 "http://chromium.org/override")); 405 "http://chromium.org/override"));
407 provider.AddPolicy(kPolicyProxyServer, 406 provider.AddPolicy(kPolicyProxyServer,
408 Value::CreateStringValue("chromium.org")); 407 Value::CreateStringValue("chromium.org"));
409 408
410 scoped_refptr<ConfigurationPolicyPrefStore> store( 409 scoped_refptr<ConfigurationPolicyPrefStore> store(
411 new ConfigurationPolicyPrefStore(&provider)); 410 new ConfigurationPolicyPrefStore(&provider));
412 EXPECT_EQ(PrefStore::READ_NO_VALUE, 411 Value* value = NULL;
413 store->GetValue(prefs::kProxyMode, NULL)); 412 ASSERT_EQ(PrefStore::READ_NO_VALUE,
danno 2011/02/04 10:32:13 Why is this an assert? Asserts are for fatal error
battre 2011/02/07 14:13:47 Done.
413 store->GetValue(prefs::kProxy, &value));
414 } 414 }
415 } 415 }
416 416
417 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test { 417 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test {
418 }; 418 };
419 419
420 // Checks that if the policy for default search is valid, i.e. there's a 420 // Checks that if the policy for default search is valid, i.e. there's a
421 // search URL, that all the elements have been given proper defaults. 421 // search URL, that all the elements have been given proper defaults.
422 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) { 422 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) {
423 const char* const search_url = "http://test.com/search?t={searchTerms}"; 423 const char* const search_url = "http://test.com/search?t={searchTerms}";
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 699
700 provider_.SetInitializationComplete(true); 700 provider_.SetInitializationComplete(true);
701 EXPECT_FALSE(store_->IsInitializationComplete()); 701 EXPECT_FALSE(store_->IsInitializationComplete());
702 702
703 store_->OnUpdatePolicy(); 703 store_->OnUpdatePolicy();
704 Mock::VerifyAndClearExpectations(&observer_); 704 Mock::VerifyAndClearExpectations(&observer_);
705 EXPECT_TRUE(store_->IsInitializationComplete()); 705 EXPECT_TRUE(store_->IsInitializationComplete());
706 } 706 }
707 707
708 } // namespace policy 708 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698