Enables compositing support for webview.
[chromium-blink-merge.git] / net / proxy / proxy_config_unittest.cc
blob47ea68946f671c8842901e206f82941074d0956c
1 // Copyright (c) 2012 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.
5 #include "net/proxy/proxy_config.h"
6 #include "net/proxy/proxy_config_service_common_unittest.h"
7 #include "net/proxy/proxy_info.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace net {
11 namespace {
13 void ExpectProxyServerEquals(const char* expectation,
14 const ProxyServer& proxy_server) {
15 if (expectation == NULL) {
16 EXPECT_FALSE(proxy_server.is_valid());
17 } else {
18 EXPECT_EQ(expectation, proxy_server.ToURI());
22 TEST(ProxyConfigTest, Equals) {
23 // Test |ProxyConfig::auto_detect|.
25 ProxyConfig config1;
26 config1.set_auto_detect(true);
28 ProxyConfig config2;
29 config2.set_auto_detect(false);
31 EXPECT_FALSE(config1.Equals(config2));
32 EXPECT_FALSE(config2.Equals(config1));
34 config2.set_auto_detect(true);
36 EXPECT_TRUE(config1.Equals(config2));
37 EXPECT_TRUE(config2.Equals(config1));
39 // Test |ProxyConfig::pac_url|.
41 config2.set_pac_url(GURL("http://wpad/wpad.dat"));
43 EXPECT_FALSE(config1.Equals(config2));
44 EXPECT_FALSE(config2.Equals(config1));
46 config1.set_pac_url(GURL("http://wpad/wpad.dat"));
48 EXPECT_TRUE(config1.Equals(config2));
49 EXPECT_TRUE(config2.Equals(config1));
51 // Test |ProxyConfig::proxy_rules|.
53 config2.proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
54 config2.proxy_rules().single_proxy =
55 ProxyServer::FromURI("myproxy:80", ProxyServer::SCHEME_HTTP);
57 EXPECT_FALSE(config1.Equals(config2));
58 EXPECT_FALSE(config2.Equals(config1));
60 config1.proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
61 config1.proxy_rules().single_proxy =
62 ProxyServer::FromURI("myproxy:100", ProxyServer::SCHEME_HTTP);
64 EXPECT_FALSE(config1.Equals(config2));
65 EXPECT_FALSE(config2.Equals(config1));
67 config1.proxy_rules().single_proxy =
68 ProxyServer::FromURI("myproxy", ProxyServer::SCHEME_HTTP);
70 EXPECT_TRUE(config1.Equals(config2));
71 EXPECT_TRUE(config2.Equals(config1));
73 // Test |ProxyConfig::bypass_rules|.
75 config2.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
77 EXPECT_FALSE(config1.Equals(config2));
78 EXPECT_FALSE(config2.Equals(config1));
80 config1.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
82 EXPECT_TRUE(config1.Equals(config2));
83 EXPECT_TRUE(config2.Equals(config1));
85 // Test |ProxyConfig::proxy_rules.reverse_bypass|.
87 config2.proxy_rules().reverse_bypass = true;
89 EXPECT_FALSE(config1.Equals(config2));
90 EXPECT_FALSE(config2.Equals(config1));
92 config1.proxy_rules().reverse_bypass = true;
94 EXPECT_TRUE(config1.Equals(config2));
95 EXPECT_TRUE(config2.Equals(config1));
98 TEST(ProxyConfigTest, ParseProxyRules) {
99 const struct {
100 const char* proxy_rules;
102 ProxyConfig::ProxyRules::Type type;
103 const char* single_proxy;
104 const char* proxy_for_http;
105 const char* proxy_for_https;
106 const char* proxy_for_ftp;
107 const char* fallback_proxy;
108 } tests[] = {
109 // One HTTP proxy for all schemes.
111 "myproxy:80",
113 ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
114 "myproxy:80",
115 NULL,
116 NULL,
117 NULL,
118 NULL,
121 // Only specify a proxy server for "http://" urls.
123 "http=myproxy:80",
125 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
126 NULL,
127 "myproxy:80",
128 NULL,
129 NULL,
130 NULL,
133 // Specify an HTTP proxy for "ftp://" and a SOCKS proxy for "https://" urls.
135 "ftp=ftp-proxy ; https=socks4://foopy",
137 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
138 NULL,
139 NULL,
140 "socks4://foopy:1080",
141 "ftp-proxy:80",
142 NULL,
145 // Give a scheme-specific proxy as well as a non-scheme specific.
146 // The first entry "foopy" takes precedance marking this list as
147 // TYPE_SINGLE_PROXY.
149 "foopy ; ftp=ftp-proxy",
151 ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
152 "foopy:80",
153 NULL,
154 NULL,
155 NULL,
156 NULL,
159 // Give a scheme-specific proxy as well as a non-scheme specific.
160 // The first entry "ftp=ftp-proxy" takes precedance marking this list as
161 // TYPE_PROXY_PER_SCHEME.
163 "ftp=ftp-proxy ; foopy",
165 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
166 NULL,
167 NULL,
168 NULL,
169 "ftp-proxy:80",
170 NULL,
173 // Include duplicate entries -- last one wins.
175 "ftp=ftp1 ; ftp=ftp2 ; ftp=ftp3",
177 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
178 NULL,
179 NULL,
180 NULL,
181 "ftp3:80",
182 NULL,
185 // Only SOCKS proxy present, others being blank.
187 "socks=foopy",
189 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
190 NULL,
191 NULL,
192 NULL,
193 NULL,
194 "socks4://foopy:1080",
197 // SOCKS proxy present along with other proxies too
199 "http=httpproxy ; https=httpsproxy ; ftp=ftpproxy ; socks=foopy ",
201 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
202 NULL,
203 "httpproxy:80",
204 "httpsproxy:80",
205 "ftpproxy:80",
206 "socks4://foopy:1080",
209 // SOCKS proxy (with modifier) present along with some proxies
210 // (FTP being blank)
212 "http=httpproxy ; https=httpsproxy ; socks=socks5://foopy ",
214 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
215 NULL,
216 "httpproxy:80",
217 "httpsproxy:80",
218 NULL,
219 "socks5://foopy:1080",
222 // Include unsupported schemes -- they are discarded.
224 "crazy=foopy ; foo=bar ; https=myhttpsproxy",
226 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
227 NULL,
228 NULL,
229 "myhttpsproxy:80",
230 NULL,
231 NULL,
235 ProxyConfig config;
237 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
238 config.proxy_rules().ParseFromString(tests[i].proxy_rules);
240 EXPECT_EQ(tests[i].type, config.proxy_rules().type);
241 ExpectProxyServerEquals(tests[i].single_proxy,
242 config.proxy_rules().single_proxy);
243 ExpectProxyServerEquals(tests[i].proxy_for_http,
244 config.proxy_rules().proxy_for_http);
245 ExpectProxyServerEquals(tests[i].proxy_for_https,
246 config.proxy_rules().proxy_for_https);
247 ExpectProxyServerEquals(tests[i].proxy_for_ftp,
248 config.proxy_rules().proxy_for_ftp);
249 ExpectProxyServerEquals(tests[i].fallback_proxy,
250 config.proxy_rules().fallback_proxy);
254 TEST(ProxyConfigTest, ProxyRulesSetBypassFlag) {
255 // Test whether the did_bypass_proxy() flag is set in proxy info correctly.
256 ProxyConfig::ProxyRules rules;
257 ProxyInfo result;
259 rules.ParseFromString("http=httpproxy:80");
260 rules.bypass_rules.AddRuleFromString(".com");
262 rules.Apply(GURL("http://example.com"), &result);
263 EXPECT_TRUE(result.is_direct_only());
264 EXPECT_TRUE(result.did_bypass_proxy());
266 rules.Apply(GURL("http://example.org"), &result);
267 EXPECT_FALSE(result.is_direct());
268 EXPECT_FALSE(result.did_bypass_proxy());
270 // Try with reversed bypass rules.
271 rules.reverse_bypass = true;
273 rules.Apply(GURL("http://example.org"), &result);
274 EXPECT_TRUE(result.is_direct_only());
275 EXPECT_TRUE(result.did_bypass_proxy());
277 rules.Apply(GURL("http://example.com"), &result);
278 EXPECT_FALSE(result.is_direct());
279 EXPECT_FALSE(result.did_bypass_proxy());
282 } // namespace
283 } // namespace net