| 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 "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_config_dictionary.h" |
| 10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
| 11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 12 #include "chrome/common/pref_store_observer_mock.h" | 12 #include "chrome/common/pref_store_observer_mock.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using testing::_; | 16 using testing::_; |
| 17 using testing::Mock; | 17 using testing::Mock; |
| 18 | 18 |
| 19 namespace policy { | 19 namespace policy { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test { | 235 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test { |
| 236 protected: | 236 protected: |
| 237 // Verify that all the proxy prefs are set to the specified expected values. | 237 // Verify that all the proxy prefs are set to the specified expected values. |
| 238 static void VerifyProxyPrefs( | 238 static void VerifyProxyPrefs( |
| 239 const ConfigurationPolicyPrefStore& store, | 239 const ConfigurationPolicyPrefStore& store, |
| 240 const std::string& expected_proxy_server, | 240 const std::string& expected_proxy_server, |
| 241 const std::string& expected_proxy_pac_url, | 241 const std::string& expected_proxy_pac_url, |
| 242 const std::string& expected_proxy_bypass_list, | 242 const std::string& expected_proxy_bypass_list, |
| 243 const ProxyPrefs::ProxyMode& expected_proxy_mode) { | 243 const ProxyPrefs::ProxyMode& expected_proxy_mode) { |
| 244 Value* value = NULL; | 244 Value* value = NULL; |
| 245 | 245 ASSERT_EQ(PrefStore::READ_OK, |
| 246 store.GetValue(prefs::kProxy, &value)); |
| 247 ASSERT_EQ(Value::TYPE_DICTIONARY, value->GetType()); |
| 248 ProxyConfigDictionary dict(static_cast<DictionaryValue*>(value)); |
| 249 std::string s; |
| 246 if (expected_proxy_server.empty()) { | 250 if (expected_proxy_server.empty()) { |
| 247 EXPECT_EQ(PrefStore::READ_USE_DEFAULT, | 251 EXPECT_FALSE(dict.GetProxyServer(&s)); |
| 248 store.GetValue(prefs::kProxyServer, NULL)); | |
| 249 } else { | 252 } else { |
| 250 EXPECT_EQ(PrefStore::READ_OK, | 253 ASSERT_TRUE(dict.GetProxyServer(&s)); |
| 251 store.GetValue(prefs::kProxyServer, &value)); | 254 EXPECT_EQ(expected_proxy_server, s); |
| 252 EXPECT_TRUE(StringValue(expected_proxy_server).Equals(value)); | |
| 253 } | 255 } |
| 254 if (expected_proxy_pac_url.empty()) { | 256 if (expected_proxy_pac_url.empty()) { |
| 255 EXPECT_EQ(PrefStore::READ_USE_DEFAULT, | 257 EXPECT_FALSE(dict.GetPacUrl(&s)); |
| 256 store.GetValue(prefs::kProxyPacUrl, NULL)); | |
| 257 } else { | 258 } else { |
| 258 EXPECT_EQ(PrefStore::READ_OK, | 259 ASSERT_TRUE(dict.GetPacUrl(&s)); |
| 259 store.GetValue(prefs::kProxyPacUrl, &value)); | 260 EXPECT_EQ(expected_proxy_pac_url, s); |
| 260 EXPECT_TRUE(StringValue(expected_proxy_pac_url).Equals(value)); | |
| 261 } | 261 } |
| 262 if (expected_proxy_bypass_list.empty()) { | 262 if (expected_proxy_bypass_list.empty()) { |
| 263 EXPECT_EQ(PrefStore::READ_USE_DEFAULT, | 263 EXPECT_FALSE(dict.GetBypassList(&s)); |
| 264 store.GetValue(prefs::kProxyBypassList, NULL)); | |
| 265 } else { | 264 } else { |
| 266 EXPECT_EQ(PrefStore::READ_OK, | 265 ASSERT_TRUE(dict.GetBypassList(&s)); |
| 267 store.GetValue(prefs::kProxyBypassList, &value)); | 266 EXPECT_EQ(expected_proxy_bypass_list, s); |
| 268 EXPECT_TRUE(StringValue(expected_proxy_bypass_list).Equals(value)); | |
| 269 } | 267 } |
| 270 EXPECT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kProxyMode, &value)); | 268 ProxyPrefs::ProxyMode mode; |
| 271 EXPECT_TRUE(FundamentalValue(expected_proxy_mode).Equals(value)); | 269 ASSERT_TRUE(dict.GetMode(&mode)); |
| 270 EXPECT_EQ(expected_proxy_mode, mode); |
| 272 } | 271 } |
| 273 }; | 272 }; |
| 274 | 273 |
| 275 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) { | 274 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) { |
| 276 MockConfigurationPolicyProvider provider; | 275 MockConfigurationPolicyProvider provider; |
| 277 provider.AddPolicy(kPolicyProxyBypassList, | 276 provider.AddPolicy(kPolicyProxyBypassList, |
| 278 Value::CreateStringValue("http://chromium.org/override")); | 277 Value::CreateStringValue("http://chromium.org/override")); |
| 279 provider.AddPolicy(kPolicyProxyServer, | 278 provider.AddPolicy(kPolicyProxyServer, |
| 280 Value::CreateStringValue("chromium.org")); | 279 Value::CreateStringValue("chromium.org")); |
| 281 provider.AddPolicy(kPolicyProxyServerMode, | 280 provider.AddPolicy(kPolicyProxyServerMode, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 provider.AddPolicy(kPolicyProxyPacUrl, | 405 provider.AddPolicy(kPolicyProxyPacUrl, |
| 407 Value::CreateStringValue("http://short.org/proxy.pac")); | 406 Value::CreateStringValue("http://short.org/proxy.pac")); |
| 408 provider.AddPolicy(kPolicyProxyBypassList, | 407 provider.AddPolicy(kPolicyProxyBypassList, |
| 409 Value::CreateStringValue( | 408 Value::CreateStringValue( |
| 410 "http://chromium.org/override")); | 409 "http://chromium.org/override")); |
| 411 provider.AddPolicy(kPolicyProxyServer, | 410 provider.AddPolicy(kPolicyProxyServer, |
| 412 Value::CreateStringValue("chromium.org")); | 411 Value::CreateStringValue("chromium.org")); |
| 413 | 412 |
| 414 scoped_refptr<ConfigurationPolicyPrefStore> store( | 413 scoped_refptr<ConfigurationPolicyPrefStore> store( |
| 415 new ConfigurationPolicyPrefStore(&provider)); | 414 new ConfigurationPolicyPrefStore(&provider)); |
| 415 Value* value = NULL; |
| 416 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 416 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
| 417 store->GetValue(prefs::kProxyMode, NULL)); | 417 store->GetValue(prefs::kProxy, &value)); |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 | 420 |
| 421 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test { | 421 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test { |
| 422 }; | 422 }; |
| 423 | 423 |
| 424 // Checks that if the policy for default search is valid, i.e. there's a | 424 // Checks that if the policy for default search is valid, i.e. there's a |
| 425 // search URL, that all the elements have been given proper defaults. | 425 // search URL, that all the elements have been given proper defaults. |
| 426 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) { | 426 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) { |
| 427 const char* const search_url = "http://test.com/search?t={searchTerms}"; | 427 const char* const search_url = "http://test.com/search?t={searchTerms}"; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 | 703 |
| 704 provider_.SetInitializationComplete(true); | 704 provider_.SetInitializationComplete(true); |
| 705 EXPECT_FALSE(store_->IsInitializationComplete()); | 705 EXPECT_FALSE(store_->IsInitializationComplete()); |
| 706 | 706 |
| 707 store_->OnUpdatePolicy(); | 707 store_->OnUpdatePolicy(); |
| 708 Mock::VerifyAndClearExpectations(&observer_); | 708 Mock::VerifyAndClearExpectations(&observer_); |
| 709 EXPECT_TRUE(store_->IsInitializationComplete()); | 709 EXPECT_TRUE(store_->IsInitializationComplete()); |
| 710 } | 710 } |
| 711 | 711 |
| 712 } // namespace policy | 712 } // namespace policy |
| OLD | NEW |