| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/proxy/proxy_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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 178 |
| 179 ASSERT_EQ(1u, resolver->pending_requests().size()); | 179 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 180 // The URL should have been simplified, stripping the username/password/hash. | 180 // The URL should have been simplified, stripping the username/password/hash. |
| 181 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 181 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
| 182 resolver->pending_requests()[0]->url()); | 182 resolver->pending_requests()[0]->url()); |
| 183 | 183 |
| 184 // We end here without ever completing the request -- destruction of | 184 // We end here without ever completing the request -- destruction of |
| 185 // ProxyService will cancel the outstanding request. | 185 // ProxyService will cancel the outstanding request. |
| 186 } | 186 } |
| 187 | 187 |
| 188 TEST(ProxyServiceTest, PAC_FailoverToDirect) { | 188 TEST(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
| 189 MockProxyConfigService* config_service = | 189 MockProxyConfigService* config_service = |
| 190 new MockProxyConfigService("http://foopy/proxy.pac"); | 190 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 191 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 191 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 192 | 192 |
| 193 scoped_refptr<ProxyService> service( | 193 scoped_refptr<ProxyService> service( |
| 194 new ProxyService(config_service, resolver)); | 194 new ProxyService(config_service, resolver)); |
| 195 | 195 |
| 196 GURL url("http://www.google.com/"); | 196 GURL url("http://www.google.com/"); |
| 197 | 197 |
| 198 ProxyInfo info; | 198 ProxyInfo info; |
| 199 TestCompletionCallback callback1; | 199 TestCompletionCallback callback1; |
| 200 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); | 200 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); |
| 201 EXPECT_EQ(ERR_IO_PENDING, rv); | 201 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 202 | 202 |
| 203 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 203 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 204 resolver->pending_set_pac_script_request()->pac_url()); | 204 resolver->pending_set_pac_script_request()->pac_url()); |
| 205 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 205 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 206 | 206 |
| 207 ASSERT_EQ(1u, resolver->pending_requests().size()); | 207 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 208 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 208 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 209 | 209 |
| 210 // Set the result in proxy resolver. | 210 // Set the result in proxy resolver. |
| 211 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); | 211 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); |
| 212 resolver->pending_requests()[0]->CompleteNow(OK); | 212 resolver->pending_requests()[0]->CompleteNow(OK); |
| 213 | 213 |
| 214 EXPECT_EQ(OK, callback1.WaitForResult()); | 214 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 215 EXPECT_FALSE(info.is_direct()); | 215 EXPECT_FALSE(info.is_direct()); |
| 216 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); | 216 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); |
| 217 | 217 |
| 218 // Now, imagine that connecting to foopy:8080 fails. | 218 // Now, imagine that connecting to foopy:8080 fails: there is nothing |
| 219 // left to fallback to, since our proxy list was NOT terminated by |
| 220 // DIRECT. |
| 221 TestCompletionCallback callback2; |
| 222 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); |
| 223 // ReconsiderProxyAfterError returns error indicating nothing left. |
| 224 EXPECT_EQ(ERR_FAILED, rv); |
| 225 EXPECT_TRUE(info.is_empty()); |
| 226 } |
| 227 |
| 228 // The proxy list could potentially contain the DIRECT fallback choice |
| 229 // in a location other than the very end of the list, and could even |
| 230 // specify it multiple times. |
| 231 // |
| 232 // This is not a typical usage, but we will obey it. |
| 233 // (If we wanted to disallow this type of input, the right place to |
| 234 // enforce it would be in parsing the PAC result string). |
| 235 // |
| 236 // This test will use the PAC result string: |
| 237 // |
| 238 // "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20" |
| 239 // |
| 240 // For which we expect it to try DIRECT, then foobar:10, then DIRECT again, |
| 241 // then foobar:20, and then give up and error. |
| 242 // |
| 243 // The important check of this test is to make sure that DIRECT is not somehow |
| 244 // cached as being a bad proxy. |
| 245 TEST(ProxyServiceTest, PAC_FailoverAfterDirect) { |
| 246 MockProxyConfigService* config_service = |
| 247 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 248 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 249 |
| 250 scoped_refptr<ProxyService> service( |
| 251 new ProxyService(config_service, resolver)); |
| 252 |
| 253 GURL url("http://www.google.com/"); |
| 254 |
| 255 ProxyInfo info; |
| 256 TestCompletionCallback callback1; |
| 257 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); |
| 258 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 259 |
| 260 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 261 resolver->pending_set_pac_script_request()->pac_url()); |
| 262 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 263 |
| 264 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 265 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 266 |
| 267 // Set the result in proxy resolver. |
| 268 resolver->pending_requests()[0]->results()->UsePacString( |
| 269 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); |
| 270 resolver->pending_requests()[0]->CompleteNow(OK); |
| 271 |
| 272 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 273 EXPECT_TRUE(info.is_direct()); |
| 274 |
| 275 // Fallback 1. |
| 219 TestCompletionCallback callback2; | 276 TestCompletionCallback callback2; |
| 220 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); | 277 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); |
| 221 EXPECT_EQ(OK, rv); | 278 EXPECT_EQ(OK, rv); |
| 279 EXPECT_FALSE(info.is_direct()); |
| 280 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); |
| 281 |
| 282 // Fallback 2. |
| 283 TestCompletionCallback callback3; |
| 284 rv = service->ReconsiderProxyAfterError(url, &info, &callback3, NULL, NULL); |
| 285 EXPECT_EQ(OK, rv); |
| 222 EXPECT_TRUE(info.is_direct()); | 286 EXPECT_TRUE(info.is_direct()); |
| 287 |
| 288 // Fallback 3. |
| 289 TestCompletionCallback callback4; |
| 290 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL); |
| 291 EXPECT_EQ(OK, rv); |
| 292 EXPECT_FALSE(info.is_direct()); |
| 293 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); |
| 294 |
| 295 // Fallback 4 -- Nothing to fall back to! |
| 296 TestCompletionCallback callback5; |
| 297 rv = service->ReconsiderProxyAfterError(url, &info, &callback5, NULL, NULL); |
| 298 EXPECT_EQ(ERR_FAILED, rv); |
| 299 EXPECT_TRUE(info.is_empty()); |
| 223 } | 300 } |
| 224 | 301 |
| 225 TEST(ProxyServiceTest, ProxyResolverFails) { | 302 TEST(ProxyServiceTest, ProxyResolverFails) { |
| 226 // Test what happens when the ProxyResolver fails (this could represent | 303 // Test what happens when the ProxyResolver fails. The download and setting |
| 227 // a failure to download the PAC script in the case of ProxyResolvers which | 304 // of the PAC script have already succeeded, so this corresponds with a |
| 228 // do the fetch internally.) | 305 // javascript runtime error while calling FindProxyForURL(). |
| 229 // TODO(eroman): change this comment. | |
| 230 | 306 |
| 231 MockProxyConfigService* config_service = | 307 MockProxyConfigService* config_service = |
| 232 new MockProxyConfigService("http://foopy/proxy.pac"); | 308 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 233 | 309 |
| 234 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 310 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 235 | 311 |
| 236 scoped_refptr<ProxyService> service( | 312 scoped_refptr<ProxyService> service( |
| 237 new ProxyService(config_service, resolver)); | 313 new ProxyService(config_service, resolver)); |
| 238 | 314 |
| 239 // Start first resolve request. | 315 // Start first resolve request. |
| 240 GURL url("http://www.google.com/"); | 316 GURL url("http://www.google.com/"); |
| 241 ProxyInfo info; | 317 ProxyInfo info; |
| 242 TestCompletionCallback callback1; | 318 TestCompletionCallback callback1; |
| 243 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); | 319 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); |
| 244 EXPECT_EQ(ERR_IO_PENDING, rv); | 320 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 245 | 321 |
| 246 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 322 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 247 resolver->pending_set_pac_script_request()->pac_url()); | 323 resolver->pending_set_pac_script_request()->pac_url()); |
| 248 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 324 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 249 | 325 |
| 250 ASSERT_EQ(1u, resolver->pending_requests().size()); | 326 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 251 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 327 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 252 | 328 |
| 253 // Fail the first resolve request in MockAsyncProxyResolver. | 329 // Fail the first resolve request in MockAsyncProxyResolver. |
| 254 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 330 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
| 255 | 331 |
| 256 EXPECT_EQ(ERR_FAILED, callback1.WaitForResult()); | 332 EXPECT_EQ(ERR_FAILED, callback1.WaitForResult()); |
| 257 | 333 |
| 258 // The second resolve request will automatically select direct connect, | 334 // The second resolve request will try to run through the proxy resolver, |
| 259 // because it has cached the configuration as being bad. | 335 // regardless of whether the first request failed in it. |
| 260 TestCompletionCallback callback2; | 336 TestCompletionCallback callback2; |
| 261 rv = service->ResolveProxy(url, &info, &callback2, NULL, NULL); | 337 rv = service->ResolveProxy(url, &info, &callback2, NULL, NULL); |
| 262 EXPECT_EQ(OK, rv); | |
| 263 EXPECT_TRUE(info.is_direct()); | |
| 264 EXPECT_TRUE(resolver->pending_requests().empty()); | |
| 265 | |
| 266 // But, if that fails, then we should give the proxy config another shot | |
| 267 // since we have never tried it with this URL before. | |
| 268 TestCompletionCallback callback3; | |
| 269 rv = service->ReconsiderProxyAfterError(url, &info, &callback3, NULL, NULL); | |
| 270 EXPECT_EQ(ERR_IO_PENDING, rv); | 338 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 271 | 339 |
| 272 ASSERT_EQ(1u, resolver->pending_requests().size()); | 340 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 273 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 341 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 274 | 342 |
| 275 // Set the result in proxy resolver. | 343 // This time we will have the resolver succeed (perhaps the PAC script has |
| 344 // a dependency on the current time). |
| 276 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 345 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
| 277 resolver->pending_requests()[0]->CompleteNow(OK); | 346 resolver->pending_requests()[0]->CompleteNow(OK); |
| 278 | 347 |
| 279 EXPECT_EQ(OK, callback3.WaitForResult()); | 348 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 280 EXPECT_FALSE(info.is_direct()); | 349 EXPECT_FALSE(info.is_direct()); |
| 281 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 350 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
| 282 } | 351 } |
| 283 | 352 |
| 284 TEST(ProxyServiceTest, ProxyFallback) { | 353 TEST(ProxyServiceTest, ProxyFallback) { |
| 285 // Test what happens when we specify multiple proxy servers and some of them | 354 // Test what happens when we specify multiple proxy servers and some of them |
| 286 // are bad. | 355 // are bad. |
| 287 | 356 |
| 288 MockProxyConfigService* config_service = | 357 MockProxyConfigService* config_service = |
| 289 new MockProxyConfigService("http://foopy/proxy.pac"); | 358 new MockProxyConfigService("http://foopy/proxy.pac"); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 EXPECT_EQ(OK, callback3.WaitForResult()); | 411 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 343 EXPECT_FALSE(info.is_direct()); | 412 EXPECT_FALSE(info.is_direct()); |
| 344 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 413 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
| 345 | 414 |
| 346 // We fake another error. It should now try the third one. | 415 // We fake another error. It should now try the third one. |
| 347 TestCompletionCallback callback4; | 416 TestCompletionCallback callback4; |
| 348 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL); | 417 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL); |
| 349 EXPECT_EQ(OK, rv); | 418 EXPECT_EQ(OK, rv); |
| 350 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 419 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 351 | 420 |
| 352 // Fake another error, the last proxy is gone, the list should now be empty. | 421 // Fake another error, the last proxy is gone, the list should now be empty, |
| 422 // so there is nothing left to try. |
| 353 TestCompletionCallback callback5; | 423 TestCompletionCallback callback5; |
| 354 rv = service->ReconsiderProxyAfterError(url, &info, &callback5, NULL, NULL); | 424 rv = service->ReconsiderProxyAfterError(url, &info, &callback5, NULL, NULL); |
| 355 EXPECT_EQ(OK, rv); // We try direct. | 425 EXPECT_EQ(ERR_FAILED, rv); |
| 426 EXPECT_FALSE(info.is_direct()); |
| 427 EXPECT_TRUE(info.is_empty()); |
| 428 |
| 429 // TODO(nsylvain): Test that the proxy can be retried after the delay. |
| 430 } |
| 431 |
| 432 // This test is similar to ProxyFallback, but this time we have an explicit |
| 433 // fallback choice to DIRECT. |
| 434 TEST(ProxyServiceTest, ProxyFallbackToDirect) { |
| 435 MockProxyConfigService* config_service = |
| 436 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 437 |
| 438 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 439 |
| 440 scoped_refptr<ProxyService> service( |
| 441 new ProxyService(config_service, resolver)); |
| 442 |
| 443 GURL url("http://www.google.com/"); |
| 444 |
| 445 // Get the proxy information. |
| 446 ProxyInfo info; |
| 447 TestCompletionCallback callback1; |
| 448 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); |
| 449 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 450 |
| 451 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 452 resolver->pending_set_pac_script_request()->pac_url()); |
| 453 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 454 |
| 455 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 456 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 457 |
| 458 // Set the result in proxy resolver. |
| 459 resolver->pending_requests()[0]->results()->UsePacString( |
| 460 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); |
| 461 resolver->pending_requests()[0]->CompleteNow(OK); |
| 462 |
| 463 // Get the first result. |
| 464 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 465 EXPECT_FALSE(info.is_direct()); |
| 466 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 467 |
| 468 // Fake an error on the proxy. |
| 469 TestCompletionCallback callback2; |
| 470 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); |
| 471 EXPECT_EQ(OK, rv); |
| 472 |
| 473 // Now we get back the second proxy. |
| 474 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 475 |
| 476 // Fake an error on this proxy as well. |
| 477 TestCompletionCallback callback3; |
| 478 rv = service->ReconsiderProxyAfterError(url, &info, &callback3, NULL, NULL); |
| 479 EXPECT_EQ(OK, rv); |
| 480 |
| 481 // Finally, we get back DIRECT. |
| 356 EXPECT_TRUE(info.is_direct()); | 482 EXPECT_TRUE(info.is_direct()); |
| 357 | 483 |
| 358 // If it fails again, we don't have anything else to try. | 484 // Now we tell the proxy service that even DIRECT failed. |
| 359 TestCompletionCallback callback6; | 485 TestCompletionCallback callback4; |
| 360 rv = service->ReconsiderProxyAfterError(url, &info, &callback6, NULL, NULL); | 486 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL); |
| 487 // There was nothing left to try after DIRECT, so we are out of |
| 488 // choices. |
| 361 EXPECT_EQ(ERR_FAILED, rv); | 489 EXPECT_EQ(ERR_FAILED, rv); |
| 362 | |
| 363 // TODO(nsylvain): Test that the proxy can be retried after the delay. | |
| 364 } | 490 } |
| 365 | 491 |
| 366 TEST(ProxyServiceTest, ProxyFallback_NewSettings) { | 492 TEST(ProxyServiceTest, ProxyFallback_NewSettings) { |
| 367 // Test proxy failover when new settings are available. | 493 // Test proxy failover when new settings are available. |
| 368 | 494 |
| 369 MockProxyConfigService* config_service = | 495 MockProxyConfigService* config_service = |
| 370 new MockProxyConfigService("http://foopy/proxy.pac"); | 496 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 371 | 497 |
| 372 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 498 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 373 | 499 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 623 |
| 498 // Fake a PAC failure. | 624 // Fake a PAC failure. |
| 499 ProxyInfo info2; | 625 ProxyInfo info2; |
| 500 TestCompletionCallback callback3; | 626 TestCompletionCallback callback3; |
| 501 rv = service->ResolveProxy(url, &info2, &callback3, NULL, NULL); | 627 rv = service->ResolveProxy(url, &info2, &callback3, NULL, NULL); |
| 502 EXPECT_EQ(ERR_IO_PENDING, rv); | 628 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 503 | 629 |
| 504 ASSERT_EQ(1u, resolver->pending_requests().size()); | 630 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 505 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 631 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 506 | 632 |
| 633 // This simulates a javascript runtime error in the PAC script. |
| 507 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 634 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
| 508 | 635 |
| 509 // No proxy servers are returned. It's a direct connection. | 636 // No proxy servers are returned, since we failed. |
| 510 EXPECT_EQ(ERR_FAILED, callback3.WaitForResult()); | 637 EXPECT_EQ(ERR_FAILED, callback3.WaitForResult()); |
| 511 EXPECT_TRUE(info2.is_direct()); | 638 EXPECT_FALSE(info2.is_direct()); |
| 639 EXPECT_TRUE(info2.is_empty()); |
| 512 | 640 |
| 513 // The PAC will now be fixed and will return a proxy server. | 641 // The PAC script will work properly next time and successfully return a |
| 514 // It should also clear the list of bad proxies. | 642 // proxy list. Since we have not marked the configuration as bad, it should |
| 515 | 643 // "just work" the next time we call it. |
| 516 // Try to resolve, it will still return "direct" because we have no reason | |
| 517 // to check the config since everything works. | |
| 518 ProxyInfo info3; | 644 ProxyInfo info3; |
| 519 TestCompletionCallback callback4; | 645 TestCompletionCallback callback4; |
| 520 rv = service->ResolveProxy(url, &info3, &callback4, NULL, NULL); | 646 rv = service->ReconsiderProxyAfterError(url, &info3, &callback4, NULL, NULL); |
| 521 EXPECT_EQ(OK, rv); | |
| 522 EXPECT_TRUE(info3.is_direct()); | |
| 523 | |
| 524 // But if the direct connection fails, we check if the ProxyInfo tried to | |
| 525 // resolve the proxy before, and if not (like in this case), we give the | |
| 526 // PAC another try. | |
| 527 TestCompletionCallback callback5; | |
| 528 rv = service->ReconsiderProxyAfterError(url, &info3, &callback5, NULL, NULL); | |
| 529 EXPECT_EQ(ERR_IO_PENDING, rv); | 647 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 530 | 648 |
| 531 ASSERT_EQ(1u, resolver->pending_requests().size()); | 649 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 532 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 650 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 533 | 651 |
| 534 resolver->pending_requests()[0]->results()->UseNamedProxy( | 652 resolver->pending_requests()[0]->results()->UseNamedProxy( |
| 535 "foopy1:8080;foopy2:9090"); | 653 "foopy1:8080;foopy2:9090"); |
| 536 resolver->pending_requests()[0]->CompleteNow(OK); | 654 resolver->pending_requests()[0]->CompleteNow(OK); |
| 537 | 655 |
| 538 // The first proxy is still there since the list of bad proxies got cleared. | 656 // The first proxy is not there since the it was added to the bad proxies |
| 539 EXPECT_EQ(OK, callback5.WaitForResult()); | 657 // list by the earlier ReconsiderProxyAfterError(). |
| 658 EXPECT_EQ(OK, callback4.WaitForResult()); |
| 540 EXPECT_FALSE(info3.is_direct()); | 659 EXPECT_FALSE(info3.is_direct()); |
| 541 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 660 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
| 542 } | 661 } |
| 543 | 662 |
| 544 TEST(ProxyServiceTest, ProxyBypassList) { | 663 TEST(ProxyServiceTest, ProxyBypassList) { |
| 545 // Test what happens when a proxy bypass list is specified. | 664 // Test what happens when a proxy bypass list is specified. |
| 546 | 665 |
| 547 ProxyInfo info; | 666 ProxyInfo info; |
| 548 ProxyConfig config; | 667 ProxyConfig config; |
| 549 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); | 668 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 ProxyInfo info2; | 1698 ProxyInfo info2; |
| 1580 TestCompletionCallback callback2; | 1699 TestCompletionCallback callback2; |
| 1581 rv = service->ResolveProxy( | 1700 rv = service->ResolveProxy( |
| 1582 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL); | 1701 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL); |
| 1583 EXPECT_EQ(OK, rv); | 1702 EXPECT_EQ(OK, rv); |
| 1584 | 1703 |
| 1585 EXPECT_TRUE(info2.is_direct()); | 1704 EXPECT_TRUE(info2.is_direct()); |
| 1586 } | 1705 } |
| 1587 | 1706 |
| 1588 } // namespace net | 1707 } // namespace net |
| OLD | NEW |