| 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" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { | 109 TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { |
| 110 net::ProxyConfig actual_config; | 110 net::ProxyConfig actual_config; |
| 111 proxy_config_service_->GetLatestProxyConfig(&actual_config); | 111 proxy_config_service_->GetLatestProxyConfig(&actual_config); |
| 112 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); | 112 EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { | 115 TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { |
| 116 pref_service_->SetManagedPref( | 116 pref_service_->SetManagedPref( |
| 117 prefs::kProxyServer, Value::CreateStringValue("http://example.com:3128")); | 117 prefs::kProxy, |
| 118 pref_service_->SetManagedPref( | 118 ProxyPrefsDictionary::CreateFixedServers("http://example.com:3128", "")); |
| 119 prefs::kProxyMode, | |
| 120 Value::CreateIntegerValue(ProxyPrefs::MODE_FIXED_SERVERS)); | |
| 121 loop_.RunAllPending(); | 119 loop_.RunAllPending(); |
| 122 | 120 |
| 123 net::ProxyConfig actual_config; | 121 net::ProxyConfig actual_config; |
| 124 proxy_config_service_->GetLatestProxyConfig(&actual_config); | 122 proxy_config_service_->GetLatestProxyConfig(&actual_config); |
| 125 EXPECT_FALSE(actual_config.auto_detect()); | 123 EXPECT_FALSE(actual_config.auto_detect()); |
| 126 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, | 124 EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, |
| 127 actual_config.proxy_rules().type); | 125 actual_config.proxy_rules().type); |
| 128 EXPECT_EQ(actual_config.proxy_rules().single_proxy, | 126 EXPECT_EQ(actual_config.proxy_rules().single_proxy, |
| 129 net::ProxyServer::FromURI("http://example.com:3128", | 127 net::ProxyServer::FromURI("http://example.com:3128", |
| 130 net::ProxyServer::SCHEME_HTTP)); | 128 net::ProxyServer::SCHEME_HTTP)); |
| 131 | 129 |
| 132 pref_service_->SetManagedPref( | 130 pref_service_->SetManagedPref(prefs::kProxy, |
| 133 prefs::kProxyMode, | 131 ProxyPrefsDictionary::CreateAutoDetect()); |
| 134 Value::CreateIntegerValue(ProxyPrefs::MODE_AUTO_DETECT)); | |
| 135 loop_.RunAllPending(); | 132 loop_.RunAllPending(); |
| 136 | 133 |
| 137 proxy_config_service_->GetLatestProxyConfig(&actual_config); | 134 proxy_config_service_->GetLatestProxyConfig(&actual_config); |
| 138 EXPECT_TRUE(actual_config.auto_detect()); | 135 EXPECT_TRUE(actual_config.auto_detect()); |
| 139 } | 136 } |
| 140 | 137 |
| 141 // Compares proxy configurations, but allows different identifiers. | 138 // Compares proxy configurations, but allows different identifiers. |
| 142 MATCHER_P(ProxyConfigMatches, config, "") { | 139 MATCHER_P(ProxyConfigMatches, config, "") { |
| 143 net::ProxyConfig reference(config); | 140 net::ProxyConfig reference(config); |
| 144 reference.set_id(arg.id()); | 141 reference.set_id(arg.id()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 157 delegate_service_->SetProxyConfig(config2); | 154 delegate_service_->SetProxyConfig(config2); |
| 158 loop_.RunAllPending(); | 155 loop_.RunAllPending(); |
| 159 Mock::VerifyAndClearExpectations(&observer); | 156 Mock::VerifyAndClearExpectations(&observer); |
| 160 | 157 |
| 161 // Override configuration, this should trigger a notification. | 158 // Override configuration, this should trigger a notification. |
| 162 net::ProxyConfig pref_config; | 159 net::ProxyConfig pref_config; |
| 163 pref_config.set_pac_url(GURL(kFixedPacUrl)); | 160 pref_config.set_pac_url(GURL(kFixedPacUrl)); |
| 164 | 161 |
| 165 EXPECT_CALL(observer, | 162 EXPECT_CALL(observer, |
| 166 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1); | 163 OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1); |
| 167 | |
| 168 pref_service_->SetManagedPref(prefs::kProxyPacUrl, | |
| 169 Value::CreateStringValue(kFixedPacUrl)); | |
| 170 // The above does not trigger a notification, because PrefProxyConfig still | |
| 171 // sees the mode as the default (ProxyPrefs::SYSTEM), so that it doesn't claim | |
| 172 // to have proxy config. | |
| 173 // TODO(battre): Remove this comment when http://crbug.com/65732 is | |
| 174 // resolved. | |
| 175 pref_service_->SetManagedPref( | 164 pref_service_->SetManagedPref( |
| 176 prefs::kProxyMode, | 165 prefs::kProxy, |
| 177 Value::CreateIntegerValue(ProxyPrefs::MODE_PAC_SCRIPT)); | 166 ProxyPrefsDictionary::CreatePacScript(kFixedPacUrl)); |
| 178 loop_.RunAllPending(); | 167 loop_.RunAllPending(); |
| 179 Mock::VerifyAndClearExpectations(&observer); | 168 Mock::VerifyAndClearExpectations(&observer); |
| 180 | 169 |
| 181 // Since there are pref overrides, delegate changes should be ignored. | 170 // Since there are pref overrides, delegate changes should be ignored. |
| 182 net::ProxyConfig config3; | 171 net::ProxyConfig config3; |
| 183 config3.proxy_rules().ParseFromString("http=config3:80"); | 172 config3.proxy_rules().ParseFromString("http=config3:80"); |
| 184 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0); | 173 EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0); |
| 185 fixed_config_.set_auto_detect(true); | 174 fixed_config_.set_auto_detect(true); |
| 186 delegate_service_->SetProxyConfig(config3); | 175 delegate_service_->SetProxyConfig(config3); |
| 187 loop_.RunAllPending(); | 176 loop_.RunAllPending(); |
| 188 Mock::VerifyAndClearExpectations(&observer); | 177 Mock::VerifyAndClearExpectations(&observer); |
| 189 | 178 |
| 190 // Clear the override should switch back to the fixed configuration. | 179 // Clear the override should switch back to the fixed configuration. |
| 191 EXPECT_CALL(observer, | 180 EXPECT_CALL(observer, |
| 192 OnProxyConfigChanged(ProxyConfigMatches(config3))).Times(1); | 181 OnProxyConfigChanged(ProxyConfigMatches(config3))).Times(1); |
| 193 pref_service_->RemoveManagedPref(prefs::kProxyMode); | 182 pref_service_->RemoveManagedPref(prefs::kProxy); |
| 194 // The above switches the mode to the default (ProxyPrefs::SYSTEM), so the | |
| 195 // next removal won't bother PrefProxyConfigService. | |
| 196 // TODO(battre): Remove this comment when http://crbug.com/65732 is | |
| 197 // completed. | |
| 198 pref_service_->RemoveManagedPref(prefs::kProxyPacUrl); | |
| 199 loop_.RunAllPending(); | 183 loop_.RunAllPending(); |
| 200 Mock::VerifyAndClearExpectations(&observer); | 184 Mock::VerifyAndClearExpectations(&observer); |
| 201 | 185 |
| 202 // Delegate service notifications should show up again. | 186 // Delegate service notifications should show up again. |
| 203 net::ProxyConfig config4; | 187 net::ProxyConfig config4; |
| 204 config4.proxy_rules().ParseFromString("socks:config4"); | 188 config4.proxy_rules().ParseFromString("socks:config4"); |
| 205 EXPECT_CALL(observer, | 189 EXPECT_CALL(observer, |
| 206 OnProxyConfigChanged(ProxyConfigMatches(config4))).Times(1); | 190 OnProxyConfigChanged(ProxyConfigMatches(config4))).Times(1); |
| 207 delegate_service_->SetProxyConfig(config4); | 191 delegate_service_->SetProxyConfig(config4); |
| 208 loop_.RunAllPending(); | 192 loop_.RunAllPending(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 net::ProxyRulesExpectation::Empty(), | 378 net::ProxyRulesExpectation::Empty(), |
| 395 }, | 379 }, |
| 396 }; | 380 }; |
| 397 | 381 |
| 398 INSTANTIATE_TEST_CASE_P( | 382 INSTANTIATE_TEST_CASE_P( |
| 399 PrefProxyConfigServiceCommandLineTestInstance, | 383 PrefProxyConfigServiceCommandLineTestInstance, |
| 400 PrefProxyConfigServiceCommandLineTest, | 384 PrefProxyConfigServiceCommandLineTest, |
| 401 testing::ValuesIn(kCommandLineTestParams)); | 385 testing::ValuesIn(kCommandLineTestParams)); |
| 402 | 386 |
| 403 } // namespace | 387 } // namespace |
| OLD | NEW |