1 // Copyright 2012 The Chromium Authors
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_resolution/proxy_info.h"
6
7 #include "net/base/net_errors.h"
8 #include "net/base/proxy_chain.h"
9 #include "net/log/net_log_with_source.h"
10 #include "net/proxy_resolution/proxy_config.h"
11 #include "net/proxy_resolution/proxy_list.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace net {
15 namespace {
16
TEST(ProxyInfoTest,ProxyInfoIsDirectOnly)17 TEST(ProxyInfoTest, ProxyInfoIsDirectOnly) {
18 // Test the is_direct_only() predicate.
19 ProxyInfo info;
20
21 // An empty ProxyInfo is not considered direct.
22 EXPECT_FALSE(info.is_direct_only());
23
24 info.UseDirect();
25 EXPECT_TRUE(info.is_direct_only());
26
27 info.UsePacString("DIRECT");
28 EXPECT_TRUE(info.is_direct_only());
29
30 info.UsePacString("PROXY myproxy:80");
31 EXPECT_FALSE(info.is_direct_only());
32
33 info.UsePacString("DIRECT; PROXY myproxy:80");
34 EXPECT_TRUE(info.is_direct());
35 EXPECT_FALSE(info.is_direct_only());
36
37 info.UsePacString("PROXY myproxy:80; DIRECT");
38 EXPECT_FALSE(info.is_direct());
39 EXPECT_FALSE(info.is_direct_only());
40 EXPECT_EQ(2u, info.proxy_list().size());
41 EXPECT_EQ("PROXY myproxy:80;DIRECT", info.proxy_list().ToDebugString());
42 // After falling back to direct, we shouldn't consider it DIRECT only.
43 EXPECT_TRUE(info.Fallback(ERR_PROXY_CONNECTION_FAILED, NetLogWithSource()));
44 EXPECT_TRUE(info.is_direct());
45 EXPECT_FALSE(info.is_direct_only());
46 }
47
48 } // namespace
49
TEST(ProxyInfoTest,UseVsOverrideProxyList)50 TEST(ProxyInfoTest, UseVsOverrideProxyList) {
51 ProxyInfo info;
52 ProxyList proxy_list;
53 proxy_list.Set("http://foo.com");
54 info.OverrideProxyList(proxy_list);
55 EXPECT_EQ("PROXY foo.com:80", info.proxy_list().ToDebugString());
56 proxy_list.Set("http://bar.com");
57 info.UseProxyList(proxy_list);
58 EXPECT_EQ("PROXY bar.com:80", info.proxy_list().ToDebugString());
59 }
60
TEST(ProxyInfoTest,IsForIpProtection)61 TEST(ProxyInfoTest, IsForIpProtection) {
62 ProxyInfo info;
63 EXPECT_FALSE(info.is_for_ip_protection());
64 info.set_is_for_ip_protection(true);
65 EXPECT_TRUE(info.is_for_ip_protection());
66 info.set_is_for_ip_protection(false);
67 EXPECT_FALSE(info.is_for_ip_protection());
68 }
69
TEST(ProxyListTest,UseProxyChain)70 TEST(ProxyListTest, UseProxyChain) {
71 ProxyInfo info;
72 ProxyChain proxy_chain =
73 ProxyChain::FromSchemeHostAndPort(ProxyServer::SCHEME_HTTP, "foo", 80);
74 info.UseProxyChain(proxy_chain);
75 EXPECT_EQ("PROXY foo:80", info.proxy_list().ToDebugString());
76 }
77
78 } // namespace net
79