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 "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 TEST(ProxyServiceTest, Direct) { | 76 TEST(ProxyServiceTest, Direct) { |
77 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 77 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
78 ProxyService service(new MockProxyConfigService( | 78 ProxyService service(new MockProxyConfigService( |
79 ProxyConfig::CreateDirect()), resolver, NULL); | 79 ProxyConfig::CreateDirect()), resolver, NULL); |
80 | 80 |
81 GURL url("http://www.google.com/"); | 81 GURL url("http://www.google.com/"); |
82 | 82 |
83 ProxyInfo info; | 83 ProxyInfo info; |
84 TestOldCompletionCallback callback; | 84 TestCompletionCallback callback; |
85 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 85 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
86 int rv = service.ResolveProxy(url, &info, &callback, NULL, log.bound()); | 86 int rv = service.ResolveProxy( |
| 87 url, &info, callback.callback(), NULL, log.bound()); |
87 EXPECT_EQ(OK, rv); | 88 EXPECT_EQ(OK, rv); |
88 EXPECT_TRUE(resolver->pending_requests().empty()); | 89 EXPECT_TRUE(resolver->pending_requests().empty()); |
89 | 90 |
90 EXPECT_TRUE(info.is_direct()); | 91 EXPECT_TRUE(info.is_direct()); |
91 | 92 |
92 // Check the NetLog was filled correctly. | 93 // Check the NetLog was filled correctly. |
93 CapturingNetLog::EntryList entries; | 94 CapturingNetLog::EntryList entries; |
94 log.GetEntries(&entries); | 95 log.GetEntries(&entries); |
95 | 96 |
96 EXPECT_EQ(3u, entries.size()); | 97 EXPECT_EQ(3u, entries.size()); |
(...skipping 10 matching lines...) Expand all Loading... |
107 MockProxyConfigService* config_service = | 108 MockProxyConfigService* config_service = |
108 new MockProxyConfigService("http://foopy/proxy.pac"); | 109 new MockProxyConfigService("http://foopy/proxy.pac"); |
109 | 110 |
110 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 111 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
111 | 112 |
112 ProxyService service(config_service, resolver, NULL); | 113 ProxyService service(config_service, resolver, NULL); |
113 | 114 |
114 GURL url("http://www.google.com/"); | 115 GURL url("http://www.google.com/"); |
115 | 116 |
116 ProxyInfo info; | 117 ProxyInfo info; |
117 TestOldCompletionCallback callback; | 118 TestCompletionCallback callback; |
118 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 119 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
119 | 120 |
120 int rv = service.ResolveProxy(url, &info, &callback, NULL, log.bound()); | 121 int rv = service.ResolveProxy( |
| 122 url, &info, callback.callback(), NULL, log.bound()); |
121 EXPECT_EQ(ERR_IO_PENDING, rv); | 123 EXPECT_EQ(ERR_IO_PENDING, rv); |
122 | 124 |
123 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 125 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
124 resolver->pending_set_pac_script_request()->script_data()->url()); | 126 resolver->pending_set_pac_script_request()->script_data()->url()); |
125 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 127 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
126 | 128 |
127 ASSERT_EQ(1u, resolver->pending_requests().size()); | 129 ASSERT_EQ(1u, resolver->pending_requests().size()); |
128 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 130 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
129 | 131 |
130 // Set the result in proxy resolver. | 132 // Set the result in proxy resolver. |
(...skipping 25 matching lines...) Expand all Loading... |
156 MockProxyConfigService* config_service = | 158 MockProxyConfigService* config_service = |
157 new MockProxyConfigService("http://foopy/proxy.pac"); | 159 new MockProxyConfigService("http://foopy/proxy.pac"); |
158 | 160 |
159 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 161 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
160 | 162 |
161 ProxyService service(config_service, resolver, NULL); | 163 ProxyService service(config_service, resolver, NULL); |
162 | 164 |
163 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 165 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
164 | 166 |
165 ProxyInfo info; | 167 ProxyInfo info; |
166 TestOldCompletionCallback callback; | 168 TestCompletionCallback callback; |
167 int rv = service.ResolveProxy(url, &info, &callback, NULL, BoundNetLog()); | 169 int rv = service.ResolveProxy( |
| 170 url, &info, callback.callback(), NULL, BoundNetLog()); |
168 EXPECT_EQ(ERR_IO_PENDING, rv); | 171 EXPECT_EQ(ERR_IO_PENDING, rv); |
169 | 172 |
170 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 173 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
171 resolver->pending_set_pac_script_request()->script_data()->url()); | 174 resolver->pending_set_pac_script_request()->script_data()->url()); |
172 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 175 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
173 | 176 |
174 ASSERT_EQ(1u, resolver->pending_requests().size()); | 177 ASSERT_EQ(1u, resolver->pending_requests().size()); |
175 // The URL should have been simplified, stripping the username/password/hash. | 178 // The URL should have been simplified, stripping the username/password/hash. |
176 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 179 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
177 resolver->pending_requests()[0]->url()); | 180 resolver->pending_requests()[0]->url()); |
178 | 181 |
179 // We end here without ever completing the request -- destruction of | 182 // We end here without ever completing the request -- destruction of |
180 // ProxyService will cancel the outstanding request. | 183 // ProxyService will cancel the outstanding request. |
181 } | 184 } |
182 | 185 |
183 TEST(ProxyServiceTest, PAC_FailoverWithoutDirect) { | 186 TEST(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
184 MockProxyConfigService* config_service = | 187 MockProxyConfigService* config_service = |
185 new MockProxyConfigService("http://foopy/proxy.pac"); | 188 new MockProxyConfigService("http://foopy/proxy.pac"); |
186 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 189 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
187 | 190 |
188 ProxyService service(config_service, resolver, NULL); | 191 ProxyService service(config_service, resolver, NULL); |
189 | 192 |
190 GURL url("http://www.google.com/"); | 193 GURL url("http://www.google.com/"); |
191 | 194 |
192 ProxyInfo info; | 195 ProxyInfo info; |
193 TestOldCompletionCallback callback1; | 196 TestCompletionCallback callback1; |
194 int rv = service.ResolveProxy(url, &info, &callback1, NULL, BoundNetLog()); | 197 int rv = service.ResolveProxy( |
| 198 url, &info, callback1.callback(), NULL, BoundNetLog()); |
195 EXPECT_EQ(ERR_IO_PENDING, rv); | 199 EXPECT_EQ(ERR_IO_PENDING, rv); |
196 | 200 |
197 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 201 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
198 resolver->pending_set_pac_script_request()->script_data()->url()); | 202 resolver->pending_set_pac_script_request()->script_data()->url()); |
199 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 203 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
200 | 204 |
201 ASSERT_EQ(1u, resolver->pending_requests().size()); | 205 ASSERT_EQ(1u, resolver->pending_requests().size()); |
202 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 206 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
203 | 207 |
204 // Set the result in proxy resolver. | 208 // Set the result in proxy resolver. |
205 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); | 209 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); |
206 resolver->pending_requests()[0]->CompleteNow(OK); | 210 resolver->pending_requests()[0]->CompleteNow(OK); |
207 | 211 |
208 EXPECT_EQ(OK, callback1.WaitForResult()); | 212 EXPECT_EQ(OK, callback1.WaitForResult()); |
209 EXPECT_FALSE(info.is_direct()); | 213 EXPECT_FALSE(info.is_direct()); |
210 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); | 214 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); |
211 | 215 |
212 // Now, imagine that connecting to foopy:8080 fails: there is nothing | 216 // Now, imagine that connecting to foopy:8080 fails: there is nothing |
213 // left to fallback to, since our proxy list was NOT terminated by | 217 // left to fallback to, since our proxy list was NOT terminated by |
214 // DIRECT. | 218 // DIRECT. |
215 TestCompletionCallback callback2; | 219 TestCompletionCallback callback2; |
216 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, | 220 rv = service.ReconsiderProxyAfterError( |
217 BoundNetLog()); | 221 url, &info, callback2.callback(), NULL, BoundNetLog()); |
218 // ReconsiderProxyAfterError returns error indicating nothing left. | 222 // ReconsiderProxyAfterError returns error indicating nothing left. |
219 EXPECT_EQ(ERR_FAILED, rv); | 223 EXPECT_EQ(ERR_FAILED, rv); |
220 EXPECT_TRUE(info.is_empty()); | 224 EXPECT_TRUE(info.is_empty()); |
221 } | 225 } |
222 | 226 |
223 // The proxy list could potentially contain the DIRECT fallback choice | 227 // The proxy list could potentially contain the DIRECT fallback choice |
224 // in a location other than the very end of the list, and could even | 228 // in a location other than the very end of the list, and could even |
225 // specify it multiple times. | 229 // specify it multiple times. |
226 // | 230 // |
227 // This is not a typical usage, but we will obey it. | 231 // This is not a typical usage, but we will obey it. |
(...skipping 12 matching lines...) Expand all Loading... |
240 TEST(ProxyServiceTest, PAC_FailoverAfterDirect) { | 244 TEST(ProxyServiceTest, PAC_FailoverAfterDirect) { |
241 MockProxyConfigService* config_service = | 245 MockProxyConfigService* config_service = |
242 new MockProxyConfigService("http://foopy/proxy.pac"); | 246 new MockProxyConfigService("http://foopy/proxy.pac"); |
243 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 247 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
244 | 248 |
245 ProxyService service(config_service, resolver, NULL); | 249 ProxyService service(config_service, resolver, NULL); |
246 | 250 |
247 GURL url("http://www.google.com/"); | 251 GURL url("http://www.google.com/"); |
248 | 252 |
249 ProxyInfo info; | 253 ProxyInfo info; |
250 TestOldCompletionCallback callback1; | 254 TestCompletionCallback callback1; |
251 int rv = service.ResolveProxy(url, &info, &callback1, NULL, BoundNetLog()); | 255 int rv = service.ResolveProxy( |
| 256 url, &info, callback1.callback(), NULL, BoundNetLog()); |
252 EXPECT_EQ(ERR_IO_PENDING, rv); | 257 EXPECT_EQ(ERR_IO_PENDING, rv); |
253 | 258 |
254 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 259 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
255 resolver->pending_set_pac_script_request()->script_data()->url()); | 260 resolver->pending_set_pac_script_request()->script_data()->url()); |
256 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 261 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
257 | 262 |
258 ASSERT_EQ(1u, resolver->pending_requests().size()); | 263 ASSERT_EQ(1u, resolver->pending_requests().size()); |
259 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 264 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
260 | 265 |
261 // Set the result in proxy resolver. | 266 // Set the result in proxy resolver. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 MockProxyConfigService* config_service = | 310 MockProxyConfigService* config_service = |
306 new MockProxyConfigService("http://foopy/proxy.pac"); | 311 new MockProxyConfigService("http://foopy/proxy.pac"); |
307 | 312 |
308 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 313 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
309 | 314 |
310 ProxyService service(config_service, resolver, NULL); | 315 ProxyService service(config_service, resolver, NULL); |
311 | 316 |
312 // Start first resolve request. | 317 // Start first resolve request. |
313 GURL url("http://www.google.com/"); | 318 GURL url("http://www.google.com/"); |
314 ProxyInfo info; | 319 ProxyInfo info; |
315 TestOldCompletionCallback callback1; | 320 TestCompletionCallback callback1; |
316 int rv = service.ResolveProxy(url, &info, &callback1, NULL, BoundNetLog()); | 321 int rv = service.ResolveProxy( |
| 322 url, &info, callback1.callback(), NULL, BoundNetLog()); |
317 EXPECT_EQ(ERR_IO_PENDING, rv); | 323 EXPECT_EQ(ERR_IO_PENDING, rv); |
318 | 324 |
319 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 325 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
320 resolver->pending_set_pac_script_request()->script_data()->url()); | 326 resolver->pending_set_pac_script_request()->script_data()->url()); |
321 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 327 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
322 | 328 |
323 ASSERT_EQ(1u, resolver->pending_requests().size()); | 329 ASSERT_EQ(1u, resolver->pending_requests().size()); |
324 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 330 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
325 | 331 |
326 // Fail the first resolve request in MockAsyncProxyResolver. | 332 // Fail the first resolve request in MockAsyncProxyResolver. |
327 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 333 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
328 | 334 |
329 // Although the proxy resolver failed the request, ProxyService implicitly | 335 // Although the proxy resolver failed the request, ProxyService implicitly |
330 // falls-back to DIRECT. | 336 // falls-back to DIRECT. |
331 EXPECT_EQ(OK, callback1.WaitForResult()); | 337 EXPECT_EQ(OK, callback1.WaitForResult()); |
332 EXPECT_TRUE(info.is_direct()); | 338 EXPECT_TRUE(info.is_direct()); |
333 | 339 |
334 // The second resolve request will try to run through the proxy resolver, | 340 // The second resolve request will try to run through the proxy resolver, |
335 // regardless of whether the first request failed in it. | 341 // regardless of whether the first request failed in it. |
336 TestOldCompletionCallback callback2; | 342 TestCompletionCallback callback2; |
337 rv = service.ResolveProxy(url, &info, &callback2, NULL, BoundNetLog()); | 343 rv = service.ResolveProxy( |
| 344 url, &info, callback2.callback(), NULL, BoundNetLog()); |
338 EXPECT_EQ(ERR_IO_PENDING, rv); | 345 EXPECT_EQ(ERR_IO_PENDING, rv); |
339 | 346 |
340 ASSERT_EQ(1u, resolver->pending_requests().size()); | 347 ASSERT_EQ(1u, resolver->pending_requests().size()); |
341 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 348 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
342 | 349 |
343 // This time we will have the resolver succeed (perhaps the PAC script has | 350 // This time we will have the resolver succeed (perhaps the PAC script has |
344 // a dependency on the current time). | 351 // a dependency on the current time). |
345 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 352 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
346 resolver->pending_requests()[0]->CompleteNow(OK); | 353 resolver->pending_requests()[0]->CompleteNow(OK); |
347 | 354 |
(...skipping 12 matching lines...) Expand all Loading... |
360 | 367 |
361 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 368 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
362 | 369 |
363 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 370 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
364 | 371 |
365 ProxyService service(config_service, resolver, NULL); | 372 ProxyService service(config_service, resolver, NULL); |
366 | 373 |
367 // Start first resolve request. | 374 // Start first resolve request. |
368 GURL url("http://www.google.com/"); | 375 GURL url("http://www.google.com/"); |
369 ProxyInfo info; | 376 ProxyInfo info; |
370 TestOldCompletionCallback callback1; | 377 TestCompletionCallback callback1; |
371 int rv = service.ResolveProxy(url, &info, &callback1, NULL, BoundNetLog()); | 378 int rv = service.ResolveProxy( |
| 379 url, &info, callback1.callback(), NULL, BoundNetLog()); |
372 EXPECT_EQ(ERR_IO_PENDING, rv); | 380 EXPECT_EQ(ERR_IO_PENDING, rv); |
373 | 381 |
374 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 382 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
375 resolver->pending_set_pac_script_request()->script_data()->url()); | 383 resolver->pending_set_pac_script_request()->script_data()->url()); |
376 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); | 384 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); |
377 | 385 |
378 ASSERT_EQ(0u, resolver->pending_requests().size()); | 386 ASSERT_EQ(0u, resolver->pending_requests().size()); |
379 | 387 |
380 // As the proxy resolver failed the request and is configured for a mandatory | 388 // As the proxy resolver failed the request and is configured for a mandatory |
381 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 389 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
382 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 390 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
383 callback1.WaitForResult()); | 391 callback1.WaitForResult()); |
384 EXPECT_FALSE(info.is_direct()); | 392 EXPECT_FALSE(info.is_direct()); |
385 | 393 |
386 // As the proxy resolver failed the request and is configured for a mandatory | 394 // As the proxy resolver failed the request and is configured for a mandatory |
387 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 395 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
388 TestOldCompletionCallback callback2; | 396 TestCompletionCallback callback2; |
389 rv = service.ResolveProxy(url, &info, &callback2, NULL, BoundNetLog()); | 397 rv = service.ResolveProxy( |
| 398 url, &info, callback2.callback(), NULL, BoundNetLog()); |
390 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); | 399 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); |
391 EXPECT_FALSE(info.is_direct()); | 400 EXPECT_FALSE(info.is_direct()); |
392 } | 401 } |
393 | 402 |
394 TEST(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { | 403 TEST(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { |
395 // Test what happens when the ProxyResolver fails that is configured to use a | 404 // Test what happens when the ProxyResolver fails that is configured to use a |
396 // mandatory PAC script. The download of the PAC script has already | 405 // mandatory PAC script. The download of the PAC script has already |
397 // succeeded but the PAC script contains no valid javascript. | 406 // succeeded but the PAC script contains no valid javascript. |
398 | 407 |
399 ProxyConfig config( | 408 ProxyConfig config( |
400 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 409 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
401 config.set_pac_mandatory(true); | 410 config.set_pac_mandatory(true); |
402 | 411 |
403 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 412 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
404 | 413 |
405 MockAsyncProxyResolverExpectsBytes* resolver = | 414 MockAsyncProxyResolverExpectsBytes* resolver = |
406 new MockAsyncProxyResolverExpectsBytes; | 415 new MockAsyncProxyResolverExpectsBytes; |
407 | 416 |
408 ProxyService service(config_service, resolver, NULL); | 417 ProxyService service(config_service, resolver, NULL); |
409 | 418 |
410 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 419 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
411 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); | 420 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); |
412 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); | 421 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); |
413 | 422 |
414 // Start resolve request. | 423 // Start resolve request. |
415 GURL url("http://www.google.com/"); | 424 GURL url("http://www.google.com/"); |
416 ProxyInfo info; | 425 ProxyInfo info; |
417 TestOldCompletionCallback callback; | 426 TestCompletionCallback callback; |
418 int rv = service.ResolveProxy(url, &info, &callback, NULL, BoundNetLog()); | 427 int rv = service.ResolveProxy( |
| 428 url, &info, callback.callback(), NULL, BoundNetLog()); |
419 EXPECT_EQ(ERR_IO_PENDING, rv); | 429 EXPECT_EQ(ERR_IO_PENDING, rv); |
420 | 430 |
421 // Check that nothing has been sent to the proxy resolver yet. | 431 // Check that nothing has been sent to the proxy resolver yet. |
422 ASSERT_EQ(0u, resolver->pending_requests().size()); | 432 ASSERT_EQ(0u, resolver->pending_requests().size()); |
423 | 433 |
424 // Downloading the PAC script succeeds. | 434 // Downloading the PAC script succeeds. |
425 EXPECT_TRUE(fetcher->has_pending_request()); | 435 EXPECT_TRUE(fetcher->has_pending_request()); |
426 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 436 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
427 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 437 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
428 | 438 |
(...skipping 20 matching lines...) Expand all Loading... |
449 | 459 |
450 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 460 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
451 | 461 |
452 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 462 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
453 | 463 |
454 ProxyService service(config_service, resolver, NULL); | 464 ProxyService service(config_service, resolver, NULL); |
455 | 465 |
456 // Start first resolve request. | 466 // Start first resolve request. |
457 GURL url("http://www.google.com/"); | 467 GURL url("http://www.google.com/"); |
458 ProxyInfo info; | 468 ProxyInfo info; |
459 TestOldCompletionCallback callback1; | 469 TestCompletionCallback callback1; |
460 int rv = service.ResolveProxy(url, &info, &callback1, NULL, BoundNetLog()); | 470 int rv = service.ResolveProxy( |
| 471 url, &info, callback1.callback(), NULL, BoundNetLog()); |
461 EXPECT_EQ(ERR_IO_PENDING, rv); | 472 EXPECT_EQ(ERR_IO_PENDING, rv); |
462 | 473 |
463 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 474 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
464 resolver->pending_set_pac_script_request()->script_data()->url()); | 475 resolver->pending_set_pac_script_request()->script_data()->url()); |
465 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 476 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
466 | 477 |
467 ASSERT_EQ(1u, resolver->pending_requests().size()); | 478 ASSERT_EQ(1u, resolver->pending_requests().size()); |
468 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 479 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
469 | 480 |
470 // Fail the first resolve request in MockAsyncProxyResolver. | 481 // Fail the first resolve request in MockAsyncProxyResolver. |
471 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 482 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
472 | 483 |
473 // As the proxy resolver failed the request and is configured for a mandatory | 484 // As the proxy resolver failed the request and is configured for a mandatory |
474 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 485 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
475 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 486 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
476 callback1.WaitForResult()); | 487 callback1.WaitForResult()); |
477 EXPECT_FALSE(info.is_direct()); | 488 EXPECT_FALSE(info.is_direct()); |
478 | 489 |
479 // The second resolve request will try to run through the proxy resolver, | 490 // The second resolve request will try to run through the proxy resolver, |
480 // regardless of whether the first request failed in it. | 491 // regardless of whether the first request failed in it. |
481 TestOldCompletionCallback callback2; | 492 TestCompletionCallback callback2; |
482 rv = service.ResolveProxy(url, &info, &callback2, NULL, BoundNetLog()); | 493 rv = service.ResolveProxy( |
| 494 url, &info, callback2.callback(), NULL, BoundNetLog()); |
483 EXPECT_EQ(ERR_IO_PENDING, rv); | 495 EXPECT_EQ(ERR_IO_PENDING, rv); |
484 | 496 |
485 ASSERT_EQ(1u, resolver->pending_requests().size()); | 497 ASSERT_EQ(1u, resolver->pending_requests().size()); |
486 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 498 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
487 | 499 |
488 // This time we will have the resolver succeed (perhaps the PAC script has | 500 // This time we will have the resolver succeed (perhaps the PAC script has |
489 // a dependency on the current time). | 501 // a dependency on the current time). |
490 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 502 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
491 resolver->pending_requests()[0]->CompleteNow(OK); | 503 resolver->pending_requests()[0]->CompleteNow(OK); |
492 | 504 |
(...skipping 10 matching lines...) Expand all Loading... |
503 new MockProxyConfigService("http://foopy/proxy.pac"); | 515 new MockProxyConfigService("http://foopy/proxy.pac"); |
504 | 516 |
505 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 517 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
506 | 518 |
507 ProxyService service(config_service, resolver, NULL); | 519 ProxyService service(config_service, resolver, NULL); |
508 | 520 |
509 GURL url("http://www.google.com/"); | 521 GURL url("http://www.google.com/"); |
510 | 522 |
511 // Get the proxy information. | 523 // Get the proxy information. |
512 ProxyInfo info; | 524 ProxyInfo info; |
513 TestOldCompletionCallback callback1; | 525 TestCompletionCallback callback1; |
514 int rv = service.ResolveProxy(url, &info, &callback1, NULL, BoundNetLog()); | 526 int rv = service.ResolveProxy( |
| 527 url, &info, callback1.callback(), NULL, BoundNetLog()); |
515 EXPECT_EQ(ERR_IO_PENDING, rv); | 528 EXPECT_EQ(ERR_IO_PENDING, rv); |
516 | 529 |
517 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 530 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
518 resolver->pending_set_pac_script_request()->script_data()->url()); | 531 resolver->pending_set_pac_script_request()->script_data()->url()); |
519 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 532 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
520 | 533 |
521 ASSERT_EQ(1u, resolver->pending_requests().size()); | 534 ASSERT_EQ(1u, resolver->pending_requests().size()); |
522 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 535 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
523 | 536 |
524 // Set the result in proxy resolver. | 537 // Set the result in proxy resolver. |
(...skipping 11 matching lines...) Expand all Loading... |
536 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, | 549 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, |
537 BoundNetLog()); | 550 BoundNetLog()); |
538 EXPECT_EQ(OK, rv); | 551 EXPECT_EQ(OK, rv); |
539 | 552 |
540 // The second proxy should be specified. | 553 // The second proxy should be specified. |
541 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 554 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
542 // Report back that the second proxy worked. This will globally mark the | 555 // Report back that the second proxy worked. This will globally mark the |
543 // first proxy as bad. | 556 // first proxy as bad. |
544 service.ReportSuccess(info); | 557 service.ReportSuccess(info); |
545 | 558 |
546 TestOldCompletionCallback callback3; | 559 TestCompletionCallback callback3; |
547 rv = service.ResolveProxy(url, &info, &callback3, NULL, BoundNetLog()); | 560 rv = service.ResolveProxy( |
| 561 url, &info, callback3.callback(), NULL, BoundNetLog()); |
548 EXPECT_EQ(ERR_IO_PENDING, rv); | 562 EXPECT_EQ(ERR_IO_PENDING, rv); |
549 | 563 |
550 ASSERT_EQ(1u, resolver->pending_requests().size()); | 564 ASSERT_EQ(1u, resolver->pending_requests().size()); |
551 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 565 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
552 | 566 |
553 // Set the result in proxy resolver -- the second result is already known | 567 // Set the result in proxy resolver -- the second result is already known |
554 // to be bad, so we will not try to use it initially. | 568 // to be bad, so we will not try to use it initially. |
555 resolver->pending_requests()[0]->results()->UseNamedProxy( | 569 resolver->pending_requests()[0]->results()->UseNamedProxy( |
556 "foopy3:7070;foopy1:8080;foopy2:9090"); | 570 "foopy3:7070;foopy1:8080;foopy2:9090"); |
557 resolver->pending_requests()[0]->CompleteNow(OK); | 571 resolver->pending_requests()[0]->CompleteNow(OK); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 new MockProxyConfigService("http://foopy/proxy.pac"); | 629 new MockProxyConfigService("http://foopy/proxy.pac"); |
616 | 630 |
617 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 631 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
618 | 632 |
619 ProxyService service(config_service, resolver, NULL); | 633 ProxyService service(config_service, resolver, NULL); |
620 | 634 |
621 GURL url("http://www.google.com/"); | 635 GURL url("http://www.google.com/"); |
622 | 636 |
623 // Get the proxy information. | 637 // Get the proxy information. |
624 ProxyInfo info; | 638 ProxyInfo info; |
625 TestOldCompletionCallback callback1; | 639 TestCompletionCallback callback1; |
626 int rv = service.ResolveProxy(url, &info, &callback1, NULL, BoundNetLog()); | 640 int rv = service.ResolveProxy( |
| 641 url, &info, callback1.callback(), NULL, BoundNetLog()); |
627 EXPECT_EQ(ERR_IO_PENDING, rv); | 642 EXPECT_EQ(ERR_IO_PENDING, rv); |
628 | 643 |
629 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 644 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
630 resolver->pending_set_pac_script_request()->script_data()->url()); | 645 resolver->pending_set_pac_script_request()->script_data()->url()); |
631 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 646 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
632 | 647 |
633 ASSERT_EQ(1u, resolver->pending_requests().size()); | 648 ASSERT_EQ(1u, resolver->pending_requests().size()); |
634 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 649 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
635 | 650 |
636 // Set the result in proxy resolver. | 651 // Set the result in proxy resolver. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 new MockProxyConfigService("http://foopy/proxy.pac"); | 692 new MockProxyConfigService("http://foopy/proxy.pac"); |
678 | 693 |
679 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 694 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
680 | 695 |
681 ProxyService service(config_service, resolver, NULL); | 696 ProxyService service(config_service, resolver, NULL); |
682 | 697 |
683 GURL url("http://www.google.com/"); | 698 GURL url("http://www.google.com/"); |
684 | 699 |
685 // Get the proxy information. | 700 // Get the proxy information. |
686 ProxyInfo info; | 701 ProxyInfo info; |
687 TestOldCompletionCallback callback1; | 702 TestCompletionCallback callback1; |
688 int rv = service.ResolveProxy(url, &info, &callback1, NULL, BoundNetLog()); | 703 int rv = service.ResolveProxy( |
| 704 url, &info, callback1.callback(), NULL, BoundNetLog()); |
689 EXPECT_EQ(ERR_IO_PENDING, rv); | 705 EXPECT_EQ(ERR_IO_PENDING, rv); |
690 | 706 |
691 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 707 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
692 resolver->pending_set_pac_script_request()->script_data()->url()); | 708 resolver->pending_set_pac_script_request()->script_data()->url()); |
693 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 709 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
694 | 710 |
695 ASSERT_EQ(1u, resolver->pending_requests().size()); | 711 ASSERT_EQ(1u, resolver->pending_requests().size()); |
696 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 712 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
697 | 713 |
698 // Set the result in proxy resolver. | 714 // Set the result in proxy resolver. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 new MockProxyConfigService("http://foopy/proxy.pac"); | 785 new MockProxyConfigService("http://foopy/proxy.pac"); |
770 | 786 |
771 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 787 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
772 | 788 |
773 ProxyService service(config_service, resolver, NULL); | 789 ProxyService service(config_service, resolver, NULL); |
774 | 790 |
775 GURL url("http://www.google.com/"); | 791 GURL url("http://www.google.com/"); |
776 | 792 |
777 // Get the proxy information. | 793 // Get the proxy information. |
778 ProxyInfo info; | 794 ProxyInfo info; |
779 TestOldCompletionCallback callback1; | 795 TestCompletionCallback callback1; |
780 int rv = service.ResolveProxy(url, &info, &callback1, NULL, BoundNetLog()); | 796 int rv = service.ResolveProxy( |
| 797 url, &info, callback1.callback(), NULL, BoundNetLog()); |
781 EXPECT_EQ(ERR_IO_PENDING, rv); | 798 EXPECT_EQ(ERR_IO_PENDING, rv); |
782 | 799 |
783 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 800 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
784 resolver->pending_set_pac_script_request()->script_data()->url()); | 801 resolver->pending_set_pac_script_request()->script_data()->url()); |
785 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 802 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
786 ASSERT_EQ(1u, resolver->pending_requests().size()); | 803 ASSERT_EQ(1u, resolver->pending_requests().size()); |
787 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 804 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
788 | 805 |
789 resolver->pending_requests()[0]->results()->UseNamedProxy( | 806 resolver->pending_requests()[0]->results()->UseNamedProxy( |
790 "foopy1:8080;foopy2:9090"); | 807 "foopy1:8080;foopy2:9090"); |
791 resolver->pending_requests()[0]->CompleteNow(OK); | 808 resolver->pending_requests()[0]->CompleteNow(OK); |
792 | 809 |
793 // The first item is valid. | 810 // The first item is valid. |
794 EXPECT_EQ(OK, callback1.WaitForResult()); | 811 EXPECT_EQ(OK, callback1.WaitForResult()); |
795 EXPECT_FALSE(info.is_direct()); | 812 EXPECT_FALSE(info.is_direct()); |
796 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 813 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
797 | 814 |
798 // Fake a proxy error. | 815 // Fake a proxy error. |
799 TestCompletionCallback callback2; | 816 TestCompletionCallback callback2; |
800 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, | 817 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, |
801 BoundNetLog()); | 818 BoundNetLog()); |
802 EXPECT_EQ(OK, rv); | 819 EXPECT_EQ(OK, rv); |
803 | 820 |
804 // The first proxy is ignored, and the second one is selected. | 821 // The first proxy is ignored, and the second one is selected. |
805 EXPECT_FALSE(info.is_direct()); | 822 EXPECT_FALSE(info.is_direct()); |
806 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 823 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
807 | 824 |
808 // Fake a PAC failure. | 825 // Fake a PAC failure. |
809 ProxyInfo info2; | 826 ProxyInfo info2; |
810 TestOldCompletionCallback callback3; | 827 TestCompletionCallback callback3; |
811 rv = service.ResolveProxy(url, &info2, &callback3, NULL, BoundNetLog()); | 828 rv = service.ResolveProxy( |
| 829 url, &info2, callback3.callback(), NULL, BoundNetLog()); |
812 EXPECT_EQ(ERR_IO_PENDING, rv); | 830 EXPECT_EQ(ERR_IO_PENDING, rv); |
813 | 831 |
814 ASSERT_EQ(1u, resolver->pending_requests().size()); | 832 ASSERT_EQ(1u, resolver->pending_requests().size()); |
815 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 833 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
816 | 834 |
817 // This simulates a javascript runtime error in the PAC script. | 835 // This simulates a javascript runtime error in the PAC script. |
818 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 836 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
819 | 837 |
820 // Although the resolver failed, the ProxyService will implicitly fall-back | 838 // Although the resolver failed, the ProxyService will implicitly fall-back |
821 // to a DIRECT connection. | 839 // to a DIRECT connection. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 874 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
857 | 875 |
858 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 876 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
859 | 877 |
860 ProxyService service(config_service, resolver, NULL); | 878 ProxyService service(config_service, resolver, NULL); |
861 | 879 |
862 GURL url("http://www.google.com/"); | 880 GURL url("http://www.google.com/"); |
863 | 881 |
864 // Get the proxy information. | 882 // Get the proxy information. |
865 ProxyInfo info; | 883 ProxyInfo info; |
866 TestOldCompletionCallback callback1; | 884 TestCompletionCallback callback1; |
867 int rv = service.ResolveProxy(url, &info, &callback1, NULL, BoundNetLog()); | 885 int rv = service.ResolveProxy( |
| 886 url, &info, callback1.callback(), NULL, BoundNetLog()); |
868 EXPECT_EQ(ERR_IO_PENDING, rv); | 887 EXPECT_EQ(ERR_IO_PENDING, rv); |
869 | 888 |
870 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 889 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
871 resolver->pending_set_pac_script_request()->script_data()->url()); | 890 resolver->pending_set_pac_script_request()->script_data()->url()); |
872 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 891 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
873 ASSERT_EQ(1u, resolver->pending_requests().size()); | 892 ASSERT_EQ(1u, resolver->pending_requests().size()); |
874 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 893 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
875 | 894 |
876 resolver->pending_requests()[0]->results()->UseNamedProxy( | 895 resolver->pending_requests()[0]->results()->UseNamedProxy( |
877 "foopy1:8080;foopy2:9090"); | 896 "foopy1:8080;foopy2:9090"); |
878 resolver->pending_requests()[0]->CompleteNow(OK); | 897 resolver->pending_requests()[0]->CompleteNow(OK); |
879 | 898 |
880 // The first item is valid. | 899 // The first item is valid. |
881 EXPECT_EQ(OK, callback1.WaitForResult()); | 900 EXPECT_EQ(OK, callback1.WaitForResult()); |
882 EXPECT_FALSE(info.is_direct()); | 901 EXPECT_FALSE(info.is_direct()); |
883 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 902 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
884 | 903 |
885 // Fake a proxy error. | 904 // Fake a proxy error. |
886 TestCompletionCallback callback2; | 905 TestCompletionCallback callback2; |
887 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, | 906 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, |
888 BoundNetLog()); | 907 BoundNetLog()); |
889 EXPECT_EQ(OK, rv); | 908 EXPECT_EQ(OK, rv); |
890 | 909 |
891 // The first proxy is ignored, and the second one is selected. | 910 // The first proxy is ignored, and the second one is selected. |
892 EXPECT_FALSE(info.is_direct()); | 911 EXPECT_FALSE(info.is_direct()); |
893 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 912 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
894 | 913 |
895 // Fake a PAC failure. | 914 // Fake a PAC failure. |
896 ProxyInfo info2; | 915 ProxyInfo info2; |
897 TestOldCompletionCallback callback3; | 916 TestCompletionCallback callback3; |
898 rv = service.ResolveProxy(url, &info2, &callback3, NULL, BoundNetLog()); | 917 rv = service.ResolveProxy( |
| 918 url, &info2, callback3.callback(), NULL, BoundNetLog()); |
899 EXPECT_EQ(ERR_IO_PENDING, rv); | 919 EXPECT_EQ(ERR_IO_PENDING, rv); |
900 | 920 |
901 ASSERT_EQ(1u, resolver->pending_requests().size()); | 921 ASSERT_EQ(1u, resolver->pending_requests().size()); |
902 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 922 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
903 | 923 |
904 // This simulates a javascript runtime error in the PAC script. | 924 // This simulates a javascript runtime error in the PAC script. |
905 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 925 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
906 | 926 |
907 // Although the resolver failed, the ProxyService will NOT fall-back | 927 // Although the resolver failed, the ProxyService will NOT fall-back |
908 // to a DIRECT connection as it is configured as mandatory. | 928 // to a DIRECT connection as it is configured as mandatory. |
(...skipping 21 matching lines...) Expand all Loading... |
930 // The first proxy is not there since the it was added to the bad proxies | 950 // The first proxy is not there since the it was added to the bad proxies |
931 // list by the earlier ReconsiderProxyAfterError(). | 951 // list by the earlier ReconsiderProxyAfterError(). |
932 EXPECT_EQ(OK, callback4.WaitForResult()); | 952 EXPECT_EQ(OK, callback4.WaitForResult()); |
933 EXPECT_FALSE(info3.is_direct()); | 953 EXPECT_FALSE(info3.is_direct()); |
934 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 954 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
935 } | 955 } |
936 | 956 |
937 TEST(ProxyServiceTest, ProxyBypassList) { | 957 TEST(ProxyServiceTest, ProxyBypassList) { |
938 // Test that the proxy bypass rules are consulted. | 958 // Test that the proxy bypass rules are consulted. |
939 | 959 |
940 TestOldCompletionCallback callback[2]; | 960 TestCompletionCallback callback[2]; |
941 ProxyInfo info[2]; | 961 ProxyInfo info[2]; |
942 ProxyConfig config; | 962 ProxyConfig config; |
943 config.proxy_rules().ParseFromString("foopy1:8080;foopy2:9090"); | 963 config.proxy_rules().ParseFromString("foopy1:8080;foopy2:9090"); |
944 config.set_auto_detect(false); | 964 config.set_auto_detect(false); |
945 config.proxy_rules().bypass_rules.ParseFromString("*.org"); | 965 config.proxy_rules().bypass_rules.ParseFromString("*.org"); |
946 | 966 |
947 ProxyService service( | 967 ProxyService service( |
948 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 968 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
949 | 969 |
950 int rv; | 970 int rv; |
951 GURL url1("http://www.webkit.org"); | 971 GURL url1("http://www.webkit.org"); |
952 GURL url2("http://www.webkit.com"); | 972 GURL url2("http://www.webkit.com"); |
953 | 973 |
954 // Request for a .org domain should bypass proxy. | 974 // Request for a .org domain should bypass proxy. |
955 rv = service.ResolveProxy(url1, &info[0], &callback[0], NULL, BoundNetLog()); | 975 rv = service.ResolveProxy( |
| 976 url1, &info[0], callback[0].callback(), NULL, BoundNetLog()); |
956 EXPECT_EQ(OK, rv); | 977 EXPECT_EQ(OK, rv); |
957 EXPECT_TRUE(info[0].is_direct()); | 978 EXPECT_TRUE(info[0].is_direct()); |
958 | 979 |
959 // Request for a .com domain hits the proxy. | 980 // Request for a .com domain hits the proxy. |
960 rv = service.ResolveProxy(url2, &info[1], &callback[1], NULL, BoundNetLog()); | 981 rv = service.ResolveProxy( |
| 982 url2, &info[1], callback[1].callback(), NULL, BoundNetLog()); |
961 EXPECT_EQ(OK, rv); | 983 EXPECT_EQ(OK, rv); |
962 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); | 984 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); |
963 } | 985 } |
964 | 986 |
965 | 987 |
966 TEST(ProxyServiceTest, PerProtocolProxyTests) { | 988 TEST(ProxyServiceTest, PerProtocolProxyTests) { |
967 ProxyConfig config; | 989 ProxyConfig config; |
968 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); | 990 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); |
969 config.set_auto_detect(false); | 991 config.set_auto_detect(false); |
970 { | 992 { |
971 ProxyService service( | 993 ProxyService service( |
972 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 994 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
973 GURL test_url("http://www.msn.com"); | 995 GURL test_url("http://www.msn.com"); |
974 ProxyInfo info; | 996 ProxyInfo info; |
975 TestOldCompletionCallback callback; | 997 TestCompletionCallback callback; |
976 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, | 998 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, |
977 BoundNetLog()); | 999 BoundNetLog()); |
978 EXPECT_EQ(OK, rv); | 1000 EXPECT_EQ(OK, rv); |
979 EXPECT_FALSE(info.is_direct()); | 1001 EXPECT_FALSE(info.is_direct()); |
980 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1002 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
981 } | 1003 } |
982 { | 1004 { |
983 ProxyService service( | 1005 ProxyService service( |
984 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1006 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
985 GURL test_url("ftp://ftp.google.com"); | 1007 GURL test_url("ftp://ftp.google.com"); |
986 ProxyInfo info; | 1008 ProxyInfo info; |
987 TestOldCompletionCallback callback; | 1009 TestCompletionCallback callback; |
988 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, | 1010 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, |
989 BoundNetLog()); | 1011 BoundNetLog()); |
990 EXPECT_EQ(OK, rv); | 1012 EXPECT_EQ(OK, rv); |
991 EXPECT_TRUE(info.is_direct()); | 1013 EXPECT_TRUE(info.is_direct()); |
992 EXPECT_EQ("direct://", info.proxy_server().ToURI()); | 1014 EXPECT_EQ("direct://", info.proxy_server().ToURI()); |
993 } | 1015 } |
994 { | 1016 { |
995 ProxyService service( | 1017 ProxyService service( |
996 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1018 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
997 GURL test_url("https://webbranch.techcu.com"); | 1019 GURL test_url("https://webbranch.techcu.com"); |
998 ProxyInfo info; | 1020 ProxyInfo info; |
999 TestOldCompletionCallback callback; | 1021 TestCompletionCallback callback; |
1000 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, | 1022 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, |
1001 BoundNetLog()); | 1023 BoundNetLog()); |
1002 EXPECT_EQ(OK, rv); | 1024 EXPECT_EQ(OK, rv); |
1003 EXPECT_FALSE(info.is_direct()); | 1025 EXPECT_FALSE(info.is_direct()); |
1004 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1026 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
1005 } | 1027 } |
1006 { | 1028 { |
1007 config.proxy_rules().ParseFromString("foopy1:8080"); | 1029 config.proxy_rules().ParseFromString("foopy1:8080"); |
1008 ProxyService service( | 1030 ProxyService service( |
1009 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1031 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1010 GURL test_url("http://www.microsoft.com"); | 1032 GURL test_url("http://www.microsoft.com"); |
1011 ProxyInfo info; | 1033 ProxyInfo info; |
1012 TestOldCompletionCallback callback; | 1034 TestCompletionCallback callback; |
1013 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, | 1035 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, |
1014 BoundNetLog()); | 1036 BoundNetLog()); |
1015 EXPECT_EQ(OK, rv); | 1037 EXPECT_EQ(OK, rv); |
1016 EXPECT_FALSE(info.is_direct()); | 1038 EXPECT_FALSE(info.is_direct()); |
1017 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1039 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1018 } | 1040 } |
1019 } | 1041 } |
1020 | 1042 |
1021 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries | 1043 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries |
1022 // fall back to the SOCKS proxy. | 1044 // fall back to the SOCKS proxy. |
1023 TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { | 1045 TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { |
1024 ProxyConfig config; | 1046 ProxyConfig config; |
1025 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); | 1047 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); |
1026 config.set_auto_detect(false); | 1048 config.set_auto_detect(false); |
1027 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 1049 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
1028 config.proxy_rules().type); | 1050 config.proxy_rules().type); |
1029 | 1051 |
1030 { | 1052 { |
1031 ProxyService service( | 1053 ProxyService service( |
1032 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1054 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1033 GURL test_url("http://www.msn.com"); | 1055 GURL test_url("http://www.msn.com"); |
1034 ProxyInfo info; | 1056 ProxyInfo info; |
1035 TestOldCompletionCallback callback; | 1057 TestCompletionCallback callback; |
1036 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, | 1058 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, |
1037 BoundNetLog()); | 1059 BoundNetLog()); |
1038 EXPECT_EQ(OK, rv); | 1060 EXPECT_EQ(OK, rv); |
1039 EXPECT_FALSE(info.is_direct()); | 1061 EXPECT_FALSE(info.is_direct()); |
1040 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1062 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1041 } | 1063 } |
1042 { | 1064 { |
1043 ProxyService service( | 1065 ProxyService service( |
1044 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1066 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1045 GURL test_url("ftp://ftp.google.com"); | 1067 GURL test_url("ftp://ftp.google.com"); |
1046 ProxyInfo info; | 1068 ProxyInfo info; |
1047 TestOldCompletionCallback callback; | 1069 TestCompletionCallback callback; |
1048 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, | 1070 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, |
1049 BoundNetLog()); | 1071 BoundNetLog()); |
1050 EXPECT_EQ(OK, rv); | 1072 EXPECT_EQ(OK, rv); |
1051 EXPECT_FALSE(info.is_direct()); | 1073 EXPECT_FALSE(info.is_direct()); |
1052 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1074 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1053 } | 1075 } |
1054 { | 1076 { |
1055 ProxyService service( | 1077 ProxyService service( |
1056 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1078 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1057 GURL test_url("https://webbranch.techcu.com"); | 1079 GURL test_url("https://webbranch.techcu.com"); |
1058 ProxyInfo info; | 1080 ProxyInfo info; |
1059 TestOldCompletionCallback callback; | 1081 TestCompletionCallback callback; |
1060 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, | 1082 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, |
1061 BoundNetLog()); | 1083 BoundNetLog()); |
1062 EXPECT_EQ(OK, rv); | 1084 EXPECT_EQ(OK, rv); |
1063 EXPECT_FALSE(info.is_direct()); | 1085 EXPECT_FALSE(info.is_direct()); |
1064 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1086 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1065 } | 1087 } |
1066 { | 1088 { |
1067 ProxyService service( | 1089 ProxyService service( |
1068 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1090 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1069 GURL test_url("unknown://www.microsoft.com"); | 1091 GURL test_url("unknown://www.microsoft.com"); |
1070 ProxyInfo info; | 1092 ProxyInfo info; |
1071 TestOldCompletionCallback callback; | 1093 TestCompletionCallback callback; |
1072 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, | 1094 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, |
1073 BoundNetLog()); | 1095 BoundNetLog()); |
1074 EXPECT_EQ(OK, rv); | 1096 EXPECT_EQ(OK, rv); |
1075 EXPECT_FALSE(info.is_direct()); | 1097 EXPECT_FALSE(info.is_direct()); |
1076 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1098 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1077 } | 1099 } |
1078 } | 1100 } |
1079 | 1101 |
1080 // Test cancellation of an in-progress request. | 1102 // Test cancellation of an in-progress request. |
1081 TEST(ProxyServiceTest, CancelInProgressRequest) { | 1103 TEST(ProxyServiceTest, CancelInProgressRequest) { |
1082 MockProxyConfigService* config_service = | 1104 MockProxyConfigService* config_service = |
1083 new MockProxyConfigService("http://foopy/proxy.pac"); | 1105 new MockProxyConfigService("http://foopy/proxy.pac"); |
1084 | 1106 |
1085 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1107 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1086 | 1108 |
1087 ProxyService service(config_service, resolver, NULL); | 1109 ProxyService service(config_service, resolver, NULL); |
1088 | 1110 |
1089 // Start 3 requests. | 1111 // Start 3 requests. |
1090 | 1112 |
1091 ProxyInfo info1; | 1113 ProxyInfo info1; |
1092 TestOldCompletionCallback callback1; | 1114 TestCompletionCallback callback1; |
1093 int rv = service.ResolveProxy( | 1115 int rv = service.ResolveProxy(GURL("http://request1"), &info1, |
1094 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 1116 callback1.callback(), NULL, BoundNetLog()); |
1095 EXPECT_EQ(ERR_IO_PENDING, rv); | 1117 EXPECT_EQ(ERR_IO_PENDING, rv); |
1096 | 1118 |
1097 // Nothing has been sent to the proxy resolver yet, since the proxy | 1119 // Nothing has been sent to the proxy resolver yet, since the proxy |
1098 // resolver has not been configured yet. | 1120 // resolver has not been configured yet. |
1099 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1121 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1100 | 1122 |
1101 // Successfully initialize the PAC script. | 1123 // Successfully initialize the PAC script. |
1102 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1124 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1103 resolver->pending_set_pac_script_request()->script_data()->url()); | 1125 resolver->pending_set_pac_script_request()->script_data()->url()); |
1104 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1126 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1105 | 1127 |
1106 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1128 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1107 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1129 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
1108 | 1130 |
1109 ProxyInfo info2; | 1131 ProxyInfo info2; |
1110 TestOldCompletionCallback callback2; | 1132 TestCompletionCallback callback2; |
1111 ProxyService::PacRequest* request2; | 1133 ProxyService::PacRequest* request2; |
1112 rv = service.ResolveProxy( | 1134 rv = service.ResolveProxy(GURL("http://request2"), &info2, |
1113 GURL("http://request2"), &info2, &callback2, &request2, BoundNetLog()); | 1135 callback2.callback(), &request2, BoundNetLog()); |
1114 EXPECT_EQ(ERR_IO_PENDING, rv); | 1136 EXPECT_EQ(ERR_IO_PENDING, rv); |
1115 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1137 ASSERT_EQ(2u, resolver->pending_requests().size()); |
1116 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1138 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
1117 | 1139 |
1118 ProxyInfo info3; | 1140 ProxyInfo info3; |
1119 TestOldCompletionCallback callback3; | 1141 TestCompletionCallback callback3; |
1120 rv = service.ResolveProxy( | 1142 rv = service.ResolveProxy(GURL("http://request3"), &info3, |
1121 GURL("http://request3"), &info3, &callback3, NULL, BoundNetLog()); | 1143 callback3.callback(), NULL, BoundNetLog()); |
1122 EXPECT_EQ(ERR_IO_PENDING, rv); | 1144 EXPECT_EQ(ERR_IO_PENDING, rv); |
1123 ASSERT_EQ(3u, resolver->pending_requests().size()); | 1145 ASSERT_EQ(3u, resolver->pending_requests().size()); |
1124 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); | 1146 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); |
1125 | 1147 |
1126 // Cancel the second request | 1148 // Cancel the second request |
1127 service.CancelPacRequest(request2); | 1149 service.CancelPacRequest(request2); |
1128 | 1150 |
1129 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1151 ASSERT_EQ(2u, resolver->pending_requests().size()); |
1130 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1152 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
1131 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); | 1153 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); |
(...skipping 28 matching lines...) Expand all Loading... |
1160 | 1182 |
1161 ProxyService service(config_service, resolver, NULL); | 1183 ProxyService service(config_service, resolver, NULL); |
1162 | 1184 |
1163 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1185 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1164 service.SetProxyScriptFetchers(fetcher, | 1186 service.SetProxyScriptFetchers(fetcher, |
1165 new DoNothingDhcpProxyScriptFetcher()); | 1187 new DoNothingDhcpProxyScriptFetcher()); |
1166 | 1188 |
1167 // Start 3 requests. | 1189 // Start 3 requests. |
1168 | 1190 |
1169 ProxyInfo info1; | 1191 ProxyInfo info1; |
1170 TestOldCompletionCallback callback1; | 1192 TestCompletionCallback callback1; |
1171 int rv = service.ResolveProxy( | 1193 int rv = service.ResolveProxy(GURL("http://request1"), &info1, |
1172 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 1194 callback1.callback(), NULL, BoundNetLog()); |
1173 EXPECT_EQ(ERR_IO_PENDING, rv); | 1195 EXPECT_EQ(ERR_IO_PENDING, rv); |
1174 | 1196 |
1175 // The first request should have triggered download of PAC script. | 1197 // The first request should have triggered download of PAC script. |
1176 EXPECT_TRUE(fetcher->has_pending_request()); | 1198 EXPECT_TRUE(fetcher->has_pending_request()); |
1177 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1199 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1178 | 1200 |
1179 ProxyInfo info2; | 1201 ProxyInfo info2; |
1180 TestOldCompletionCallback callback2; | 1202 TestCompletionCallback callback2; |
1181 rv = service.ResolveProxy( | 1203 rv = service.ResolveProxy(GURL("http://request2"), &info2, |
1182 GURL("http://request2"), &info2, &callback2, NULL, BoundNetLog()); | 1204 callback2.callback(), NULL, BoundNetLog()); |
1183 EXPECT_EQ(ERR_IO_PENDING, rv); | 1205 EXPECT_EQ(ERR_IO_PENDING, rv); |
1184 | 1206 |
1185 ProxyInfo info3; | 1207 ProxyInfo info3; |
1186 TestOldCompletionCallback callback3; | 1208 TestCompletionCallback callback3; |
1187 rv = service.ResolveProxy( | 1209 rv = service.ResolveProxy(GURL("http://request3"), &info3, |
1188 GURL("http://request3"), &info3, &callback3, NULL, BoundNetLog()); | 1210 callback3.callback(), NULL, BoundNetLog()); |
1189 EXPECT_EQ(ERR_IO_PENDING, rv); | 1211 EXPECT_EQ(ERR_IO_PENDING, rv); |
1190 | 1212 |
1191 // Nothing has been sent to the resolver yet. | 1213 // Nothing has been sent to the resolver yet. |
1192 EXPECT_TRUE(resolver->pending_requests().empty()); | 1214 EXPECT_TRUE(resolver->pending_requests().empty()); |
1193 | 1215 |
1194 // At this point the ProxyService should be waiting for the | 1216 // At this point the ProxyService should be waiting for the |
1195 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1217 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
1196 // PAC script download completion. | 1218 // PAC script download completion. |
1197 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 1219 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
1198 | 1220 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 | 1262 |
1241 ProxyService service(config_service, resolver, NULL); | 1263 ProxyService service(config_service, resolver, NULL); |
1242 | 1264 |
1243 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1265 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1244 service.SetProxyScriptFetchers(fetcher, | 1266 service.SetProxyScriptFetchers(fetcher, |
1245 new DoNothingDhcpProxyScriptFetcher()); | 1267 new DoNothingDhcpProxyScriptFetcher()); |
1246 | 1268 |
1247 // Start 2 requests. | 1269 // Start 2 requests. |
1248 | 1270 |
1249 ProxyInfo info1; | 1271 ProxyInfo info1; |
1250 TestOldCompletionCallback callback1; | 1272 TestCompletionCallback callback1; |
1251 int rv = service.ResolveProxy( | 1273 int rv = service.ResolveProxy(GURL("http://request1"), &info1, |
1252 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 1274 callback1.callback(), NULL, BoundNetLog()); |
1253 EXPECT_EQ(ERR_IO_PENDING, rv); | 1275 EXPECT_EQ(ERR_IO_PENDING, rv); |
1254 | 1276 |
1255 // The first request should have triggered download of PAC script. | 1277 // The first request should have triggered download of PAC script. |
1256 EXPECT_TRUE(fetcher->has_pending_request()); | 1278 EXPECT_TRUE(fetcher->has_pending_request()); |
1257 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1279 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1258 | 1280 |
1259 ProxyInfo info2; | 1281 ProxyInfo info2; |
1260 TestOldCompletionCallback callback2; | 1282 TestCompletionCallback callback2; |
1261 rv = service.ResolveProxy( | 1283 rv = service.ResolveProxy(GURL("http://request2"), &info2, |
1262 GURL("http://request2"), &info2, &callback2, NULL, BoundNetLog()); | 1284 callback2.callback(), NULL, BoundNetLog()); |
1263 EXPECT_EQ(ERR_IO_PENDING, rv); | 1285 EXPECT_EQ(ERR_IO_PENDING, rv); |
1264 | 1286 |
1265 // At this point the ProxyService should be waiting for the | 1287 // At this point the ProxyService should be waiting for the |
1266 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1288 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
1267 // PAC script download completion. | 1289 // PAC script download completion. |
1268 | 1290 |
1269 // We now change out the ProxyService's script fetcher. We should restart | 1291 // We now change out the ProxyService's script fetcher. We should restart |
1270 // the initialization with the new fetcher. | 1292 // the initialization with the new fetcher. |
1271 | 1293 |
1272 fetcher = new MockProxyScriptFetcher; | 1294 fetcher = new MockProxyScriptFetcher; |
(...skipping 25 matching lines...) Expand all Loading... |
1298 new MockAsyncProxyResolverExpectsBytes; | 1320 new MockAsyncProxyResolverExpectsBytes; |
1299 | 1321 |
1300 ProxyService service(config_service, resolver, NULL); | 1322 ProxyService service(config_service, resolver, NULL); |
1301 | 1323 |
1302 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1324 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1303 service.SetProxyScriptFetchers(fetcher, | 1325 service.SetProxyScriptFetchers(fetcher, |
1304 new DoNothingDhcpProxyScriptFetcher()); | 1326 new DoNothingDhcpProxyScriptFetcher()); |
1305 | 1327 |
1306 // Start 3 requests. | 1328 // Start 3 requests. |
1307 ProxyInfo info1; | 1329 ProxyInfo info1; |
1308 TestOldCompletionCallback callback1; | 1330 TestCompletionCallback callback1; |
1309 ProxyService::PacRequest* request1; | 1331 ProxyService::PacRequest* request1; |
1310 CapturingBoundNetLog log1(CapturingNetLog::kUnbounded); | 1332 CapturingBoundNetLog log1(CapturingNetLog::kUnbounded); |
1311 int rv = service.ResolveProxy( | 1333 int rv = service.ResolveProxy(GURL("http://request1"), &info1, |
1312 GURL("http://request1"), &info1, &callback1, &request1, log1.bound()); | 1334 callback1.callback(), &request1, log1.bound()); |
1313 EXPECT_EQ(ERR_IO_PENDING, rv); | 1335 EXPECT_EQ(ERR_IO_PENDING, rv); |
1314 | 1336 |
1315 // The first request should have triggered download of PAC script. | 1337 // The first request should have triggered download of PAC script. |
1316 EXPECT_TRUE(fetcher->has_pending_request()); | 1338 EXPECT_TRUE(fetcher->has_pending_request()); |
1317 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1339 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1318 | 1340 |
1319 ProxyInfo info2; | 1341 ProxyInfo info2; |
1320 TestOldCompletionCallback callback2; | 1342 TestCompletionCallback callback2; |
1321 ProxyService::PacRequest* request2; | 1343 ProxyService::PacRequest* request2; |
1322 rv = service.ResolveProxy( | 1344 rv = service.ResolveProxy(GURL("http://request2"), &info2, |
1323 GURL("http://request2"), &info2, &callback2, &request2, BoundNetLog()); | 1345 callback2.callback(), &request2, BoundNetLog()); |
1324 EXPECT_EQ(ERR_IO_PENDING, rv); | 1346 EXPECT_EQ(ERR_IO_PENDING, rv); |
1325 | 1347 |
1326 ProxyInfo info3; | 1348 ProxyInfo info3; |
1327 TestOldCompletionCallback callback3; | 1349 TestCompletionCallback callback3; |
1328 rv = service.ResolveProxy( | 1350 rv = service.ResolveProxy(GURL("http://request3"), &info3, |
1329 GURL("http://request3"), &info3, &callback3, NULL, BoundNetLog()); | 1351 callback3.callback(), NULL, BoundNetLog()); |
1330 EXPECT_EQ(ERR_IO_PENDING, rv); | 1352 EXPECT_EQ(ERR_IO_PENDING, rv); |
1331 | 1353 |
1332 // Nothing has been sent to the resolver yet. | 1354 // Nothing has been sent to the resolver yet. |
1333 EXPECT_TRUE(resolver->pending_requests().empty()); | 1355 EXPECT_TRUE(resolver->pending_requests().empty()); |
1334 | 1356 |
1335 // Cancel the first 2 requests. | 1357 // Cancel the first 2 requests. |
1336 service.CancelPacRequest(request1); | 1358 service.CancelPacRequest(request1); |
1337 service.CancelPacRequest(request2); | 1359 service.CancelPacRequest(request2); |
1338 | 1360 |
1339 // At this point the ProxyService should be waiting for the | 1361 // At this point the ProxyService should be waiting for the |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 new MockAsyncProxyResolverExpectsBytes; | 1413 new MockAsyncProxyResolverExpectsBytes; |
1392 ProxyService service(config_service, resolver, NULL); | 1414 ProxyService service(config_service, resolver, NULL); |
1393 | 1415 |
1394 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1416 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1395 service.SetProxyScriptFetchers(fetcher, | 1417 service.SetProxyScriptFetchers(fetcher, |
1396 new DoNothingDhcpProxyScriptFetcher()); | 1418 new DoNothingDhcpProxyScriptFetcher()); |
1397 | 1419 |
1398 // Start 2 requests. | 1420 // Start 2 requests. |
1399 | 1421 |
1400 ProxyInfo info1; | 1422 ProxyInfo info1; |
1401 TestOldCompletionCallback callback1; | 1423 TestCompletionCallback callback1; |
1402 int rv = service.ResolveProxy( | 1424 int rv = service.ResolveProxy(GURL("http://request1"), &info1, |
1403 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 1425 callback1.callback(), NULL, BoundNetLog()); |
1404 EXPECT_EQ(ERR_IO_PENDING, rv); | 1426 EXPECT_EQ(ERR_IO_PENDING, rv); |
1405 | 1427 |
1406 ProxyInfo info2; | 1428 ProxyInfo info2; |
1407 TestOldCompletionCallback callback2; | 1429 TestCompletionCallback callback2; |
1408 ProxyService::PacRequest* request2; | 1430 ProxyService::PacRequest* request2; |
1409 rv = service.ResolveProxy( | 1431 rv = service.ResolveProxy(GURL("http://request2"), &info2, |
1410 GURL("http://request2"), &info2, &callback2, &request2, BoundNetLog()); | 1432 callback2.callback(), &request2, BoundNetLog()); |
1411 EXPECT_EQ(ERR_IO_PENDING, rv); | 1433 EXPECT_EQ(ERR_IO_PENDING, rv); |
1412 | 1434 |
1413 // Check that nothing has been sent to the proxy resolver yet. | 1435 // Check that nothing has been sent to the proxy resolver yet. |
1414 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1436 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1415 | 1437 |
1416 // It should be trying to auto-detect first -- FAIL the autodetect during | 1438 // It should be trying to auto-detect first -- FAIL the autodetect during |
1417 // the script download. | 1439 // the script download. |
1418 EXPECT_TRUE(fetcher->has_pending_request()); | 1440 EXPECT_TRUE(fetcher->has_pending_request()); |
1419 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1441 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1420 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); | 1442 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 new MockAsyncProxyResolverExpectsBytes; | 1484 new MockAsyncProxyResolverExpectsBytes; |
1463 ProxyService service(config_service, resolver, NULL); | 1485 ProxyService service(config_service, resolver, NULL); |
1464 | 1486 |
1465 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1487 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1466 service.SetProxyScriptFetchers(fetcher, | 1488 service.SetProxyScriptFetchers(fetcher, |
1467 new DoNothingDhcpProxyScriptFetcher()); | 1489 new DoNothingDhcpProxyScriptFetcher()); |
1468 | 1490 |
1469 // Start 2 requests. | 1491 // Start 2 requests. |
1470 | 1492 |
1471 ProxyInfo info1; | 1493 ProxyInfo info1; |
1472 TestOldCompletionCallback callback1; | 1494 TestCompletionCallback callback1; |
1473 int rv = service.ResolveProxy( | 1495 int rv = service.ResolveProxy(GURL("http://request1"), &info1, |
1474 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 1496 callback1.callback(), NULL, BoundNetLog()); |
1475 EXPECT_EQ(ERR_IO_PENDING, rv); | 1497 EXPECT_EQ(ERR_IO_PENDING, rv); |
1476 | 1498 |
1477 ProxyInfo info2; | 1499 ProxyInfo info2; |
1478 TestOldCompletionCallback callback2; | 1500 TestCompletionCallback callback2; |
1479 ProxyService::PacRequest* request2; | 1501 ProxyService::PacRequest* request2; |
1480 rv = service.ResolveProxy( | 1502 rv = service.ResolveProxy(GURL("http://request2"), &info2, |
1481 GURL("http://request2"), &info2, &callback2, &request2, BoundNetLog()); | 1503 callback2.callback(), &request2, BoundNetLog()); |
1482 EXPECT_EQ(ERR_IO_PENDING, rv); | 1504 EXPECT_EQ(ERR_IO_PENDING, rv); |
1483 | 1505 |
1484 // Check that nothing has been sent to the proxy resolver yet. | 1506 // Check that nothing has been sent to the proxy resolver yet. |
1485 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1507 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1486 | 1508 |
1487 // It should be trying to auto-detect first -- succeed the download. | 1509 // It should be trying to auto-detect first -- succeed the download. |
1488 EXPECT_TRUE(fetcher->has_pending_request()); | 1510 EXPECT_TRUE(fetcher->has_pending_request()); |
1489 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1511 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1490 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 1512 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
1491 | 1513 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 new MockAsyncProxyResolverExpectsBytes; | 1557 new MockAsyncProxyResolverExpectsBytes; |
1536 ProxyService service(config_service, resolver, NULL); | 1558 ProxyService service(config_service, resolver, NULL); |
1537 | 1559 |
1538 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1560 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1539 service.SetProxyScriptFetchers(fetcher, | 1561 service.SetProxyScriptFetchers(fetcher, |
1540 new DoNothingDhcpProxyScriptFetcher()); | 1562 new DoNothingDhcpProxyScriptFetcher()); |
1541 | 1563 |
1542 // Start 2 requests. | 1564 // Start 2 requests. |
1543 | 1565 |
1544 ProxyInfo info1; | 1566 ProxyInfo info1; |
1545 TestOldCompletionCallback callback1; | 1567 TestCompletionCallback callback1; |
1546 int rv = service.ResolveProxy( | 1568 int rv = service.ResolveProxy(GURL("http://request1"), &info1, |
1547 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 1569 callback1.callback(), NULL, BoundNetLog()); |
1548 EXPECT_EQ(ERR_IO_PENDING, rv); | 1570 EXPECT_EQ(ERR_IO_PENDING, rv); |
1549 | 1571 |
1550 ProxyInfo info2; | 1572 ProxyInfo info2; |
1551 TestOldCompletionCallback callback2; | 1573 TestCompletionCallback callback2; |
1552 ProxyService::PacRequest* request2; | 1574 ProxyService::PacRequest* request2; |
1553 rv = service.ResolveProxy( | 1575 rv = service.ResolveProxy(GURL("http://request2"), &info2, |
1554 GURL("http://request2"), &info2, &callback2, &request2, BoundNetLog()); | 1576 callback2.callback(), &request2, BoundNetLog()); |
1555 EXPECT_EQ(ERR_IO_PENDING, rv); | 1577 EXPECT_EQ(ERR_IO_PENDING, rv); |
1556 | 1578 |
1557 // Check that nothing has been sent to the proxy resolver yet. | 1579 // Check that nothing has been sent to the proxy resolver yet. |
1558 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1580 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1559 | 1581 |
1560 // It should be trying to auto-detect first -- fail the download. | 1582 // It should be trying to auto-detect first -- fail the download. |
1561 EXPECT_TRUE(fetcher->has_pending_request()); | 1583 EXPECT_TRUE(fetcher->has_pending_request()); |
1562 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1584 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1563 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); | 1585 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); |
1564 | 1586 |
(...skipping 28 matching lines...) Expand all Loading... |
1593 new MockAsyncProxyResolverExpectsBytes; | 1615 new MockAsyncProxyResolverExpectsBytes; |
1594 ProxyService service(config_service, resolver, NULL); | 1616 ProxyService service(config_service, resolver, NULL); |
1595 | 1617 |
1596 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1618 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1597 service.SetProxyScriptFetchers(fetcher, | 1619 service.SetProxyScriptFetchers(fetcher, |
1598 new DoNothingDhcpProxyScriptFetcher()); | 1620 new DoNothingDhcpProxyScriptFetcher()); |
1599 | 1621 |
1600 // Start 1 requests. | 1622 // Start 1 requests. |
1601 | 1623 |
1602 ProxyInfo info1; | 1624 ProxyInfo info1; |
1603 TestOldCompletionCallback callback1; | 1625 TestCompletionCallback callback1; |
1604 int rv = service.ResolveProxy( | 1626 int rv = service.ResolveProxy( |
1605 GURL("http://www.google.com"), &info1, &callback1, NULL, BoundNetLog()); | 1627 GURL("http://www.google.com"), &info1, callback1.callback(), NULL, BoundNe
tLog()); |
1606 EXPECT_EQ(ERR_IO_PENDING, rv); | 1628 EXPECT_EQ(ERR_IO_PENDING, rv); |
1607 | 1629 |
1608 // Check that nothing has been sent to the proxy resolver yet. | 1630 // Check that nothing has been sent to the proxy resolver yet. |
1609 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1631 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1610 | 1632 |
1611 // It should be trying to auto-detect first -- succeed the download. | 1633 // It should be trying to auto-detect first -- succeed the download. |
1612 EXPECT_TRUE(fetcher->has_pending_request()); | 1634 EXPECT_TRUE(fetcher->has_pending_request()); |
1613 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1635 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1614 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 1636 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
1615 | 1637 |
1616 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 1638 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
1617 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1639 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
1618 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1640 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1619 | 1641 |
1620 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1642 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1621 EXPECT_EQ(GURL("http://www.google.com"), | 1643 EXPECT_EQ(GURL("http://www.google.com"), |
1622 resolver->pending_requests()[0]->url()); | 1644 resolver->pending_requests()[0]->url()); |
1623 | 1645 |
1624 // Complete the pending request. | 1646 // Complete the pending request. |
1625 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 1647 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
1626 resolver->pending_requests()[0]->CompleteNow(OK); | 1648 resolver->pending_requests()[0]->CompleteNow(OK); |
1627 | 1649 |
1628 // Verify that request ran as expected. | 1650 // Verify that request ran as expected. |
1629 EXPECT_EQ(OK, callback1.WaitForResult()); | 1651 EXPECT_EQ(OK, callback1.WaitForResult()); |
1630 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1652 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
1631 | 1653 |
1632 // Start another request, it should pickup the bypass item. | 1654 // Start another request, it should pickup the bypass item. |
1633 ProxyInfo info2; | 1655 ProxyInfo info2; |
1634 TestOldCompletionCallback callback2; | 1656 TestCompletionCallback callback2; |
1635 rv = service.ResolveProxy( | 1657 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, |
1636 GURL("http://www.google.com"), &info2, &callback2, NULL, BoundNetLog()); | 1658 callback2.callback(), NULL, BoundNetLog()); |
1637 EXPECT_EQ(ERR_IO_PENDING, rv); | 1659 EXPECT_EQ(ERR_IO_PENDING, rv); |
1638 | 1660 |
1639 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1661 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1640 EXPECT_EQ(GURL("http://www.google.com"), | 1662 EXPECT_EQ(GURL("http://www.google.com"), |
1641 resolver->pending_requests()[0]->url()); | 1663 resolver->pending_requests()[0]->url()); |
1642 | 1664 |
1643 // Complete the pending request. | 1665 // Complete the pending request. |
1644 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 1666 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
1645 resolver->pending_requests()[0]->CompleteNow(OK); | 1667 resolver->pending_requests()[0]->CompleteNow(OK); |
1646 | 1668 |
(...skipping 14 matching lines...) Expand all Loading... |
1661 new MockAsyncProxyResolverExpectsBytes; | 1683 new MockAsyncProxyResolverExpectsBytes; |
1662 ProxyService service(config_service, resolver, NULL); | 1684 ProxyService service(config_service, resolver, NULL); |
1663 | 1685 |
1664 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1686 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1665 service.SetProxyScriptFetchers(fetcher, | 1687 service.SetProxyScriptFetchers(fetcher, |
1666 new DoNothingDhcpProxyScriptFetcher()); | 1688 new DoNothingDhcpProxyScriptFetcher()); |
1667 | 1689 |
1668 // Start 1 request. | 1690 // Start 1 request. |
1669 | 1691 |
1670 ProxyInfo info1; | 1692 ProxyInfo info1; |
1671 TestOldCompletionCallback callback1; | 1693 TestCompletionCallback callback1; |
1672 int rv = service.ResolveProxy( | 1694 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, |
1673 GURL("http://www.google.com"), &info1, &callback1, NULL, BoundNetLog()); | 1695 callback1.callback(), NULL, BoundNetLog()); |
1674 EXPECT_EQ(ERR_IO_PENDING, rv); | 1696 EXPECT_EQ(ERR_IO_PENDING, rv); |
1675 | 1697 |
1676 // Check that nothing has been sent to the proxy resolver yet. | 1698 // Check that nothing has been sent to the proxy resolver yet. |
1677 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1699 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1678 | 1700 |
1679 // InitProxyResolver should have issued a request to the ProxyScriptFetcher | 1701 // InitProxyResolver should have issued a request to the ProxyScriptFetcher |
1680 // and be waiting on that to complete. | 1702 // and be waiting on that to complete. |
1681 EXPECT_TRUE(fetcher->has_pending_request()); | 1703 EXPECT_TRUE(fetcher->has_pending_request()); |
1682 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1704 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1683 } | 1705 } |
1684 | 1706 |
1685 // Delete the ProxyService while InitProxyResolver has an outstanding | 1707 // Delete the ProxyService while InitProxyResolver has an outstanding |
1686 // request to the proxy resolver. When run under valgrind, should not | 1708 // request to the proxy resolver. When run under valgrind, should not |
1687 // have any memory errors (used to be that the ProxyResolver was | 1709 // have any memory errors (used to be that the ProxyResolver was |
1688 // being deleted prior to the InitProxyResolver). | 1710 // being deleted prior to the InitProxyResolver). |
1689 TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { | 1711 TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { |
1690 MockProxyConfigService* config_service = | 1712 MockProxyConfigService* config_service = |
1691 new MockProxyConfigService("http://foopy/proxy.pac"); | 1713 new MockProxyConfigService("http://foopy/proxy.pac"); |
1692 | 1714 |
1693 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1715 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1694 | 1716 |
1695 ProxyService service(config_service, resolver, NULL); | 1717 ProxyService service(config_service, resolver, NULL); |
1696 | 1718 |
1697 GURL url("http://www.google.com/"); | 1719 GURL url("http://www.google.com/"); |
1698 | 1720 |
1699 ProxyInfo info; | 1721 ProxyInfo info; |
1700 TestOldCompletionCallback callback; | 1722 TestCompletionCallback callback; |
1701 int rv = service.ResolveProxy(url, &info, &callback, NULL, BoundNetLog()); | 1723 int rv = service.ResolveProxy( |
| 1724 url, &info, callback.callback(), NULL, BoundNetLog()); |
1702 EXPECT_EQ(ERR_IO_PENDING, rv); | 1725 EXPECT_EQ(ERR_IO_PENDING, rv); |
1703 | 1726 |
1704 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1727 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1705 resolver->pending_set_pac_script_request()->script_data()->url()); | 1728 resolver->pending_set_pac_script_request()->script_data()->url()); |
1706 } | 1729 } |
1707 | 1730 |
1708 TEST(ProxyServiceTest, ResetProxyConfigService) { | 1731 TEST(ProxyServiceTest, ResetProxyConfigService) { |
1709 ProxyConfig config1; | 1732 ProxyConfig config1; |
1710 config1.proxy_rules().ParseFromString("foopy1:8080"); | 1733 config1.proxy_rules().ParseFromString("foopy1:8080"); |
1711 config1.set_auto_detect(false); | 1734 config1.set_auto_detect(false); |
1712 ProxyService service( | 1735 ProxyService service( |
1713 new MockProxyConfigService(config1), | 1736 new MockProxyConfigService(config1), |
1714 new MockAsyncProxyResolverExpectsBytes, NULL); | 1737 new MockAsyncProxyResolverExpectsBytes, NULL); |
1715 | 1738 |
1716 ProxyInfo info; | 1739 ProxyInfo info; |
1717 TestOldCompletionCallback callback1; | 1740 TestCompletionCallback callback1; |
1718 int rv = service.ResolveProxy( | 1741 int rv = service.ResolveProxy(GURL("http://request1"), &info, |
1719 GURL("http://request1"), &info, &callback1, NULL, BoundNetLog()); | 1742 callback1.callback(), NULL, BoundNetLog()); |
1720 EXPECT_EQ(OK, rv); | 1743 EXPECT_EQ(OK, rv); |
1721 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1744 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1722 | 1745 |
1723 ProxyConfig config2; | 1746 ProxyConfig config2; |
1724 config2.proxy_rules().ParseFromString("foopy2:8080"); | 1747 config2.proxy_rules().ParseFromString("foopy2:8080"); |
1725 config2.set_auto_detect(false); | 1748 config2.set_auto_detect(false); |
1726 service.ResetConfigService(new MockProxyConfigService(config2)); | 1749 service.ResetConfigService(new MockProxyConfigService(config2)); |
1727 TestOldCompletionCallback callback2; | 1750 TestCompletionCallback callback2; |
1728 rv = service.ResolveProxy( | 1751 rv = service.ResolveProxy(GURL("http://request2"), &info, |
1729 GURL("http://request2"), &info, &callback2, NULL, BoundNetLog()); | 1752 callback2.callback(), NULL, BoundNetLog()); |
1730 EXPECT_EQ(OK, rv); | 1753 EXPECT_EQ(OK, rv); |
1731 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1754 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
1732 } | 1755 } |
1733 | 1756 |
1734 // Test that when going from a configuration that required PAC to one | 1757 // Test that when going from a configuration that required PAC to one |
1735 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 1758 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
1736 TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 1759 TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
1737 ProxyConfig config = ProxyConfig::CreateAutoDetect(); | 1760 ProxyConfig config = ProxyConfig::CreateAutoDetect(); |
1738 | 1761 |
1739 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1762 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
1740 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1763 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1741 ProxyService service(config_service, resolver, NULL); | 1764 ProxyService service(config_service, resolver, NULL); |
1742 | 1765 |
1743 // Start 1 request. | 1766 // Start 1 request. |
1744 | 1767 |
1745 ProxyInfo info1; | 1768 ProxyInfo info1; |
1746 TestOldCompletionCallback callback1; | 1769 TestCompletionCallback callback1; |
1747 int rv = service.ResolveProxy( | 1770 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, |
1748 GURL("http://www.google.com"), &info1, &callback1, NULL, BoundNetLog()); | 1771 callback1.callback(), NULL, BoundNetLog()); |
1749 EXPECT_EQ(ERR_IO_PENDING, rv); | 1772 EXPECT_EQ(ERR_IO_PENDING, rv); |
1750 | 1773 |
1751 // Check that nothing has been sent to the proxy resolver yet. | 1774 // Check that nothing has been sent to the proxy resolver yet. |
1752 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1775 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1753 | 1776 |
1754 // Successfully set the autodetect script. | 1777 // Successfully set the autodetect script. |
1755 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 1778 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
1756 resolver->pending_set_pac_script_request()->script_data()->type()); | 1779 resolver->pending_set_pac_script_request()->script_data()->type()); |
1757 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1780 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1758 | 1781 |
1759 // Complete the pending request. | 1782 // Complete the pending request. |
1760 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1783 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1761 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 1784 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
1762 resolver->pending_requests()[0]->CompleteNow(OK); | 1785 resolver->pending_requests()[0]->CompleteNow(OK); |
1763 | 1786 |
1764 // Verify that request ran as expected. | 1787 // Verify that request ran as expected. |
1765 EXPECT_EQ(OK, callback1.WaitForResult()); | 1788 EXPECT_EQ(OK, callback1.WaitForResult()); |
1766 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1789 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
1767 | 1790 |
1768 // Force the ProxyService to pull down a new proxy configuration. | 1791 // Force the ProxyService to pull down a new proxy configuration. |
1769 // (Even though the configuration isn't old/bad). | 1792 // (Even though the configuration isn't old/bad). |
1770 // | 1793 // |
1771 // This new configuration no longer has auto_detect set, so | 1794 // This new configuration no longer has auto_detect set, so |
1772 // requests should complete synchronously now as direct-connect. | 1795 // requests should complete synchronously now as direct-connect. |
1773 config_service->SetConfig(ProxyConfig::CreateDirect()); | 1796 config_service->SetConfig(ProxyConfig::CreateDirect()); |
1774 | 1797 |
1775 // Start another request -- the effective configuration has changed. | 1798 // Start another request -- the effective configuration has changed. |
1776 ProxyInfo info2; | 1799 ProxyInfo info2; |
1777 TestOldCompletionCallback callback2; | 1800 TestCompletionCallback callback2; |
1778 rv = service.ResolveProxy( | 1801 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, |
1779 GURL("http://www.google.com"), &info2, &callback2, NULL, BoundNetLog()); | 1802 callback2.callback(), NULL, BoundNetLog()); |
1780 EXPECT_EQ(OK, rv); | 1803 EXPECT_EQ(OK, rv); |
1781 | 1804 |
1782 EXPECT_TRUE(info2.is_direct()); | 1805 EXPECT_TRUE(info2.is_direct()); |
1783 } | 1806 } |
1784 | 1807 |
1785 TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { | 1808 TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { |
1786 MockProxyConfigService* config_service = | 1809 MockProxyConfigService* config_service = |
1787 new MockProxyConfigService("http://foopy/proxy.pac"); | 1810 new MockProxyConfigService("http://foopy/proxy.pac"); |
1788 | 1811 |
1789 MockAsyncProxyResolverExpectsBytes* resolver = | 1812 MockAsyncProxyResolverExpectsBytes* resolver = |
1790 new MockAsyncProxyResolverExpectsBytes; | 1813 new MockAsyncProxyResolverExpectsBytes; |
1791 | 1814 |
1792 CapturingNetLog log(CapturingNetLog::kUnbounded); | 1815 CapturingNetLog log(CapturingNetLog::kUnbounded); |
1793 | 1816 |
1794 ProxyService service(config_service, resolver, &log); | 1817 ProxyService service(config_service, resolver, &log); |
1795 | 1818 |
1796 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1819 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1797 service.SetProxyScriptFetchers(fetcher, | 1820 service.SetProxyScriptFetchers(fetcher, |
1798 new DoNothingDhcpProxyScriptFetcher()); | 1821 new DoNothingDhcpProxyScriptFetcher()); |
1799 | 1822 |
1800 // Disable the "wait after IP address changes" hack, so this unit-test can | 1823 // Disable the "wait after IP address changes" hack, so this unit-test can |
1801 // complete quickly. | 1824 // complete quickly. |
1802 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); | 1825 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); |
1803 | 1826 |
1804 // Start 1 request. | 1827 // Start 1 request. |
1805 | 1828 |
1806 ProxyInfo info1; | 1829 ProxyInfo info1; |
1807 TestOldCompletionCallback callback1; | 1830 TestCompletionCallback callback1; |
1808 int rv = service.ResolveProxy( | 1831 int rv = service.ResolveProxy(GURL("http://request1"), &info1, |
1809 GURL("http://request1"), &info1, &callback1, NULL, BoundNetLog()); | 1832 callback1.callback(), NULL, BoundNetLog()); |
1810 EXPECT_EQ(ERR_IO_PENDING, rv); | 1833 EXPECT_EQ(ERR_IO_PENDING, rv); |
1811 | 1834 |
1812 // The first request should have triggered initial download of PAC script. | 1835 // The first request should have triggered initial download of PAC script. |
1813 EXPECT_TRUE(fetcher->has_pending_request()); | 1836 EXPECT_TRUE(fetcher->has_pending_request()); |
1814 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1837 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1815 | 1838 |
1816 // Nothing has been sent to the resolver yet. | 1839 // Nothing has been sent to the resolver yet. |
1817 EXPECT_TRUE(resolver->pending_requests().empty()); | 1840 EXPECT_TRUE(resolver->pending_requests().empty()); |
1818 | 1841 |
1819 // At this point the ProxyService should be waiting for the | 1842 // At this point the ProxyService should be waiting for the |
(...skipping 19 matching lines...) Expand all Loading... |
1839 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1862 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
1840 | 1863 |
1841 // Now simluate a change in the network. The ProxyConfigService is still | 1864 // Now simluate a change in the network. The ProxyConfigService is still |
1842 // going to return the same PAC URL as before, but this URL needs to be | 1865 // going to return the same PAC URL as before, but this URL needs to be |
1843 // refetched on the new network. | 1866 // refetched on the new network. |
1844 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1867 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
1845 MessageLoop::current()->RunAllPending(); // Notification happens async. | 1868 MessageLoop::current()->RunAllPending(); // Notification happens async. |
1846 | 1869 |
1847 // Start a second request. | 1870 // Start a second request. |
1848 ProxyInfo info2; | 1871 ProxyInfo info2; |
1849 TestOldCompletionCallback callback2; | 1872 TestCompletionCallback callback2; |
1850 rv = service.ResolveProxy( | 1873 rv = service.ResolveProxy(GURL("http://request2"), &info2, |
1851 GURL("http://request2"), &info2, &callback2, NULL, BoundNetLog()); | 1874 callback2.callback(), NULL, BoundNetLog()); |
1852 EXPECT_EQ(ERR_IO_PENDING, rv); | 1875 EXPECT_EQ(ERR_IO_PENDING, rv); |
1853 | 1876 |
1854 // This second request should have triggered the re-download of the PAC | 1877 // This second request should have triggered the re-download of the PAC |
1855 // script (since we marked the network as having changed). | 1878 // script (since we marked the network as having changed). |
1856 EXPECT_TRUE(fetcher->has_pending_request()); | 1879 EXPECT_TRUE(fetcher->has_pending_request()); |
1857 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1880 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1858 | 1881 |
1859 // Nothing has been sent to the resolver yet. | 1882 // Nothing has been sent to the resolver yet. |
1860 EXPECT_TRUE(resolver->pending_requests().empty()); | 1883 EXPECT_TRUE(resolver->pending_requests().empty()); |
1861 | 1884 |
(...skipping 11 matching lines...) Expand all Loading... |
1873 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 1896 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
1874 | 1897 |
1875 // Complete the pending second request. | 1898 // Complete the pending second request. |
1876 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 1899 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
1877 resolver->pending_requests()[0]->CompleteNow(OK); | 1900 resolver->pending_requests()[0]->CompleteNow(OK); |
1878 | 1901 |
1879 // Wait for completion callback, and verify that the request ran as expected. | 1902 // Wait for completion callback, and verify that the request ran as expected. |
1880 EXPECT_EQ(OK, callback2.WaitForResult()); | 1903 EXPECT_EQ(OK, callback2.WaitForResult()); |
1881 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1904 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
1882 | 1905 |
1883 // Check that the expected events were outputted to the log stream. | 1906 // Check that the expected events were output to the log stream. In particular |
1884 // In particular, PROXY_CONFIG_CHANGED should have only been emitted once | 1907 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial |
1885 // (for the initial setup), and NOT a second time when the IP address | 1908 // setup), and NOT a second time when the IP address changed. |
1886 // changed. | |
1887 CapturingNetLog::EntryList entries; | 1909 CapturingNetLog::EntryList entries; |
1888 log.GetEntries(&entries); | 1910 log.GetEntries(&entries); |
1889 | 1911 |
1890 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, | 1912 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, |
1891 NetLog::TYPE_PROXY_CONFIG_CHANGED)); | 1913 NetLog::TYPE_PROXY_CONFIG_CHANGED)); |
1892 ASSERT_EQ(9u, entries.size()); | 1914 ASSERT_EQ(9u, entries.size()); |
1893 for (size_t i = 1; i < entries.size(); ++i) | 1915 for (size_t i = 1; i < entries.size(); ++i) |
1894 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); | 1916 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); |
1895 } | 1917 } |
1896 | 1918 |
1897 } // namespace net | 1919 } // namespace net |
OLD | NEW |