| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "net/proxy/proxy_config_service_win.h" | 5 #include "net/proxy/proxy_config_service_win.h" |
| 6 | 6 |
| 7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
| 8 #include "net/proxy/proxy_config.h" | 8 #include "net/proxy/proxy_config.h" |
| 9 #include "net/proxy/proxy_config_service_common_unittest.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 11 |
| 11 namespace net { | 12 namespace net { |
| 12 | 13 |
| 13 static ProxyConfig::ProxyRules MakeProxyRules( | |
| 14 ProxyConfig::ProxyRules::Type type, | |
| 15 const char* single_proxy, | |
| 16 const char* proxy_for_http, | |
| 17 const char* proxy_for_https, | |
| 18 const char* proxy_for_ftp) { | |
| 19 ProxyConfig::ProxyRules rules; | |
| 20 rules.type = type; | |
| 21 rules.single_proxy = ProxyServer::FromURI(single_proxy); | |
| 22 rules.proxy_for_http = ProxyServer::FromURI(proxy_for_http); | |
| 23 rules.proxy_for_https = ProxyServer::FromURI(proxy_for_https); | |
| 24 rules.proxy_for_ftp = ProxyServer::FromURI(proxy_for_ftp); | |
| 25 return rules; | |
| 26 } | |
| 27 | |
| 28 static ProxyConfig::ProxyRules MakeSingleProxyRules(const char* single_proxy) { | |
| 29 return MakeProxyRules(ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, | |
| 30 single_proxy, "", "", ""); | |
| 31 } | |
| 32 | |
| 33 static ProxyConfig::ProxyRules MakeProxyPerSchemeRules( | |
| 34 const char* proxy_http, | |
| 35 const char* proxy_https, | |
| 36 const char* proxy_ftp) { | |
| 37 return MakeProxyRules(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | |
| 38 "", proxy_http, proxy_https, proxy_ftp); | |
| 39 } | |
| 40 | |
| 41 TEST(ProxyConfigServiceWinTest, SetFromIEConfig) { | 14 TEST(ProxyConfigServiceWinTest, SetFromIEConfig) { |
| 42 const struct { | 15 const struct { |
| 43 // Input. | 16 // Input. |
| 44 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config; | 17 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config; |
| 45 | 18 |
| 46 // Expected outputs (fields of the ProxyConfig). | 19 // Expected outputs (fields of the ProxyConfig). |
| 47 bool auto_detect; | 20 bool auto_detect; |
| 48 GURL pac_url; | 21 GURL pac_url; |
| 49 ProxyConfig::ProxyRules proxy_rules; | 22 ProxyConfig::ProxyRules proxy_rules; |
| 50 const char* proxy_bypass_list; // newline separated | 23 const char* proxy_bypass_list; // newline separated |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 false, // bypass_local_names | 159 false, // bypass_local_names |
| 187 }, | 160 }, |
| 188 }; | 161 }; |
| 189 | 162 |
| 190 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 163 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 191 ProxyConfig config; | 164 ProxyConfig config; |
| 192 ProxyConfigServiceWin::SetFromIEConfig(&config, tests[i].ie_config); | 165 ProxyConfigServiceWin::SetFromIEConfig(&config, tests[i].ie_config); |
| 193 | 166 |
| 194 EXPECT_EQ(tests[i].auto_detect, config.auto_detect); | 167 EXPECT_EQ(tests[i].auto_detect, config.auto_detect); |
| 195 EXPECT_EQ(tests[i].pac_url, config.pac_url); | 168 EXPECT_EQ(tests[i].pac_url, config.pac_url); |
| 196 | 169 EXPECT_EQ(tests[i].proxy_bypass_list, |
| 197 // Join the proxy bypass list using "\n" to make it into a single string. | 170 FlattenProxyBypass(config.proxy_bypass)); |
| 198 std::string flattened_proxy_bypass; | |
| 199 typedef std::vector<std::string> BypassList; | |
| 200 for (BypassList::const_iterator it = config.proxy_bypass.begin(); | |
| 201 it != config.proxy_bypass.end(); ++it) { | |
| 202 flattened_proxy_bypass += *it + "\n"; | |
| 203 } | |
| 204 | |
| 205 EXPECT_EQ(tests[i].proxy_bypass_list, flattened_proxy_bypass); | |
| 206 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); | 171 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); |
| 207 EXPECT_TRUE(tests[i].proxy_rules == config.proxy_rules); | 172 EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules); |
| 208 } | 173 } |
| 209 } | 174 } |
| 210 | 175 |
| 211 } // namespace net | 176 } // namespace net |
| OLD | NEW |