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 3 // found in the LICENSE file. 4 5 #include "net/proxy/proxy_config_service_win.h" 6 7 #include "net/base/net_errors.h" 8 #include "net/proxy/proxy_config.h" 9 #include "net/proxy/proxy_config_service_common_unittest.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 12 namespace net { 13 14 TEST(ProxyConfigServiceWinTest, SetFromIEConfig) { 15 const struct { 16 // Input. 17 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config; 18 19 // Expected outputs (fields of the ProxyConfig). 20 bool auto_detect; 21 GURL pac_url; 22 ProxyConfig::ProxyRules proxy_rules; 23 const char* proxy_bypass_list; // newline separated 24 bool bypass_local_names; 25 } tests[] = { 26 // Auto detect. 27 { 28 { // Input. 29 TRUE, // fAutoDetect 30 NULL, // lpszAutoConfigUrl 31 NULL, // lpszProxy 32 NULL, // lpszProxyBypass 33 }, 34 35 // Expected result. 36 true, // auto_detect 37 GURL(), // pac_url 38 ProxyConfig::ProxyRules(), // proxy_rules 39 "", // proxy_bypass_list 40 false, // bypass_local_names 41 }, 42 43 // Valid PAC url 44 { 45 { // Input. 46 FALSE, // fAutoDetect 47 L"http://wpad/wpad.dat", // lpszAutoConfigUrl 48 NULL, // lpszProxy 49 NULL, // lpszProxy_bypass 50 }, 51 52 // Expected result. 53 false, // auto_detect 54 GURL("http://wpad/wpad.dat"), // pac_url 55 ProxyConfig::ProxyRules(), // proxy_rules 56 "", // proxy_bypass_list 57 false, // bypass_local_names 58 }, 59 60 // Invalid PAC url string. 61 { 62 { // Input. 63 FALSE, // fAutoDetect 64 L"wpad.dat", // lpszAutoConfigUrl 65 NULL, // lpszProxy 66 NULL, // lpszProxy_bypass 67 }, 68 69 // Expected result. 70 false, // auto_detect 71 GURL(), // pac_url 72 ProxyConfig::ProxyRules(), // proxy_rules 73 "", // proxy_bypass_list 74 false, // bypass_local_names 75 }, 76 77 // Single-host in proxy list. 78 { 79 { // Input. 80 FALSE, // fAutoDetect 81 NULL, // lpszAutoConfigUrl 82 L"www.google.com", // lpszProxy 83 NULL, // lpszProxy_bypass 84 }, 85 86 // Expected result. 87 false, // auto_detect 88 GURL(), // pac_url 89 MakeSingleProxyRules("www.google.com"), // proxy_rules 90 "", // proxy_bypass_list 91 false, // bypass_local_names 92 }, 93 94 // Per-scheme proxy rules. 95 { 96 { // Input. 97 FALSE, // fAutoDetect 98 NULL, // lpszAutoConfigUrl 99 L"http=www.google.com:80;https=www.foo.com:110", // lpszProxy 100 NULL, // lpszProxy_bypass 101 }, 102 103 // Expected result. 104 false, // auto_detect 105 GURL(), // pac_url 106 MakeProxyPerSchemeRules("www.google.com:80", "www.foo.com:110", ""), 107 "", // proxy_bypass_list 108 false, // bypass_local_names 109 }, 110 111 // SOCKS proxy configuration 112 { 113 { // Input. 114 FALSE, // fAutoDetect 115 NULL, // lpszAutoConfigUrl 116 L"http=www.google.com:80;https=www.foo.com:110;" 117 L"ftp=ftpproxy:20;socks=foopy:130", // lpszProxy 118 NULL, // lpszProxy_bypass 119 }, 120 121 // Expected result. 122 false, // auto_detect 123 GURL(), // pac_url 124 MakeProxyPerSchemeRules("www.google.com:80", "www.foo.com:110", 125 "ftpproxy:20", "foopy:130"), 126 "", // proxy_bypass_list 127 false, // bypass_local_names 128 }, 129 130 // Bypass local names. 131 { 132 { // Input. 133 TRUE, // fAutoDetect 134 NULL, // lpszAutoConfigUrl 135 NULL, // lpszProxy 136 L"<local>", // lpszProxy_bypass 137 }, 138 139 true, // auto_detect 140 GURL(), // pac_url 141 ProxyConfig::ProxyRules(), // proxy_rules 142 "", // proxy_bypass_list 143 true, // bypass_local_names 144 }, 145 146 // Bypass "google.com" and local names, using semicolon as delimeter 147 // (ignoring white space). 148 { 149 { // Input. 150 TRUE, // fAutoDetect 151 NULL, // lpszAutoConfigUrl 152 NULL, // lpszProxy 153 L"<local> ; google.com", // lpszProxy_bypass 154 }, 155 156 // Expected result. 157 true, // auto_detect 158 GURL(), // pac_url 159 ProxyConfig::ProxyRules(), // proxy_rules 160 "google.com\n", // proxy_bypass_list 161 true, // bypass_local_names 162 }, 163 164 // Bypass "foo.com" and "google.com", using lines as delimeter. 165 { 166 { // Input. 167 TRUE, // fAutoDetect 168 NULL, // lpszAutoConfigUrl 169 NULL, // lpszProxy 170 L"foo.com\r\ngoogle.com", // lpszProxy_bypass 171 }, 172 173 // Expected result. 174 true, // auto_detect 175 GURL(), // pac_url 176 ProxyConfig::ProxyRules(), // proxy_rules 177 "foo.com\ngoogle.com\n", // proxy_bypass_list 178 false, // bypass_local_names 179 }, 180 }; 181 182 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 183 ProxyConfig config; 184 ProxyConfigServiceWin::SetFromIEConfig(&config, tests[i].ie_config); 185 186 EXPECT_EQ(tests[i].auto_detect, config.auto_detect); 187 EXPECT_EQ(tests[i].pac_url, config.pac_url); 188 EXPECT_EQ(tests[i].proxy_bypass_list, 189 FlattenProxyBypass(config.proxy_bypass)); 190 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); 191 EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules); 192 } 193 } 194 195 } // namespace net 196