Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(995)

Side by Side Diff: net/proxy/proxy_list_unittest.cc

Issue 552164: Merge 34903, 34928, 35008, 35549, 36054 to the 249s branch.... (Closed) Base URL: svn://chrome-svn/chrome/branches/249s/src/
Patch Set: Fix some other merge conflicts Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_list.cc ('k') | net/proxy/proxy_server.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Modified: svn:mergeinfo
Merged /trunk/src/net/proxy/proxy_list_unittest.cc:r34903,34928,35008,35549,36054
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_list.h" 5 #include "net/proxy/proxy_list.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace net {
9
10 namespace {
11
8 // Test parsing from a PAC string. 12 // Test parsing from a PAC string.
9 TEST(ProxyListTest, SetFromPacString) { 13 TEST(ProxyListTest, SetFromPacString) {
10 const struct { 14 const struct {
11 const char* pac_input; 15 const char* pac_input;
12 const char* pac_output; 16 const char* pac_output;
13 } tests[] = { 17 } tests[] = {
14 // Valid inputs: 18 // Valid inputs:
15 { "PROXY foopy:10", 19 { "PROXY foopy:10",
16 "PROXY foopy:10", 20 "PROXY foopy:10",
17 }, 21 },
18 { " DIRECT", // leading space. 22 { " DIRECT", // leading space.
19 "DIRECT", 23 "DIRECT",
20 }, 24 },
21 { "PROXY foopy1 ; proxy foopy2;\t DIRECT", 25 { "PROXY foopy1 ; proxy foopy2;\t DIRECT",
22 "PROXY foopy1:80;PROXY foopy2:80;DIRECT", 26 "PROXY foopy1:80;PROXY foopy2:80;DIRECT",
23 }, 27 },
24 { "proxy foopy1 ; SOCKS foopy2", 28 { "proxy foopy1 ; SOCKS foopy2",
25 "PROXY foopy1:80;SOCKS foopy2:1080", 29 "PROXY foopy1:80;SOCKS foopy2:1080",
26 }, 30 },
31 // Try putting DIRECT first.
32 { "DIRECT ; proxy foopy1 ; DIRECT ; SOCKS5 foopy2;DIRECT ",
33 "DIRECT;PROXY foopy1:80;DIRECT;SOCKS5 foopy2:1080;DIRECT",
34 },
35 // Try putting DIRECT consecutively.
36 { "DIRECT ; proxy foopy1:80; DIRECT ; DIRECT",
37 "DIRECT;PROXY foopy1:80;DIRECT;DIRECT",
38 },
27 39
28 // Invalid inputs (parts which aren't understood get 40 // Invalid inputs (parts which aren't understood get
29 // silently discarded): 41 // silently discarded):
42 //
43 // If the proxy list string parsed to empty, automatically fall-back to
44 // DIRECT.
30 { "PROXY-foopy:10", 45 { "PROXY-foopy:10",
31 "DIRECT", 46 "DIRECT",
32 }, 47 },
33 { "PROXY", 48 { "PROXY",
34 "DIRECT", 49 "DIRECT",
35 }, 50 },
36 { "PROXY foopy1 ; JUNK ; JUNK ; SOCKS5 foopy2 ; ;", 51 { "PROXY foopy1 ; JUNK ; JUNK ; SOCKS5 foopy2 ; ;",
37 "PROXY foopy1:80;SOCKS5 foopy2:1080", 52 "PROXY foopy1:80;SOCKS5 foopy2:1080",
38 }, 53 },
39 }; 54 };
40 55
41 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 56 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
42 net::ProxyList list; 57 ProxyList list;
43 list.SetFromPacString(tests[i].pac_input); 58 list.SetFromPacString(tests[i].pac_input);
44 EXPECT_EQ(tests[i].pac_output, list.ToPacString()); 59 EXPECT_EQ(tests[i].pac_output, list.ToPacString());
60 EXPECT_FALSE(list.IsEmpty());
45 } 61 }
46 } 62 }
47 63
48 TEST(ProxyListTest, RemoveProxiesWithoutScheme) { 64 TEST(ProxyListTest, RemoveProxiesWithoutScheme) {
49 const struct { 65 const struct {
50 const char* pac_input; 66 const char* pac_input;
51 int filter; 67 int filter;
52 const char* filtered_pac_output; 68 const char* filtered_pac_output;
53 } tests[] = { 69 } tests[] = {
54 { "PROXY foopy:10 ; SOCKS5 foopy2 ; SOCKS foopy11 ; PROXY foopy3 ; DIRECT", 70 { "PROXY foopy:10 ; SOCKS5 foopy2 ; SOCKS foopy11 ; PROXY foopy3 ; DIRECT",
55 // Remove anything that isn't HTTP or DIRECT. 71 // Remove anything that isn't HTTP or DIRECT.
56 net::ProxyServer::SCHEME_DIRECT | net::ProxyServer::SCHEME_HTTP, 72 ProxyServer::SCHEME_DIRECT | ProxyServer::SCHEME_HTTP,
57 "PROXY foopy:10;PROXY foopy3:80;DIRECT", 73 "PROXY foopy:10;PROXY foopy3:80;DIRECT",
58 }, 74 },
59 { "PROXY foopy:10 | SOCKS5 foopy2", 75 { "PROXY foopy:10 ; SOCKS5 foopy2",
60 // Remove anything that isn't HTTP or SOCKS5. 76 // Remove anything that isn't HTTP or SOCKS5.
61 net::ProxyServer::SCHEME_DIRECT | net::ProxyServer::SCHEME_SOCKS4, 77 ProxyServer::SCHEME_DIRECT | ProxyServer::SCHEME_SOCKS4,
62 "DIRECT", 78 "",
63 }, 79 },
64 }; 80 };
65 81
66 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 82 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
67 net::ProxyList list; 83 ProxyList list;
68 list.SetFromPacString(tests[i].pac_input); 84 list.SetFromPacString(tests[i].pac_input);
69 list.RemoveProxiesWithoutScheme(tests[i].filter); 85 list.RemoveProxiesWithoutScheme(tests[i].filter);
70 EXPECT_EQ(tests[i].filtered_pac_output, list.ToPacString()); 86 EXPECT_EQ(tests[i].filtered_pac_output, list.ToPacString());
71 } 87 }
72 } 88 }
89
90 TEST(ProxyListTest, DeprioritizeBadProxies) {
91 // Retry info that marks a proxy as being bad for a *very* long time (to avoid
92 // the test depending on the current time.)
93 ProxyRetryInfo proxy_retry_info;
94 proxy_retry_info.bad_until =
95 base::TimeTicks::Now() + base::TimeDelta::FromDays(1);
96
97 // Call DeprioritizeBadProxies with an empty map -- should have no effect.
98 {
99 ProxyList list;
100 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80");
101
102 ProxyRetryInfoMap retry_info_map;
103 list.DeprioritizeBadProxies(retry_info_map);
104 EXPECT_EQ("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80",
105 list.ToPacString());
106 }
107
108 // Call DeprioritizeBadProxies with 2 of the three proxies marked as bad.
109 // These proxies should be retried last.
110 {
111 ProxyList list;
112 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80");
113
114 ProxyRetryInfoMap retry_info_map;
115 retry_info_map["foopy1:80"] = proxy_retry_info;
116 retry_info_map["foopy3:80"] = proxy_retry_info;
117 retry_info_map["socks5://localhost:1080"] = proxy_retry_info;
118
119 list.DeprioritizeBadProxies(retry_info_map);
120
121 EXPECT_EQ("PROXY foopy2:80;PROXY foopy1:80;PROXY foopy3:80",
122 list.ToPacString());
123 }
124
125 // Call DeprioritizeBadProxies where ALL of the proxies are marked as bad.
126 // This should have no effect on the order.
127 {
128 ProxyList list;
129 list.SetFromPacString("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80");
130
131 ProxyRetryInfoMap retry_info_map;
132 retry_info_map["foopy1:80"] = proxy_retry_info;
133 retry_info_map["foopy2:80"] = proxy_retry_info;
134 retry_info_map["foopy3:80"] = proxy_retry_info;
135
136 list.DeprioritizeBadProxies(retry_info_map);
137
138 EXPECT_EQ("PROXY foopy1:80;PROXY foopy2:80;PROXY foopy3:80",
139 list.ToPacString());
140 }
141 }
142
143 } // namesapce
144
145 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_list.cc ('k') | net/proxy/proxy_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698