Chromium Code Reviews| 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 "chrome/browser/net/pref_proxy_config_service.h" | 5 #include "chrome/browser/net/pref_proxy_config_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "chrome/browser/net/chrome_url_request_context.h" | 9 #include "chrome/browser/net/chrome_url_request_context.h" |
| 10 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 10 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
| 11 #include "chrome/browser/prefs/proxy_prefs.h" | |
| 11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/test/testing_pref_service.h" | 14 #include "chrome/test/testing_pref_service.h" |
| 14 #include "net/proxy/proxy_config_service_common_unittest.h" | 15 #include "net/proxy/proxy_config_service_common_unittest.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 using testing::_; | 19 using testing::_; |
| 19 using testing::Mock; | 20 using testing::Mock; |
| 20 | 21 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 | 108 |
| 108 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { | 109 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { |
| 109 net::ProxyConfig actual_config; | 110 net::ProxyConfig actual_config; |
| 110 proxy_config_service_->GetLatestProxyConfig(&actual_config); | 111 proxy_config_service_->GetLatestProxyConfig(&actual_config); |
| 111 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); | 112 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); |
| 112 } | 113 } |
| 113 | 114 |
| 114 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { | 115 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { |
| 115 pref_service_->SetManagedPref( | 116 pref_service_->SetManagedPref( |
| 116 prefs::kProxyServer, Value::CreateStringValue("http://example.com:3128")); | 117 prefs::kProxyServer, Value::CreateStringValue("http://example.com:3128")); |
| 118 pref_service_->SetManagedPref( | |
| 119 prefs::kProxyServerMode, | |
| 120 Value::CreateIntegerValue(ProxyPrefs::MANUAL)); | |
| 117 loop_.RunAllPending(); | 121 loop_.RunAllPending(); |
| 118 | 122 |
| 119 net::ProxyConfig actual_config; | 123 net::ProxyConfig actual_config; |
| 120 proxy_config_service_->GetLatestProxyConfig(&actual_config); | 124 proxy_config_service_->GetLatestProxyConfig(&actual_config); |
| 121 EXPECT_FALSE(actual_config.auto_detect()); | 125 EXPECT_FALSE(actual_config.auto_detect()); |
| 122 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, | 126 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, |
| 123 actual_config.proxy_rules().type); | 127 actual_config.proxy_rules().type); |
| 124 EXPECT_EQ(actual_config.proxy_rules().single_proxy, | 128 EXPECT_EQ(actual_config.proxy_rules().single_proxy, |
| 125 net::ProxyServer::FromURI("http://example.com:3128", | 129 net::ProxyServer::FromURI("http://example.com:3128", |
| 126 net::ProxyServer::SCHEME_HTTP)); | 130 net::ProxyServer::SCHEME_HTTP)); |
| 127 | 131 |
| 128 pref_service_->SetManagedPref( | 132 pref_service_->SetManagedPref( |
| 129 prefs::kProxyAutoDetect, Value::CreateBooleanValue(true)); | 133 prefs::kProxyServerMode, |
| 134 Value::CreateIntegerValue(ProxyPrefs::AUTO_DETECT)); | |
| 130 loop_.RunAllPending(); | 135 loop_.RunAllPending(); |
| 131 | 136 |
| 132 proxy_config_service_->GetLatestProxyConfig(&actual_config); | 137 proxy_config_service_->GetLatestProxyConfig(&actual_config); |
| 133 EXPECT_TRUE(actual_config.auto_detect()); | 138 EXPECT_TRUE(actual_config.auto_detect()); |
| 134 } | 139 } |
| 135 | 140 |
| 136 // Compares proxy configurations, but allows different identifiers. | 141 // Compares proxy configurations, but allows different identifiers. |
| 137 MATCHER_P(ProxyConfigMatches, config, "") { | 142 MATCHER_P(ProxyConfigMatches, config, "") { |
| 138 net::ProxyConfig reference(config); | 143 net::ProxyConfig reference(config); |
| 139 reference.set_id(arg.id()); | 144 reference.set_id(arg.id()); |
| 140 return reference.Equals(arg); | 145 return reference.Equals(arg); |
| 141 } | 146 } |
| 142 | 147 |
| 143 TEST_F(PrefProxyConfigServiceTest, Observers) { | 148 // TODO(battre): Enable this test when http://crbug.com/65732 is fixed. (Move |
| 149 // proxy preferences into a dictionary.) The problem is that currently the | |
| 150 // observer gets fired twice, because two preferences are set. | |
|
danno
2010/12/17 14:21:11
Reactivate this test (even though it tests double
gfeher
2010/12/17 15:44:17
Done.
| |
| 151 TEST_F(PrefProxyConfigServiceTest, DISABLED_Observers) { | |
| 144 MockObserver observer; | 152 MockObserver observer; |
| 145 proxy_config_service_->AddObserver(&observer); | 153 proxy_config_service_->AddObserver(&observer); |
| 146 | 154 |
| 147 // Firing the observers in the delegate should trigger a notification. | 155 // Firing the observers in the delegate should trigger a notification. |
| 148 net::ProxyConfig config2; | 156 net::ProxyConfig config2; |
| 149 config2.set_auto_detect(true); | 157 config2.set_auto_detect(true); |
| 150 EXPECT_CALL(observer, | 158 EXPECT_CALL(observer, |
| 151 OnProxyConfigChanged(ProxyConfigMatches(config2))).Times(1); | 159 OnProxyConfigChanged(ProxyConfigMatches(config2))).Times(1); |
| 152 delegate_service_->SetProxyConfig(config2); | 160 delegate_service_->SetProxyConfig(config2); |
| 153 loop_.RunAllPending(); | 161 loop_.RunAllPending(); |
| 154 Mock::VerifyAndClearExpectations(&observer); | 162 Mock::VerifyAndClearExpectations(&observer); |
| 155 | 163 |
| 156 // Override configuration, this should trigger a notification. | 164 // Override configuration, this should trigger a notification. |
| 157 net::ProxyConfig pref_config; | 165 net::ProxyConfig pref_config; |
| 158 pref_config.set_pac_url(GURL(kFixedPacUrl)); | 166 pref_config.set_pac_url(GURL(kFixedPacUrl)); |
| 159 EXPECT_CALL(observer, | 167 EXPECT_CALL(observer, |
| 160 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1); | 168 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1); |
| 161 pref_service_->SetManagedPref(prefs::kProxyPacUrl, | 169 pref_service_->SetManagedPref(prefs::kProxyPacUrl, |
| 162 Value::CreateStringValue(kFixedPacUrl)); | 170 Value::CreateStringValue(kFixedPacUrl)); |
| 171 pref_service_->SetManagedPref( | |
| 172 prefs::kProxyServerMode, | |
| 173 Value::CreateIntegerValue(ProxyPrefs::MANUAL)); | |
| 163 loop_.RunAllPending(); | 174 loop_.RunAllPending(); |
| 164 Mock::VerifyAndClearExpectations(&observer); | 175 Mock::VerifyAndClearExpectations(&observer); |
| 165 | 176 |
| 166 // Since there are pref overrides, delegate changes should be ignored. | 177 // Since there are pref overrides, delegate changes should be ignored. |
| 167 net::ProxyConfig config3; | 178 net::ProxyConfig config3; |
| 168 config3.proxy_rules().ParseFromString("http=config3:80"); | 179 config3.proxy_rules().ParseFromString("http=config3:80"); |
| 169 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0); | 180 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0); |
| 170 fixed_config_.set_auto_detect(true); | 181 fixed_config_.set_auto_detect(true); |
| 171 delegate_service_->SetProxyConfig(config3); | 182 delegate_service_->SetProxyConfig(config3); |
| 172 loop_.RunAllPending(); | 183 loop_.RunAllPending(); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 net::ProxyRulesExpectation::Empty(), | 388 net::ProxyRulesExpectation::Empty(), |
| 378 }, | 389 }, |
| 379 }; | 390 }; |
| 380 | 391 |
| 381 INSTANTIATE_TEST_CASE_P( | 392 INSTANTIATE_TEST_CASE_P( |
| 382 PrefProxyConfigServiceCommandLineTestInstance, | 393 PrefProxyConfigServiceCommandLineTestInstance, |
| 383 PrefProxyConfigServiceCommandLineTest, | 394 PrefProxyConfigServiceCommandLineTest, |
| 384 testing::ValuesIn(kCommandLineTestParams)); | 395 testing::ValuesIn(kCommandLineTestParams)); |
| 385 | 396 |
| 386 } // namespace | 397 } // namespace |
| OLD | NEW |