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

Side by Side Diff: chrome/browser/net/chrome_url_request_context_unittest.cc

Issue 115029: Making command-line specified proxy settings more flexible - allowing for set... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | « chrome/browser/net/chrome_url_request_context.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-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 "base/command_line.h"
6 #include "chrome/browser/net/chrome_url_request_context.h"
7 #include "chrome/common/chrome_switches.h"
8 #include "net/proxy/proxy_config.h"
9 #include "net/proxy/proxy_config_service_common_unittest.h"
10
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 // Builds an identifier for each test in an array.
14 #define TEST_DESC(desc) StringPrintf("at line %d <%s>", __LINE__, desc)
15
16 TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
17 // Build the input command lines here.
18 CommandLine empty(L"foo.exe");
19 CommandLine no_proxy(L"foo.exe");
20 no_proxy.AppendSwitch(switches::kNoProxyServer);
21 CommandLine no_proxy_extra_params(L"foo.exe");
22 no_proxy_extra_params.AppendSwitch(switches::kNoProxyServer);
23 no_proxy_extra_params.AppendSwitchWithValue(switches::kProxyServer,
24 L"http://proxy:8888");
25 CommandLine single_proxy(L"foo.exe");
26 single_proxy.AppendSwitchWithValue(switches::kProxyServer,
27 L"http://proxy:8888");
28 CommandLine per_scheme_proxy(L"foo.exe");
29 per_scheme_proxy.AppendSwitchWithValue(switches::kProxyServer,
30 L"http=httpproxy:8888;ftp=ftpproxy:8889");
31 CommandLine per_scheme_proxy_bypass(L"foo.exe");
32 per_scheme_proxy_bypass.AppendSwitchWithValue(switches::kProxyServer,
33 L"http=httpproxy:8888;ftp=ftpproxy:8889");
34 per_scheme_proxy_bypass.AppendSwitchWithValue(
35 switches::kProxyServerBypassUrls,
36 L".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8");
37 CommandLine with_pac_url(L"foo.exe");
38 with_pac_url.AppendSwitchWithValue(switches::kProxyServerPacUrl,
39 L"http://wpad/wpad.dat");
40 with_pac_url.AppendSwitchWithValue(
41 switches::kProxyServerBypassUrls,
42 L".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8");
43 CommandLine with_auto_detect(L"foo.exe");
44 with_auto_detect.AppendSwitch(switches::kProxyServerAutoDetect);
45
46 // Inspired from proxy_config_service_win_unittest.cc.
47 const struct {
48 // Short description to identify the test
49 std::string description;
50
51 // The command line to build a ProxyConfig from.
52 const CommandLine& command_line;
53
54 // Expected outputs (fields of the ProxyConfig).
55 bool is_null;
56 bool auto_detect;
57 GURL pac_url;
58 net::ProxyConfig::ProxyRules proxy_rules;
59 const char* proxy_bypass_list; // newline separated
60 bool bypass_local_names;
61 } tests[] = {
62 {
63 TEST_DESC("Empty command line"),
64 // Input
65 empty,
66 // Expected result
67 true, // is_null
68 false, // auto_detect
69 GURL(), // pac_url
70 net::ProxyConfig::ProxyRules(), // proxy_rules
71 "", // proxy_bypass_list
72 false // bypass_local_names
73 },
74 {
75 TEST_DESC("No proxy"),
76 // Input
77 no_proxy,
78 // Expected result
79 false, // is_null
80 false, // auto_detect
81 GURL(), // pac_url
82 net::ProxyConfig::ProxyRules(), // proxy_rules
83 "", // proxy_bypass_list
84 false // bypass_local_names
85 },
86 {
87 TEST_DESC("No proxy with extra parameters."),
88 // Input
89 no_proxy_extra_params,
90 // Expected result
91 false, // is_null
92 false, // auto_detect
93 GURL(), // pac_url
94 net::ProxyConfig::ProxyRules(), // proxy_rules
95 "", // proxy_bypass_list
96 false // bypass_local_names
97 },
98 {
99 TEST_DESC("Single proxy."),
100 // Input
101 single_proxy,
102 // Expected result
103 false, // is_null
104 false, // auto_detect
105 GURL(), // pac_url
106 net::MakeSingleProxyRules("http://proxy:8888"), // proxy_rules
107 "", // proxy_bypass_list
108 false // bypass_local_names
109 },
110 {
111 TEST_DESC("Per scheme proxy."),
112 // Input
113 per_scheme_proxy,
114 // Expected result
115 false, // is_null
116 false, // auto_detect
117 GURL(), // pac_url
118 net::MakeProxyPerSchemeRules("httpproxy:8888",
119 "",
120 "ftpproxy:8889"), // proxy_rules
121 "", // proxy_bypass_list
122 false // bypass_local_names
123 },
124 {
125 TEST_DESC("Per scheme proxy with bypass URLs."),
126 // Input
127 per_scheme_proxy_bypass,
128 // Expected result
129 false, // is_null
130 false, // auto_detect
131 GURL(), // pac_url
132 net::MakeProxyPerSchemeRules("httpproxy:8888",
133 "",
134 "ftpproxy:8889"), // proxy_rules
135 "*.google.com\n*foo.com:99\n1.2.3.4:22\n127.0.0.1/8\n",
136 false // bypass_local_names
137 },
138 {
139 TEST_DESC("Pac URL with proxy bypass URLs"),
140 // Input
141 with_pac_url,
142 // Expected result
143 false, // is_null
144 false, // auto_detect
145 GURL("http://wpad/wpad.dat"), // pac_url
146 net::ProxyConfig::ProxyRules(), // proxy_rules
147 "*.google.com\n*foo.com:99\n1.2.3.4:22\n127.0.0.1/8\n",
148 false // bypass_local_names
149 },
150 {
151 TEST_DESC("Autodetect"),
152 // Input
153 with_auto_detect,
154 // Expected result
155 false, // is_null
156 true, // auto_detect
157 GURL(), // pac_url
158 net::ProxyConfig::ProxyRules(), // proxy_rules
159 "", // proxy_bypass_list
160 false // bypass_local_names
161 }
162 };
163
164 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) {
165 SCOPED_TRACE(StringPrintf("Test[%d] %s", i, tests[i].description.c_str()));
166 scoped_ptr<net::ProxyConfig> config(CreateProxyConfig(
167 CommandLine(tests[i].command_line)));
168
169 if (tests[i].is_null) {
170 EXPECT_TRUE(config == NULL);
171 } else {
172 EXPECT_TRUE(config != NULL);
173 EXPECT_EQ(tests[i].auto_detect, config->auto_detect);
174 EXPECT_EQ(tests[i].pac_url, config->pac_url);
175 EXPECT_EQ(tests[i].proxy_bypass_list,
176 net::FlattenProxyBypass(config->proxy_bypass));
177 EXPECT_EQ(tests[i].bypass_local_names, config->proxy_bypass_local_names);
178 EXPECT_EQ(tests[i].proxy_rules, config->proxy_rules);
179 }
180 }
181 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698