Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 #include "net/proxy/proxy_config_service.h" | 21 #include "net/proxy/proxy_config_service.h" |
| 22 #include "net/proxy/proxy_resolver.h" | 22 #include "net/proxy/proxy_resolver.h" |
| 23 #include "net/proxy/proxy_script_fetcher.h" | 23 #include "net/proxy/proxy_script_fetcher.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 // TODO(eroman): Write a test which exercises | 26 // TODO(eroman): Write a test which exercises |
| 27 // ProxyService::SuspendAllPendingRequests(). | 27 // ProxyService::SuspendAllPendingRequests(). |
| 28 namespace net { | 28 namespace net { |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // This test fixture is used to partially disable the background polling done by | |
| 32 // the ProxyService (which it uses to detect whenever its PAC script contents or | |
| 33 // WPAD results have changed). | |
| 34 // | |
| 35 // We disable the feature by setting the poll interval to something really | |
| 36 // large, so it will never actually be reached even on the slowest bots that run | |
| 37 // these tests. | |
| 38 // | |
| 39 // We disable the polling in order to avoid any timing dependencies in the | |
| 40 // tests. If the bot were to run the tests very slowly and we hadn't disabled | |
| 41 // polling, then it is possible it might start a background re-try in the middle | |
|
wtc
2012/01/03 23:54:45
Nit: remove "it is possible"
eroman
2012/01/04 03:41:47
Done.
| |
| 42 // of our test and confuse our expectations leading to flaky failures. | |
| 43 // | |
| 44 // The tests which verify the polling code re-enable the polling behavior but | |
| 45 // are careful to avoid timing problems. | |
| 46 class ProxyServiceTest : public testing::Test { | |
| 47 protected: | |
| 48 virtual void SetUp() OVERRIDE { | |
| 49 testing::Test::SetUp(); | |
| 50 previous_policy_ = ProxyService::set_pac_script_poll_policy( | |
| 51 ProxyService::POLL_POLICY_NEVER); | |
| 52 } | |
| 53 | |
| 54 virtual void TearDown() OVERRIDE { | |
| 55 // Restore the original policy. | |
| 56 ProxyService::set_pac_script_poll_policy(previous_policy_); | |
| 57 testing::Test::TearDown(); | |
| 58 } | |
| 59 | |
| 60 ProxyService::PollPolicy previous_policy_; | |
|
wtc
2012/01/03 23:54:45
Nit: initialize this member in a constructor?
eroman
2012/01/04 03:41:47
leaving as-is, since there isn't a good value to i
wtc
2012/01/04 22:14:15
OK, I think this is fine for the following reasons
| |
| 61 }; | |
| 62 | |
| 31 const char kValidPacScript1[] = "pac-script-v1-FindProxyForURL"; | 63 const char kValidPacScript1[] = "pac-script-v1-FindProxyForURL"; |
| 32 const char kValidPacScript2[] = "pac-script-v2-FindProxyForURL"; | 64 const char kValidPacScript2[] = "pac-script-v2-FindProxyForURL"; |
| 33 | 65 |
| 34 class MockProxyConfigService: public ProxyConfigService { | 66 class MockProxyConfigService: public ProxyConfigService { |
| 35 public: | 67 public: |
| 36 explicit MockProxyConfigService(const ProxyConfig& config) | 68 explicit MockProxyConfigService(const ProxyConfig& config) |
| 37 : availability_(CONFIG_VALID), | 69 : availability_(CONFIG_VALID), |
| 38 config_(config) { | 70 config_(config) { |
| 39 } | 71 } |
| 40 | 72 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 66 } | 98 } |
| 67 | 99 |
| 68 private: | 100 private: |
| 69 ConfigAvailability availability_; | 101 ConfigAvailability availability_; |
| 70 ProxyConfig config_; | 102 ProxyConfig config_; |
| 71 ObserverList<Observer, true> observers_; | 103 ObserverList<Observer, true> observers_; |
| 72 }; | 104 }; |
| 73 | 105 |
| 74 } // namespace | 106 } // namespace |
| 75 | 107 |
| 76 TEST(ProxyServiceTest, Direct) { | 108 TEST_F(ProxyServiceTest, Direct) { |
| 77 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 109 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 78 ProxyService service(new MockProxyConfigService( | 110 ProxyService service(new MockProxyConfigService( |
| 79 ProxyConfig::CreateDirect()), resolver, NULL); | 111 ProxyConfig::CreateDirect()), resolver, NULL); |
| 80 | 112 |
| 81 GURL url("http://www.google.com/"); | 113 GURL url("http://www.google.com/"); |
| 82 | 114 |
| 83 ProxyInfo info; | 115 ProxyInfo info; |
| 84 TestCompletionCallback callback; | 116 TestCompletionCallback callback; |
| 85 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 117 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 86 int rv = service.ResolveProxy( | 118 int rv = service.ResolveProxy( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 97 EXPECT_EQ(3u, entries.size()); | 129 EXPECT_EQ(3u, entries.size()); |
| 98 EXPECT_TRUE(LogContainsBeginEvent( | 130 EXPECT_TRUE(LogContainsBeginEvent( |
| 99 entries, 0, NetLog::TYPE_PROXY_SERVICE)); | 131 entries, 0, NetLog::TYPE_PROXY_SERVICE)); |
| 100 EXPECT_TRUE(LogContainsEvent( | 132 EXPECT_TRUE(LogContainsEvent( |
| 101 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 133 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, |
| 102 NetLog::PHASE_NONE)); | 134 NetLog::PHASE_NONE)); |
| 103 EXPECT_TRUE(LogContainsEndEvent( | 135 EXPECT_TRUE(LogContainsEndEvent( |
| 104 entries, 2, NetLog::TYPE_PROXY_SERVICE)); | 136 entries, 2, NetLog::TYPE_PROXY_SERVICE)); |
| 105 } | 137 } |
| 106 | 138 |
| 107 TEST(ProxyServiceTest, PAC) { | 139 TEST_F(ProxyServiceTest, PAC) { |
| 108 MockProxyConfigService* config_service = | 140 MockProxyConfigService* config_service = |
| 109 new MockProxyConfigService("http://foopy/proxy.pac"); | 141 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 110 | 142 |
| 111 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 143 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 112 | 144 |
| 113 ProxyService service(config_service, resolver, NULL); | 145 ProxyService service(config_service, resolver, NULL); |
| 114 | 146 |
| 115 GURL url("http://www.google.com/"); | 147 GURL url("http://www.google.com/"); |
| 116 | 148 |
| 117 ProxyInfo info; | 149 ProxyInfo info; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 147 EXPECT_TRUE(LogContainsBeginEvent( | 179 EXPECT_TRUE(LogContainsBeginEvent( |
| 148 entries, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 180 entries, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
| 149 EXPECT_TRUE(LogContainsEndEvent( | 181 EXPECT_TRUE(LogContainsEndEvent( |
| 150 entries, 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 182 entries, 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
| 151 EXPECT_TRUE(LogContainsEndEvent( | 183 EXPECT_TRUE(LogContainsEndEvent( |
| 152 entries, 4, NetLog::TYPE_PROXY_SERVICE)); | 184 entries, 4, NetLog::TYPE_PROXY_SERVICE)); |
| 153 } | 185 } |
| 154 | 186 |
| 155 // Test that the proxy resolver does not see the URL's username/password | 187 // Test that the proxy resolver does not see the URL's username/password |
| 156 // or its reference section. | 188 // or its reference section. |
| 157 TEST(ProxyServiceTest, PAC_NoIdentityOrHash) { | 189 TEST_F(ProxyServiceTest, PAC_NoIdentityOrHash) { |
| 158 MockProxyConfigService* config_service = | 190 MockProxyConfigService* config_service = |
| 159 new MockProxyConfigService("http://foopy/proxy.pac"); | 191 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 160 | 192 |
| 161 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 193 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 162 | 194 |
| 163 ProxyService service(config_service, resolver, NULL); | 195 ProxyService service(config_service, resolver, NULL); |
| 164 | 196 |
| 165 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 197 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
| 166 | 198 |
| 167 ProxyInfo info; | 199 ProxyInfo info; |
| 168 TestCompletionCallback callback; | 200 TestCompletionCallback callback; |
| 169 int rv = service.ResolveProxy( | 201 int rv = service.ResolveProxy( |
| 170 url, &info, callback.callback(), NULL, BoundNetLog()); | 202 url, &info, callback.callback(), NULL, BoundNetLog()); |
| 171 EXPECT_EQ(ERR_IO_PENDING, rv); | 203 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 172 | 204 |
| 173 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 205 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 174 resolver->pending_set_pac_script_request()->script_data()->url()); | 206 resolver->pending_set_pac_script_request()->script_data()->url()); |
| 175 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 207 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 176 | 208 |
| 177 ASSERT_EQ(1u, resolver->pending_requests().size()); | 209 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 178 // The URL should have been simplified, stripping the username/password/hash. | 210 // The URL should have been simplified, stripping the username/password/hash. |
| 179 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 211 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
| 180 resolver->pending_requests()[0]->url()); | 212 resolver->pending_requests()[0]->url()); |
| 181 | 213 |
| 182 // We end here without ever completing the request -- destruction of | 214 // We end here without ever completing the request -- destruction of |
| 183 // ProxyService will cancel the outstanding request. | 215 // ProxyService will cancel the outstanding request. |
| 184 } | 216 } |
| 185 | 217 |
| 186 TEST(ProxyServiceTest, PAC_FailoverWithoutDirect) { | 218 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
| 187 MockProxyConfigService* config_service = | 219 MockProxyConfigService* config_service = |
| 188 new MockProxyConfigService("http://foopy/proxy.pac"); | 220 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 189 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 221 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 190 | 222 |
| 191 ProxyService service(config_service, resolver, NULL); | 223 ProxyService service(config_service, resolver, NULL); |
| 192 | 224 |
| 193 GURL url("http://www.google.com/"); | 225 GURL url("http://www.google.com/"); |
| 194 | 226 |
| 195 ProxyInfo info; | 227 ProxyInfo info; |
| 196 TestCompletionCallback callback1; | 228 TestCompletionCallback callback1; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 // | 266 // |
| 235 // This test will use the PAC result string: | 267 // This test will use the PAC result string: |
| 236 // | 268 // |
| 237 // "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20" | 269 // "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20" |
| 238 // | 270 // |
| 239 // For which we expect it to try DIRECT, then foobar:10, then DIRECT again, | 271 // For which we expect it to try DIRECT, then foobar:10, then DIRECT again, |
| 240 // then foobar:20, and then give up and error. | 272 // then foobar:20, and then give up and error. |
| 241 // | 273 // |
| 242 // The important check of this test is to make sure that DIRECT is not somehow | 274 // The important check of this test is to make sure that DIRECT is not somehow |
| 243 // cached as being a bad proxy. | 275 // cached as being a bad proxy. |
| 244 TEST(ProxyServiceTest, PAC_FailoverAfterDirect) { | 276 TEST_F(ProxyServiceTest, PAC_FailoverAfterDirect) { |
| 245 MockProxyConfigService* config_service = | 277 MockProxyConfigService* config_service = |
| 246 new MockProxyConfigService("http://foopy/proxy.pac"); | 278 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 247 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 279 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 248 | 280 |
| 249 ProxyService service(config_service, resolver, NULL); | 281 ProxyService service(config_service, resolver, NULL); |
| 250 | 282 |
| 251 GURL url("http://www.google.com/"); | 283 GURL url("http://www.google.com/"); |
| 252 | 284 |
| 253 ProxyInfo info; | 285 ProxyInfo info; |
| 254 TestCompletionCallback callback1; | 286 TestCompletionCallback callback1; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); | 327 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); |
| 296 | 328 |
| 297 // Fallback 4 -- Nothing to fall back to! | 329 // Fallback 4 -- Nothing to fall back to! |
| 298 TestCompletionCallback callback5; | 330 TestCompletionCallback callback5; |
| 299 rv = service.ReconsiderProxyAfterError(url, &info, callback5.callback(), NULL, | 331 rv = service.ReconsiderProxyAfterError(url, &info, callback5.callback(), NULL, |
| 300 BoundNetLog()); | 332 BoundNetLog()); |
| 301 EXPECT_EQ(ERR_FAILED, rv); | 333 EXPECT_EQ(ERR_FAILED, rv); |
| 302 EXPECT_TRUE(info.is_empty()); | 334 EXPECT_TRUE(info.is_empty()); |
| 303 } | 335 } |
| 304 | 336 |
| 305 TEST(ProxyServiceTest, ProxyResolverFails) { | 337 TEST_F(ProxyServiceTest, ProxyResolverFails) { |
| 306 // Test what happens when the ProxyResolver fails. The download and setting | 338 // Test what happens when the ProxyResolver fails. The download and setting |
| 307 // of the PAC script have already succeeded, so this corresponds with a | 339 // of the PAC script have already succeeded, so this corresponds with a |
| 308 // javascript runtime error while calling FindProxyForURL(). | 340 // javascript runtime error while calling FindProxyForURL(). |
| 309 | 341 |
| 310 MockProxyConfigService* config_service = | 342 MockProxyConfigService* config_service = |
| 311 new MockProxyConfigService("http://foopy/proxy.pac"); | 343 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 312 | 344 |
| 313 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 345 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 314 | 346 |
| 315 ProxyService service(config_service, resolver, NULL); | 347 ProxyService service(config_service, resolver, NULL); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 // This time we will have the resolver succeed (perhaps the PAC script has | 382 // This time we will have the resolver succeed (perhaps the PAC script has |
| 351 // a dependency on the current time). | 383 // a dependency on the current time). |
| 352 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 384 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
| 353 resolver->pending_requests()[0]->CompleteNow(OK); | 385 resolver->pending_requests()[0]->CompleteNow(OK); |
| 354 | 386 |
| 355 EXPECT_EQ(OK, callback2.WaitForResult()); | 387 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 356 EXPECT_FALSE(info.is_direct()); | 388 EXPECT_FALSE(info.is_direct()); |
| 357 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 389 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
| 358 } | 390 } |
| 359 | 391 |
| 360 TEST(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { | 392 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { |
| 361 // Test what happens when the ProxyScriptResolver fails to download a | 393 // Test what happens when the ProxyScriptResolver fails to download a |
| 362 // mandatory PAC script. | 394 // mandatory PAC script. |
| 363 | 395 |
| 364 ProxyConfig config( | 396 ProxyConfig config( |
| 365 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 397 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
| 366 config.set_pac_mandatory(true); | 398 config.set_pac_mandatory(true); |
| 367 | 399 |
| 368 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 400 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 369 | 401 |
| 370 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 402 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 393 | 425 |
| 394 // As the proxy resolver failed the request and is configured for a mandatory | 426 // As the proxy resolver failed the request and is configured for a mandatory |
| 395 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 427 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
| 396 TestCompletionCallback callback2; | 428 TestCompletionCallback callback2; |
| 397 rv = service.ResolveProxy( | 429 rv = service.ResolveProxy( |
| 398 url, &info, callback2.callback(), NULL, BoundNetLog()); | 430 url, &info, callback2.callback(), NULL, BoundNetLog()); |
| 399 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); | 431 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); |
| 400 EXPECT_FALSE(info.is_direct()); | 432 EXPECT_FALSE(info.is_direct()); |
| 401 } | 433 } |
| 402 | 434 |
| 403 TEST(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { | 435 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { |
| 404 // Test what happens when the ProxyResolver fails that is configured to use a | 436 // Test what happens when the ProxyResolver fails that is configured to use a |
| 405 // mandatory PAC script. The download of the PAC script has already | 437 // mandatory PAC script. The download of the PAC script has already |
| 406 // succeeded but the PAC script contains no valid javascript. | 438 // succeeded but the PAC script contains no valid javascript. |
| 407 | 439 |
| 408 ProxyConfig config( | 440 ProxyConfig config( |
| 409 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 441 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
| 410 config.set_pac_mandatory(true); | 442 config.set_pac_mandatory(true); |
| 411 | 443 |
| 412 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 444 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 413 | 445 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 440 ASSERT_EQ(0u, resolver->pending_requests().size()); | 472 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 441 | 473 |
| 442 // Since ProxyScriptDecider failed to identify a valid PAC and PAC was | 474 // Since ProxyScriptDecider failed to identify a valid PAC and PAC was |
| 443 // mandatory for this configuration, the ProxyService must not implicitly | 475 // mandatory for this configuration, the ProxyService must not implicitly |
| 444 // fall-back to DIRECT. | 476 // fall-back to DIRECT. |
| 445 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 477 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
| 446 callback.WaitForResult()); | 478 callback.WaitForResult()); |
| 447 EXPECT_FALSE(info.is_direct()); | 479 EXPECT_FALSE(info.is_direct()); |
| 448 } | 480 } |
| 449 | 481 |
| 450 TEST(ProxyServiceTest, ProxyResolverFailsInJavaScriptMandatoryPac) { | 482 TEST_F(ProxyServiceTest, ProxyResolverFailsInJavaScriptMandatoryPac) { |
| 451 // Test what happens when the ProxyResolver fails that is configured to use a | 483 // Test what happens when the ProxyResolver fails that is configured to use a |
| 452 // mandatory PAC script. The download and setting of the PAC script have | 484 // mandatory PAC script. The download and setting of the PAC script have |
| 453 // already succeeded, so this corresponds with a javascript runtime error | 485 // already succeeded, so this corresponds with a javascript runtime error |
| 454 // while calling FindProxyForURL(). | 486 // while calling FindProxyForURL(). |
| 455 | 487 |
| 456 ProxyConfig config( | 488 ProxyConfig config( |
| 457 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 489 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
| 458 config.set_pac_mandatory(true); | 490 config.set_pac_mandatory(true); |
| 459 | 491 |
| 460 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 492 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 // This time we will have the resolver succeed (perhaps the PAC script has | 532 // This time we will have the resolver succeed (perhaps the PAC script has |
| 501 // a dependency on the current time). | 533 // a dependency on the current time). |
| 502 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 534 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
| 503 resolver->pending_requests()[0]->CompleteNow(OK); | 535 resolver->pending_requests()[0]->CompleteNow(OK); |
| 504 | 536 |
| 505 EXPECT_EQ(OK, callback2.WaitForResult()); | 537 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 506 EXPECT_FALSE(info.is_direct()); | 538 EXPECT_FALSE(info.is_direct()); |
| 507 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 539 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
| 508 } | 540 } |
| 509 | 541 |
| 510 TEST(ProxyServiceTest, ProxyFallback) { | 542 TEST_F(ProxyServiceTest, ProxyFallback) { |
| 511 // Test what happens when we specify multiple proxy servers and some of them | 543 // Test what happens when we specify multiple proxy servers and some of them |
| 512 // are bad. | 544 // are bad. |
| 513 | 545 |
| 514 MockProxyConfigService* config_service = | 546 MockProxyConfigService* config_service = |
| 515 new MockProxyConfigService("http://foopy/proxy.pac"); | 547 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 516 | 548 |
| 517 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 549 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 518 | 550 |
| 519 ProxyService service(config_service, resolver, NULL); | 551 ProxyService service(config_service, resolver, NULL); |
| 520 | 552 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 // ... therefore, we should see the second proxy first. | 649 // ... therefore, we should see the second proxy first. |
| 618 EXPECT_EQ(OK, callback7.WaitForResult()); | 650 EXPECT_EQ(OK, callback7.WaitForResult()); |
| 619 EXPECT_FALSE(info.is_direct()); | 651 EXPECT_FALSE(info.is_direct()); |
| 620 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 652 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
| 621 | 653 |
| 622 // TODO(nsylvain): Test that the proxy can be retried after the delay. | 654 // TODO(nsylvain): Test that the proxy can be retried after the delay. |
| 623 } | 655 } |
| 624 | 656 |
| 625 // This test is similar to ProxyFallback, but this time we have an explicit | 657 // This test is similar to ProxyFallback, but this time we have an explicit |
| 626 // fallback choice to DIRECT. | 658 // fallback choice to DIRECT. |
| 627 TEST(ProxyServiceTest, ProxyFallbackToDirect) { | 659 TEST_F(ProxyServiceTest, ProxyFallbackToDirect) { |
| 628 MockProxyConfigService* config_service = | 660 MockProxyConfigService* config_service = |
| 629 new MockProxyConfigService("http://foopy/proxy.pac"); | 661 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 630 | 662 |
| 631 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 663 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 632 | 664 |
| 633 ProxyService service(config_service, resolver, NULL); | 665 ProxyService service(config_service, resolver, NULL); |
| 634 | 666 |
| 635 GURL url("http://www.google.com/"); | 667 GURL url("http://www.google.com/"); |
| 636 | 668 |
| 637 // Get the proxy information. | 669 // Get the proxy information. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 | 710 |
| 679 // Now we tell the proxy service that even DIRECT failed. | 711 // Now we tell the proxy service that even DIRECT failed. |
| 680 TestCompletionCallback callback4; | 712 TestCompletionCallback callback4; |
| 681 rv = service.ReconsiderProxyAfterError(url, &info, callback4.callback(), NULL, | 713 rv = service.ReconsiderProxyAfterError(url, &info, callback4.callback(), NULL, |
| 682 BoundNetLog()); | 714 BoundNetLog()); |
| 683 // There was nothing left to try after DIRECT, so we are out of | 715 // There was nothing left to try after DIRECT, so we are out of |
| 684 // choices. | 716 // choices. |
| 685 EXPECT_EQ(ERR_FAILED, rv); | 717 EXPECT_EQ(ERR_FAILED, rv); |
| 686 } | 718 } |
| 687 | 719 |
| 688 TEST(ProxyServiceTest, ProxyFallback_NewSettings) { | 720 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { |
| 689 // Test proxy failover when new settings are available. | 721 // Test proxy failover when new settings are available. |
| 690 | 722 |
| 691 MockProxyConfigService* config_service = | 723 MockProxyConfigService* config_service = |
| 692 new MockProxyConfigService("http://foopy/proxy.pac"); | 724 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 693 | 725 |
| 694 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 726 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 695 | 727 |
| 696 ProxyService service(config_service, resolver, NULL); | 728 ProxyService service(config_service, resolver, NULL); |
| 697 | 729 |
| 698 GURL url("http://www.google.com/"); | 730 GURL url("http://www.google.com/"); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 803 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 772 | 804 |
| 773 resolver->pending_requests()[0]->results()->UseNamedProxy( | 805 resolver->pending_requests()[0]->results()->UseNamedProxy( |
| 774 "foopy1:8080;foopy2:9090"); | 806 "foopy1:8080;foopy2:9090"); |
| 775 resolver->pending_requests()[0]->CompleteNow(OK); | 807 resolver->pending_requests()[0]->CompleteNow(OK); |
| 776 | 808 |
| 777 EXPECT_EQ(OK, callback4.WaitForResult()); | 809 EXPECT_EQ(OK, callback4.WaitForResult()); |
| 778 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 810 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 779 } | 811 } |
| 780 | 812 |
| 781 TEST(ProxyServiceTest, ProxyFallback_BadConfig) { | 813 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { |
| 782 // Test proxy failover when the configuration is bad. | 814 // Test proxy failover when the configuration is bad. |
| 783 | 815 |
| 784 MockProxyConfigService* config_service = | 816 MockProxyConfigService* config_service = |
| 785 new MockProxyConfigService("http://foopy/proxy.pac"); | 817 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 786 | 818 |
| 787 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 819 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 788 | 820 |
| 789 ProxyService service(config_service, resolver, NULL); | 821 ProxyService service(config_service, resolver, NULL); |
| 790 | 822 |
| 791 GURL url("http://www.google.com/"); | 823 GURL url("http://www.google.com/"); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 "foopy1:8080;foopy2:9090"); | 889 "foopy1:8080;foopy2:9090"); |
| 858 resolver->pending_requests()[0]->CompleteNow(OK); | 890 resolver->pending_requests()[0]->CompleteNow(OK); |
| 859 | 891 |
| 860 // The first proxy is not there since the it was added to the bad proxies | 892 // The first proxy is not there since the it was added to the bad proxies |
| 861 // list by the earlier ReconsiderProxyAfterError(). | 893 // list by the earlier ReconsiderProxyAfterError(). |
| 862 EXPECT_EQ(OK, callback4.WaitForResult()); | 894 EXPECT_EQ(OK, callback4.WaitForResult()); |
| 863 EXPECT_FALSE(info3.is_direct()); | 895 EXPECT_FALSE(info3.is_direct()); |
| 864 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 896 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
| 865 } | 897 } |
| 866 | 898 |
| 867 TEST(ProxyServiceTest, ProxyFallback_BadConfigMandatory) { | 899 TEST_F(ProxyServiceTest, ProxyFallback_BadConfigMandatory) { |
| 868 // Test proxy failover when the configuration is bad. | 900 // Test proxy failover when the configuration is bad. |
| 869 | 901 |
| 870 ProxyConfig config( | 902 ProxyConfig config( |
| 871 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 903 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
| 872 | 904 |
| 873 config.set_pac_mandatory(true); | 905 config.set_pac_mandatory(true); |
| 874 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 906 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 875 | 907 |
| 876 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 908 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 877 | 909 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 947 "foopy1:8080;foopy2:9090"); | 979 "foopy1:8080;foopy2:9090"); |
| 948 resolver->pending_requests()[0]->CompleteNow(OK); | 980 resolver->pending_requests()[0]->CompleteNow(OK); |
| 949 | 981 |
| 950 // The first proxy is not there since the it was added to the bad proxies | 982 // The first proxy is not there since the it was added to the bad proxies |
| 951 // list by the earlier ReconsiderProxyAfterError(). | 983 // list by the earlier ReconsiderProxyAfterError(). |
| 952 EXPECT_EQ(OK, callback4.WaitForResult()); | 984 EXPECT_EQ(OK, callback4.WaitForResult()); |
| 953 EXPECT_FALSE(info3.is_direct()); | 985 EXPECT_FALSE(info3.is_direct()); |
| 954 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 986 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
| 955 } | 987 } |
| 956 | 988 |
| 957 TEST(ProxyServiceTest, ProxyBypassList) { | 989 TEST_F(ProxyServiceTest, ProxyBypassList) { |
| 958 // Test that the proxy bypass rules are consulted. | 990 // Test that the proxy bypass rules are consulted. |
| 959 | 991 |
| 960 TestCompletionCallback callback[2]; | 992 TestCompletionCallback callback[2]; |
| 961 ProxyInfo info[2]; | 993 ProxyInfo info[2]; |
| 962 ProxyConfig config; | 994 ProxyConfig config; |
| 963 config.proxy_rules().ParseFromString("foopy1:8080;foopy2:9090"); | 995 config.proxy_rules().ParseFromString("foopy1:8080;foopy2:9090"); |
| 964 config.set_auto_detect(false); | 996 config.set_auto_detect(false); |
| 965 config.proxy_rules().bypass_rules.ParseFromString("*.org"); | 997 config.proxy_rules().bypass_rules.ParseFromString("*.org"); |
| 966 | 998 |
| 967 ProxyService service( | 999 ProxyService service( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 978 EXPECT_TRUE(info[0].is_direct()); | 1010 EXPECT_TRUE(info[0].is_direct()); |
| 979 | 1011 |
| 980 // Request for a .com domain hits the proxy. | 1012 // Request for a .com domain hits the proxy. |
| 981 rv = service.ResolveProxy( | 1013 rv = service.ResolveProxy( |
| 982 url2, &info[1], callback[1].callback(), NULL, BoundNetLog()); | 1014 url2, &info[1], callback[1].callback(), NULL, BoundNetLog()); |
| 983 EXPECT_EQ(OK, rv); | 1015 EXPECT_EQ(OK, rv); |
| 984 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); | 1016 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); |
| 985 } | 1017 } |
| 986 | 1018 |
| 987 | 1019 |
| 988 TEST(ProxyServiceTest, PerProtocolProxyTests) { | 1020 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { |
| 989 ProxyConfig config; | 1021 ProxyConfig config; |
| 990 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); | 1022 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); |
| 991 config.set_auto_detect(false); | 1023 config.set_auto_detect(false); |
| 992 { | 1024 { |
| 993 ProxyService service( | 1025 ProxyService service( |
| 994 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1026 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
| 995 GURL test_url("http://www.msn.com"); | 1027 GURL test_url("http://www.msn.com"); |
| 996 ProxyInfo info; | 1028 ProxyInfo info; |
| 997 TestCompletionCallback callback; | 1029 TestCompletionCallback callback; |
| 998 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1030 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1035 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1067 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, |
| 1036 BoundNetLog()); | 1068 BoundNetLog()); |
| 1037 EXPECT_EQ(OK, rv); | 1069 EXPECT_EQ(OK, rv); |
| 1038 EXPECT_FALSE(info.is_direct()); | 1070 EXPECT_FALSE(info.is_direct()); |
| 1039 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1071 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1040 } | 1072 } |
| 1041 } | 1073 } |
| 1042 | 1074 |
| 1043 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries | 1075 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries |
| 1044 // fall back to the SOCKS proxy. | 1076 // fall back to the SOCKS proxy. |
| 1045 TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { | 1077 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { |
| 1046 ProxyConfig config; | 1078 ProxyConfig config; |
| 1047 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); | 1079 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); |
| 1048 config.set_auto_detect(false); | 1080 config.set_auto_detect(false); |
| 1049 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 1081 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
| 1050 config.proxy_rules().type); | 1082 config.proxy_rules().type); |
| 1051 | 1083 |
| 1052 { | 1084 { |
| 1053 ProxyService service( | 1085 ProxyService service( |
| 1054 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1086 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
| 1055 GURL test_url("http://www.msn.com"); | 1087 GURL test_url("http://www.msn.com"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 TestCompletionCallback callback; | 1125 TestCompletionCallback callback; |
| 1094 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1126 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, |
| 1095 BoundNetLog()); | 1127 BoundNetLog()); |
| 1096 EXPECT_EQ(OK, rv); | 1128 EXPECT_EQ(OK, rv); |
| 1097 EXPECT_FALSE(info.is_direct()); | 1129 EXPECT_FALSE(info.is_direct()); |
| 1098 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1130 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
| 1099 } | 1131 } |
| 1100 } | 1132 } |
| 1101 | 1133 |
| 1102 // Test cancellation of an in-progress request. | 1134 // Test cancellation of an in-progress request. |
| 1103 TEST(ProxyServiceTest, CancelInProgressRequest) { | 1135 TEST_F(ProxyServiceTest, CancelInProgressRequest) { |
| 1104 MockProxyConfigService* config_service = | 1136 MockProxyConfigService* config_service = |
| 1105 new MockProxyConfigService("http://foopy/proxy.pac"); | 1137 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1106 | 1138 |
| 1107 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1139 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 1108 | 1140 |
| 1109 ProxyService service(config_service, resolver, NULL); | 1141 ProxyService service(config_service, resolver, NULL); |
| 1110 | 1142 |
| 1111 // Start 3 requests. | 1143 // Start 3 requests. |
| 1112 | 1144 |
| 1113 ProxyInfo info1; | 1145 ProxyInfo info1; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1166 | 1198 |
| 1167 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 1199 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
| 1168 ASSERT_EQ(1u, resolver->cancelled_requests().size()); | 1200 ASSERT_EQ(1u, resolver->cancelled_requests().size()); |
| 1169 EXPECT_EQ(GURL("http://request2"), resolver->cancelled_requests()[0]->url()); | 1201 EXPECT_EQ(GURL("http://request2"), resolver->cancelled_requests()[0]->url()); |
| 1170 | 1202 |
| 1171 EXPECT_EQ(OK, callback3.WaitForResult()); | 1203 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 1172 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 1204 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
| 1173 } | 1205 } |
| 1174 | 1206 |
| 1175 // Test the initial PAC download for resolver that expects bytes. | 1207 // Test the initial PAC download for resolver that expects bytes. |
| 1176 TEST(ProxyServiceTest, InitialPACScriptDownload) { | 1208 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { |
| 1177 MockProxyConfigService* config_service = | 1209 MockProxyConfigService* config_service = |
| 1178 new MockProxyConfigService("http://foopy/proxy.pac"); | 1210 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1179 | 1211 |
| 1180 MockAsyncProxyResolverExpectsBytes* resolver = | 1212 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1181 new MockAsyncProxyResolverExpectsBytes; | 1213 new MockAsyncProxyResolverExpectsBytes; |
| 1182 | 1214 |
| 1183 ProxyService service(config_service, resolver, NULL); | 1215 ProxyService service(config_service, resolver, NULL); |
| 1184 | 1216 |
| 1185 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1217 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1186 service.SetProxyScriptFetchers(fetcher, | 1218 service.SetProxyScriptFetchers(fetcher, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1246 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1278 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 1247 | 1279 |
| 1248 EXPECT_EQ(OK, callback2.WaitForResult()); | 1280 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 1249 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1281 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 1250 | 1282 |
| 1251 EXPECT_EQ(OK, callback3.WaitForResult()); | 1283 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 1252 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 1284 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
| 1253 } | 1285 } |
| 1254 | 1286 |
| 1255 // Test changing the ProxyScriptFetcher while PAC download is in progress. | 1287 // Test changing the ProxyScriptFetcher while PAC download is in progress. |
| 1256 TEST(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { | 1288 TEST_F(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { |
| 1257 MockProxyConfigService* config_service = | 1289 MockProxyConfigService* config_service = |
| 1258 new MockProxyConfigService("http://foopy/proxy.pac"); | 1290 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1259 | 1291 |
| 1260 MockAsyncProxyResolverExpectsBytes* resolver = | 1292 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1261 new MockAsyncProxyResolverExpectsBytes; | 1293 new MockAsyncProxyResolverExpectsBytes; |
| 1262 | 1294 |
| 1263 ProxyService service(config_service, resolver, NULL); | 1295 ProxyService service(config_service, resolver, NULL); |
| 1264 | 1296 |
| 1265 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1297 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1266 service.SetProxyScriptFetchers(fetcher, | 1298 service.SetProxyScriptFetchers(fetcher, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1305 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 1337 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 1306 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1338 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
| 1307 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1339 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1308 | 1340 |
| 1309 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1341 ASSERT_EQ(2u, resolver->pending_requests().size()); |
| 1310 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1342 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 1311 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1343 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
| 1312 } | 1344 } |
| 1313 | 1345 |
| 1314 // Test cancellation of a request, while the PAC script is being fetched. | 1346 // Test cancellation of a request, while the PAC script is being fetched. |
| 1315 TEST(ProxyServiceTest, CancelWhilePACFetching) { | 1347 TEST_F(ProxyServiceTest, CancelWhilePACFetching) { |
| 1316 MockProxyConfigService* config_service = | 1348 MockProxyConfigService* config_service = |
| 1317 new MockProxyConfigService("http://foopy/proxy.pac"); | 1349 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1318 | 1350 |
| 1319 MockAsyncProxyResolverExpectsBytes* resolver = | 1351 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1320 new MockAsyncProxyResolverExpectsBytes; | 1352 new MockAsyncProxyResolverExpectsBytes; |
| 1321 | 1353 |
| 1322 ProxyService service(config_service, resolver, NULL); | 1354 ProxyService service(config_service, resolver, NULL); |
| 1323 | 1355 |
| 1324 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1356 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1325 service.SetProxyScriptFetchers(fetcher, | 1357 service.SetProxyScriptFetchers(fetcher, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1395 entries1, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 1427 entries1, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
| 1396 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before | 1428 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before |
| 1397 // the cancellation occured. | 1429 // the cancellation occured. |
| 1398 EXPECT_TRUE(LogContainsEvent( | 1430 EXPECT_TRUE(LogContainsEvent( |
| 1399 entries1, 2, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE)); | 1431 entries1, 2, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE)); |
| 1400 EXPECT_TRUE(LogContainsEndEvent( | 1432 EXPECT_TRUE(LogContainsEndEvent( |
| 1401 entries1, 3, NetLog::TYPE_PROXY_SERVICE)); | 1433 entries1, 3, NetLog::TYPE_PROXY_SERVICE)); |
| 1402 } | 1434 } |
| 1403 | 1435 |
| 1404 // Test that if auto-detect fails, we fall-back to the custom pac. | 1436 // Test that if auto-detect fails, we fall-back to the custom pac. |
| 1405 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { | 1437 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { |
| 1406 ProxyConfig config; | 1438 ProxyConfig config; |
| 1407 config.set_auto_detect(true); | 1439 config.set_auto_detect(true); |
| 1408 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 1440 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 1409 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. | 1441 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. |
| 1410 | 1442 |
| 1411 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1443 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1412 MockAsyncProxyResolverExpectsBytes* resolver = | 1444 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1413 new MockAsyncProxyResolverExpectsBytes; | 1445 new MockAsyncProxyResolverExpectsBytes; |
| 1414 ProxyService service(config_service, resolver, NULL); | 1446 ProxyService service(config_service, resolver, NULL); |
| 1415 | 1447 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1466 // Verify that requests ran as expected. | 1498 // Verify that requests ran as expected. |
| 1467 EXPECT_EQ(OK, callback1.WaitForResult()); | 1499 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 1468 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1500 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 1469 | 1501 |
| 1470 EXPECT_EQ(OK, callback2.WaitForResult()); | 1502 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 1471 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1503 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 1472 } | 1504 } |
| 1473 | 1505 |
| 1474 // This is the same test as FallbackFromAutodetectToCustomPac, except | 1506 // This is the same test as FallbackFromAutodetectToCustomPac, except |
| 1475 // the auto-detect script fails parsing rather than downloading. | 1507 // the auto-detect script fails parsing rather than downloading. |
| 1476 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { | 1508 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { |
| 1477 ProxyConfig config; | 1509 ProxyConfig config; |
| 1478 config.set_auto_detect(true); | 1510 config.set_auto_detect(true); |
| 1479 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 1511 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 1480 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. | 1512 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. |
| 1481 | 1513 |
| 1482 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1514 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1483 MockAsyncProxyResolverExpectsBytes* resolver = | 1515 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1484 new MockAsyncProxyResolverExpectsBytes; | 1516 new MockAsyncProxyResolverExpectsBytes; |
| 1485 ProxyService service(config_service, resolver, NULL); | 1517 ProxyService service(config_service, resolver, NULL); |
| 1486 | 1518 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1539 // Verify that requests ran as expected. | 1571 // Verify that requests ran as expected. |
| 1540 EXPECT_EQ(OK, callback1.WaitForResult()); | 1572 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 1541 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1573 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 1542 | 1574 |
| 1543 EXPECT_EQ(OK, callback2.WaitForResult()); | 1575 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 1544 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1576 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 1545 } | 1577 } |
| 1546 | 1578 |
| 1547 // Test that if all of auto-detect, a custom PAC script, and manual settings | 1579 // Test that if all of auto-detect, a custom PAC script, and manual settings |
| 1548 // are given, then we will try them in that order. | 1580 // are given, then we will try them in that order. |
| 1549 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { | 1581 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { |
| 1550 ProxyConfig config; | 1582 ProxyConfig config; |
| 1551 config.set_auto_detect(true); | 1583 config.set_auto_detect(true); |
| 1552 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 1584 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 1553 config.proxy_rules().ParseFromString("http=foopy:80"); | 1585 config.proxy_rules().ParseFromString("http=foopy:80"); |
| 1554 | 1586 |
| 1555 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1587 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1556 MockAsyncProxyResolverExpectsBytes* resolver = | 1588 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1557 new MockAsyncProxyResolverExpectsBytes; | 1589 new MockAsyncProxyResolverExpectsBytes; |
| 1558 ProxyService service(config_service, resolver, NULL); | 1590 ProxyService service(config_service, resolver, NULL); |
| 1559 | 1591 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1596 // Verify that requests ran as expected -- they should have fallen back to | 1628 // Verify that requests ran as expected -- they should have fallen back to |
| 1597 // the manual proxy configuration for HTTP urls. | 1629 // the manual proxy configuration for HTTP urls. |
| 1598 EXPECT_EQ(OK, callback1.WaitForResult()); | 1630 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 1599 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); | 1631 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); |
| 1600 | 1632 |
| 1601 EXPECT_EQ(OK, callback2.WaitForResult()); | 1633 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 1602 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); | 1634 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); |
| 1603 } | 1635 } |
| 1604 | 1636 |
| 1605 // Test that the bypass rules are NOT applied when using autodetect. | 1637 // Test that the bypass rules are NOT applied when using autodetect. |
| 1606 TEST(ProxyServiceTest, BypassDoesntApplyToPac) { | 1638 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { |
| 1607 ProxyConfig config; | 1639 ProxyConfig config; |
| 1608 config.set_auto_detect(true); | 1640 config.set_auto_detect(true); |
| 1609 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 1641 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 1610 config.proxy_rules().ParseFromString("http=foopy:80"); // Not used. | 1642 config.proxy_rules().ParseFromString("http=foopy:80"); // Not used. |
| 1611 config.proxy_rules().bypass_rules.ParseFromString("www.google.com"); | 1643 config.proxy_rules().bypass_rules.ParseFromString("www.google.com"); |
| 1612 | 1644 |
| 1613 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1645 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1614 MockAsyncProxyResolverExpectsBytes* resolver = | 1646 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1615 new MockAsyncProxyResolverExpectsBytes; | 1647 new MockAsyncProxyResolverExpectsBytes; |
| 1616 ProxyService service(config_service, resolver, NULL); | 1648 ProxyService service(config_service, resolver, NULL); |
| 1617 | 1649 |
| 1618 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1650 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1619 service.SetProxyScriptFetchers(fetcher, | 1651 service.SetProxyScriptFetchers(fetcher, |
| 1620 new DoNothingDhcpProxyScriptFetcher()); | 1652 new DoNothingDhcpProxyScriptFetcher()); |
| 1621 | 1653 |
| 1622 // Start 1 requests. | 1654 // Start 1 requests. |
| 1623 | 1655 |
| 1624 ProxyInfo info1; | 1656 ProxyInfo info1; |
| 1625 TestCompletionCallback callback1; | 1657 TestCompletionCallback callback1; |
| 1626 int rv = service.ResolveProxy( | 1658 int rv = service.ResolveProxy( |
| 1627 GURL("http://www.google.com"), &info1, callback1.callback(), NULL, BoundNe tLog()); | 1659 GURL("http://www.google.com"), &info1, callback1.callback(), NULL, |
| 1660 BoundNetLog()); | |
| 1628 EXPECT_EQ(ERR_IO_PENDING, rv); | 1661 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1629 | 1662 |
| 1630 // Check that nothing has been sent to the proxy resolver yet. | 1663 // Check that nothing has been sent to the proxy resolver yet. |
| 1631 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1664 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 1632 | 1665 |
| 1633 // It should be trying to auto-detect first -- succeed the download. | 1666 // It should be trying to auto-detect first -- succeed the download. |
| 1634 EXPECT_TRUE(fetcher->has_pending_request()); | 1667 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1635 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1668 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 1636 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 1669 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 1637 | 1670 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1667 resolver->pending_requests()[0]->CompleteNow(OK); | 1700 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1668 | 1701 |
| 1669 EXPECT_EQ(OK, callback2.WaitForResult()); | 1702 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 1670 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1703 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 1671 } | 1704 } |
| 1672 | 1705 |
| 1673 // Delete the ProxyService while InitProxyResolver has an outstanding | 1706 // Delete the ProxyService while InitProxyResolver has an outstanding |
| 1674 // request to the script fetcher. When run under valgrind, should not | 1707 // request to the script fetcher. When run under valgrind, should not |
| 1675 // have any memory errors (used to be that the ProxyScriptFetcher was | 1708 // have any memory errors (used to be that the ProxyScriptFetcher was |
| 1676 // being deleted prior to the InitProxyResolver). | 1709 // being deleted prior to the InitProxyResolver). |
| 1677 TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { | 1710 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { |
| 1678 ProxyConfig config = | 1711 ProxyConfig config = |
| 1679 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); | 1712 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); |
| 1680 | 1713 |
| 1681 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1714 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1682 MockAsyncProxyResolverExpectsBytes* resolver = | 1715 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1683 new MockAsyncProxyResolverExpectsBytes; | 1716 new MockAsyncProxyResolverExpectsBytes; |
| 1684 ProxyService service(config_service, resolver, NULL); | 1717 ProxyService service(config_service, resolver, NULL); |
| 1685 | 1718 |
| 1686 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1719 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1687 service.SetProxyScriptFetchers(fetcher, | 1720 service.SetProxyScriptFetchers(fetcher, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1701 // InitProxyResolver should have issued a request to the ProxyScriptFetcher | 1734 // InitProxyResolver should have issued a request to the ProxyScriptFetcher |
| 1702 // and be waiting on that to complete. | 1735 // and be waiting on that to complete. |
| 1703 EXPECT_TRUE(fetcher->has_pending_request()); | 1736 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1704 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1737 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 1705 } | 1738 } |
| 1706 | 1739 |
| 1707 // Delete the ProxyService while InitProxyResolver has an outstanding | 1740 // Delete the ProxyService while InitProxyResolver has an outstanding |
| 1708 // request to the proxy resolver. When run under valgrind, should not | 1741 // request to the proxy resolver. When run under valgrind, should not |
| 1709 // have any memory errors (used to be that the ProxyResolver was | 1742 // have any memory errors (used to be that the ProxyResolver was |
| 1710 // being deleted prior to the InitProxyResolver). | 1743 // being deleted prior to the InitProxyResolver). |
| 1711 TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { | 1744 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { |
| 1712 MockProxyConfigService* config_service = | 1745 MockProxyConfigService* config_service = |
| 1713 new MockProxyConfigService("http://foopy/proxy.pac"); | 1746 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1714 | 1747 |
| 1715 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1748 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 1716 | 1749 |
| 1717 ProxyService service(config_service, resolver, NULL); | 1750 ProxyService service(config_service, resolver, NULL); |
| 1718 | 1751 |
| 1719 GURL url("http://www.google.com/"); | 1752 GURL url("http://www.google.com/"); |
| 1720 | 1753 |
| 1721 ProxyInfo info; | 1754 ProxyInfo info; |
| 1722 TestCompletionCallback callback; | 1755 TestCompletionCallback callback; |
| 1723 int rv = service.ResolveProxy( | 1756 int rv = service.ResolveProxy( |
| 1724 url, &info, callback.callback(), NULL, BoundNetLog()); | 1757 url, &info, callback.callback(), NULL, BoundNetLog()); |
| 1725 EXPECT_EQ(ERR_IO_PENDING, rv); | 1758 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1726 | 1759 |
| 1727 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1760 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1728 resolver->pending_set_pac_script_request()->script_data()->url()); | 1761 resolver->pending_set_pac_script_request()->script_data()->url()); |
| 1729 } | 1762 } |
| 1730 | 1763 |
| 1731 TEST(ProxyServiceTest, ResetProxyConfigService) { | 1764 TEST_F(ProxyServiceTest, ResetProxyConfigService) { |
| 1732 ProxyConfig config1; | 1765 ProxyConfig config1; |
| 1733 config1.proxy_rules().ParseFromString("foopy1:8080"); | 1766 config1.proxy_rules().ParseFromString("foopy1:8080"); |
| 1734 config1.set_auto_detect(false); | 1767 config1.set_auto_detect(false); |
| 1735 ProxyService service( | 1768 ProxyService service( |
| 1736 new MockProxyConfigService(config1), | 1769 new MockProxyConfigService(config1), |
| 1737 new MockAsyncProxyResolverExpectsBytes, NULL); | 1770 new MockAsyncProxyResolverExpectsBytes, NULL); |
| 1738 | 1771 |
| 1739 ProxyInfo info; | 1772 ProxyInfo info; |
| 1740 TestCompletionCallback callback1; | 1773 TestCompletionCallback callback1; |
| 1741 int rv = service.ResolveProxy(GURL("http://request1"), &info, | 1774 int rv = service.ResolveProxy(GURL("http://request1"), &info, |
| 1742 callback1.callback(), NULL, BoundNetLog()); | 1775 callback1.callback(), NULL, BoundNetLog()); |
| 1743 EXPECT_EQ(OK, rv); | 1776 EXPECT_EQ(OK, rv); |
| 1744 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1777 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1745 | 1778 |
| 1746 ProxyConfig config2; | 1779 ProxyConfig config2; |
| 1747 config2.proxy_rules().ParseFromString("foopy2:8080"); | 1780 config2.proxy_rules().ParseFromString("foopy2:8080"); |
| 1748 config2.set_auto_detect(false); | 1781 config2.set_auto_detect(false); |
| 1749 service.ResetConfigService(new MockProxyConfigService(config2)); | 1782 service.ResetConfigService(new MockProxyConfigService(config2)); |
| 1750 TestCompletionCallback callback2; | 1783 TestCompletionCallback callback2; |
| 1751 rv = service.ResolveProxy(GURL("http://request2"), &info, | 1784 rv = service.ResolveProxy(GURL("http://request2"), &info, |
| 1752 callback2.callback(), NULL, BoundNetLog()); | 1785 callback2.callback(), NULL, BoundNetLog()); |
| 1753 EXPECT_EQ(OK, rv); | 1786 EXPECT_EQ(OK, rv); |
| 1754 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1787 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
| 1755 } | 1788 } |
| 1756 | 1789 |
| 1757 // Test that when going from a configuration that required PAC to one | 1790 // Test that when going from a configuration that required PAC to one |
| 1758 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 1791 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
| 1759 TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 1792 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
| 1760 ProxyConfig config = ProxyConfig::CreateAutoDetect(); | 1793 ProxyConfig config = ProxyConfig::CreateAutoDetect(); |
| 1761 | 1794 |
| 1762 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1795 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1763 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1796 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 1764 ProxyService service(config_service, resolver, NULL); | 1797 ProxyService service(config_service, resolver, NULL); |
| 1765 | 1798 |
| 1766 // Start 1 request. | 1799 // Start 1 request. |
| 1767 | 1800 |
| 1768 ProxyInfo info1; | 1801 ProxyInfo info1; |
| 1769 TestCompletionCallback callback1; | 1802 TestCompletionCallback callback1; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1798 // Start another request -- the effective configuration has changed. | 1831 // Start another request -- the effective configuration has changed. |
| 1799 ProxyInfo info2; | 1832 ProxyInfo info2; |
| 1800 TestCompletionCallback callback2; | 1833 TestCompletionCallback callback2; |
| 1801 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, | 1834 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, |
| 1802 callback2.callback(), NULL, BoundNetLog()); | 1835 callback2.callback(), NULL, BoundNetLog()); |
| 1803 EXPECT_EQ(OK, rv); | 1836 EXPECT_EQ(OK, rv); |
| 1804 | 1837 |
| 1805 EXPECT_TRUE(info2.is_direct()); | 1838 EXPECT_TRUE(info2.is_direct()); |
| 1806 } | 1839 } |
| 1807 | 1840 |
| 1808 TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { | 1841 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { |
| 1809 MockProxyConfigService* config_service = | 1842 MockProxyConfigService* config_service = |
| 1810 new MockProxyConfigService("http://foopy/proxy.pac"); | 1843 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1811 | 1844 |
| 1812 MockAsyncProxyResolverExpectsBytes* resolver = | 1845 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1813 new MockAsyncProxyResolverExpectsBytes; | 1846 new MockAsyncProxyResolverExpectsBytes; |
| 1814 | 1847 |
| 1815 CapturingNetLog log(CapturingNetLog::kUnbounded); | 1848 CapturingNetLog log(CapturingNetLog::kUnbounded); |
| 1816 | 1849 |
| 1817 ProxyService service(config_service, resolver, &log); | 1850 ProxyService service(config_service, resolver, &log); |
| 1818 | 1851 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1909 CapturingNetLog::EntryList entries; | 1942 CapturingNetLog::EntryList entries; |
| 1910 log.GetEntries(&entries); | 1943 log.GetEntries(&entries); |
| 1911 | 1944 |
| 1912 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, | 1945 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, |
| 1913 NetLog::TYPE_PROXY_CONFIG_CHANGED)); | 1946 NetLog::TYPE_PROXY_CONFIG_CHANGED)); |
| 1914 ASSERT_EQ(9u, entries.size()); | 1947 ASSERT_EQ(9u, entries.size()); |
| 1915 for (size_t i = 1; i < entries.size(); ++i) | 1948 for (size_t i = 1; i < entries.size(); ++i) |
| 1916 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); | 1949 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); |
| 1917 } | 1950 } |
| 1918 | 1951 |
| 1952 // This test verifies that the PAC script specified by the settings is | |
| 1953 // periodically polled for changes. Specifically, if the initial fetch fails due | |
| 1954 // to a network error, we will eventually re-configure the service to use the | |
| 1955 // script once it becomes available. | |
| 1956 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) { | |
|
wtc
2012/01/03 23:54:45
I didn't review the unit tests carefully. I merel
eroman
2012/01/04 03:41:47
Sounds good, I'll leave that to a follow-up change
| |
| 1957 // Change the retry policy to wait a mere 1 ms before retrying, so the test | |
| 1958 // runs quickly. | |
| 1959 ProxyService::set_pac_script_poll_policy( | |
| 1960 ProxyService::POLL_POLICY_IMMEDIATE); | |
| 1961 | |
| 1962 MockProxyConfigService* config_service = | |
| 1963 new MockProxyConfigService("http://foopy/proxy.pac"); | |
| 1964 | |
| 1965 MockAsyncProxyResolverExpectsBytes* resolver = | |
| 1966 new MockAsyncProxyResolverExpectsBytes; | |
| 1967 | |
| 1968 CapturingNetLog log(CapturingNetLog::kUnbounded); | |
| 1969 | |
| 1970 ProxyService service(config_service, resolver, &log); | |
| 1971 | |
| 1972 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | |
| 1973 service.SetProxyScriptFetchers(fetcher, | |
| 1974 new DoNothingDhcpProxyScriptFetcher()); | |
| 1975 | |
| 1976 // Start 1 request. | |
| 1977 | |
| 1978 ProxyInfo info1; | |
| 1979 TestCompletionCallback callback1; | |
| 1980 int rv = service.ResolveProxy( | |
| 1981 GURL("http://request1"), &info1, callback1.callback(), | |
| 1982 NULL, BoundNetLog()); | |
| 1983 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 1984 | |
| 1985 // The first request should have triggered initial download of PAC script. | |
| 1986 EXPECT_TRUE(fetcher->has_pending_request()); | |
| 1987 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | |
| 1988 | |
| 1989 // Nothing has been sent to the resolver yet. | |
| 1990 EXPECT_TRUE(resolver->pending_requests().empty()); | |
| 1991 | |
| 1992 // At this point the ProxyService should be waiting for the | |
| 1993 // ProxyScriptFetcher to invoke its completion callback, notifying it of | |
| 1994 // PAC script download completion. | |
| 1995 // | |
| 1996 // We simulate a failed download attempt, the proxy service should now | |
| 1997 // fall-back to DIRECT connections. | |
| 1998 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); | |
| 1999 | |
| 2000 ASSERT_TRUE(resolver->pending_requests().empty()); | |
| 2001 | |
| 2002 // Wait for completion callback, and verify it used DIRECT. | |
| 2003 EXPECT_EQ(OK, callback1.WaitForResult()); | |
| 2004 EXPECT_TRUE(info1.is_direct()); | |
| 2005 | |
| 2006 // At this point we have initialized the proxy service using a PAC script, | |
| 2007 // however it failed and fell-back to DIRECT. | |
| 2008 // | |
| 2009 // A background task to periodically re-check the PAC script for validity will | |
| 2010 // have been started. We will now wait for the next download attempt to start. | |
| 2011 // | |
| 2012 // Note that we shouldn't have to wait long here, since our test enables a | |
| 2013 // special unit-test mode. | |
| 2014 fetcher->WaitUntilFetch(); | |
| 2015 | |
| 2016 ASSERT_TRUE(resolver->pending_requests().empty()); | |
| 2017 | |
| 2018 // Make sure that our background checker is trying to download the expected | |
| 2019 // PAC script (same one as before). This time we will simulate a successful | |
| 2020 // download of the script. | |
| 2021 EXPECT_TRUE(fetcher->has_pending_request()); | |
| 2022 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | |
| 2023 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | |
| 2024 | |
| 2025 MessageLoop::current()->RunAllPending(); | |
| 2026 | |
| 2027 // Now that the PAC script is downloaded, it should be used to initialize the | |
| 2028 // ProxyResolver. Simulate a successful parse. | |
| 2029 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | |
| 2030 resolver->pending_set_pac_script_request()->script_data()->utf16()); | |
| 2031 resolver->pending_set_pac_script_request()->CompleteNow(OK); | |
| 2032 | |
| 2033 // At this point the ProxyService should have re-configured itself to use the | |
| 2034 // PAC script (thereby recovering from the initial fetch failure). We will | |
| 2035 // verify that the next Resolve request uses the resolver rather than | |
| 2036 // DIRECT. | |
| 2037 | |
| 2038 // Start a second request. | |
| 2039 ProxyInfo info2; | |
| 2040 TestCompletionCallback callback2; | |
| 2041 rv = service.ResolveProxy( | |
| 2042 GURL("http://request2"), &info2, callback2.callback(), NULL, | |
| 2043 BoundNetLog()); | |
| 2044 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 2045 | |
| 2046 // Check that it was sent to the resolver. | |
| 2047 ASSERT_EQ(1u, resolver->pending_requests().size()); | |
| 2048 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | |
| 2049 | |
| 2050 // Complete the pending second request. | |
| 2051 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | |
| 2052 resolver->pending_requests()[0]->CompleteNow(OK); | |
| 2053 | |
| 2054 // Wait for completion callback, and verify that the request ran as expected. | |
| 2055 EXPECT_EQ(OK, callback2.WaitForResult()); | |
| 2056 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | |
| 2057 } | |
| 2058 | |
| 2059 // This test verifies that the PAC script specified by the settings is | |
| 2060 // periodically polled for changes. Specifically, if the initial fetch succeeds, | |
| 2061 // however at a later time its *contents* change, we will eventually | |
| 2062 // re-configure the service to use the new script. | |
| 2063 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentChange) { | |
| 2064 // Change the retry policy to wait a mere 1 ms before retrying, so the test | |
| 2065 // runs quickly. | |
| 2066 ProxyService::set_pac_script_poll_policy( | |
| 2067 ProxyService::POLL_POLICY_IMMEDIATE); | |
| 2068 | |
| 2069 MockProxyConfigService* config_service = | |
| 2070 new MockProxyConfigService("http://foopy/proxy.pac"); | |
| 2071 | |
| 2072 MockAsyncProxyResolverExpectsBytes* resolver = | |
| 2073 new MockAsyncProxyResolverExpectsBytes; | |
| 2074 | |
| 2075 CapturingNetLog log(CapturingNetLog::kUnbounded); | |
| 2076 | |
| 2077 ProxyService service(config_service, resolver, &log); | |
| 2078 | |
| 2079 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | |
| 2080 service.SetProxyScriptFetchers(fetcher, | |
| 2081 new DoNothingDhcpProxyScriptFetcher()); | |
| 2082 | |
| 2083 // Start 1 request. | |
| 2084 | |
| 2085 ProxyInfo info1; | |
| 2086 TestCompletionCallback callback1; | |
| 2087 int rv = service.ResolveProxy( | |
| 2088 GURL("http://request1"), &info1, callback1.callback(), NULL, | |
| 2089 BoundNetLog()); | |
| 2090 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 2091 | |
| 2092 // The first request should have triggered initial download of PAC script. | |
| 2093 EXPECT_TRUE(fetcher->has_pending_request()); | |
| 2094 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | |
| 2095 | |
| 2096 // Nothing has been sent to the resolver yet. | |
| 2097 EXPECT_TRUE(resolver->pending_requests().empty()); | |
| 2098 | |
| 2099 // At this point the ProxyService should be waiting for the | |
| 2100 // ProxyScriptFetcher to invoke its completion callback, notifying it of | |
| 2101 // PAC script download completion. | |
| 2102 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | |
| 2103 | |
| 2104 // Now that the PAC script is downloaded, the request will have been sent to | |
| 2105 // the proxy resolver. | |
| 2106 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | |
| 2107 resolver->pending_set_pac_script_request()->script_data()->utf16()); | |
| 2108 resolver->pending_set_pac_script_request()->CompleteNow(OK); | |
| 2109 | |
| 2110 ASSERT_EQ(1u, resolver->pending_requests().size()); | |
| 2111 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | |
| 2112 | |
| 2113 // Complete the pending request. | |
| 2114 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | |
| 2115 resolver->pending_requests()[0]->CompleteNow(OK); | |
| 2116 | |
| 2117 // Wait for completion callback, and verify that the request ran as expected. | |
| 2118 EXPECT_EQ(OK, callback1.WaitForResult()); | |
| 2119 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | |
| 2120 | |
| 2121 // At this point we have initialized the proxy service using a PAC script. | |
| 2122 // | |
| 2123 // A background task to periodically re-check the PAC script for validity will | |
| 2124 // have been started. We will now wait for the next download attempt to start. | |
| 2125 // | |
| 2126 // Note that we shouldn't have to wait long here, since our test enables a | |
| 2127 // special unit-test mode. | |
| 2128 fetcher->WaitUntilFetch(); | |
| 2129 | |
| 2130 ASSERT_TRUE(resolver->pending_requests().empty()); | |
| 2131 | |
| 2132 // Make sure that our background checker is trying to download the expected | |
| 2133 // PAC script (same one as before). This time we will simulate a successful | |
| 2134 // download of a DIFFERENT script. | |
| 2135 EXPECT_TRUE(fetcher->has_pending_request()); | |
| 2136 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | |
| 2137 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); | |
| 2138 | |
| 2139 MessageLoop::current()->RunAllPending(); | |
| 2140 | |
| 2141 // Now that the PAC script is downloaded, it should be used to initialize the | |
| 2142 // ProxyResolver. Simulate a successful parse. | |
| 2143 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | |
| 2144 resolver->pending_set_pac_script_request()->script_data()->utf16()); | |
| 2145 resolver->pending_set_pac_script_request()->CompleteNow(OK); | |
| 2146 | |
| 2147 // At this point the ProxyService should have re-configured itself to use the | |
| 2148 // new PAC script. | |
| 2149 | |
| 2150 // Start a second request. | |
| 2151 ProxyInfo info2; | |
| 2152 TestCompletionCallback callback2; | |
| 2153 rv = service.ResolveProxy( | |
| 2154 GURL("http://request2"), &info2, callback2.callback(), NULL, | |
| 2155 BoundNetLog()); | |
| 2156 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 2157 | |
| 2158 // Check that it was sent to the resolver. | |
| 2159 ASSERT_EQ(1u, resolver->pending_requests().size()); | |
| 2160 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | |
| 2161 | |
| 2162 // Complete the pending second request. | |
| 2163 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | |
| 2164 resolver->pending_requests()[0]->CompleteNow(OK); | |
| 2165 | |
| 2166 // Wait for completion callback, and verify that the request ran as expected. | |
| 2167 EXPECT_EQ(OK, callback2.WaitForResult()); | |
| 2168 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | |
| 2169 } | |
| 2170 | |
| 2171 // This test verifies that the PAC script specified by the settings is | |
| 2172 // periodically polled for changes. Specifically, if the initial fetch succeeds | |
| 2173 // and so does the next poll, however the contents of the downloaded script | |
| 2174 // have NOT changed, then we do not bother to re-initialize the proxy resolver. | |
| 2175 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentUnchanged) { | |
| 2176 // Change the retry policy to wait a mere 1 ms before retrying, so the test | |
| 2177 // runs quickly. | |
| 2178 ProxyService::set_pac_script_poll_policy( | |
| 2179 ProxyService::POLL_POLICY_IMMEDIATE); | |
| 2180 | |
| 2181 MockProxyConfigService* config_service = | |
| 2182 new MockProxyConfigService("http://foopy/proxy.pac"); | |
| 2183 | |
| 2184 MockAsyncProxyResolverExpectsBytes* resolver = | |
| 2185 new MockAsyncProxyResolverExpectsBytes; | |
| 2186 | |
| 2187 CapturingNetLog log(CapturingNetLog::kUnbounded); | |
| 2188 | |
| 2189 ProxyService service(config_service, resolver, &log); | |
| 2190 | |
| 2191 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | |
| 2192 service.SetProxyScriptFetchers(fetcher, | |
| 2193 new DoNothingDhcpProxyScriptFetcher()); | |
| 2194 | |
| 2195 // Start 1 request. | |
| 2196 | |
| 2197 ProxyInfo info1; | |
| 2198 TestCompletionCallback callback1; | |
| 2199 int rv = service.ResolveProxy( | |
| 2200 GURL("http://request1"), &info1, callback1.callback(), NULL, | |
| 2201 BoundNetLog()); | |
| 2202 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 2203 | |
| 2204 // The first request should have triggered initial download of PAC script. | |
| 2205 EXPECT_TRUE(fetcher->has_pending_request()); | |
| 2206 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | |
| 2207 | |
| 2208 // Nothing has been sent to the resolver yet. | |
| 2209 EXPECT_TRUE(resolver->pending_requests().empty()); | |
| 2210 | |
| 2211 // At this point the ProxyService should be waiting for the | |
| 2212 // ProxyScriptFetcher to invoke its completion callback, notifying it of | |
| 2213 // PAC script download completion. | |
| 2214 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | |
| 2215 | |
| 2216 // Now that the PAC script is downloaded, the request will have been sent to | |
| 2217 // the proxy resolver. | |
| 2218 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | |
| 2219 resolver->pending_set_pac_script_request()->script_data()->utf16()); | |
| 2220 resolver->pending_set_pac_script_request()->CompleteNow(OK); | |
| 2221 | |
| 2222 ASSERT_EQ(1u, resolver->pending_requests().size()); | |
| 2223 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | |
| 2224 | |
| 2225 // Complete the pending request. | |
| 2226 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | |
| 2227 resolver->pending_requests()[0]->CompleteNow(OK); | |
| 2228 | |
| 2229 // Wait for completion callback, and verify that the request ran as expected. | |
| 2230 EXPECT_EQ(OK, callback1.WaitForResult()); | |
| 2231 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | |
| 2232 | |
| 2233 // At this point we have initialized the proxy service using a PAC script. | |
| 2234 // | |
| 2235 // A background task to periodically re-check the PAC script for validity will | |
| 2236 // have been started. We will now wait for the next download attempt to start. | |
| 2237 // | |
| 2238 // Note that we shouldn't have to wait long here, since our test enables a | |
| 2239 // special unit-test mode. | |
| 2240 fetcher->WaitUntilFetch(); | |
| 2241 | |
| 2242 ASSERT_TRUE(resolver->pending_requests().empty()); | |
| 2243 | |
| 2244 // Make sure that our background checker is trying to download the expected | |
| 2245 // PAC script (same one as before). We will simulate the same response as | |
| 2246 // last time (i.e. the script is unchanged). | |
| 2247 EXPECT_TRUE(fetcher->has_pending_request()); | |
| 2248 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | |
| 2249 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | |
| 2250 | |
| 2251 MessageLoop::current()->RunAllPending(); | |
| 2252 | |
| 2253 ASSERT_FALSE(resolver->has_pending_set_pac_script_request()); | |
| 2254 | |
| 2255 // At this point the ProxyService is still running the same PAC script as | |
| 2256 // before. | |
| 2257 | |
| 2258 // Start a second request. | |
| 2259 ProxyInfo info2; | |
| 2260 TestCompletionCallback callback2; | |
| 2261 rv = service.ResolveProxy( | |
| 2262 GURL("http://request2"), &info2, callback2.callback(), NULL, | |
| 2263 BoundNetLog()); | |
| 2264 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 2265 | |
| 2266 // Check that it was sent to the resolver. | |
| 2267 ASSERT_EQ(1u, resolver->pending_requests().size()); | |
| 2268 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | |
| 2269 | |
| 2270 // Complete the pending second request. | |
| 2271 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | |
| 2272 resolver->pending_requests()[0]->CompleteNow(OK); | |
| 2273 | |
| 2274 // Wait for completion callback, and verify that the request ran as expected. | |
| 2275 EXPECT_EQ(OK, callback2.WaitForResult()); | |
| 2276 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | |
| 2277 } | |
| 2278 | |
| 2279 // This test verifies that the PAC script specified by the settings is | |
| 2280 // periodically polled for changes. Specifically, if the initial fetch succeeds, | |
| 2281 // however at a later time it starts to fail, we should re-configure the | |
| 2282 // ProxyService to stop using that PAC script. | |
| 2283 TEST_F(ProxyServiceTest, PACScriptRefetchAfterSuccess) { | |
| 2284 // Change the retry policy to wait a mere 1 ms before retrying, so the test | |
| 2285 // runs quickly. | |
| 2286 ProxyService::set_pac_script_poll_policy( | |
| 2287 ProxyService::POLL_POLICY_IMMEDIATE); | |
| 2288 | |
| 2289 MockProxyConfigService* config_service = | |
| 2290 new MockProxyConfigService("http://foopy/proxy.pac"); | |
| 2291 | |
| 2292 MockAsyncProxyResolverExpectsBytes* resolver = | |
| 2293 new MockAsyncProxyResolverExpectsBytes; | |
| 2294 | |
| 2295 CapturingNetLog log(CapturingNetLog::kUnbounded); | |
| 2296 | |
| 2297 ProxyService service(config_service, resolver, &log); | |
| 2298 | |
| 2299 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | |
| 2300 service.SetProxyScriptFetchers(fetcher, | |
| 2301 new DoNothingDhcpProxyScriptFetcher()); | |
| 2302 | |
| 2303 // Start 1 request. | |
| 2304 | |
| 2305 ProxyInfo info1; | |
| 2306 TestCompletionCallback callback1; | |
| 2307 int rv = service.ResolveProxy( | |
| 2308 GURL("http://request1"), &info1, callback1.callback(), NULL, | |
| 2309 BoundNetLog()); | |
| 2310 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 2311 | |
| 2312 // The first request should have triggered initial download of PAC script. | |
| 2313 EXPECT_TRUE(fetcher->has_pending_request()); | |
| 2314 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | |
| 2315 | |
| 2316 // Nothing has been sent to the resolver yet. | |
| 2317 EXPECT_TRUE(resolver->pending_requests().empty()); | |
| 2318 | |
| 2319 // At this point the ProxyService should be waiting for the | |
| 2320 // ProxyScriptFetcher to invoke its completion callback, notifying it of | |
| 2321 // PAC script download completion. | |
| 2322 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | |
| 2323 | |
| 2324 // Now that the PAC script is downloaded, the request will have been sent to | |
| 2325 // the proxy resolver. | |
| 2326 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | |
| 2327 resolver->pending_set_pac_script_request()->script_data()->utf16()); | |
| 2328 resolver->pending_set_pac_script_request()->CompleteNow(OK); | |
| 2329 | |
| 2330 ASSERT_EQ(1u, resolver->pending_requests().size()); | |
| 2331 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | |
| 2332 | |
| 2333 // Complete the pending request. | |
| 2334 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | |
| 2335 resolver->pending_requests()[0]->CompleteNow(OK); | |
| 2336 | |
| 2337 // Wait for completion callback, and verify that the request ran as expected. | |
| 2338 EXPECT_EQ(OK, callback1.WaitForResult()); | |
| 2339 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | |
| 2340 | |
| 2341 // At this point we have initialized the proxy service using a PAC script. | |
| 2342 // | |
| 2343 // A background task to periodically re-check the PAC script for validity will | |
| 2344 // have been started. We will now wait for the next download attempt to start. | |
| 2345 // | |
| 2346 // Note that we shouldn't have to wait long here, since our test enables a | |
| 2347 // special unit-test mode. | |
| 2348 fetcher->WaitUntilFetch(); | |
| 2349 | |
| 2350 ASSERT_TRUE(resolver->pending_requests().empty()); | |
| 2351 | |
| 2352 // Make sure that our background checker is trying to download the expected | |
| 2353 // PAC script (same one as before). This time we will simulate a failure | |
| 2354 // to download the script. | |
| 2355 EXPECT_TRUE(fetcher->has_pending_request()); | |
| 2356 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | |
| 2357 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); | |
| 2358 | |
| 2359 MessageLoop::current()->RunAllPending(); | |
| 2360 | |
| 2361 // At this point the ProxyService should have re-configured itself to use | |
| 2362 // DIRECT connections rather than the given proxy resolver. | |
| 2363 | |
| 2364 // Start a second request. | |
| 2365 ProxyInfo info2; | |
| 2366 TestCompletionCallback callback2; | |
| 2367 rv = service.ResolveProxy( | |
| 2368 GURL("http://request2"), &info2, callback2.callback(), NULL, | |
| 2369 BoundNetLog()); | |
| 2370 EXPECT_EQ(OK, rv); | |
| 2371 EXPECT_TRUE(info2.is_direct()); | |
| 2372 } | |
| 2373 | |
| 1919 } // namespace net | 2374 } // namespace net |
| OLD | NEW |