OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/proxy_config_service_impl.h" | 5 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 const char* ftp_uri; | 32 const char* ftp_uri; |
33 const char* socks_uri; | 33 const char* socks_uri; |
34 const char* bypass_rules; | 34 const char* bypass_rules; |
35 }; | 35 }; |
36 | 36 |
37 // Builds an identifier for each test in an array. | 37 // Builds an identifier for each test in an array. |
38 #define TEST_DESC(desc) base::StringPrintf("at line %d <%s>", __LINE__, desc) | 38 #define TEST_DESC(desc) base::StringPrintf("at line %d <%s>", __LINE__, desc) |
39 | 39 |
40 // Shortcuts to declare enums within chromeos's ProxyConfig. | 40 // Shortcuts to declare enums within chromeos's ProxyConfig. |
41 #define MK_MODE(mode) ProxyConfigServiceImpl::ProxyConfig::MODE_##mode | 41 #define MK_MODE(mode) ProxyConfigServiceImpl::ProxyConfig::MODE_##mode |
42 #define MK_SRC(src) ProxyConfigServiceImpl::ProxyConfig::SOURCE_##src | |
43 #define MK_SCHM(scheme) net::ProxyServer::SCHEME_##scheme | 42 #define MK_SCHM(scheme) net::ProxyServer::SCHEME_##scheme |
44 | 43 |
45 // Inspired from net/proxy/proxy_config_service_linux_unittest.cc. | 44 // Inspired from net/proxy/proxy_config_service_linux_unittest.cc. |
46 const struct { | 45 const struct { |
47 // Short description to identify the test | 46 // Short description to identify the test |
48 std::string description; | 47 std::string description; |
49 | 48 |
50 bool is_valid; | 49 bool is_valid; |
51 bool test_read_write_access; | |
52 | 50 |
53 Input input; | 51 Input input; |
54 | 52 |
55 // Expected outputs from fields of net::ProxyConfig (via IO). | 53 // Expected outputs from fields of net::ProxyConfig (via IO). |
56 bool auto_detect; | 54 bool auto_detect; |
57 GURL pac_url; | 55 GURL pac_url; |
58 net::ProxyRulesExpectation proxy_rules; | 56 net::ProxyRulesExpectation proxy_rules; |
59 } tests[] = { | 57 } tests[] = { |
60 { | 58 { |
61 TEST_DESC("No proxying"), | 59 TEST_DESC("No proxying"), |
62 | 60 |
63 true, // is_valid | 61 true, // is_valid |
64 true, // test_read_write_access | |
65 | 62 |
66 { // Input. | 63 { // Input. |
67 MK_MODE(DIRECT), // mode | 64 MK_MODE(DIRECT), // mode |
68 }, | 65 }, |
69 | 66 |
70 // Expected result. | 67 // Expected result. |
71 false, // auto_detect | 68 false, // auto_detect |
72 GURL(), // pac_url | 69 GURL(), // pac_url |
73 net::ProxyRulesExpectation::Empty(), // proxy_rules | 70 net::ProxyRulesExpectation::Empty(), // proxy_rules |
74 }, | 71 }, |
75 | 72 |
76 { | 73 { |
77 TEST_DESC("Auto detect"), | 74 TEST_DESC("Auto detect"), |
78 | 75 |
79 true, // is_valid | 76 true, // is_valid |
80 true, // test_read_write_access | |
81 | 77 |
82 { // Input. | 78 { // Input. |
83 MK_MODE(AUTO_DETECT), // mode | 79 MK_MODE(AUTO_DETECT), // mode |
84 }, | 80 }, |
85 | 81 |
86 // Expected result. | 82 // Expected result. |
87 true, // auto_detect | 83 true, // auto_detect |
88 GURL(), // pac_url | 84 GURL(), // pac_url |
89 net::ProxyRulesExpectation::Empty(), // proxy_rules | 85 net::ProxyRulesExpectation::Empty(), // proxy_rules |
90 }, | 86 }, |
91 | 87 |
92 { | 88 { |
93 TEST_DESC("Valid PAC URL"), | 89 TEST_DESC("Valid PAC URL"), |
94 | 90 |
95 true, // is_valid | 91 true, // is_valid |
96 true, // test_read_write_access | |
97 | 92 |
98 { // Input. | 93 { // Input. |
99 MK_MODE(PAC_SCRIPT), // mode | 94 MK_MODE(PAC_SCRIPT), // mode |
100 "http://wpad/wpad.dat", // pac_url | 95 "http://wpad/wpad.dat", // pac_url |
101 }, | 96 }, |
102 | 97 |
103 // Expected result. | 98 // Expected result. |
104 false, // auto_detect | 99 false, // auto_detect |
105 GURL("http://wpad/wpad.dat"), // pac_url | 100 GURL("http://wpad/wpad.dat"), // pac_url |
106 net::ProxyRulesExpectation::Empty(), // proxy_rules | 101 net::ProxyRulesExpectation::Empty(), // proxy_rules |
107 }, | 102 }, |
108 | 103 |
109 { | 104 { |
110 TEST_DESC("Invalid PAC URL"), | 105 TEST_DESC("Invalid PAC URL"), |
111 | 106 |
112 false, // is_valid | 107 false, // is_valid |
113 false, // test_read_write_access | |
114 | 108 |
115 { // Input. | 109 { // Input. |
116 MK_MODE(PAC_SCRIPT), // mode | 110 MK_MODE(PAC_SCRIPT), // mode |
117 "wpad.dat", // pac_url | 111 "wpad.dat", // pac_url |
118 }, | 112 }, |
119 | 113 |
120 // Expected result. | 114 // Expected result. |
121 false, // auto_detect | 115 false, // auto_detect |
122 GURL(), // pac_url | 116 GURL(), // pac_url |
123 net::ProxyRulesExpectation::Empty(), // proxy_rules | 117 net::ProxyRulesExpectation::Empty(), // proxy_rules |
124 }, | 118 }, |
125 | 119 |
126 { | 120 { |
127 TEST_DESC("Single-host in proxy list"), | 121 TEST_DESC("Single-host in proxy list"), |
128 | 122 |
129 true, // is_valid | 123 true, // is_valid |
130 true, // test_read_write_access | |
131 | 124 |
132 { // Input. | 125 { // Input. |
133 MK_MODE(SINGLE_PROXY), // mode | 126 MK_MODE(SINGLE_PROXY), // mode |
134 NULL, // pac_url | 127 NULL, // pac_url |
135 "www.google.com", // single_uri | 128 "www.google.com", // single_uri |
136 }, | 129 }, |
137 | 130 |
138 // Expected result. | 131 // Expected result. |
139 false, // auto_detect | 132 false, // auto_detect |
140 GURL(), // pac_url | 133 GURL(), // pac_url |
141 net::ProxyRulesExpectation::Single( // proxy_rules | 134 net::ProxyRulesExpectation::Single( // proxy_rules |
142 "www.google.com:80", // single proxy | 135 "www.google.com:80", // single proxy |
143 ""), // bypass rules | 136 ""), // bypass rules |
144 }, | 137 }, |
145 | 138 |
146 { | 139 { |
147 TEST_DESC("Single-host, different port"), | 140 TEST_DESC("Single-host, different port"), |
148 | 141 |
149 true, // is_valid | 142 true, // is_valid |
150 false, // test_read_write_access | |
151 | 143 |
152 { // Input. | 144 { // Input. |
153 MK_MODE(SINGLE_PROXY), // mode | 145 MK_MODE(SINGLE_PROXY), // mode |
154 NULL, // pac_url | 146 NULL, // pac_url |
155 "www.google.com:99", // single_uri | 147 "www.google.com:99", // single_uri |
156 }, | 148 }, |
157 | 149 |
158 // Expected result. | 150 // Expected result. |
159 false, // auto_detect | 151 false, // auto_detect |
160 GURL(), // pac_url | 152 GURL(), // pac_url |
161 net::ProxyRulesExpectation::Single( // proxy_rules | 153 net::ProxyRulesExpectation::Single( // proxy_rules |
162 "www.google.com:99", // single | 154 "www.google.com:99", // single |
163 ""), // bypass rules | 155 ""), // bypass rules |
164 }, | 156 }, |
165 | 157 |
166 { | 158 { |
167 TEST_DESC("Tolerate a scheme"), | 159 TEST_DESC("Tolerate a scheme"), |
168 | 160 |
169 true, // is_valid | 161 true, // is_valid |
170 false, // test_read_write_access | |
171 | 162 |
172 { // Input. | 163 { // Input. |
173 MK_MODE(SINGLE_PROXY), // mode | 164 MK_MODE(SINGLE_PROXY), // mode |
174 NULL, // pac_url | 165 NULL, // pac_url |
175 "http://www.google.com:99", // single_uri | 166 "http://www.google.com:99", // single_uri |
176 }, | 167 }, |
177 | 168 |
178 // Expected result. | 169 // Expected result. |
179 false, // auto_detect | 170 false, // auto_detect |
180 GURL(), // pac_url | 171 GURL(), // pac_url |
181 net::ProxyRulesExpectation::Single( // proxy_rules | 172 net::ProxyRulesExpectation::Single( // proxy_rules |
182 "www.google.com:99", // single proxy | 173 "www.google.com:99", // single proxy |
183 ""), // bypass rules | 174 ""), // bypass rules |
184 }, | 175 }, |
185 | 176 |
186 { | 177 { |
187 TEST_DESC("Per-scheme proxy rules"), | 178 TEST_DESC("Per-scheme proxy rules"), |
188 | 179 |
189 true, // is_valid | 180 true, // is_valid |
190 true, // test_read_write_access | |
191 | 181 |
192 { // Input. | 182 { // Input. |
193 MK_MODE(PROXY_PER_SCHEME), // mode | 183 MK_MODE(PROXY_PER_SCHEME), // mode |
194 NULL, // pac_url | 184 NULL, // pac_url |
195 NULL, // single_uri | 185 NULL, // single_uri |
196 "www.google.com:80", // http_uri | 186 "www.google.com:80", // http_uri |
197 "www.foo.com:110", // https_uri | 187 "www.foo.com:110", // https_uri |
198 "ftp.foo.com:121", // ftp_uri | 188 "ftp.foo.com:121", // ftp_uri |
199 "socks.com:888", // socks_uri | 189 "socks.com:888", // socks_uri |
200 }, | 190 }, |
201 | 191 |
202 // Expected result. | 192 // Expected result. |
203 false, // auto_detect | 193 false, // auto_detect |
204 GURL(), // pac_url | 194 GURL(), // pac_url |
205 net::ProxyRulesExpectation::PerSchemeWithSocks( // proxy_rules | 195 net::ProxyRulesExpectation::PerSchemeWithSocks( // proxy_rules |
206 "www.google.com:80", // http | 196 "www.google.com:80", // http |
207 "https://www.foo.com:110", // https | 197 "https://www.foo.com:110", // https |
208 "ftp.foo.com:121", // ftp | 198 "ftp.foo.com:121", // ftp |
209 "socks5://socks.com:888", // fallback proxy | 199 "socks5://socks.com:888", // fallback proxy |
210 ""), // bypass rules | 200 ""), // bypass rules |
211 }, | 201 }, |
212 | 202 |
213 { | 203 { |
214 TEST_DESC("Bypass rules"), | 204 TEST_DESC("Bypass rules"), |
215 | 205 |
216 true, // is_valid | 206 true, // is_valid |
217 true, // test_read_write_access | |
218 | 207 |
219 { // Input. | 208 { // Input. |
220 MK_MODE(SINGLE_PROXY), // mode | 209 MK_MODE(SINGLE_PROXY), // mode |
221 NULL, // pac_url | 210 NULL, // pac_url |
222 "www.google.com", // single_uri | 211 "www.google.com", // single_uri |
223 NULL, NULL, NULL, NULL, // per-proto | 212 NULL, NULL, NULL, NULL, // per-proto |
224 "*.google.com, *foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // bypass_rules | 213 "*.google.com, *foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // bypass_rules |
225 }, | 214 }, |
226 | 215 |
227 // Expected result. | 216 // Expected result. |
(...skipping 21 matching lines...) Expand all Loading... |
249 | 238 |
250 void CreateConfigService( | 239 void CreateConfigService( |
251 const ProxyConfigServiceImpl::ProxyConfig& init_config) { | 240 const ProxyConfigServiceImpl::ProxyConfig& init_config) { |
252 // Instantiate proxy config service with |init_config|. | 241 // Instantiate proxy config service with |init_config|. |
253 config_service_ = new ProxyConfigServiceImpl(init_config); | 242 config_service_ = new ProxyConfigServiceImpl(init_config); |
254 config_service_->SetTesting(); | 243 config_service_->SetTesting(); |
255 } | 244 } |
256 | 245 |
257 void SetAutomaticProxy( | 246 void SetAutomaticProxy( |
258 ProxyConfigServiceImpl::ProxyConfig::Mode mode, | 247 ProxyConfigServiceImpl::ProxyConfig::Mode mode, |
259 ProxyConfigServiceImpl::ProxyConfig::Source source, | |
260 const char* pac_url, | 248 const char* pac_url, |
261 ProxyConfigServiceImpl::ProxyConfig* config, | 249 ProxyConfigServiceImpl::ProxyConfig* config, |
262 ProxyConfigServiceImpl::ProxyConfig::AutomaticProxy* automatic_proxy) { | 250 ProxyConfigServiceImpl::ProxyConfig::AutomaticProxy* automatic_proxy) { |
263 config->mode = mode; | 251 config->mode = mode; |
264 automatic_proxy->source = source; | |
265 if (pac_url) | 252 if (pac_url) |
266 automatic_proxy->pac_url = GURL(pac_url); | 253 automatic_proxy->pac_url = GURL(pac_url); |
267 } | 254 } |
268 | 255 |
269 void SetManualProxy( | 256 void SetManualProxy( |
270 ProxyConfigServiceImpl::ProxyConfig::Mode mode, | 257 ProxyConfigServiceImpl::ProxyConfig::Mode mode, |
271 ProxyConfigServiceImpl::ProxyConfig::Source source, | |
272 const char* server_uri, | 258 const char* server_uri, |
273 net::ProxyServer::Scheme scheme, | 259 net::ProxyServer::Scheme scheme, |
274 ProxyConfigServiceImpl::ProxyConfig* config, | 260 ProxyConfigServiceImpl::ProxyConfig* config, |
275 ProxyConfigServiceImpl::ProxyConfig::ManualProxy* manual_proxy) { | 261 ProxyConfigServiceImpl::ProxyConfig::ManualProxy* manual_proxy) { |
276 if (!server_uri) | 262 if (!server_uri) |
277 return; | 263 return; |
278 config->mode = mode; | 264 config->mode = mode; |
279 manual_proxy->source = source; | |
280 manual_proxy->server = net::ProxyServer::FromURI(server_uri, scheme); | 265 manual_proxy->server = net::ProxyServer::FromURI(server_uri, scheme); |
281 } | 266 } |
282 | 267 |
283 void InitConfigWithTestInput( | 268 void InitConfigWithTestInput( |
284 const Input& input, ProxyConfigServiceImpl::ProxyConfig::Source source, | 269 const Input& input, ProxyConfigServiceImpl::ProxyConfig* init_config) { |
285 ProxyConfigServiceImpl::ProxyConfig* init_config) { | |
286 switch (input.mode) { | 270 switch (input.mode) { |
287 case MK_MODE(DIRECT): | 271 case MK_MODE(DIRECT): |
288 case MK_MODE(AUTO_DETECT): | 272 case MK_MODE(AUTO_DETECT): |
289 case MK_MODE(PAC_SCRIPT): | 273 case MK_MODE(PAC_SCRIPT): |
290 SetAutomaticProxy(input.mode, source, input.pac_url, init_config, | 274 SetAutomaticProxy(input.mode, input.pac_url, init_config, |
291 &init_config->automatic_proxy); | 275 &init_config->automatic_proxy); |
292 return; | 276 return; |
293 case MK_MODE(SINGLE_PROXY): | 277 case MK_MODE(SINGLE_PROXY): |
294 SetManualProxy(input.mode, source, input.single_uri, MK_SCHM(HTTP), | 278 SetManualProxy(input.mode, input.single_uri, MK_SCHM(HTTP), |
295 init_config, &init_config->single_proxy); | 279 init_config, &init_config->single_proxy); |
296 break; | 280 break; |
297 case MK_MODE(PROXY_PER_SCHEME): | 281 case MK_MODE(PROXY_PER_SCHEME): |
298 SetManualProxy(input.mode, source, input.http_uri, MK_SCHM(HTTP), | 282 SetManualProxy(input.mode, input.http_uri, MK_SCHM(HTTP), |
299 init_config, &init_config->http_proxy); | 283 init_config, &init_config->http_proxy); |
300 SetManualProxy(input.mode, source, input.https_uri, MK_SCHM(HTTPS), | 284 SetManualProxy(input.mode, input.https_uri, MK_SCHM(HTTPS), |
301 init_config, &init_config->https_proxy); | 285 init_config, &init_config->https_proxy); |
302 SetManualProxy(input.mode, source, input.ftp_uri, MK_SCHM(HTTP), | 286 SetManualProxy(input.mode, input.ftp_uri, MK_SCHM(HTTP), |
303 init_config, &init_config->ftp_proxy); | 287 init_config, &init_config->ftp_proxy); |
304 SetManualProxy(input.mode, source, input.socks_uri, MK_SCHM(SOCKS5), | 288 SetManualProxy(input.mode, input.socks_uri, MK_SCHM(SOCKS5), |
305 init_config, &init_config->socks_proxy); | 289 init_config, &init_config->socks_proxy); |
306 break; | 290 break; |
307 } | 291 } |
308 if (input.bypass_rules) { | 292 if (input.bypass_rules) { |
309 init_config->bypass_rules.ParseFromString(input.bypass_rules); | 293 init_config->bypass_rules.ParseFromString(input.bypass_rules); |
310 } | 294 } |
311 } | 295 } |
312 | 296 |
313 void TestReadWriteAccessForMode(const Input& input, | |
314 ProxyConfigServiceImpl::ProxyConfig::Source source) { | |
315 // Init config from |source|. | |
316 ProxyConfigServiceImpl::ProxyConfig init_config; | |
317 InitConfigWithTestInput(input, source, &init_config); | |
318 CreateConfigService(init_config); | |
319 | |
320 ProxyConfigServiceImpl::ProxyConfig config; | |
321 config_service()->UIGetProxyConfig(&config); | |
322 | |
323 // For owner, write access to config should be equal CanBeWrittenByOwner(). | |
324 // For non-owner, config is never writeable. | |
325 bool expected_writeable_by_owner = CanBeWrittenByOwner(source); | |
326 if (config.mode == MK_MODE(PROXY_PER_SCHEME)) { | |
327 if (input.http_uri) { | |
328 EXPECT_EQ(expected_writeable_by_owner, | |
329 config.CanBeWrittenByUser(true, "http")); | |
330 EXPECT_FALSE(config.CanBeWrittenByUser(false, "http")); | |
331 } | |
332 if (input.https_uri) { | |
333 EXPECT_EQ(expected_writeable_by_owner, | |
334 config.CanBeWrittenByUser(true, "http")); | |
335 EXPECT_FALSE(config.CanBeWrittenByUser(false, "https")); | |
336 } | |
337 if (input.ftp_uri) { | |
338 EXPECT_EQ(expected_writeable_by_owner, | |
339 config.CanBeWrittenByUser(true, "http")); | |
340 EXPECT_FALSE(config.CanBeWrittenByUser(false, "ftp")); | |
341 } | |
342 if (input.socks_uri) { | |
343 EXPECT_EQ(expected_writeable_by_owner, | |
344 config.CanBeWrittenByUser(true, "http")); | |
345 EXPECT_FALSE(config.CanBeWrittenByUser(false, "socks")); | |
346 } | |
347 } else { | |
348 EXPECT_EQ(expected_writeable_by_owner, | |
349 config.CanBeWrittenByUser(true, std::string())); | |
350 EXPECT_FALSE(config.CanBeWrittenByUser(false, std::string())); | |
351 } | |
352 } | |
353 | |
354 void TestReadWriteAccessForScheme( | |
355 ProxyConfigServiceImpl::ProxyConfig::Source source, | |
356 const char* server_uri, | |
357 const std::string& scheme) { | |
358 // Init with manual |scheme| proxy. | |
359 ProxyConfigServiceImpl::ProxyConfig init_config; | |
360 ProxyConfigServiceImpl::ProxyConfig::ManualProxy* proxy = | |
361 init_config.MapSchemeToProxy(scheme); | |
362 net::ProxyServer::Scheme net_scheme = MK_SCHM(HTTP); | |
363 if (scheme == "http" || scheme == "ftp") | |
364 net_scheme = MK_SCHM(HTTP); | |
365 else if (scheme == "https") | |
366 net_scheme = MK_SCHM(HTTPS); | |
367 else if (scheme == "socks") | |
368 net_scheme = MK_SCHM(SOCKS4); | |
369 SetManualProxy(MK_MODE(PROXY_PER_SCHEME), source, server_uri, net_scheme, | |
370 &init_config, proxy); | |
371 CreateConfigService(init_config); | |
372 | |
373 ProxyConfigServiceImpl::ProxyConfig config; | |
374 config_service()->UIGetProxyConfig(&config); | |
375 | |
376 // For owner, write access to config should be equal CanBeWrittenByOwner(). | |
377 // For non-owner, config is never writeable. | |
378 bool expected_writeable_by_owner = CanBeWrittenByOwner(source); | |
379 EXPECT_EQ(expected_writeable_by_owner, | |
380 config.CanBeWrittenByUser(true, scheme)); | |
381 EXPECT_FALSE(config.CanBeWrittenByUser(false, scheme)); | |
382 | |
383 const char* all_schemes[] = { | |
384 "http", "https", "ftp", "socks", | |
385 }; | |
386 | |
387 // Rest of protos should be writeable by owner, but not writeable by | |
388 // non-owner. | |
389 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(all_schemes); ++i) { | |
390 if (scheme == all_schemes[i]) | |
391 continue; | |
392 EXPECT_TRUE(config.CanBeWrittenByUser(true, all_schemes[i])); | |
393 EXPECT_FALSE(config.CanBeWrittenByUser(false, all_schemes[i])); | |
394 } | |
395 } | |
396 | |
397 // Synchronously gets the latest proxy config. | 297 // Synchronously gets the latest proxy config. |
398 bool SyncGetLatestProxyConfig(net::ProxyConfig* config) { | 298 bool SyncGetLatestProxyConfig(net::ProxyConfig* config) { |
399 // Let message loop process all messages. | 299 // Let message loop process all messages. |
400 MessageLoop::current()->RunAllPending(); | 300 MessageLoop::current()->RunAllPending(); |
401 // Calls IOGetProxyConfig (which is called from | 301 // Calls IOGetProxyConfig (which is called from |
402 // ProxyConfigService::GetLatestProxyConfig), running on faked IO thread. | 302 // ProxyConfigService::GetLatestProxyConfig), running on faked IO thread. |
403 return config_service_->IOGetProxyConfig(config); | 303 return config_service_->IOGetProxyConfig(config); |
404 } | 304 } |
405 | 305 |
406 ProxyConfigServiceImpl* config_service() const { | 306 ProxyConfigServiceImpl* config_service() const { |
407 return config_service_; | 307 return config_service_; |
408 } | 308 } |
409 | 309 |
410 private: | 310 private: |
411 bool CanBeWrittenByOwner( | |
412 ProxyConfigServiceImpl::ProxyConfig::Source source) const { | |
413 return source == MK_SRC(POLICY) ? false : true; | |
414 } | |
415 | |
416 ScopedStubCrosEnabler stub_cros_enabler_; | 311 ScopedStubCrosEnabler stub_cros_enabler_; |
417 MessageLoop message_loop_; | 312 MessageLoop message_loop_; |
418 BrowserThread ui_thread_; | 313 BrowserThread ui_thread_; |
419 BrowserThread io_thread_; | 314 BrowserThread io_thread_; |
420 | 315 |
421 scoped_refptr<ProxyConfigServiceImpl> config_service_; | 316 scoped_refptr<ProxyConfigServiceImpl> config_service_; |
422 }; | 317 }; |
423 | 318 |
424 TEST_F(ProxyConfigServiceImplTest, ChromeosProxyConfigToNetProxyConfig) { | 319 TEST_F(ProxyConfigServiceImplTest, ChromeosProxyConfigToNetProxyConfig) { |
425 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 320 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
426 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | 321 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, |
427 tests[i].description.c_str())); | 322 tests[i].description.c_str())); |
428 | 323 |
429 ProxyConfigServiceImpl::ProxyConfig init_config; | 324 ProxyConfigServiceImpl::ProxyConfig init_config; |
430 InitConfigWithTestInput(tests[i].input, MK_SRC(OWNER), &init_config); | 325 InitConfigWithTestInput(tests[i].input, &init_config); |
431 CreateConfigService(init_config); | 326 CreateConfigService(init_config); |
432 | 327 |
433 net::ProxyConfig config; | 328 net::ProxyConfig config; |
434 SyncGetLatestProxyConfig(&config); | 329 SyncGetLatestProxyConfig(&config); |
435 | 330 |
436 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 331 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
437 EXPECT_EQ(tests[i].pac_url, config.pac_url()); | 332 EXPECT_EQ(tests[i].pac_url, config.pac_url()); |
438 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); | 333 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); |
439 } | 334 } |
440 } | 335 } |
441 | 336 |
442 TEST_F(ProxyConfigServiceImplTest, ModifyFromUI) { | 337 TEST_F(ProxyConfigServiceImplTest, ModifyFromUI) { |
443 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 338 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
444 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | 339 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, |
445 tests[i].description.c_str())); | 340 tests[i].description.c_str())); |
446 | 341 |
447 // Init with direct. | 342 // Init with direct. |
448 ProxyConfigServiceImpl::ProxyConfig init_config; | 343 ProxyConfigServiceImpl::ProxyConfig init_config; |
449 SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(OWNER), NULL, &init_config, | 344 SetAutomaticProxy(MK_MODE(DIRECT), NULL, &init_config, |
450 &init_config.automatic_proxy); | 345 &init_config.automatic_proxy); |
451 CreateConfigService(init_config); | 346 CreateConfigService(init_config); |
452 | 347 |
453 // Set config to tests[i].input via UI. | 348 // Set config to tests[i].input via UI. |
454 net::ProxyBypassRules bypass_rules; | 349 net::ProxyBypassRules bypass_rules; |
455 const Input& input = tests[i].input; | 350 const Input& input = tests[i].input; |
456 switch (input.mode) { | 351 switch (input.mode) { |
457 case MK_MODE(DIRECT) : | 352 case MK_MODE(DIRECT) : |
458 config_service()->UISetProxyConfigToDirect(); | 353 config_service()->UISetProxyConfigToDirect(); |
459 break; | 354 break; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 availability_ = availability; | 454 availability_ = availability; |
560 } | 455 } |
561 | 456 |
562 scoped_refptr<ProxyConfigServiceImpl> config_service_; | 457 scoped_refptr<ProxyConfigServiceImpl> config_service_; |
563 net::ProxyConfigService::ConfigAvailability availability_; | 458 net::ProxyConfigService::ConfigAvailability availability_; |
564 net::ProxyConfig config_; | 459 net::ProxyConfig config_; |
565 }; | 460 }; |
566 | 461 |
567 // Init with direct. | 462 // Init with direct. |
568 ProxyConfigServiceImpl::ProxyConfig init_config; | 463 ProxyConfigServiceImpl::ProxyConfig init_config; |
569 SetAutomaticProxy(MK_MODE(DIRECT), MK_SRC(OWNER), NULL, &init_config, | 464 SetAutomaticProxy(MK_MODE(DIRECT), NULL, &init_config, |
570 &init_config.automatic_proxy); | 465 &init_config.automatic_proxy); |
571 CreateConfigService(init_config); | 466 CreateConfigService(init_config); |
572 | 467 |
573 ProxyChangedObserver observer(config_service()); | 468 ProxyChangedObserver observer(config_service()); |
574 | 469 |
575 // Set to pac script from UI. | 470 // Set to pac script from UI. |
576 EXPECT_TRUE(config_service()->UISetProxyConfigToPACScript( | 471 EXPECT_TRUE(config_service()->UISetProxyConfigToPACScript( |
577 GURL("http://wpad.dat"))); | 472 GURL("http://wpad.dat"))); |
578 // Retrieve config from IO thread. | 473 // Retrieve config from IO thread. |
579 net::ProxyConfig io_config; | 474 net::ProxyConfig io_config; |
580 SyncGetLatestProxyConfig(&io_config); | 475 SyncGetLatestProxyConfig(&io_config); |
581 | 476 |
582 // Observer should have gotten the same new proxy config. | 477 // Observer should have gotten the same new proxy config. |
583 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, observer.availability()); | 478 EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, observer.availability()); |
584 EXPECT_TRUE(io_config.Equals(observer.config())); | 479 EXPECT_TRUE(io_config.Equals(observer.config())); |
585 } | 480 } |
586 | 481 |
587 TEST_F(ProxyConfigServiceImplTest, SerializeAndDeserializeForNetwork) { | 482 TEST_F(ProxyConfigServiceImplTest, SerializeAndDeserializeForNetwork) { |
588 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 483 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
589 if (!tests[i].is_valid) | 484 if (!tests[i].is_valid) |
590 continue; | 485 continue; |
591 | 486 |
592 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | 487 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, |
593 tests[i].description.c_str())); | 488 tests[i].description.c_str())); |
594 | 489 |
595 ProxyConfigServiceImpl::ProxyConfig source_config; | 490 ProxyConfigServiceImpl::ProxyConfig source_config; |
596 InitConfigWithTestInput(tests[i].input, MK_SRC(OWNER), &source_config); | 491 InitConfigWithTestInput(tests[i].input, &source_config); |
597 | 492 |
598 // Serialize source_config into std::string. | 493 // Serialize source_config into std::string. |
599 std::string serialized_value; | 494 std::string serialized_value; |
600 EXPECT_TRUE(source_config.SerializeForNetwork(&serialized_value)); | 495 EXPECT_TRUE(source_config.SerializeForNetwork(&serialized_value)); |
601 | 496 |
602 // Deserialize std:string into target_config. | 497 // Deserialize std:string into target_config. |
603 ProxyConfigServiceImpl::ProxyConfig target_config; | 498 ProxyConfigServiceImpl::ProxyConfig target_config; |
604 EXPECT_TRUE(target_config.DeserializeForNetwork(serialized_value)); | 499 EXPECT_TRUE(target_config.DeserializeForNetwork(serialized_value)); |
605 | 500 |
606 // Compare the configs after serialization and deserialization. | 501 // Compare the configs after serialization and deserialization. |
607 net::ProxyConfig net_src_cfg; | 502 net::ProxyConfig net_src_cfg; |
608 net::ProxyConfig net_tgt_cfg; | 503 net::ProxyConfig net_tgt_cfg; |
609 source_config.ToNetProxyConfig(&net_src_cfg); | 504 source_config.ToNetProxyConfig(&net_src_cfg); |
610 target_config.ToNetProxyConfig(&net_tgt_cfg); | 505 target_config.ToNetProxyConfig(&net_tgt_cfg); |
611 #if !defined(NDEBUG) | 506 #if !defined(NDEBUG) |
612 if (!net_src_cfg.Equals(net_tgt_cfg)) { | 507 if (!net_src_cfg.Equals(net_tgt_cfg)) { |
613 std::string src_output, tgt_output; | 508 std::string src_output, tgt_output; |
614 JSONStringValueSerializer src_serializer(&src_output); | 509 JSONStringValueSerializer src_serializer(&src_output); |
615 src_serializer.Serialize(*net_src_cfg.ToValue()); | 510 src_serializer.Serialize(*net_src_cfg.ToValue()); |
616 JSONStringValueSerializer tgt_serializer(&tgt_output); | 511 JSONStringValueSerializer tgt_serializer(&tgt_output); |
617 tgt_serializer.Serialize(*net_tgt_cfg.ToValue()); | 512 tgt_serializer.Serialize(*net_tgt_cfg.ToValue()); |
618 VLOG(1) << "source:\n" << src_output | 513 VLOG(1) << "source:\n" << src_output |
619 << "\ntarget:\n" << tgt_output; | 514 << "\ntarget:\n" << tgt_output; |
620 } | 515 } |
621 #endif // !defined(NDEBUG) | 516 #endif // !defined(NDEBUG) |
622 EXPECT_TRUE(net_src_cfg.Equals(net_tgt_cfg)); | 517 EXPECT_TRUE(net_src_cfg.Equals(net_tgt_cfg)); |
623 } | 518 } |
624 } | 519 } |
625 | 520 |
626 TEST_F(ProxyConfigServiceImplTest, ReadWriteAccessForPolicySource) { | |
627 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | |
628 if (!tests[i].test_read_write_access) | |
629 continue; | |
630 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | |
631 tests[i].description.c_str())); | |
632 TestReadWriteAccessForMode(tests[i].input, MK_SRC(POLICY)); | |
633 } | |
634 } | |
635 | |
636 TEST_F(ProxyConfigServiceImplTest, ReadWriteAccessForOwnerSource) { | |
637 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | |
638 if (!tests[i].test_read_write_access) | |
639 continue; | |
640 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | |
641 tests[i].description.c_str())); | |
642 TestReadWriteAccessForMode(tests[i].input, MK_SRC(OWNER)); | |
643 } | |
644 } | |
645 | |
646 TEST_F(ProxyConfigServiceImplTest, ReadWriteAccessForMixedSchemes) { | |
647 const char* http_uri = "www.google.com:80"; | |
648 const char* https_uri = "www.foo.com:110"; | |
649 const char* ftp_uri = "ftp.foo.com:121"; | |
650 const char* socks_uri = "socks.com:888"; | |
651 | |
652 // Init with policy source. | |
653 TestReadWriteAccessForScheme(MK_SRC(POLICY), http_uri, "http"); | |
654 TestReadWriteAccessForScheme(MK_SRC(POLICY), https_uri, "https"); | |
655 TestReadWriteAccessForScheme(MK_SRC(POLICY), ftp_uri, "ftp"); | |
656 TestReadWriteAccessForScheme(MK_SRC(POLICY), socks_uri, "socks"); | |
657 | |
658 // Init with owner source. | |
659 TestReadWriteAccessForScheme(MK_SRC(OWNER), http_uri, "http"); | |
660 TestReadWriteAccessForScheme(MK_SRC(OWNER), https_uri, "https"); | |
661 TestReadWriteAccessForScheme(MK_SRC(OWNER), ftp_uri, "ftp"); | |
662 TestReadWriteAccessForScheme(MK_SRC(OWNER), socks_uri, "socks"); | |
663 } | |
664 | |
665 } // namespace chromeos | 521 } // namespace chromeos |
OLD | NEW |