| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 polling policy will decide to poll every 1 ms. |
| 32 class ImmediatePollPolicy : public ProxyService::PacPollPolicy { |
| 33 public: |
| 34 ImmediatePollPolicy() {} |
| 35 |
| 36 virtual Mode GetInitialDelay(int error, int64* next_delay_ms) const OVERRIDE { |
| 37 *next_delay_ms = 1; |
| 38 return MODE_USE_TIMER; |
| 39 } |
| 40 |
| 41 virtual Mode GetNextDelay(int64 current_delay_ms, |
| 42 int64* next_delay_ms) const OVERRIDE { |
| 43 return GetInitialDelay(OK, next_delay_ms); |
| 44 } |
| 45 |
| 46 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(ImmediatePollPolicy); |
| 48 }; |
| 49 |
| 50 // This polling policy chooses a fantastically large delay. In other words, it |
| 51 // will never trigger a poll |
| 52 class NeverPollPolicy : public ProxyService::PacPollPolicy { |
| 53 public: |
| 54 NeverPollPolicy() {} |
| 55 |
| 56 virtual Mode GetInitialDelay(int error, int64* next_delay_ms) const OVERRIDE { |
| 57 *next_delay_ms = 0xFFFFFFFF; // Big number of milliseconds! |
| 58 return MODE_USE_TIMER; |
| 59 } |
| 60 |
| 61 virtual Mode GetNextDelay(int64 current_delay_ms, |
| 62 int64* next_delay_ms) const OVERRIDE { |
| 63 return GetInitialDelay(OK, next_delay_ms); |
| 64 } |
| 65 |
| 66 private: |
| 67 DISALLOW_COPY_AND_ASSIGN(NeverPollPolicy); |
| 68 }; |
| 69 |
| 70 // This polling policy starts a poll immediately after network activity. |
| 71 class ImmediateAfterActivityPollPolicy : public ProxyService::PacPollPolicy { |
| 72 public: |
| 73 ImmediateAfterActivityPollPolicy() {} |
| 74 |
| 75 virtual Mode GetInitialDelay(int error, int64* next_delay_ms) const OVERRIDE { |
| 76 *next_delay_ms = 0; |
| 77 return MODE_START_AFTER_ACTIVITY; |
| 78 } |
| 79 |
| 80 virtual Mode GetNextDelay(int64 current_delay_ms, |
| 81 int64* next_delay_ms) const OVERRIDE { |
| 82 return GetInitialDelay(OK, next_delay_ms); |
| 83 } |
| 84 |
| 85 private: |
| 86 DISALLOW_COPY_AND_ASSIGN(ImmediateAfterActivityPollPolicy); |
| 87 }; |
| 88 |
| 31 // This test fixture is used to partially disable the background polling done by | 89 // 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 | 90 // the ProxyService (which it uses to detect whenever its PAC script contents or |
| 33 // WPAD results have changed). | 91 // WPAD results have changed). |
| 34 // | 92 // |
| 35 // We disable the feature by setting the poll interval to something really | 93 // 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 | 94 // large, so it will never actually be reached even on the slowest bots that run |
| 37 // these tests. | 95 // these tests. |
| 38 // | 96 // |
| 39 // We disable the polling in order to avoid any timing dependencies in the | 97 // 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 | 98 // tests. If the bot were to run the tests very slowly and we hadn't disabled |
| 41 // polling, then it might start a background re-try in the middle of our test | 99 // polling, then it might start a background re-try in the middle of our test |
| 42 // and confuse our expectations leading to flaky failures. | 100 // and confuse our expectations leading to flaky failures. |
| 43 // | 101 // |
| 44 // The tests which verify the polling code re-enable the polling behavior but | 102 // The tests which verify the polling code re-enable the polling behavior but |
| 45 // are careful to avoid timing problems. | 103 // are careful to avoid timing problems. |
| 46 class ProxyServiceTest : public testing::Test { | 104 class ProxyServiceTest : public testing::Test { |
| 47 protected: | 105 protected: |
| 48 virtual void SetUp() OVERRIDE { | 106 virtual void SetUp() OVERRIDE { |
| 49 testing::Test::SetUp(); | 107 testing::Test::SetUp(); |
| 50 previous_policy_ = ProxyService::set_pac_script_poll_policy( | 108 previous_policy_ = |
| 51 ProxyService::POLL_POLICY_NEVER); | 109 ProxyService::set_pac_script_poll_policy(&never_poll_policy_); |
| 52 } | 110 } |
| 53 | 111 |
| 54 virtual void TearDown() OVERRIDE { | 112 virtual void TearDown() OVERRIDE { |
| 55 // Restore the original policy. | 113 // Restore the original policy. |
| 56 ProxyService::set_pac_script_poll_policy(previous_policy_); | 114 ProxyService::set_pac_script_poll_policy(previous_policy_); |
| 57 testing::Test::TearDown(); | 115 testing::Test::TearDown(); |
| 58 } | 116 } |
| 59 | 117 |
| 60 ProxyService::PollPolicy previous_policy_; | 118 private: |
| 119 NeverPollPolicy never_poll_policy_; |
| 120 const ProxyService::PacPollPolicy* previous_policy_; |
| 61 }; | 121 }; |
| 62 | 122 |
| 63 const char kValidPacScript1[] = "pac-script-v1-FindProxyForURL"; | 123 const char kValidPacScript1[] = "pac-script-v1-FindProxyForURL"; |
| 64 const char kValidPacScript2[] = "pac-script-v2-FindProxyForURL"; | 124 const char kValidPacScript2[] = "pac-script-v2-FindProxyForURL"; |
| 65 | 125 |
| 66 class MockProxyConfigService: public ProxyConfigService { | 126 class MockProxyConfigService: public ProxyConfigService { |
| 67 public: | 127 public: |
| 68 explicit MockProxyConfigService(const ProxyConfig& config) | 128 explicit MockProxyConfigService(const ProxyConfig& config) |
| 69 : availability_(CONFIG_VALID), | 129 : availability_(CONFIG_VALID), |
| 70 config_(config) { | 130 config_(config) { |
| (...skipping 1878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1949 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); | 2009 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); |
| 1950 } | 2010 } |
| 1951 | 2011 |
| 1952 // This test verifies that the PAC script specified by the settings is | 2012 // This test verifies that the PAC script specified by the settings is |
| 1953 // periodically polled for changes. Specifically, if the initial fetch fails due | 2013 // 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 | 2014 // to a network error, we will eventually re-configure the service to use the |
| 1955 // script once it becomes available. | 2015 // script once it becomes available. |
| 1956 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) { | 2016 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) { |
| 1957 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 2017 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
| 1958 // runs quickly. | 2018 // runs quickly. |
| 1959 ProxyService::set_pac_script_poll_policy( | 2019 ImmediatePollPolicy poll_policy; |
| 1960 ProxyService::POLL_POLICY_IMMEDIATE); | 2020 ProxyService::set_pac_script_poll_policy(&poll_policy); |
| 1961 | 2021 |
| 1962 MockProxyConfigService* config_service = | 2022 MockProxyConfigService* config_service = |
| 1963 new MockProxyConfigService("http://foopy/proxy.pac"); | 2023 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1964 | 2024 |
| 1965 MockAsyncProxyResolverExpectsBytes* resolver = | 2025 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1966 new MockAsyncProxyResolverExpectsBytes; | 2026 new MockAsyncProxyResolverExpectsBytes; |
| 1967 | 2027 |
| 1968 CapturingNetLog log(CapturingNetLog::kUnbounded); | 2028 CapturingNetLog log(CapturingNetLog::kUnbounded); |
| 1969 | 2029 |
| 1970 ProxyService service(config_service, resolver, &log); | 2030 ProxyService service(config_service, resolver, &log); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2056 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2116 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 2057 } | 2117 } |
| 2058 | 2118 |
| 2059 // This test verifies that the PAC script specified by the settings is | 2119 // This test verifies that the PAC script specified by the settings is |
| 2060 // periodically polled for changes. Specifically, if the initial fetch succeeds, | 2120 // periodically polled for changes. Specifically, if the initial fetch succeeds, |
| 2061 // however at a later time its *contents* change, we will eventually | 2121 // however at a later time its *contents* change, we will eventually |
| 2062 // re-configure the service to use the new script. | 2122 // re-configure the service to use the new script. |
| 2063 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentChange) { | 2123 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentChange) { |
| 2064 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 2124 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
| 2065 // runs quickly. | 2125 // runs quickly. |
| 2066 ProxyService::set_pac_script_poll_policy( | 2126 ImmediatePollPolicy poll_policy; |
| 2067 ProxyService::POLL_POLICY_IMMEDIATE); | 2127 ProxyService::set_pac_script_poll_policy(&poll_policy); |
| 2068 | 2128 |
| 2069 MockProxyConfigService* config_service = | 2129 MockProxyConfigService* config_service = |
| 2070 new MockProxyConfigService("http://foopy/proxy.pac"); | 2130 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2071 | 2131 |
| 2072 MockAsyncProxyResolverExpectsBytes* resolver = | 2132 MockAsyncProxyResolverExpectsBytes* resolver = |
| 2073 new MockAsyncProxyResolverExpectsBytes; | 2133 new MockAsyncProxyResolverExpectsBytes; |
| 2074 | 2134 |
| 2075 CapturingNetLog log(CapturingNetLog::kUnbounded); | 2135 CapturingNetLog log(CapturingNetLog::kUnbounded); |
| 2076 | 2136 |
| 2077 ProxyService service(config_service, resolver, &log); | 2137 ProxyService service(config_service, resolver, &log); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2168 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2228 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 2169 } | 2229 } |
| 2170 | 2230 |
| 2171 // This test verifies that the PAC script specified by the settings is | 2231 // This test verifies that the PAC script specified by the settings is |
| 2172 // periodically polled for changes. Specifically, if the initial fetch succeeds | 2232 // periodically polled for changes. Specifically, if the initial fetch succeeds |
| 2173 // and so does the next poll, however the contents of the downloaded script | 2233 // 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. | 2234 // have NOT changed, then we do not bother to re-initialize the proxy resolver. |
| 2175 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentUnchanged) { | 2235 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentUnchanged) { |
| 2176 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 2236 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
| 2177 // runs quickly. | 2237 // runs quickly. |
| 2178 ProxyService::set_pac_script_poll_policy( | 2238 ImmediatePollPolicy poll_policy; |
| 2179 ProxyService::POLL_POLICY_IMMEDIATE); | 2239 ProxyService::set_pac_script_poll_policy(&poll_policy); |
| 2180 | 2240 |
| 2181 MockProxyConfigService* config_service = | 2241 MockProxyConfigService* config_service = |
| 2182 new MockProxyConfigService("http://foopy/proxy.pac"); | 2242 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2183 | 2243 |
| 2184 MockAsyncProxyResolverExpectsBytes* resolver = | 2244 MockAsyncProxyResolverExpectsBytes* resolver = |
| 2185 new MockAsyncProxyResolverExpectsBytes; | 2245 new MockAsyncProxyResolverExpectsBytes; |
| 2186 | 2246 |
| 2187 CapturingNetLog log(CapturingNetLog::kUnbounded); | 2247 CapturingNetLog log(CapturingNetLog::kUnbounded); |
| 2188 | 2248 |
| 2189 ProxyService service(config_service, resolver, &log); | 2249 ProxyService service(config_service, resolver, &log); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2276 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2336 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 2277 } | 2337 } |
| 2278 | 2338 |
| 2279 // This test verifies that the PAC script specified by the settings is | 2339 // This test verifies that the PAC script specified by the settings is |
| 2280 // periodically polled for changes. Specifically, if the initial fetch succeeds, | 2340 // 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 | 2341 // however at a later time it starts to fail, we should re-configure the |
| 2282 // ProxyService to stop using that PAC script. | 2342 // ProxyService to stop using that PAC script. |
| 2283 TEST_F(ProxyServiceTest, PACScriptRefetchAfterSuccess) { | 2343 TEST_F(ProxyServiceTest, PACScriptRefetchAfterSuccess) { |
| 2284 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 2344 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
| 2285 // runs quickly. | 2345 // runs quickly. |
| 2286 ProxyService::set_pac_script_poll_policy( | 2346 ImmediatePollPolicy poll_policy; |
| 2287 ProxyService::POLL_POLICY_IMMEDIATE); | 2347 ProxyService::set_pac_script_poll_policy(&poll_policy); |
| 2288 | 2348 |
| 2289 MockProxyConfigService* config_service = | 2349 MockProxyConfigService* config_service = |
| 2290 new MockProxyConfigService("http://foopy/proxy.pac"); | 2350 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2291 | 2351 |
| 2292 MockAsyncProxyResolverExpectsBytes* resolver = | 2352 MockAsyncProxyResolverExpectsBytes* resolver = |
| 2293 new MockAsyncProxyResolverExpectsBytes; | 2353 new MockAsyncProxyResolverExpectsBytes; |
| 2294 | 2354 |
| 2295 CapturingNetLog log(CapturingNetLog::kUnbounded); | 2355 CapturingNetLog log(CapturingNetLog::kUnbounded); |
| 2296 | 2356 |
| 2297 ProxyService service(config_service, resolver, &log); | 2357 ProxyService service(config_service, resolver, &log); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2364 // Start a second request. | 2424 // Start a second request. |
| 2365 ProxyInfo info2; | 2425 ProxyInfo info2; |
| 2366 TestCompletionCallback callback2; | 2426 TestCompletionCallback callback2; |
| 2367 rv = service.ResolveProxy( | 2427 rv = service.ResolveProxy( |
| 2368 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2428 GURL("http://request2"), &info2, callback2.callback(), NULL, |
| 2369 BoundNetLog()); | 2429 BoundNetLog()); |
| 2370 EXPECT_EQ(OK, rv); | 2430 EXPECT_EQ(OK, rv); |
| 2371 EXPECT_TRUE(info2.is_direct()); | 2431 EXPECT_TRUE(info2.is_direct()); |
| 2372 } | 2432 } |
| 2373 | 2433 |
| 2434 // Tests that the code which decides at what times to poll the PAC |
| 2435 // script follows the expected policy. |
| 2436 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { |
| 2437 // Retrieve the internal polling policy implementation used by ProxyService. |
| 2438 scoped_ptr<ProxyService::PacPollPolicy> policy = |
| 2439 ProxyService::CreateDefaultPacPollPolicy(); |
| 2440 |
| 2441 ProxyService::PacPollPolicy::Mode mode; |
| 2442 int64 delay_ms = -1; |
| 2443 |
| 2444 // After a failure, we should start polling at 4 seconds. |
| 2445 mode = policy->GetInitialDelay(ERR_FAILED, &delay_ms); |
| 2446 EXPECT_EQ(4000, delay_ms); |
| 2447 EXPECT_EQ(ProxyService::PacPollPolicy::MODE_USE_TIMER, mode); |
| 2448 |
| 2449 // After a success, we should start polling at 16 seconds. |
| 2450 mode = policy->GetInitialDelay(OK, &delay_ms); |
| 2451 EXPECT_EQ(16000, delay_ms); |
| 2452 EXPECT_EQ(ProxyService::PacPollPolicy::MODE_USE_TIMER, mode); |
| 2453 |
| 2454 // The delay should be doubled each time. |
| 2455 mode = policy->GetNextDelay(4000, &delay_ms); |
| 2456 EXPECT_EQ(8000, delay_ms); |
| 2457 EXPECT_EQ(ProxyService::PacPollPolicy::MODE_USE_TIMER, mode); |
| 2458 mode = policy->GetNextDelay(delay_ms, &delay_ms); |
| 2459 EXPECT_EQ(16000, delay_ms); |
| 2460 EXPECT_EQ(ProxyService::PacPollPolicy::MODE_USE_TIMER, mode); |
| 2461 |
| 2462 // Once we reach 32 seconds, the polling should stop being done using |
| 2463 // a timer, however it should keep doubling. |
| 2464 mode = policy->GetNextDelay(delay_ms, &delay_ms); |
| 2465 EXPECT_EQ(32000, delay_ms); |
| 2466 EXPECT_EQ(ProxyService::PacPollPolicy::MODE_START_AFTER_ACTIVITY, mode); |
| 2467 mode = policy->GetNextDelay(delay_ms, &delay_ms); |
| 2468 EXPECT_EQ(64000, delay_ms); |
| 2469 EXPECT_EQ(ProxyService::PacPollPolicy::MODE_START_AFTER_ACTIVITY, mode); |
| 2470 |
| 2471 // Once we reach 2 minutes, the polling delay should stop increasing. |
| 2472 mode = policy->GetNextDelay(delay_ms, &delay_ms); |
| 2473 EXPECT_EQ(120000, delay_ms); |
| 2474 EXPECT_EQ(ProxyService::PacPollPolicy::MODE_START_AFTER_ACTIVITY, mode); |
| 2475 mode = policy->GetNextDelay(delay_ms, &delay_ms); |
| 2476 EXPECT_EQ(120000, delay_ms); |
| 2477 EXPECT_EQ(ProxyService::PacPollPolicy::MODE_START_AFTER_ACTIVITY, mode); |
| 2478 } |
| 2479 |
| 2480 // This tests the polling of the PAC script. Specifically, it tests that |
| 2481 // polling occurs in response to user activity. |
| 2482 TEST_F(ProxyServiceTest, PACScriptRefetchAfterActivity) { |
| 2483 ImmediateAfterActivityPollPolicy poll_policy; |
| 2484 ProxyService::set_pac_script_poll_policy(&poll_policy); |
| 2485 |
| 2486 MockProxyConfigService* config_service = |
| 2487 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2488 |
| 2489 MockAsyncProxyResolverExpectsBytes* resolver = |
| 2490 new MockAsyncProxyResolverExpectsBytes; |
| 2491 |
| 2492 CapturingNetLog log(CapturingNetLog::kUnbounded); |
| 2493 |
| 2494 ProxyService service(config_service, resolver, &log); |
| 2495 |
| 2496 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2497 service.SetProxyScriptFetchers(fetcher, |
| 2498 new DoNothingDhcpProxyScriptFetcher()); |
| 2499 |
| 2500 // Start 1 request. |
| 2501 |
| 2502 ProxyInfo info1; |
| 2503 TestCompletionCallback callback1; |
| 2504 int rv = service.ResolveProxy( |
| 2505 GURL("http://request1"), &info1, callback1.callback(), NULL, |
| 2506 BoundNetLog()); |
| 2507 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2508 |
| 2509 // The first request should have triggered initial download of PAC script. |
| 2510 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2511 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2512 |
| 2513 // Nothing has been sent to the resolver yet. |
| 2514 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 2515 |
| 2516 // At this point the ProxyService should be waiting for the |
| 2517 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 2518 // PAC script download completion. |
| 2519 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2520 |
| 2521 // Now that the PAC script is downloaded, the request will have been sent to |
| 2522 // the proxy resolver. |
| 2523 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 2524 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
| 2525 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 2526 |
| 2527 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 2528 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 2529 |
| 2530 // Complete the pending request. |
| 2531 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 2532 resolver->pending_requests()[0]->CompleteNow(OK); |
| 2533 |
| 2534 // Wait for completion callback, and verify that the request ran as expected. |
| 2535 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 2536 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 2537 |
| 2538 // At this point we have initialized the proxy service using a PAC script. |
| 2539 // Our PAC poller is set to update ONLY in response to network activity, |
| 2540 // (i.e. another call to ResolveProxy()). |
| 2541 |
| 2542 ASSERT_FALSE(fetcher->has_pending_request()); |
| 2543 ASSERT_TRUE(resolver->pending_requests().empty()); |
| 2544 |
| 2545 // Start a second request. |
| 2546 ProxyInfo info2; |
| 2547 TestCompletionCallback callback2; |
| 2548 rv = service.ResolveProxy( |
| 2549 GURL("http://request2"), &info2, callback2.callback(), NULL, |
| 2550 BoundNetLog()); |
| 2551 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2552 |
| 2553 // This request should have sent work to the resolver; complete it. |
| 2554 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 2555 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
| 2556 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
| 2557 resolver->pending_requests()[0]->CompleteNow(OK); |
| 2558 |
| 2559 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 2560 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 2561 |
| 2562 // In response to getting that resolve request, the poller should have |
| 2563 // started the next poll, and made it as far as to request the download. |
| 2564 |
| 2565 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2566 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2567 |
| 2568 // This time we will fail the download, to simulate a PAC script change. |
| 2569 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); |
| 2570 |
| 2571 // Drain the message loop, so ProxyService is notified of the change |
| 2572 // and has a chance to re-configure itself. |
| 2573 MessageLoop::current()->RunAllPending(); |
| 2574 |
| 2575 // Start a third request -- this time we expect to get a direct connection |
| 2576 // since the PAC script poller experienced a failure. |
| 2577 ProxyInfo info3; |
| 2578 TestCompletionCallback callback3; |
| 2579 rv = service.ResolveProxy( |
| 2580 GURL("http://request3"), &info3, callback3.callback(), NULL, |
| 2581 BoundNetLog()); |
| 2582 EXPECT_EQ(OK, rv); |
| 2583 EXPECT_TRUE(info3.is_direct()); |
| 2584 } |
| 2585 |
| 2374 } // namespace net | 2586 } // namespace net |
| OLD | NEW |