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

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

Issue 5005002: Dynamically refresh pref-configured proxies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Jochen's comments. Created 10 years, 1 month 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
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 "chrome/browser/net/chrome_url_request_context.h"
6
7 #include "base/command_line.h"
8 #include "base/format_macros.h"
9 #include "chrome/browser/policy/configuration_policy_pref_store.h"
10 #include "chrome/browser/prefs/command_line_pref_store.h"
11 #include "chrome/browser/prefs/default_pref_store.h"
12 #include "chrome/browser/prefs/pref_value_store.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/testing_pref_service.h"
15 #include "net/proxy/proxy_config.h"
16 #include "net/proxy/proxy_config_service_common_unittest.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 // Builds an identifier for each test in an array.
20 #define TEST_DESC(desc) StringPrintf("at line %d <%s>", __LINE__, desc)
21
22 TEST(ChromeURLRequestContextTest, CreateProxyConfigTest) {
23 FilePath unused_path(FILE_PATH_LITERAL("foo.exe"));
24 // Build the input command lines here.
25 CommandLine empty(unused_path);
26 CommandLine no_proxy(unused_path);
27 no_proxy.AppendSwitch(switches::kNoProxyServer);
28 CommandLine no_proxy_extra_params(unused_path);
29 no_proxy_extra_params.AppendSwitch(switches::kNoProxyServer);
30 no_proxy_extra_params.AppendSwitchASCII(switches::kProxyServer,
31 "http://proxy:8888");
32 CommandLine single_proxy(unused_path);
33 single_proxy.AppendSwitchASCII(switches::kProxyServer, "http://proxy:8888");
34 CommandLine per_scheme_proxy(unused_path);
35 per_scheme_proxy.AppendSwitchASCII(switches::kProxyServer,
36 "http=httpproxy:8888;ftp=ftpproxy:8889");
37 CommandLine per_scheme_proxy_bypass(unused_path);
38 per_scheme_proxy_bypass.AppendSwitchASCII(
39 switches::kProxyServer,
40 "http=httpproxy:8888;ftp=ftpproxy:8889");
41 per_scheme_proxy_bypass.AppendSwitchASCII(
42 switches::kProxyBypassList,
43 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8");
44 CommandLine with_pac_url(unused_path);
45 with_pac_url.AppendSwitchASCII(switches::kProxyPacUrl, "http://wpad/wpad.dat") ;
46 with_pac_url.AppendSwitchASCII(
47 switches::kProxyBypassList,
48 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8");
49 CommandLine with_auto_detect(unused_path);
50 with_auto_detect.AppendSwitch(switches::kProxyAutoDetect);
51
52 // Inspired from proxy_config_service_win_unittest.cc.
53 const struct {
54 // Short description to identify the test
55 std::string description;
56
57 // The command line to build a ProxyConfig from.
58 const CommandLine& command_line;
59
60 // Expected outputs (fields of the ProxyConfig).
61 bool is_null;
62 bool auto_detect;
63 GURL pac_url;
64 net::ProxyRulesExpectation proxy_rules;
65 } tests[] = {
66 {
67 TEST_DESC("Empty command line"),
68 // Input
69 empty,
70 // Expected result
71 true, // is_null
72 false, // auto_detect
73 GURL(), // pac_url
74 net::ProxyRulesExpectation::Empty(),
75 },
76 {
77 TEST_DESC("No proxy"),
78 // Input
79 no_proxy,
80 // Expected result
81 false, // is_null
82 false, // auto_detect
83 GURL(), // pac_url
84 net::ProxyRulesExpectation::Empty(),
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::ProxyRulesExpectation::Empty(),
95 },
96 {
97 TEST_DESC("Single proxy."),
98 // Input
99 single_proxy,
100 // Expected result
101 false, // is_null
102 false, // auto_detect
103 GURL(), // pac_url
104 net::ProxyRulesExpectation::Single(
105 "proxy:8888", // single proxy
106 ""), // bypass rules
107 },
108 {
109 TEST_DESC("Per scheme proxy."),
110 // Input
111 per_scheme_proxy,
112 // Expected result
113 false, // is_null
114 false, // auto_detect
115 GURL(), // pac_url
116 net::ProxyRulesExpectation::PerScheme(
117 "httpproxy:8888", // http
118 "", // https
119 "ftpproxy:8889", // ftp
120 ""), // bypass rules
121 },
122 {
123 TEST_DESC("Per scheme proxy with bypass URLs."),
124 // Input
125 per_scheme_proxy_bypass,
126 // Expected result
127 false, // is_null
128 false, // auto_detect
129 GURL(), // pac_url
130 net::ProxyRulesExpectation::PerScheme(
131 "httpproxy:8888", // http
132 "", // https
133 "ftpproxy:8889", // ftp
134 "*.google.com,foo.com:99,1.2.3.4:22,127.0.0.1/8"),
135 },
136 {
137 TEST_DESC("Pac URL with proxy bypass URLs"),
138 // Input
139 with_pac_url,
140 // Expected result
141 false, // is_null
142 false, // auto_detect
143 GURL("http://wpad/wpad.dat"), // pac_url
144 net::ProxyRulesExpectation::EmptyWithBypass(
145 "*.google.com,foo.com:99,1.2.3.4:22,127.0.0.1/8"),
146 },
147 {
148 TEST_DESC("Autodetect"),
149 // Input
150 with_auto_detect,
151 // Expected result
152 false, // is_null
153 true, // auto_detect
154 GURL(), // pac_url
155 net::ProxyRulesExpectation::Empty(),
156 }
157 };
158
159 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) {
160 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i,
161 tests[i].description.c_str()));
162 CommandLine command_line(tests[i].command_line);
163 // Only configuration-policy and default prefs are needed.
164 PrefService prefs(new TestingPrefService::TestingPrefValueStore(
165 new policy::ConfigurationPolicyPrefStore(NULL),
166 new policy::ConfigurationPolicyPrefStore(NULL), NULL,
167 new CommandLinePrefStore(&command_line), NULL, NULL,
168 new DefaultPrefStore()));
169 ChromeURLRequestContextGetter::RegisterUserPrefs(&prefs);
170 scoped_ptr<net::ProxyConfig> config(CreateProxyConfig(&prefs));
171
172 if (tests[i].is_null) {
173 EXPECT_TRUE(config == NULL);
174 } else {
175 EXPECT_TRUE(config != NULL);
176 EXPECT_EQ(tests[i].auto_detect, config->auto_detect());
177 EXPECT_EQ(tests[i].pac_url, config->pac_url());
178 EXPECT_TRUE(tests[i].proxy_rules.Matches(config->proxy_rules()));
179 }
180 }
181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698