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 17 matching lines...) Expand all Loading... |
28 // TODO(eroman): Write a test which exercises | 28 // TODO(eroman): Write a test which exercises |
29 // ProxyService::SuspendAllPendingRequests(). | 29 // ProxyService::SuspendAllPendingRequests(). |
30 namespace net { | 30 namespace net { |
31 namespace { | 31 namespace { |
32 | 32 |
33 // This polling policy will decide to poll every 1 ms. | 33 // This polling policy will decide to poll every 1 ms. |
34 class ImmediatePollPolicy : public ProxyService::PacPollPolicy { | 34 class ImmediatePollPolicy : public ProxyService::PacPollPolicy { |
35 public: | 35 public: |
36 ImmediatePollPolicy() {} | 36 ImmediatePollPolicy() {} |
37 | 37 |
38 virtual Mode GetNextDelay(int error, base::TimeDelta current_delay, | 38 virtual Mode GetNextDelay(int error, |
| 39 base::TimeDelta current_delay, |
39 base::TimeDelta* next_delay) const OVERRIDE { | 40 base::TimeDelta* next_delay) const OVERRIDE { |
40 *next_delay = base::TimeDelta::FromMilliseconds(1); | 41 *next_delay = base::TimeDelta::FromMilliseconds(1); |
41 return MODE_USE_TIMER; | 42 return MODE_USE_TIMER; |
42 } | 43 } |
43 | 44 |
44 private: | 45 private: |
45 DISALLOW_COPY_AND_ASSIGN(ImmediatePollPolicy); | 46 DISALLOW_COPY_AND_ASSIGN(ImmediatePollPolicy); |
46 }; | 47 }; |
47 | 48 |
48 // This polling policy chooses a fantastically large delay. In other words, it | 49 // This polling policy chooses a fantastically large delay. In other words, it |
49 // will never trigger a poll | 50 // will never trigger a poll |
50 class NeverPollPolicy : public ProxyService::PacPollPolicy { | 51 class NeverPollPolicy : public ProxyService::PacPollPolicy { |
51 public: | 52 public: |
52 NeverPollPolicy() {} | 53 NeverPollPolicy() {} |
53 | 54 |
54 virtual Mode GetNextDelay(int error, base::TimeDelta current_delay, | 55 virtual Mode GetNextDelay(int error, |
| 56 base::TimeDelta current_delay, |
55 base::TimeDelta* next_delay) const OVERRIDE { | 57 base::TimeDelta* next_delay) const OVERRIDE { |
56 *next_delay = base::TimeDelta::FromDays(60); | 58 *next_delay = base::TimeDelta::FromDays(60); |
57 return MODE_USE_TIMER; | 59 return MODE_USE_TIMER; |
58 } | 60 } |
59 | 61 |
60 private: | 62 private: |
61 DISALLOW_COPY_AND_ASSIGN(NeverPollPolicy); | 63 DISALLOW_COPY_AND_ASSIGN(NeverPollPolicy); |
62 }; | 64 }; |
63 | 65 |
64 // This polling policy starts a poll immediately after network activity. | 66 // This polling policy starts a poll immediately after network activity. |
65 class ImmediateAfterActivityPollPolicy : public ProxyService::PacPollPolicy { | 67 class ImmediateAfterActivityPollPolicy : public ProxyService::PacPollPolicy { |
66 public: | 68 public: |
67 ImmediateAfterActivityPollPolicy() {} | 69 ImmediateAfterActivityPollPolicy() {} |
68 | 70 |
69 virtual Mode GetNextDelay(int error, base::TimeDelta current_delay, | 71 virtual Mode GetNextDelay(int error, |
| 72 base::TimeDelta current_delay, |
70 base::TimeDelta* next_delay) const OVERRIDE { | 73 base::TimeDelta* next_delay) const OVERRIDE { |
71 *next_delay = base::TimeDelta(); | 74 *next_delay = base::TimeDelta(); |
72 return MODE_START_AFTER_ACTIVITY; | 75 return MODE_START_AFTER_ACTIVITY; |
73 } | 76 } |
74 | 77 |
75 private: | 78 private: |
76 DISALLOW_COPY_AND_ASSIGN(ImmediateAfterActivityPollPolicy); | 79 DISALLOW_COPY_AND_ASSIGN(ImmediateAfterActivityPollPolicy); |
77 }; | 80 }; |
78 | 81 |
79 // This test fixture is used to partially disable the background polling done by | 82 // This test fixture is used to partially disable the background polling done by |
(...skipping 26 matching lines...) Expand all Loading... |
106 } | 109 } |
107 | 110 |
108 private: | 111 private: |
109 NeverPollPolicy never_poll_policy_; | 112 NeverPollPolicy never_poll_policy_; |
110 const ProxyService::PacPollPolicy* previous_policy_; | 113 const ProxyService::PacPollPolicy* previous_policy_; |
111 }; | 114 }; |
112 | 115 |
113 const char kValidPacScript1[] = "pac-script-v1-FindProxyForURL"; | 116 const char kValidPacScript1[] = "pac-script-v1-FindProxyForURL"; |
114 const char kValidPacScript2[] = "pac-script-v2-FindProxyForURL"; | 117 const char kValidPacScript2[] = "pac-script-v2-FindProxyForURL"; |
115 | 118 |
116 class MockProxyConfigService: public ProxyConfigService { | 119 class MockProxyConfigService : public ProxyConfigService { |
117 public: | 120 public: |
118 explicit MockProxyConfigService(const ProxyConfig& config) | 121 explicit MockProxyConfigService(const ProxyConfig& config) |
119 : availability_(CONFIG_VALID), | 122 : availability_(CONFIG_VALID), config_(config) {} |
120 config_(config) { | |
121 } | |
122 | 123 |
123 explicit MockProxyConfigService(const std::string& pac_url) | 124 explicit MockProxyConfigService(const std::string& pac_url) |
124 : availability_(CONFIG_VALID), | 125 : availability_(CONFIG_VALID), |
125 config_(ProxyConfig::CreateFromCustomPacURL(GURL(pac_url))) { | 126 config_(ProxyConfig::CreateFromCustomPacURL(GURL(pac_url))) {} |
126 } | |
127 | 127 |
128 virtual void AddObserver(Observer* observer) OVERRIDE { | 128 virtual void AddObserver(Observer* observer) OVERRIDE { |
129 observers_.AddObserver(observer); | 129 observers_.AddObserver(observer); |
130 } | 130 } |
131 | 131 |
132 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 132 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
133 observers_.RemoveObserver(observer); | 133 observers_.RemoveObserver(observer); |
134 } | 134 } |
135 | 135 |
136 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* results) | 136 virtual ConfigAvailability GetLatestProxyConfig( |
137 OVERRIDE { | 137 ProxyConfig* results) OVERRIDE { |
138 if (availability_ == CONFIG_VALID) | 138 if (availability_ == CONFIG_VALID) |
139 *results = config_; | 139 *results = config_; |
140 return availability_; | 140 return availability_; |
141 } | 141 } |
142 | 142 |
143 void SetConfig(const ProxyConfig& config) { | 143 void SetConfig(const ProxyConfig& config) { |
144 availability_ = CONFIG_VALID; | 144 availability_ = CONFIG_VALID; |
145 config_ = config; | 145 config_ = config; |
146 FOR_EACH_OBSERVER(Observer, observers_, | 146 FOR_EACH_OBSERVER( |
147 OnProxyConfigChanged(config_, availability_)); | 147 Observer, observers_, OnProxyConfigChanged(config_, availability_)); |
148 } | 148 } |
149 | 149 |
150 private: | 150 private: |
151 ConfigAvailability availability_; | 151 ConfigAvailability availability_; |
152 ProxyConfig config_; | 152 ProxyConfig config_; |
153 ObserverList<Observer, true> observers_; | 153 ObserverList<Observer, true> observers_; |
154 }; | 154 }; |
155 | 155 |
156 } // namespace | 156 } // namespace |
157 | 157 |
158 TEST_F(ProxyServiceTest, Direct) { | 158 TEST_F(ProxyServiceTest, Direct) { |
159 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 159 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
160 ProxyService service(new MockProxyConfigService( | 160 ProxyService service( |
161 ProxyConfig::CreateDirect()), resolver, NULL); | 161 new MockProxyConfigService(ProxyConfig::CreateDirect()), resolver, NULL); |
162 | 162 |
163 GURL url("http://www.google.com/"); | 163 GURL url("http://www.google.com/"); |
164 | 164 |
165 ProxyInfo info; | 165 ProxyInfo info; |
166 TestCompletionCallback callback; | 166 TestCompletionCallback callback; |
167 CapturingBoundNetLog log; | 167 CapturingBoundNetLog log; |
168 int rv = service.ResolveProxy( | 168 int rv = |
169 url, &info, callback.callback(), NULL, log.bound()); | 169 service.ResolveProxy(url, &info, callback.callback(), NULL, log.bound()); |
170 EXPECT_EQ(OK, rv); | 170 EXPECT_EQ(OK, rv); |
171 EXPECT_TRUE(resolver->pending_requests().empty()); | 171 EXPECT_TRUE(resolver->pending_requests().empty()); |
172 | 172 |
173 EXPECT_TRUE(info.is_direct()); | 173 EXPECT_TRUE(info.is_direct()); |
174 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); | 174 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); |
175 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); | 175 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); |
176 | 176 |
177 // Check the NetLog was filled correctly. | 177 // Check the NetLog was filled correctly. |
178 CapturingNetLog::CapturedEntryList entries; | 178 CapturingNetLog::CapturedEntryList entries; |
179 log.GetEntries(&entries); | 179 log.GetEntries(&entries); |
180 | 180 |
181 EXPECT_EQ(3u, entries.size()); | 181 EXPECT_EQ(3u, entries.size()); |
182 EXPECT_TRUE(LogContainsBeginEvent( | 182 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, NetLog::TYPE_PROXY_SERVICE)); |
183 entries, 0, NetLog::TYPE_PROXY_SERVICE)); | 183 EXPECT_TRUE(LogContainsEvent(entries, |
184 EXPECT_TRUE(LogContainsEvent( | 184 1, |
185 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 185 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, |
186 NetLog::PHASE_NONE)); | 186 NetLog::PHASE_NONE)); |
187 EXPECT_TRUE(LogContainsEndEvent( | 187 EXPECT_TRUE(LogContainsEndEvent(entries, 2, NetLog::TYPE_PROXY_SERVICE)); |
188 entries, 2, NetLog::TYPE_PROXY_SERVICE)); | |
189 } | 188 } |
190 | 189 |
191 TEST_F(ProxyServiceTest, PAC) { | 190 TEST_F(ProxyServiceTest, PAC) { |
192 MockProxyConfigService* config_service = | 191 MockProxyConfigService* config_service = |
193 new MockProxyConfigService("http://foopy/proxy.pac"); | 192 new MockProxyConfigService("http://foopy/proxy.pac"); |
194 | 193 |
195 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 194 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
196 | 195 |
197 ProxyService service(config_service, resolver, NULL); | 196 ProxyService service(config_service, resolver, NULL); |
198 | 197 |
(...skipping 28 matching lines...) Expand all Loading... |
227 | 226 |
228 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 227 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
229 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 228 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
230 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 229 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
231 | 230 |
232 // Check the NetLog was filled correctly. | 231 // Check the NetLog was filled correctly. |
233 CapturingNetLog::CapturedEntryList entries; | 232 CapturingNetLog::CapturedEntryList entries; |
234 log.GetEntries(&entries); | 233 log.GetEntries(&entries); |
235 | 234 |
236 EXPECT_EQ(5u, entries.size()); | 235 EXPECT_EQ(5u, entries.size()); |
237 EXPECT_TRUE(LogContainsBeginEvent( | 236 EXPECT_TRUE(LogContainsBeginEvent(entries, 0, NetLog::TYPE_PROXY_SERVICE)); |
238 entries, 0, NetLog::TYPE_PROXY_SERVICE)); | |
239 EXPECT_TRUE(LogContainsBeginEvent( | 237 EXPECT_TRUE(LogContainsBeginEvent( |
240 entries, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 238 entries, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
241 EXPECT_TRUE(LogContainsEndEvent( | 239 EXPECT_TRUE(LogContainsEndEvent( |
242 entries, 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 240 entries, 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
243 EXPECT_TRUE(LogContainsEndEvent( | 241 EXPECT_TRUE(LogContainsEndEvent(entries, 4, NetLog::TYPE_PROXY_SERVICE)); |
244 entries, 4, NetLog::TYPE_PROXY_SERVICE)); | |
245 } | 242 } |
246 | 243 |
247 // Test that the proxy resolver does not see the URL's username/password | 244 // Test that the proxy resolver does not see the URL's username/password |
248 // or its reference section. | 245 // or its reference section. |
249 TEST_F(ProxyServiceTest, PAC_NoIdentityOrHash) { | 246 TEST_F(ProxyServiceTest, PAC_NoIdentityOrHash) { |
250 MockProxyConfigService* config_service = | 247 MockProxyConfigService* config_service = |
251 new MockProxyConfigService("http://foopy/proxy.pac"); | 248 new MockProxyConfigService("http://foopy/proxy.pac"); |
252 | 249 |
253 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 250 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
254 | 251 |
255 ProxyService service(config_service, resolver, NULL); | 252 ProxyService service(config_service, resolver, NULL); |
256 | 253 |
257 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 254 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
258 | 255 |
259 ProxyInfo info; | 256 ProxyInfo info; |
260 TestCompletionCallback callback; | 257 TestCompletionCallback callback; |
261 int rv = service.ResolveProxy( | 258 int rv = service.ResolveProxy( |
262 url, &info, callback.callback(), NULL, BoundNetLog()); | 259 url, &info, callback.callback(), NULL, BoundNetLog()); |
263 EXPECT_EQ(ERR_IO_PENDING, rv); | 260 EXPECT_EQ(ERR_IO_PENDING, rv); |
264 | 261 |
265 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 262 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
266 resolver->pending_set_pac_script_request()->script_data()->url()); | 263 resolver->pending_set_pac_script_request()->script_data()->url()); |
267 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 264 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
268 | 265 |
269 ASSERT_EQ(1u, resolver->pending_requests().size()); | 266 ASSERT_EQ(1u, resolver->pending_requests().size()); |
270 // The URL should have been simplified, stripping the username/password/hash. | 267 // The URL should have been simplified, stripping the username/password/hash. |
271 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 268 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
272 resolver->pending_requests()[0]->url()); | 269 resolver->pending_requests()[0]->url()); |
273 | 270 |
274 // We end here without ever completing the request -- destruction of | 271 // We end here without ever completing the request -- destruction of |
275 // ProxyService will cancel the outstanding request. | 272 // ProxyService will cancel the outstanding request. |
276 } | 273 } |
277 | 274 |
278 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { | 275 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
279 MockProxyConfigService* config_service = | 276 MockProxyConfigService* config_service = |
280 new MockProxyConfigService("http://foopy/proxy.pac"); | 277 new MockProxyConfigService("http://foopy/proxy.pac"); |
281 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 278 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
282 | 279 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // Set the result in proxy resolver. | 400 // Set the result in proxy resolver. |
404 resolver->pending_requests()[0]->results()->UsePacString( | 401 resolver->pending_requests()[0]->results()->UsePacString( |
405 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); | 402 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); |
406 resolver->pending_requests()[0]->CompleteNow(OK); | 403 resolver->pending_requests()[0]->CompleteNow(OK); |
407 | 404 |
408 EXPECT_EQ(OK, callback1.WaitForResult()); | 405 EXPECT_EQ(OK, callback1.WaitForResult()); |
409 EXPECT_TRUE(info.is_direct()); | 406 EXPECT_TRUE(info.is_direct()); |
410 | 407 |
411 // Fallback 1. | 408 // Fallback 1. |
412 TestCompletionCallback callback2; | 409 TestCompletionCallback callback2; |
413 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, | 410 rv = service.ReconsiderProxyAfterError( |
414 BoundNetLog()); | 411 url, &info, callback2.callback(), NULL, BoundNetLog()); |
415 EXPECT_EQ(OK, rv); | 412 EXPECT_EQ(OK, rv); |
416 EXPECT_FALSE(info.is_direct()); | 413 EXPECT_FALSE(info.is_direct()); |
417 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); | 414 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); |
418 | 415 |
419 // Fallback 2. | 416 // Fallback 2. |
420 TestCompletionCallback callback3; | 417 TestCompletionCallback callback3; |
421 rv = service.ReconsiderProxyAfterError(url, &info, callback3.callback(), NULL, | 418 rv = service.ReconsiderProxyAfterError( |
422 BoundNetLog()); | 419 url, &info, callback3.callback(), NULL, BoundNetLog()); |
423 EXPECT_EQ(OK, rv); | 420 EXPECT_EQ(OK, rv); |
424 EXPECT_TRUE(info.is_direct()); | 421 EXPECT_TRUE(info.is_direct()); |
425 | 422 |
426 // Fallback 3. | 423 // Fallback 3. |
427 TestCompletionCallback callback4; | 424 TestCompletionCallback callback4; |
428 rv = service.ReconsiderProxyAfterError(url, &info, callback4.callback(), NULL, | 425 rv = service.ReconsiderProxyAfterError( |
429 BoundNetLog()); | 426 url, &info, callback4.callback(), NULL, BoundNetLog()); |
430 EXPECT_EQ(OK, rv); | 427 EXPECT_EQ(OK, rv); |
431 EXPECT_FALSE(info.is_direct()); | 428 EXPECT_FALSE(info.is_direct()); |
432 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); | 429 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); |
433 | 430 |
434 // Fallback 4 -- Nothing to fall back to! | 431 // Fallback 4 -- Nothing to fall back to! |
435 TestCompletionCallback callback5; | 432 TestCompletionCallback callback5; |
436 rv = service.ReconsiderProxyAfterError(url, &info, callback5.callback(), NULL, | 433 rv = service.ReconsiderProxyAfterError( |
437 BoundNetLog()); | 434 url, &info, callback5.callback(), NULL, BoundNetLog()); |
438 EXPECT_EQ(ERR_FAILED, rv); | 435 EXPECT_EQ(ERR_FAILED, rv); |
439 EXPECT_TRUE(info.is_empty()); | 436 EXPECT_TRUE(info.is_empty()); |
440 } | 437 } |
441 | 438 |
442 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { | 439 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { |
443 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied | 440 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied |
444 // to ProxyInfo after the proxy is resolved via a PAC script. | 441 // to ProxyInfo after the proxy is resolved via a PAC script. |
445 ProxyConfig config = | 442 ProxyConfig config = |
446 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); | 443 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); |
447 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 444 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 EXPECT_TRUE(fetcher->has_pending_request()); | 608 EXPECT_TRUE(fetcher->has_pending_request()); |
612 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 609 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
613 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 610 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
614 | 611 |
615 EXPECT_FALSE(fetcher->has_pending_request()); | 612 EXPECT_FALSE(fetcher->has_pending_request()); |
616 ASSERT_EQ(0u, resolver->pending_requests().size()); | 613 ASSERT_EQ(0u, resolver->pending_requests().size()); |
617 | 614 |
618 // Since ProxyScriptDecider failed to identify a valid PAC and PAC was | 615 // Since ProxyScriptDecider failed to identify a valid PAC and PAC was |
619 // mandatory for this configuration, the ProxyService must not implicitly | 616 // mandatory for this configuration, the ProxyService must not implicitly |
620 // fall-back to DIRECT. | 617 // fall-back to DIRECT. |
621 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 618 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, callback.WaitForResult()); |
622 callback.WaitForResult()); | |
623 EXPECT_FALSE(info.is_direct()); | 619 EXPECT_FALSE(info.is_direct()); |
624 } | 620 } |
625 | 621 |
626 TEST_F(ProxyServiceTest, ProxyResolverFailsInJavaScriptMandatoryPac) { | 622 TEST_F(ProxyServiceTest, ProxyResolverFailsInJavaScriptMandatoryPac) { |
627 // Test what happens when the ProxyResolver fails that is configured to use a | 623 // Test what happens when the ProxyResolver fails that is configured to use a |
628 // mandatory PAC script. The download and setting of the PAC script have | 624 // mandatory PAC script. The download and setting of the PAC script have |
629 // already succeeded, so this corresponds with a javascript runtime error | 625 // already succeeded, so this corresponds with a javascript runtime error |
630 // while calling FindProxyForURL(). | 626 // while calling FindProxyForURL(). |
631 | 627 |
632 ProxyConfig config( | 628 ProxyConfig config( |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 717 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
722 | 718 |
723 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 719 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
724 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 720 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
725 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 721 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
726 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); | 722 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); |
727 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time(); | 723 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time(); |
728 | 724 |
729 // Fake an error on the proxy. | 725 // Fake an error on the proxy. |
730 TestCompletionCallback callback2; | 726 TestCompletionCallback callback2; |
731 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, | 727 rv = service.ReconsiderProxyAfterError( |
732 BoundNetLog()); | 728 url, &info, callback2.callback(), NULL, BoundNetLog()); |
733 EXPECT_EQ(OK, rv); | 729 EXPECT_EQ(OK, rv); |
734 | 730 |
735 // Proxy times should not have been modified by fallback. | 731 // Proxy times should not have been modified by fallback. |
736 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 732 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
737 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 733 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
738 | 734 |
739 // The second proxy should be specified. | 735 // The second proxy should be specified. |
740 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 736 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
741 // Report back that the second proxy worked. This will globally mark the | 737 // Report back that the second proxy worked. This will globally mark the |
742 // first proxy as bad. | 738 // first proxy as bad. |
(...skipping 20 matching lines...) Expand all Loading... |
763 // Proxy times should have been updated, so get them again. | 759 // Proxy times should have been updated, so get them again. |
764 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 760 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
765 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 761 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
766 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 762 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
767 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 763 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
768 proxy_resolve_start_time = info.proxy_resolve_start_time(); | 764 proxy_resolve_start_time = info.proxy_resolve_start_time(); |
769 proxy_resolve_end_time = info.proxy_resolve_end_time(); | 765 proxy_resolve_end_time = info.proxy_resolve_end_time(); |
770 | 766 |
771 // We fake another error. It should now try the third one. | 767 // We fake another error. It should now try the third one. |
772 TestCompletionCallback callback4; | 768 TestCompletionCallback callback4; |
773 rv = service.ReconsiderProxyAfterError(url, &info, callback4.callback(), NULL, | 769 rv = service.ReconsiderProxyAfterError( |
774 BoundNetLog()); | 770 url, &info, callback4.callback(), NULL, BoundNetLog()); |
775 EXPECT_EQ(OK, rv); | 771 EXPECT_EQ(OK, rv); |
776 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 772 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
777 | 773 |
778 // We fake another error. At this point we have tried all of the | 774 // We fake another error. At this point we have tried all of the |
779 // proxy servers we thought were valid; next we try the proxy server | 775 // proxy servers we thought were valid; next we try the proxy server |
780 // that was in our bad proxies map (foopy1:8080). | 776 // that was in our bad proxies map (foopy1:8080). |
781 TestCompletionCallback callback5; | 777 TestCompletionCallback callback5; |
782 rv = service.ReconsiderProxyAfterError(url, &info, callback5.callback(), NULL, | 778 rv = service.ReconsiderProxyAfterError( |
783 BoundNetLog()); | 779 url, &info, callback5.callback(), NULL, BoundNetLog()); |
784 EXPECT_EQ(OK, rv); | 780 EXPECT_EQ(OK, rv); |
785 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 781 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
786 | 782 |
787 // Fake another error, the last proxy is gone, the list should now be empty, | 783 // Fake another error, the last proxy is gone, the list should now be empty, |
788 // so there is nothing left to try. | 784 // so there is nothing left to try. |
789 TestCompletionCallback callback6; | 785 TestCompletionCallback callback6; |
790 rv = service.ReconsiderProxyAfterError(url, &info, callback6.callback(), NULL, | 786 rv = service.ReconsiderProxyAfterError( |
791 BoundNetLog()); | 787 url, &info, callback6.callback(), NULL, BoundNetLog()); |
792 EXPECT_EQ(ERR_FAILED, rv); | 788 EXPECT_EQ(ERR_FAILED, rv); |
793 EXPECT_FALSE(info.is_direct()); | 789 EXPECT_FALSE(info.is_direct()); |
794 EXPECT_TRUE(info.is_empty()); | 790 EXPECT_TRUE(info.is_empty()); |
795 | 791 |
796 // Proxy times should not have been modified by fallback. | 792 // Proxy times should not have been modified by fallback. |
797 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 793 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
798 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 794 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
799 | 795 |
800 // Look up proxies again | 796 // Look up proxies again |
801 TestCompletionCallback callback7; | 797 TestCompletionCallback callback7; |
802 rv = service.ResolveProxy(url, &info, callback7.callback(), NULL, | 798 rv = service.ResolveProxy( |
803 BoundNetLog()); | 799 url, &info, callback7.callback(), NULL, BoundNetLog()); |
804 EXPECT_EQ(ERR_IO_PENDING, rv); | 800 EXPECT_EQ(ERR_IO_PENDING, rv); |
805 | 801 |
806 ASSERT_EQ(1u, resolver->pending_requests().size()); | 802 ASSERT_EQ(1u, resolver->pending_requests().size()); |
807 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 803 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
808 | 804 |
809 // This time, the first 3 results have been found to be bad, but only the | 805 // This time, the first 3 results have been found to be bad, but only the |
810 // first proxy has been confirmed ... | 806 // first proxy has been confirmed ... |
811 resolver->pending_requests()[0]->results()->UseNamedProxy( | 807 resolver->pending_requests()[0]->results()->UseNamedProxy( |
812 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); | 808 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); |
813 resolver->pending_requests()[0]->CompleteNow(OK); | 809 resolver->pending_requests()[0]->CompleteNow(OK); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); | 850 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); |
855 resolver->pending_requests()[0]->CompleteNow(OK); | 851 resolver->pending_requests()[0]->CompleteNow(OK); |
856 | 852 |
857 // Get the first result. | 853 // Get the first result. |
858 EXPECT_EQ(OK, callback1.WaitForResult()); | 854 EXPECT_EQ(OK, callback1.WaitForResult()); |
859 EXPECT_FALSE(info.is_direct()); | 855 EXPECT_FALSE(info.is_direct()); |
860 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 856 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
861 | 857 |
862 // Fake an error on the proxy. | 858 // Fake an error on the proxy. |
863 TestCompletionCallback callback2; | 859 TestCompletionCallback callback2; |
864 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, | 860 rv = service.ReconsiderProxyAfterError( |
865 BoundNetLog()); | 861 url, &info, callback2.callback(), NULL, BoundNetLog()); |
866 EXPECT_EQ(OK, rv); | 862 EXPECT_EQ(OK, rv); |
867 | 863 |
868 // Now we get back the second proxy. | 864 // Now we get back the second proxy. |
869 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 865 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
870 | 866 |
871 // Fake an error on this proxy as well. | 867 // Fake an error on this proxy as well. |
872 TestCompletionCallback callback3; | 868 TestCompletionCallback callback3; |
873 rv = service.ReconsiderProxyAfterError(url, &info, callback3.callback(), NULL, | 869 rv = service.ReconsiderProxyAfterError( |
874 BoundNetLog()); | 870 url, &info, callback3.callback(), NULL, BoundNetLog()); |
875 EXPECT_EQ(OK, rv); | 871 EXPECT_EQ(OK, rv); |
876 | 872 |
877 // Finally, we get back DIRECT. | 873 // Finally, we get back DIRECT. |
878 EXPECT_TRUE(info.is_direct()); | 874 EXPECT_TRUE(info.is_direct()); |
879 | 875 |
880 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 876 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
881 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 877 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
882 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 878 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
883 | 879 |
884 // Now we tell the proxy service that even DIRECT failed. | 880 // Now we tell the proxy service that even DIRECT failed. |
885 TestCompletionCallback callback4; | 881 TestCompletionCallback callback4; |
886 rv = service.ReconsiderProxyAfterError(url, &info, callback4.callback(), NULL, | 882 rv = service.ReconsiderProxyAfterError( |
887 BoundNetLog()); | 883 url, &info, callback4.callback(), NULL, BoundNetLog()); |
888 // There was nothing left to try after DIRECT, so we are out of | 884 // There was nothing left to try after DIRECT, so we are out of |
889 // choices. | 885 // choices. |
890 EXPECT_EQ(ERR_FAILED, rv); | 886 EXPECT_EQ(ERR_FAILED, rv); |
891 } | 887 } |
892 | 888 |
893 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { | 889 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { |
894 // Test proxy failover when new settings are available. | 890 // Test proxy failover when new settings are available. |
895 | 891 |
896 MockProxyConfigService* config_service = | 892 MockProxyConfigService* config_service = |
897 new MockProxyConfigService("http://foopy/proxy.pac"); | 893 new MockProxyConfigService("http://foopy/proxy.pac"); |
(...skipping 26 matching lines...) Expand all Loading... |
924 // The first item is valid. | 920 // The first item is valid. |
925 EXPECT_EQ(OK, callback1.WaitForResult()); | 921 EXPECT_EQ(OK, callback1.WaitForResult()); |
926 EXPECT_FALSE(info.is_direct()); | 922 EXPECT_FALSE(info.is_direct()); |
927 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 923 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
928 | 924 |
929 // Fake an error on the proxy, and also a new configuration on the proxy. | 925 // Fake an error on the proxy, and also a new configuration on the proxy. |
930 config_service->SetConfig( | 926 config_service->SetConfig( |
931 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); | 927 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); |
932 | 928 |
933 TestCompletionCallback callback2; | 929 TestCompletionCallback callback2; |
934 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, | 930 rv = service.ReconsiderProxyAfterError( |
935 BoundNetLog()); | 931 url, &info, callback2.callback(), NULL, BoundNetLog()); |
936 EXPECT_EQ(ERR_IO_PENDING, rv); | 932 EXPECT_EQ(ERR_IO_PENDING, rv); |
937 | 933 |
938 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), | 934 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), |
939 resolver->pending_set_pac_script_request()->script_data()->url()); | 935 resolver->pending_set_pac_script_request()->script_data()->url()); |
940 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 936 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
941 | 937 |
942 ASSERT_EQ(1u, resolver->pending_requests().size()); | 938 ASSERT_EQ(1u, resolver->pending_requests().size()); |
943 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 939 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
944 | 940 |
945 resolver->pending_requests()[0]->results()->UseNamedProxy( | 941 resolver->pending_requests()[0]->results()->UseNamedProxy( |
946 "foopy1:8080;foopy2:9090"); | 942 "foopy1:8080;foopy2:9090"); |
947 resolver->pending_requests()[0]->CompleteNow(OK); | 943 resolver->pending_requests()[0]->CompleteNow(OK); |
948 | 944 |
949 // The first proxy is still there since the configuration changed. | 945 // The first proxy is still there since the configuration changed. |
950 EXPECT_EQ(OK, callback2.WaitForResult()); | 946 EXPECT_EQ(OK, callback2.WaitForResult()); |
951 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 947 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
952 | 948 |
953 // We fake another error. It should now ignore the first one. | 949 // We fake another error. It should now ignore the first one. |
954 TestCompletionCallback callback3; | 950 TestCompletionCallback callback3; |
955 rv = service.ReconsiderProxyAfterError(url, &info, callback3.callback(), NULL, | 951 rv = service.ReconsiderProxyAfterError( |
956 BoundNetLog()); | 952 url, &info, callback3.callback(), NULL, BoundNetLog()); |
957 EXPECT_EQ(OK, rv); | 953 EXPECT_EQ(OK, rv); |
958 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 954 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
959 | 955 |
960 // We simulate a new configuration. | 956 // We simulate a new configuration. |
961 config_service->SetConfig( | 957 config_service->SetConfig( |
962 ProxyConfig::CreateFromCustomPacURL( | 958 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new2/proxy.pac"))); |
963 GURL("http://foopy-new2/proxy.pac"))); | |
964 | 959 |
965 // We fake another error. It should go back to the first proxy. | 960 // We fake another error. It should go back to the first proxy. |
966 TestCompletionCallback callback4; | 961 TestCompletionCallback callback4; |
967 rv = service.ReconsiderProxyAfterError(url, &info, callback4.callback(), NULL, | 962 rv = service.ReconsiderProxyAfterError( |
968 BoundNetLog()); | 963 url, &info, callback4.callback(), NULL, BoundNetLog()); |
969 EXPECT_EQ(ERR_IO_PENDING, rv); | 964 EXPECT_EQ(ERR_IO_PENDING, rv); |
970 | 965 |
971 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), | 966 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), |
972 resolver->pending_set_pac_script_request()->script_data()->url()); | 967 resolver->pending_set_pac_script_request()->script_data()->url()); |
973 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 968 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
974 | 969 |
975 ASSERT_EQ(1u, resolver->pending_requests().size()); | 970 ASSERT_EQ(1u, resolver->pending_requests().size()); |
976 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 971 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
977 | 972 |
978 resolver->pending_requests()[0]->results()->UseNamedProxy( | 973 resolver->pending_requests()[0]->results()->UseNamedProxy( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 "foopy1:8080;foopy2:9090"); | 1011 "foopy1:8080;foopy2:9090"); |
1017 resolver->pending_requests()[0]->CompleteNow(OK); | 1012 resolver->pending_requests()[0]->CompleteNow(OK); |
1018 | 1013 |
1019 // The first item is valid. | 1014 // The first item is valid. |
1020 EXPECT_EQ(OK, callback1.WaitForResult()); | 1015 EXPECT_EQ(OK, callback1.WaitForResult()); |
1021 EXPECT_FALSE(info.is_direct()); | 1016 EXPECT_FALSE(info.is_direct()); |
1022 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1017 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1023 | 1018 |
1024 // Fake a proxy error. | 1019 // Fake a proxy error. |
1025 TestCompletionCallback callback2; | 1020 TestCompletionCallback callback2; |
1026 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, | 1021 rv = service.ReconsiderProxyAfterError( |
1027 BoundNetLog()); | 1022 url, &info, callback2.callback(), NULL, BoundNetLog()); |
1028 EXPECT_EQ(OK, rv); | 1023 EXPECT_EQ(OK, rv); |
1029 | 1024 |
1030 // The first proxy is ignored, and the second one is selected. | 1025 // The first proxy is ignored, and the second one is selected. |
1031 EXPECT_FALSE(info.is_direct()); | 1026 EXPECT_FALSE(info.is_direct()); |
1032 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1027 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1033 | 1028 |
1034 // Fake a PAC failure. | 1029 // Fake a PAC failure. |
1035 ProxyInfo info2; | 1030 ProxyInfo info2; |
1036 TestCompletionCallback callback3; | 1031 TestCompletionCallback callback3; |
1037 rv = service.ResolveProxy( | 1032 rv = service.ResolveProxy( |
(...skipping 10 matching lines...) Expand all Loading... |
1048 // to a DIRECT connection. | 1043 // to a DIRECT connection. |
1049 EXPECT_EQ(OK, callback3.WaitForResult()); | 1044 EXPECT_EQ(OK, callback3.WaitForResult()); |
1050 EXPECT_TRUE(info2.is_direct()); | 1045 EXPECT_TRUE(info2.is_direct()); |
1051 EXPECT_FALSE(info2.is_empty()); | 1046 EXPECT_FALSE(info2.is_empty()); |
1052 | 1047 |
1053 // The PAC script will work properly next time and successfully return a | 1048 // The PAC script will work properly next time and successfully return a |
1054 // proxy list. Since we have not marked the configuration as bad, it should | 1049 // proxy list. Since we have not marked the configuration as bad, it should |
1055 // "just work" the next time we call it. | 1050 // "just work" the next time we call it. |
1056 ProxyInfo info3; | 1051 ProxyInfo info3; |
1057 TestCompletionCallback callback4; | 1052 TestCompletionCallback callback4; |
1058 rv = service.ReconsiderProxyAfterError(url, &info3, callback4.callback(), | 1053 rv = service.ReconsiderProxyAfterError( |
1059 NULL, BoundNetLog()); | 1054 url, &info3, callback4.callback(), NULL, BoundNetLog()); |
1060 EXPECT_EQ(ERR_IO_PENDING, rv); | 1055 EXPECT_EQ(ERR_IO_PENDING, rv); |
1061 | 1056 |
1062 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1057 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1063 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1058 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1064 | 1059 |
1065 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1060 resolver->pending_requests()[0]->results()->UseNamedProxy( |
1066 "foopy1:8080;foopy2:9090"); | 1061 "foopy1:8080;foopy2:9090"); |
1067 resolver->pending_requests()[0]->CompleteNow(OK); | 1062 resolver->pending_requests()[0]->CompleteNow(OK); |
1068 | 1063 |
1069 // The first proxy is not there since the it was added to the bad proxies | 1064 // The first proxy is not there since the it was added to the bad proxies |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 "foopy1:8080;foopy2:9090"); | 1104 "foopy1:8080;foopy2:9090"); |
1110 resolver->pending_requests()[0]->CompleteNow(OK); | 1105 resolver->pending_requests()[0]->CompleteNow(OK); |
1111 | 1106 |
1112 // The first item is valid. | 1107 // The first item is valid. |
1113 EXPECT_EQ(OK, callback1.WaitForResult()); | 1108 EXPECT_EQ(OK, callback1.WaitForResult()); |
1114 EXPECT_FALSE(info.is_direct()); | 1109 EXPECT_FALSE(info.is_direct()); |
1115 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1110 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1116 | 1111 |
1117 // Fake a proxy error. | 1112 // Fake a proxy error. |
1118 TestCompletionCallback callback2; | 1113 TestCompletionCallback callback2; |
1119 rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, | 1114 rv = service.ReconsiderProxyAfterError( |
1120 BoundNetLog()); | 1115 url, &info, callback2.callback(), NULL, BoundNetLog()); |
1121 EXPECT_EQ(OK, rv); | 1116 EXPECT_EQ(OK, rv); |
1122 | 1117 |
1123 // The first proxy is ignored, and the second one is selected. | 1118 // The first proxy is ignored, and the second one is selected. |
1124 EXPECT_FALSE(info.is_direct()); | 1119 EXPECT_FALSE(info.is_direct()); |
1125 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1120 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1126 | 1121 |
1127 // Fake a PAC failure. | 1122 // Fake a PAC failure. |
1128 ProxyInfo info2; | 1123 ProxyInfo info2; |
1129 TestCompletionCallback callback3; | 1124 TestCompletionCallback callback3; |
1130 rv = service.ResolveProxy( | 1125 rv = service.ResolveProxy( |
(...skipping 11 matching lines...) Expand all Loading... |
1142 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1137 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1143 callback3.WaitForResult()); | 1138 callback3.WaitForResult()); |
1144 EXPECT_FALSE(info2.is_direct()); | 1139 EXPECT_FALSE(info2.is_direct()); |
1145 EXPECT_TRUE(info2.is_empty()); | 1140 EXPECT_TRUE(info2.is_empty()); |
1146 | 1141 |
1147 // The PAC script will work properly next time and successfully return a | 1142 // The PAC script will work properly next time and successfully return a |
1148 // proxy list. Since we have not marked the configuration as bad, it should | 1143 // proxy list. Since we have not marked the configuration as bad, it should |
1149 // "just work" the next time we call it. | 1144 // "just work" the next time we call it. |
1150 ProxyInfo info3; | 1145 ProxyInfo info3; |
1151 TestCompletionCallback callback4; | 1146 TestCompletionCallback callback4; |
1152 rv = service.ReconsiderProxyAfterError(url, &info3, callback4.callback(), | 1147 rv = service.ReconsiderProxyAfterError( |
1153 NULL, BoundNetLog()); | 1148 url, &info3, callback4.callback(), NULL, BoundNetLog()); |
1154 EXPECT_EQ(ERR_IO_PENDING, rv); | 1149 EXPECT_EQ(ERR_IO_PENDING, rv); |
1155 | 1150 |
1156 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1151 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1157 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1152 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1158 | 1153 |
1159 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1154 resolver->pending_requests()[0]->results()->UseNamedProxy( |
1160 "foopy1:8080;foopy2:9090"); | 1155 "foopy1:8080;foopy2:9090"); |
1161 resolver->pending_requests()[0]->CompleteNow(OK); | 1156 resolver->pending_requests()[0]->CompleteNow(OK); |
1162 | 1157 |
1163 // The first proxy is not there since the it was added to the bad proxies | 1158 // The first proxy is not there since the it was added to the bad proxies |
(...skipping 26 matching lines...) Expand all Loading... |
1190 EXPECT_EQ(OK, rv); | 1185 EXPECT_EQ(OK, rv); |
1191 EXPECT_TRUE(info[0].is_direct()); | 1186 EXPECT_TRUE(info[0].is_direct()); |
1192 | 1187 |
1193 // Request for a .com domain hits the proxy. | 1188 // Request for a .com domain hits the proxy. |
1194 rv = service.ResolveProxy( | 1189 rv = service.ResolveProxy( |
1195 url2, &info[1], callback[1].callback(), NULL, BoundNetLog()); | 1190 url2, &info[1], callback[1].callback(), NULL, BoundNetLog()); |
1196 EXPECT_EQ(OK, rv); | 1191 EXPECT_EQ(OK, rv); |
1197 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); | 1192 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); |
1198 } | 1193 } |
1199 | 1194 |
1200 | |
1201 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { | 1195 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { |
1202 ProxyConfig config; | 1196 ProxyConfig config; |
1203 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); | 1197 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); |
1204 config.set_auto_detect(false); | 1198 config.set_auto_detect(false); |
1205 { | 1199 { |
1206 ProxyService service( | 1200 ProxyService service( |
1207 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1201 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1208 GURL test_url("http://www.msn.com"); | 1202 GURL test_url("http://www.msn.com"); |
1209 ProxyInfo info; | 1203 ProxyInfo info; |
1210 TestCompletionCallback callback; | 1204 TestCompletionCallback callback; |
1211 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1205 int rv = service.ResolveProxy( |
1212 BoundNetLog()); | 1206 test_url, &info, callback.callback(), NULL, BoundNetLog()); |
1213 EXPECT_EQ(OK, rv); | 1207 EXPECT_EQ(OK, rv); |
1214 EXPECT_FALSE(info.is_direct()); | 1208 EXPECT_FALSE(info.is_direct()); |
1215 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1209 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1216 } | 1210 } |
1217 { | 1211 { |
1218 ProxyService service( | 1212 ProxyService service( |
1219 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1213 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1220 GURL test_url("ftp://ftp.google.com"); | 1214 GURL test_url("ftp://ftp.google.com"); |
1221 ProxyInfo info; | 1215 ProxyInfo info; |
1222 TestCompletionCallback callback; | 1216 TestCompletionCallback callback; |
1223 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1217 int rv = service.ResolveProxy( |
1224 BoundNetLog()); | 1218 test_url, &info, callback.callback(), NULL, BoundNetLog()); |
1225 EXPECT_EQ(OK, rv); | 1219 EXPECT_EQ(OK, rv); |
1226 EXPECT_TRUE(info.is_direct()); | 1220 EXPECT_TRUE(info.is_direct()); |
1227 EXPECT_EQ("direct://", info.proxy_server().ToURI()); | 1221 EXPECT_EQ("direct://", info.proxy_server().ToURI()); |
1228 } | 1222 } |
1229 { | 1223 { |
1230 ProxyService service( | 1224 ProxyService service( |
1231 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1225 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1232 GURL test_url("https://webbranch.techcu.com"); | 1226 GURL test_url("https://webbranch.techcu.com"); |
1233 ProxyInfo info; | 1227 ProxyInfo info; |
1234 TestCompletionCallback callback; | 1228 TestCompletionCallback callback; |
1235 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1229 int rv = service.ResolveProxy( |
1236 BoundNetLog()); | 1230 test_url, &info, callback.callback(), NULL, BoundNetLog()); |
1237 EXPECT_EQ(OK, rv); | 1231 EXPECT_EQ(OK, rv); |
1238 EXPECT_FALSE(info.is_direct()); | 1232 EXPECT_FALSE(info.is_direct()); |
1239 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1233 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
1240 } | 1234 } |
1241 { | 1235 { |
1242 config.proxy_rules().ParseFromString("foopy1:8080"); | 1236 config.proxy_rules().ParseFromString("foopy1:8080"); |
1243 ProxyService service( | 1237 ProxyService service( |
1244 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1238 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1245 GURL test_url("http://www.microsoft.com"); | 1239 GURL test_url("http://www.microsoft.com"); |
1246 ProxyInfo info; | 1240 ProxyInfo info; |
1247 TestCompletionCallback callback; | 1241 TestCompletionCallback callback; |
1248 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1242 int rv = service.ResolveProxy( |
1249 BoundNetLog()); | 1243 test_url, &info, callback.callback(), NULL, BoundNetLog()); |
1250 EXPECT_EQ(OK, rv); | 1244 EXPECT_EQ(OK, rv); |
1251 EXPECT_FALSE(info.is_direct()); | 1245 EXPECT_FALSE(info.is_direct()); |
1252 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1246 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1253 } | 1247 } |
1254 } | 1248 } |
1255 | 1249 |
1256 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { | 1250 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { |
1257 // Test that the proxy config source is set correctly when resolving proxies | 1251 // Test that the proxy config source is set correctly when resolving proxies |
1258 // using manual proxy rules. Namely, the config source should only be set if | 1252 // using manual proxy rules. Namely, the config source should only be set if |
1259 // any of the rules were applied. | 1253 // any of the rules were applied. |
1260 { | 1254 { |
1261 ProxyConfig config; | 1255 ProxyConfig config; |
1262 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1256 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1263 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1257 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1264 ProxyService service( | 1258 ProxyService service( |
1265 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1259 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1266 GURL test_url("http://www.google.com"); | 1260 GURL test_url("http://www.google.com"); |
1267 ProxyInfo info; | 1261 ProxyInfo info; |
1268 TestCompletionCallback callback; | 1262 TestCompletionCallback callback; |
1269 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1263 int rv = service.ResolveProxy( |
1270 BoundNetLog()); | 1264 test_url, &info, callback.callback(), NULL, BoundNetLog()); |
1271 ASSERT_EQ(OK, rv); | 1265 ASSERT_EQ(OK, rv); |
1272 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. | 1266 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. |
1273 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1267 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1274 } | 1268 } |
1275 { | 1269 { |
1276 ProxyConfig config; | 1270 ProxyConfig config; |
1277 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1271 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1278 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1272 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1279 ProxyService service( | 1273 ProxyService service( |
1280 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1274 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1281 GURL test_url("https://www.google.com"); | 1275 GURL test_url("https://www.google.com"); |
1282 ProxyInfo info; | 1276 ProxyInfo info; |
1283 TestCompletionCallback callback; | 1277 TestCompletionCallback callback; |
1284 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1278 int rv = service.ResolveProxy( |
1285 BoundNetLog()); | 1279 test_url, &info, callback.callback(), NULL, BoundNetLog()); |
1286 ASSERT_EQ(OK, rv); | 1280 ASSERT_EQ(OK, rv); |
1287 // Used the HTTPS proxy. So source should be TEST. | 1281 // Used the HTTPS proxy. So source should be TEST. |
1288 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1282 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1289 } | 1283 } |
1290 { | 1284 { |
1291 ProxyConfig config; | 1285 ProxyConfig config; |
1292 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1286 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1293 ProxyService service( | 1287 ProxyService service( |
1294 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1288 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1295 GURL test_url("http://www.google.com"); | 1289 GURL test_url("http://www.google.com"); |
1296 ProxyInfo info; | 1290 ProxyInfo info; |
1297 TestCompletionCallback callback; | 1291 TestCompletionCallback callback; |
1298 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1292 int rv = service.ResolveProxy( |
1299 BoundNetLog()); | 1293 test_url, &info, callback.callback(), NULL, BoundNetLog()); |
1300 ASSERT_EQ(OK, rv); | 1294 ASSERT_EQ(OK, rv); |
1301 // ProxyConfig is empty. Source should still be TEST. | 1295 // ProxyConfig is empty. Source should still be TEST. |
1302 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1296 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1303 } | 1297 } |
1304 } | 1298 } |
1305 | 1299 |
1306 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries | 1300 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries |
1307 // fall back to the SOCKS proxy. | 1301 // fall back to the SOCKS proxy. |
1308 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { | 1302 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { |
1309 ProxyConfig config; | 1303 ProxyConfig config; |
1310 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); | 1304 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); |
1311 config.set_auto_detect(false); | 1305 config.set_auto_detect(false); |
1312 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 1306 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
1313 config.proxy_rules().type); | 1307 config.proxy_rules().type); |
1314 | 1308 |
1315 { | 1309 { |
1316 ProxyService service( | 1310 ProxyService service( |
1317 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1311 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1318 GURL test_url("http://www.msn.com"); | 1312 GURL test_url("http://www.msn.com"); |
1319 ProxyInfo info; | 1313 ProxyInfo info; |
1320 TestCompletionCallback callback; | 1314 TestCompletionCallback callback; |
1321 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1315 int rv = service.ResolveProxy( |
1322 BoundNetLog()); | 1316 test_url, &info, callback.callback(), NULL, BoundNetLog()); |
1323 EXPECT_EQ(OK, rv); | 1317 EXPECT_EQ(OK, rv); |
1324 EXPECT_FALSE(info.is_direct()); | 1318 EXPECT_FALSE(info.is_direct()); |
1325 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1319 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1326 } | 1320 } |
1327 { | 1321 { |
1328 ProxyService service( | 1322 ProxyService service( |
1329 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1323 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1330 GURL test_url("ftp://ftp.google.com"); | 1324 GURL test_url("ftp://ftp.google.com"); |
1331 ProxyInfo info; | 1325 ProxyInfo info; |
1332 TestCompletionCallback callback; | 1326 TestCompletionCallback callback; |
1333 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1327 int rv = service.ResolveProxy( |
1334 BoundNetLog()); | 1328 test_url, &info, callback.callback(), NULL, BoundNetLog()); |
1335 EXPECT_EQ(OK, rv); | 1329 EXPECT_EQ(OK, rv); |
1336 EXPECT_FALSE(info.is_direct()); | 1330 EXPECT_FALSE(info.is_direct()); |
1337 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1331 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1338 } | 1332 } |
1339 { | 1333 { |
1340 ProxyService service( | 1334 ProxyService service( |
1341 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1335 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1342 GURL test_url("https://webbranch.techcu.com"); | 1336 GURL test_url("https://webbranch.techcu.com"); |
1343 ProxyInfo info; | 1337 ProxyInfo info; |
1344 TestCompletionCallback callback; | 1338 TestCompletionCallback callback; |
1345 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1339 int rv = service.ResolveProxy( |
1346 BoundNetLog()); | 1340 test_url, &info, callback.callback(), NULL, BoundNetLog()); |
1347 EXPECT_EQ(OK, rv); | 1341 EXPECT_EQ(OK, rv); |
1348 EXPECT_FALSE(info.is_direct()); | 1342 EXPECT_FALSE(info.is_direct()); |
1349 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1343 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1350 } | 1344 } |
1351 { | 1345 { |
1352 ProxyService service( | 1346 ProxyService service( |
1353 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1347 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1354 GURL test_url("unknown://www.microsoft.com"); | 1348 GURL test_url("unknown://www.microsoft.com"); |
1355 ProxyInfo info; | 1349 ProxyInfo info; |
1356 TestCompletionCallback callback; | 1350 TestCompletionCallback callback; |
1357 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1351 int rv = service.ResolveProxy( |
1358 BoundNetLog()); | 1352 test_url, &info, callback.callback(), NULL, BoundNetLog()); |
1359 EXPECT_EQ(OK, rv); | 1353 EXPECT_EQ(OK, rv); |
1360 EXPECT_FALSE(info.is_direct()); | 1354 EXPECT_FALSE(info.is_direct()); |
1361 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1355 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1362 } | 1356 } |
1363 } | 1357 } |
1364 | 1358 |
1365 // Test cancellation of an in-progress request. | 1359 // Test cancellation of an in-progress request. |
1366 TEST_F(ProxyServiceTest, CancelInProgressRequest) { | 1360 TEST_F(ProxyServiceTest, CancelInProgressRequest) { |
1367 MockProxyConfigService* config_service = | 1361 MockProxyConfigService* config_service = |
1368 new MockProxyConfigService("http://foopy/proxy.pac"); | 1362 new MockProxyConfigService("http://foopy/proxy.pac"); |
1369 | 1363 |
1370 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1364 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1371 | 1365 |
1372 ProxyService service(config_service, resolver, NULL); | 1366 ProxyService service(config_service, resolver, NULL); |
1373 | 1367 |
1374 // Start 3 requests. | 1368 // Start 3 requests. |
1375 | 1369 |
1376 ProxyInfo info1; | 1370 ProxyInfo info1; |
1377 TestCompletionCallback callback1; | 1371 TestCompletionCallback callback1; |
1378 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1372 int rv = service.ResolveProxy(GURL("http://request1"), |
1379 callback1.callback(), NULL, BoundNetLog()); | 1373 &info1, |
| 1374 callback1.callback(), |
| 1375 NULL, |
| 1376 BoundNetLog()); |
1380 EXPECT_EQ(ERR_IO_PENDING, rv); | 1377 EXPECT_EQ(ERR_IO_PENDING, rv); |
1381 | 1378 |
1382 // Nothing has been sent to the proxy resolver yet, since the proxy | 1379 // Nothing has been sent to the proxy resolver yet, since the proxy |
1383 // resolver has not been configured yet. | 1380 // resolver has not been configured yet. |
1384 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1381 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1385 | 1382 |
1386 // Successfully initialize the PAC script. | 1383 // Successfully initialize the PAC script. |
1387 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1384 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1388 resolver->pending_set_pac_script_request()->script_data()->url()); | 1385 resolver->pending_set_pac_script_request()->script_data()->url()); |
1389 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1386 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1390 | 1387 |
1391 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1388 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1392 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1389 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
1393 | 1390 |
1394 ProxyInfo info2; | 1391 ProxyInfo info2; |
1395 TestCompletionCallback callback2; | 1392 TestCompletionCallback callback2; |
1396 ProxyService::PacRequest* request2; | 1393 ProxyService::PacRequest* request2; |
1397 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1394 rv = service.ResolveProxy(GURL("http://request2"), |
1398 callback2.callback(), &request2, BoundNetLog()); | 1395 &info2, |
| 1396 callback2.callback(), |
| 1397 &request2, |
| 1398 BoundNetLog()); |
1399 EXPECT_EQ(ERR_IO_PENDING, rv); | 1399 EXPECT_EQ(ERR_IO_PENDING, rv); |
1400 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1400 ASSERT_EQ(2u, resolver->pending_requests().size()); |
1401 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1401 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
1402 | 1402 |
1403 ProxyInfo info3; | 1403 ProxyInfo info3; |
1404 TestCompletionCallback callback3; | 1404 TestCompletionCallback callback3; |
1405 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1405 rv = service.ResolveProxy(GURL("http://request3"), |
1406 callback3.callback(), NULL, BoundNetLog()); | 1406 &info3, |
| 1407 callback3.callback(), |
| 1408 NULL, |
| 1409 BoundNetLog()); |
1407 EXPECT_EQ(ERR_IO_PENDING, rv); | 1410 EXPECT_EQ(ERR_IO_PENDING, rv); |
1408 ASSERT_EQ(3u, resolver->pending_requests().size()); | 1411 ASSERT_EQ(3u, resolver->pending_requests().size()); |
1409 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); | 1412 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); |
1410 | 1413 |
1411 // Cancel the second request | 1414 // Cancel the second request |
1412 service.CancelPacRequest(request2); | 1415 service.CancelPacRequest(request2); |
1413 | 1416 |
1414 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1417 ASSERT_EQ(2u, resolver->pending_requests().size()); |
1415 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1418 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
1416 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); | 1419 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); |
(...skipping 30 matching lines...) Expand all Loading... |
1447 | 1450 |
1448 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1451 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1449 service.SetProxyScriptFetchers(fetcher, | 1452 service.SetProxyScriptFetchers(fetcher, |
1450 new DoNothingDhcpProxyScriptFetcher()); | 1453 new DoNothingDhcpProxyScriptFetcher()); |
1451 | 1454 |
1452 // Start 3 requests. | 1455 // Start 3 requests. |
1453 | 1456 |
1454 ProxyInfo info1; | 1457 ProxyInfo info1; |
1455 TestCompletionCallback callback1; | 1458 TestCompletionCallback callback1; |
1456 ProxyService::PacRequest* request1; | 1459 ProxyService::PacRequest* request1; |
1457 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1460 int rv = service.ResolveProxy(GURL("http://request1"), |
1458 callback1.callback(), &request1, BoundNetLog()); | 1461 &info1, |
| 1462 callback1.callback(), |
| 1463 &request1, |
| 1464 BoundNetLog()); |
1459 EXPECT_EQ(ERR_IO_PENDING, rv); | 1465 EXPECT_EQ(ERR_IO_PENDING, rv); |
1460 | 1466 |
1461 // The first request should have triggered download of PAC script. | 1467 // The first request should have triggered download of PAC script. |
1462 EXPECT_TRUE(fetcher->has_pending_request()); | 1468 EXPECT_TRUE(fetcher->has_pending_request()); |
1463 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1469 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1464 | 1470 |
1465 ProxyInfo info2; | 1471 ProxyInfo info2; |
1466 TestCompletionCallback callback2; | 1472 TestCompletionCallback callback2; |
1467 ProxyService::PacRequest* request2; | 1473 ProxyService::PacRequest* request2; |
1468 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1474 rv = service.ResolveProxy(GURL("http://request2"), |
1469 callback2.callback(), &request2, BoundNetLog()); | 1475 &info2, |
| 1476 callback2.callback(), |
| 1477 &request2, |
| 1478 BoundNetLog()); |
1470 EXPECT_EQ(ERR_IO_PENDING, rv); | 1479 EXPECT_EQ(ERR_IO_PENDING, rv); |
1471 | 1480 |
1472 ProxyInfo info3; | 1481 ProxyInfo info3; |
1473 TestCompletionCallback callback3; | 1482 TestCompletionCallback callback3; |
1474 ProxyService::PacRequest* request3; | 1483 ProxyService::PacRequest* request3; |
1475 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1484 rv = service.ResolveProxy(GURL("http://request3"), |
1476 callback3.callback(), &request3, BoundNetLog()); | 1485 &info3, |
| 1486 callback3.callback(), |
| 1487 &request3, |
| 1488 BoundNetLog()); |
1477 EXPECT_EQ(ERR_IO_PENDING, rv); | 1489 EXPECT_EQ(ERR_IO_PENDING, rv); |
1478 | 1490 |
1479 // Nothing has been sent to the resolver yet. | 1491 // Nothing has been sent to the resolver yet. |
1480 EXPECT_TRUE(resolver->pending_requests().empty()); | 1492 EXPECT_TRUE(resolver->pending_requests().empty()); |
1481 | 1493 |
1482 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1494 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
1483 service.GetLoadState(request1)); | 1495 service.GetLoadState(request1)); |
1484 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1496 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
1485 service.GetLoadState(request2)); | 1497 service.GetLoadState(request2)); |
1486 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1498 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 ProxyService service(config_service, resolver, NULL); | 1561 ProxyService service(config_service, resolver, NULL); |
1550 | 1562 |
1551 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1563 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1552 service.SetProxyScriptFetchers(fetcher, | 1564 service.SetProxyScriptFetchers(fetcher, |
1553 new DoNothingDhcpProxyScriptFetcher()); | 1565 new DoNothingDhcpProxyScriptFetcher()); |
1554 | 1566 |
1555 // Start 2 requests. | 1567 // Start 2 requests. |
1556 | 1568 |
1557 ProxyInfo info1; | 1569 ProxyInfo info1; |
1558 TestCompletionCallback callback1; | 1570 TestCompletionCallback callback1; |
1559 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1571 int rv = service.ResolveProxy(GURL("http://request1"), |
1560 callback1.callback(), NULL, BoundNetLog()); | 1572 &info1, |
| 1573 callback1.callback(), |
| 1574 NULL, |
| 1575 BoundNetLog()); |
1561 EXPECT_EQ(ERR_IO_PENDING, rv); | 1576 EXPECT_EQ(ERR_IO_PENDING, rv); |
1562 | 1577 |
1563 // The first request should have triggered download of PAC script. | 1578 // The first request should have triggered download of PAC script. |
1564 EXPECT_TRUE(fetcher->has_pending_request()); | 1579 EXPECT_TRUE(fetcher->has_pending_request()); |
1565 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1580 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1566 | 1581 |
1567 ProxyInfo info2; | 1582 ProxyInfo info2; |
1568 TestCompletionCallback callback2; | 1583 TestCompletionCallback callback2; |
1569 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1584 rv = service.ResolveProxy(GURL("http://request2"), |
1570 callback2.callback(), NULL, BoundNetLog()); | 1585 &info2, |
| 1586 callback2.callback(), |
| 1587 NULL, |
| 1588 BoundNetLog()); |
1571 EXPECT_EQ(ERR_IO_PENDING, rv); | 1589 EXPECT_EQ(ERR_IO_PENDING, rv); |
1572 | 1590 |
1573 // At this point the ProxyService should be waiting for the | 1591 // At this point the ProxyService should be waiting for the |
1574 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1592 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
1575 // PAC script download completion. | 1593 // PAC script download completion. |
1576 | 1594 |
1577 // We now change out the ProxyService's script fetcher. We should restart | 1595 // We now change out the ProxyService's script fetcher. We should restart |
1578 // the initialization with the new fetcher. | 1596 // the initialization with the new fetcher. |
1579 | 1597 |
1580 fetcher = new MockProxyScriptFetcher; | 1598 fetcher = new MockProxyScriptFetcher; |
(...skipping 28 matching lines...) Expand all Loading... |
1609 | 1627 |
1610 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1628 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1611 service.SetProxyScriptFetchers(fetcher, | 1629 service.SetProxyScriptFetchers(fetcher, |
1612 new DoNothingDhcpProxyScriptFetcher()); | 1630 new DoNothingDhcpProxyScriptFetcher()); |
1613 | 1631 |
1614 // Start 3 requests. | 1632 // Start 3 requests. |
1615 ProxyInfo info1; | 1633 ProxyInfo info1; |
1616 TestCompletionCallback callback1; | 1634 TestCompletionCallback callback1; |
1617 ProxyService::PacRequest* request1; | 1635 ProxyService::PacRequest* request1; |
1618 CapturingBoundNetLog log1; | 1636 CapturingBoundNetLog log1; |
1619 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1637 int rv = service.ResolveProxy(GURL("http://request1"), |
1620 callback1.callback(), &request1, log1.bound()); | 1638 &info1, |
| 1639 callback1.callback(), |
| 1640 &request1, |
| 1641 log1.bound()); |
1621 EXPECT_EQ(ERR_IO_PENDING, rv); | 1642 EXPECT_EQ(ERR_IO_PENDING, rv); |
1622 | 1643 |
1623 // The first request should have triggered download of PAC script. | 1644 // The first request should have triggered download of PAC script. |
1624 EXPECT_TRUE(fetcher->has_pending_request()); | 1645 EXPECT_TRUE(fetcher->has_pending_request()); |
1625 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1646 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1626 | 1647 |
1627 ProxyInfo info2; | 1648 ProxyInfo info2; |
1628 TestCompletionCallback callback2; | 1649 TestCompletionCallback callback2; |
1629 ProxyService::PacRequest* request2; | 1650 ProxyService::PacRequest* request2; |
1630 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1651 rv = service.ResolveProxy(GURL("http://request2"), |
1631 callback2.callback(), &request2, BoundNetLog()); | 1652 &info2, |
| 1653 callback2.callback(), |
| 1654 &request2, |
| 1655 BoundNetLog()); |
1632 EXPECT_EQ(ERR_IO_PENDING, rv); | 1656 EXPECT_EQ(ERR_IO_PENDING, rv); |
1633 | 1657 |
1634 ProxyInfo info3; | 1658 ProxyInfo info3; |
1635 TestCompletionCallback callback3; | 1659 TestCompletionCallback callback3; |
1636 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1660 rv = service.ResolveProxy(GURL("http://request3"), |
1637 callback3.callback(), NULL, BoundNetLog()); | 1661 &info3, |
| 1662 callback3.callback(), |
| 1663 NULL, |
| 1664 BoundNetLog()); |
1638 EXPECT_EQ(ERR_IO_PENDING, rv); | 1665 EXPECT_EQ(ERR_IO_PENDING, rv); |
1639 | 1666 |
1640 // Nothing has been sent to the resolver yet. | 1667 // Nothing has been sent to the resolver yet. |
1641 EXPECT_TRUE(resolver->pending_requests().empty()); | 1668 EXPECT_TRUE(resolver->pending_requests().empty()); |
1642 | 1669 |
1643 // Cancel the first 2 requests. | 1670 // Cancel the first 2 requests. |
1644 service.CancelPacRequest(request1); | 1671 service.CancelPacRequest(request1); |
1645 service.CancelPacRequest(request2); | 1672 service.CancelPacRequest(request2); |
1646 | 1673 |
1647 // At this point the ProxyService should be waiting for the | 1674 // At this point the ProxyService should be waiting for the |
(...skipping 20 matching lines...) Expand all Loading... |
1668 EXPECT_TRUE(resolver->cancelled_requests().empty()); | 1695 EXPECT_TRUE(resolver->cancelled_requests().empty()); |
1669 | 1696 |
1670 EXPECT_FALSE(callback1.have_result()); // Cancelled. | 1697 EXPECT_FALSE(callback1.have_result()); // Cancelled. |
1671 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 1698 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
1672 | 1699 |
1673 CapturingNetLog::CapturedEntryList entries1; | 1700 CapturingNetLog::CapturedEntryList entries1; |
1674 log1.GetEntries(&entries1); | 1701 log1.GetEntries(&entries1); |
1675 | 1702 |
1676 // Check the NetLog for request 1 (which was cancelled) got filled properly. | 1703 // Check the NetLog for request 1 (which was cancelled) got filled properly. |
1677 EXPECT_EQ(4u, entries1.size()); | 1704 EXPECT_EQ(4u, entries1.size()); |
1678 EXPECT_TRUE(LogContainsBeginEvent( | 1705 EXPECT_TRUE(LogContainsBeginEvent(entries1, 0, NetLog::TYPE_PROXY_SERVICE)); |
1679 entries1, 0, NetLog::TYPE_PROXY_SERVICE)); | |
1680 EXPECT_TRUE(LogContainsBeginEvent( | 1706 EXPECT_TRUE(LogContainsBeginEvent( |
1681 entries1, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 1707 entries1, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
1682 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before | 1708 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before |
1683 // the cancellation occured. | 1709 // the cancellation occured. |
1684 EXPECT_TRUE(LogContainsEvent( | 1710 EXPECT_TRUE(LogContainsEvent( |
1685 entries1, 2, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE)); | 1711 entries1, 2, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE)); |
1686 EXPECT_TRUE(LogContainsEndEvent( | 1712 EXPECT_TRUE(LogContainsEndEvent(entries1, 3, NetLog::TYPE_PROXY_SERVICE)); |
1687 entries1, 3, NetLog::TYPE_PROXY_SERVICE)); | |
1688 } | 1713 } |
1689 | 1714 |
1690 // Test that if auto-detect fails, we fall-back to the custom pac. | 1715 // Test that if auto-detect fails, we fall-back to the custom pac. |
1691 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { | 1716 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { |
1692 ProxyConfig config; | 1717 ProxyConfig config; |
1693 config.set_auto_detect(true); | 1718 config.set_auto_detect(true); |
1694 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 1719 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
1695 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. | 1720 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. |
1696 | 1721 |
1697 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1722 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
1698 MockAsyncProxyResolverExpectsBytes* resolver = | 1723 MockAsyncProxyResolverExpectsBytes* resolver = |
1699 new MockAsyncProxyResolverExpectsBytes; | 1724 new MockAsyncProxyResolverExpectsBytes; |
1700 ProxyService service(config_service, resolver, NULL); | 1725 ProxyService service(config_service, resolver, NULL); |
1701 | 1726 |
1702 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1727 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1703 service.SetProxyScriptFetchers(fetcher, | 1728 service.SetProxyScriptFetchers(fetcher, |
1704 new DoNothingDhcpProxyScriptFetcher()); | 1729 new DoNothingDhcpProxyScriptFetcher()); |
1705 | 1730 |
1706 // Start 2 requests. | 1731 // Start 2 requests. |
1707 | 1732 |
1708 ProxyInfo info1; | 1733 ProxyInfo info1; |
1709 TestCompletionCallback callback1; | 1734 TestCompletionCallback callback1; |
1710 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1735 int rv = service.ResolveProxy(GURL("http://request1"), |
1711 callback1.callback(), NULL, BoundNetLog()); | 1736 &info1, |
| 1737 callback1.callback(), |
| 1738 NULL, |
| 1739 BoundNetLog()); |
1712 EXPECT_EQ(ERR_IO_PENDING, rv); | 1740 EXPECT_EQ(ERR_IO_PENDING, rv); |
1713 | 1741 |
1714 ProxyInfo info2; | 1742 ProxyInfo info2; |
1715 TestCompletionCallback callback2; | 1743 TestCompletionCallback callback2; |
1716 ProxyService::PacRequest* request2; | 1744 ProxyService::PacRequest* request2; |
1717 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1745 rv = service.ResolveProxy(GURL("http://request2"), |
1718 callback2.callback(), &request2, BoundNetLog()); | 1746 &info2, |
| 1747 callback2.callback(), |
| 1748 &request2, |
| 1749 BoundNetLog()); |
1719 EXPECT_EQ(ERR_IO_PENDING, rv); | 1750 EXPECT_EQ(ERR_IO_PENDING, rv); |
1720 | 1751 |
1721 // Check that nothing has been sent to the proxy resolver yet. | 1752 // Check that nothing has been sent to the proxy resolver yet. |
1722 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1753 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1723 | 1754 |
1724 // It should be trying to auto-detect first -- FAIL the autodetect during | 1755 // It should be trying to auto-detect first -- FAIL the autodetect during |
1725 // the script download. | 1756 // the script download. |
1726 EXPECT_TRUE(fetcher->has_pending_request()); | 1757 EXPECT_TRUE(fetcher->has_pending_request()); |
1727 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1758 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1728 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 1759 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 ProxyService service(config_service, resolver, NULL); | 1808 ProxyService service(config_service, resolver, NULL); |
1778 | 1809 |
1779 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1810 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1780 service.SetProxyScriptFetchers(fetcher, | 1811 service.SetProxyScriptFetchers(fetcher, |
1781 new DoNothingDhcpProxyScriptFetcher()); | 1812 new DoNothingDhcpProxyScriptFetcher()); |
1782 | 1813 |
1783 // Start 2 requests. | 1814 // Start 2 requests. |
1784 | 1815 |
1785 ProxyInfo info1; | 1816 ProxyInfo info1; |
1786 TestCompletionCallback callback1; | 1817 TestCompletionCallback callback1; |
1787 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1818 int rv = service.ResolveProxy(GURL("http://request1"), |
1788 callback1.callback(), NULL, BoundNetLog()); | 1819 &info1, |
| 1820 callback1.callback(), |
| 1821 NULL, |
| 1822 BoundNetLog()); |
1789 EXPECT_EQ(ERR_IO_PENDING, rv); | 1823 EXPECT_EQ(ERR_IO_PENDING, rv); |
1790 | 1824 |
1791 ProxyInfo info2; | 1825 ProxyInfo info2; |
1792 TestCompletionCallback callback2; | 1826 TestCompletionCallback callback2; |
1793 ProxyService::PacRequest* request2; | 1827 ProxyService::PacRequest* request2; |
1794 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1828 rv = service.ResolveProxy(GURL("http://request2"), |
1795 callback2.callback(), &request2, BoundNetLog()); | 1829 &info2, |
| 1830 callback2.callback(), |
| 1831 &request2, |
| 1832 BoundNetLog()); |
1796 EXPECT_EQ(ERR_IO_PENDING, rv); | 1833 EXPECT_EQ(ERR_IO_PENDING, rv); |
1797 | 1834 |
1798 // Check that nothing has been sent to the proxy resolver yet. | 1835 // Check that nothing has been sent to the proxy resolver yet. |
1799 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1836 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1800 | 1837 |
1801 // It should be trying to auto-detect first -- succeed the download. | 1838 // It should be trying to auto-detect first -- succeed the download. |
1802 EXPECT_TRUE(fetcher->has_pending_request()); | 1839 EXPECT_TRUE(fetcher->has_pending_request()); |
1803 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1840 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1804 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 1841 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
1805 | 1842 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1850 ProxyService service(config_service, resolver, NULL); | 1887 ProxyService service(config_service, resolver, NULL); |
1851 | 1888 |
1852 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1889 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1853 service.SetProxyScriptFetchers(fetcher, | 1890 service.SetProxyScriptFetchers(fetcher, |
1854 new DoNothingDhcpProxyScriptFetcher()); | 1891 new DoNothingDhcpProxyScriptFetcher()); |
1855 | 1892 |
1856 // Start 2 requests. | 1893 // Start 2 requests. |
1857 | 1894 |
1858 ProxyInfo info1; | 1895 ProxyInfo info1; |
1859 TestCompletionCallback callback1; | 1896 TestCompletionCallback callback1; |
1860 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1897 int rv = service.ResolveProxy(GURL("http://request1"), |
1861 callback1.callback(), NULL, BoundNetLog()); | 1898 &info1, |
| 1899 callback1.callback(), |
| 1900 NULL, |
| 1901 BoundNetLog()); |
1862 EXPECT_EQ(ERR_IO_PENDING, rv); | 1902 EXPECT_EQ(ERR_IO_PENDING, rv); |
1863 | 1903 |
1864 ProxyInfo info2; | 1904 ProxyInfo info2; |
1865 TestCompletionCallback callback2; | 1905 TestCompletionCallback callback2; |
1866 ProxyService::PacRequest* request2; | 1906 ProxyService::PacRequest* request2; |
1867 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1907 rv = service.ResolveProxy(GURL("http://request2"), |
1868 callback2.callback(), &request2, BoundNetLog()); | 1908 &info2, |
| 1909 callback2.callback(), |
| 1910 &request2, |
| 1911 BoundNetLog()); |
1869 EXPECT_EQ(ERR_IO_PENDING, rv); | 1912 EXPECT_EQ(ERR_IO_PENDING, rv); |
1870 | 1913 |
1871 // Check that nothing has been sent to the proxy resolver yet. | 1914 // Check that nothing has been sent to the proxy resolver yet. |
1872 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1915 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1873 | 1916 |
1874 // It should be trying to auto-detect first -- fail the download. | 1917 // It should be trying to auto-detect first -- fail the download. |
1875 EXPECT_TRUE(fetcher->has_pending_request()); | 1918 EXPECT_TRUE(fetcher->has_pending_request()); |
1876 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1919 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1877 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 1920 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
1878 | 1921 |
(...skipping 29 matching lines...) Expand all Loading... |
1908 ProxyService service(config_service, resolver, NULL); | 1951 ProxyService service(config_service, resolver, NULL); |
1909 | 1952 |
1910 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1953 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1911 service.SetProxyScriptFetchers(fetcher, | 1954 service.SetProxyScriptFetchers(fetcher, |
1912 new DoNothingDhcpProxyScriptFetcher()); | 1955 new DoNothingDhcpProxyScriptFetcher()); |
1913 | 1956 |
1914 // Start 1 requests. | 1957 // Start 1 requests. |
1915 | 1958 |
1916 ProxyInfo info1; | 1959 ProxyInfo info1; |
1917 TestCompletionCallback callback1; | 1960 TestCompletionCallback callback1; |
1918 int rv = service.ResolveProxy( | 1961 int rv = service.ResolveProxy(GURL("http://www.google.com"), |
1919 GURL("http://www.google.com"), &info1, callback1.callback(), NULL, | 1962 &info1, |
1920 BoundNetLog()); | 1963 callback1.callback(), |
| 1964 NULL, |
| 1965 BoundNetLog()); |
1921 EXPECT_EQ(ERR_IO_PENDING, rv); | 1966 EXPECT_EQ(ERR_IO_PENDING, rv); |
1922 | 1967 |
1923 // Check that nothing has been sent to the proxy resolver yet. | 1968 // Check that nothing has been sent to the proxy resolver yet. |
1924 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1969 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1925 | 1970 |
1926 // It should be trying to auto-detect first -- succeed the download. | 1971 // It should be trying to auto-detect first -- succeed the download. |
1927 EXPECT_TRUE(fetcher->has_pending_request()); | 1972 EXPECT_TRUE(fetcher->has_pending_request()); |
1928 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1973 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1929 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 1974 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
1930 | 1975 |
1931 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 1976 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
1932 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1977 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
1933 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1978 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1934 | 1979 |
1935 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1980 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1936 EXPECT_EQ(GURL("http://www.google.com"), | 1981 EXPECT_EQ(GURL("http://www.google.com"), |
1937 resolver->pending_requests()[0]->url()); | 1982 resolver->pending_requests()[0]->url()); |
1938 | 1983 |
1939 // Complete the pending request. | 1984 // Complete the pending request. |
1940 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 1985 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
1941 resolver->pending_requests()[0]->CompleteNow(OK); | 1986 resolver->pending_requests()[0]->CompleteNow(OK); |
1942 | 1987 |
1943 // Verify that request ran as expected. | 1988 // Verify that request ran as expected. |
1944 EXPECT_EQ(OK, callback1.WaitForResult()); | 1989 EXPECT_EQ(OK, callback1.WaitForResult()); |
1945 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1990 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
1946 | 1991 |
1947 // Start another request, it should pickup the bypass item. | 1992 // Start another request, it should pickup the bypass item. |
1948 ProxyInfo info2; | 1993 ProxyInfo info2; |
1949 TestCompletionCallback callback2; | 1994 TestCompletionCallback callback2; |
1950 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, | 1995 rv = service.ResolveProxy(GURL("http://www.google.com"), |
1951 callback2.callback(), NULL, BoundNetLog()); | 1996 &info2, |
| 1997 callback2.callback(), |
| 1998 NULL, |
| 1999 BoundNetLog()); |
1952 EXPECT_EQ(ERR_IO_PENDING, rv); | 2000 EXPECT_EQ(ERR_IO_PENDING, rv); |
1953 | 2001 |
1954 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2002 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1955 EXPECT_EQ(GURL("http://www.google.com"), | 2003 EXPECT_EQ(GURL("http://www.google.com"), |
1956 resolver->pending_requests()[0]->url()); | 2004 resolver->pending_requests()[0]->url()); |
1957 | 2005 |
1958 // Complete the pending request. | 2006 // Complete the pending request. |
1959 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2007 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
1960 resolver->pending_requests()[0]->CompleteNow(OK); | 2008 resolver->pending_requests()[0]->CompleteNow(OK); |
1961 | 2009 |
1962 EXPECT_EQ(OK, callback2.WaitForResult()); | 2010 EXPECT_EQ(OK, callback2.WaitForResult()); |
1963 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2011 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
1964 } | 2012 } |
1965 | 2013 |
1966 // Delete the ProxyService while InitProxyResolver has an outstanding | 2014 // Delete the ProxyService while InitProxyResolver has an outstanding |
1967 // request to the script fetcher. When run under valgrind, should not | 2015 // request to the script fetcher. When run under valgrind, should not |
1968 // have any memory errors (used to be that the ProxyScriptFetcher was | 2016 // have any memory errors (used to be that the ProxyScriptFetcher was |
1969 // being deleted prior to the InitProxyResolver). | 2017 // being deleted prior to the InitProxyResolver). |
1970 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { | 2018 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { |
1971 ProxyConfig config = | 2019 ProxyConfig config = |
1972 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); | 2020 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); |
1973 | 2021 |
1974 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2022 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
1975 MockAsyncProxyResolverExpectsBytes* resolver = | 2023 MockAsyncProxyResolverExpectsBytes* resolver = |
1976 new MockAsyncProxyResolverExpectsBytes; | 2024 new MockAsyncProxyResolverExpectsBytes; |
1977 ProxyService service(config_service, resolver, NULL); | 2025 ProxyService service(config_service, resolver, NULL); |
1978 | 2026 |
1979 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2027 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1980 service.SetProxyScriptFetchers(fetcher, | 2028 service.SetProxyScriptFetchers(fetcher, |
1981 new DoNothingDhcpProxyScriptFetcher()); | 2029 new DoNothingDhcpProxyScriptFetcher()); |
1982 | 2030 |
1983 // Start 1 request. | 2031 // Start 1 request. |
1984 | 2032 |
1985 ProxyInfo info1; | 2033 ProxyInfo info1; |
1986 TestCompletionCallback callback1; | 2034 TestCompletionCallback callback1; |
1987 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, | 2035 int rv = service.ResolveProxy(GURL("http://www.google.com"), |
1988 callback1.callback(), NULL, BoundNetLog()); | 2036 &info1, |
| 2037 callback1.callback(), |
| 2038 NULL, |
| 2039 BoundNetLog()); |
1989 EXPECT_EQ(ERR_IO_PENDING, rv); | 2040 EXPECT_EQ(ERR_IO_PENDING, rv); |
1990 | 2041 |
1991 // Check that nothing has been sent to the proxy resolver yet. | 2042 // Check that nothing has been sent to the proxy resolver yet. |
1992 ASSERT_EQ(0u, resolver->pending_requests().size()); | 2043 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1993 | 2044 |
1994 // InitProxyResolver should have issued a request to the ProxyScriptFetcher | 2045 // InitProxyResolver should have issued a request to the ProxyScriptFetcher |
1995 // and be waiting on that to complete. | 2046 // and be waiting on that to complete. |
1996 EXPECT_TRUE(fetcher->has_pending_request()); | 2047 EXPECT_TRUE(fetcher->has_pending_request()); |
1997 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2048 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1998 } | 2049 } |
(...skipping 19 matching lines...) Expand all Loading... |
2018 EXPECT_EQ(ERR_IO_PENDING, rv); | 2069 EXPECT_EQ(ERR_IO_PENDING, rv); |
2019 | 2070 |
2020 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 2071 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
2021 resolver->pending_set_pac_script_request()->script_data()->url()); | 2072 resolver->pending_set_pac_script_request()->script_data()->url()); |
2022 } | 2073 } |
2023 | 2074 |
2024 TEST_F(ProxyServiceTest, ResetProxyConfigService) { | 2075 TEST_F(ProxyServiceTest, ResetProxyConfigService) { |
2025 ProxyConfig config1; | 2076 ProxyConfig config1; |
2026 config1.proxy_rules().ParseFromString("foopy1:8080"); | 2077 config1.proxy_rules().ParseFromString("foopy1:8080"); |
2027 config1.set_auto_detect(false); | 2078 config1.set_auto_detect(false); |
2028 ProxyService service( | 2079 ProxyService service(new MockProxyConfigService(config1), |
2029 new MockProxyConfigService(config1), | 2080 new MockAsyncProxyResolverExpectsBytes, |
2030 new MockAsyncProxyResolverExpectsBytes, NULL); | 2081 NULL); |
2031 | 2082 |
2032 ProxyInfo info; | 2083 ProxyInfo info; |
2033 TestCompletionCallback callback1; | 2084 TestCompletionCallback callback1; |
2034 int rv = service.ResolveProxy(GURL("http://request1"), &info, | 2085 int rv = service.ResolveProxy(GURL("http://request1"), |
2035 callback1.callback(), NULL, BoundNetLog()); | 2086 &info, |
| 2087 callback1.callback(), |
| 2088 NULL, |
| 2089 BoundNetLog()); |
2036 EXPECT_EQ(OK, rv); | 2090 EXPECT_EQ(OK, rv); |
2037 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 2091 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
2038 | 2092 |
2039 ProxyConfig config2; | 2093 ProxyConfig config2; |
2040 config2.proxy_rules().ParseFromString("foopy2:8080"); | 2094 config2.proxy_rules().ParseFromString("foopy2:8080"); |
2041 config2.set_auto_detect(false); | 2095 config2.set_auto_detect(false); |
2042 service.ResetConfigService(new MockProxyConfigService(config2)); | 2096 service.ResetConfigService(new MockProxyConfigService(config2)); |
2043 TestCompletionCallback callback2; | 2097 TestCompletionCallback callback2; |
2044 rv = service.ResolveProxy(GURL("http://request2"), &info, | 2098 rv = service.ResolveProxy(GURL("http://request2"), |
2045 callback2.callback(), NULL, BoundNetLog()); | 2099 &info, |
| 2100 callback2.callback(), |
| 2101 NULL, |
| 2102 BoundNetLog()); |
2046 EXPECT_EQ(OK, rv); | 2103 EXPECT_EQ(OK, rv); |
2047 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 2104 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
2048 } | 2105 } |
2049 | 2106 |
2050 // Test that when going from a configuration that required PAC to one | 2107 // Test that when going from a configuration that required PAC to one |
2051 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 2108 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
2052 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 2109 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
2053 ProxyConfig config = ProxyConfig::CreateAutoDetect(); | 2110 ProxyConfig config = ProxyConfig::CreateAutoDetect(); |
2054 | 2111 |
2055 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2112 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2056 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 2113 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
2057 ProxyService service(config_service, resolver, NULL); | 2114 ProxyService service(config_service, resolver, NULL); |
2058 | 2115 |
2059 // Start 1 request. | 2116 // Start 1 request. |
2060 | 2117 |
2061 ProxyInfo info1; | 2118 ProxyInfo info1; |
2062 TestCompletionCallback callback1; | 2119 TestCompletionCallback callback1; |
2063 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, | 2120 int rv = service.ResolveProxy(GURL("http://www.google.com"), |
2064 callback1.callback(), NULL, BoundNetLog()); | 2121 &info1, |
| 2122 callback1.callback(), |
| 2123 NULL, |
| 2124 BoundNetLog()); |
2065 EXPECT_EQ(ERR_IO_PENDING, rv); | 2125 EXPECT_EQ(ERR_IO_PENDING, rv); |
2066 | 2126 |
2067 // Check that nothing has been sent to the proxy resolver yet. | 2127 // Check that nothing has been sent to the proxy resolver yet. |
2068 ASSERT_EQ(0u, resolver->pending_requests().size()); | 2128 ASSERT_EQ(0u, resolver->pending_requests().size()); |
2069 | 2129 |
2070 // Successfully set the autodetect script. | 2130 // Successfully set the autodetect script. |
2071 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 2131 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
2072 resolver->pending_set_pac_script_request()->script_data()->type()); | 2132 resolver->pending_set_pac_script_request()->script_data()->type()); |
2073 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 2133 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
2074 | 2134 |
2075 // Complete the pending request. | 2135 // Complete the pending request. |
2076 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2136 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2077 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2137 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2078 resolver->pending_requests()[0]->CompleteNow(OK); | 2138 resolver->pending_requests()[0]->CompleteNow(OK); |
2079 | 2139 |
2080 // Verify that request ran as expected. | 2140 // Verify that request ran as expected. |
2081 EXPECT_EQ(OK, callback1.WaitForResult()); | 2141 EXPECT_EQ(OK, callback1.WaitForResult()); |
2082 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2142 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2083 | 2143 |
2084 // Force the ProxyService to pull down a new proxy configuration. | 2144 // Force the ProxyService to pull down a new proxy configuration. |
2085 // (Even though the configuration isn't old/bad). | 2145 // (Even though the configuration isn't old/bad). |
2086 // | 2146 // |
2087 // This new configuration no longer has auto_detect set, so | 2147 // This new configuration no longer has auto_detect set, so |
2088 // requests should complete synchronously now as direct-connect. | 2148 // requests should complete synchronously now as direct-connect. |
2089 config_service->SetConfig(ProxyConfig::CreateDirect()); | 2149 config_service->SetConfig(ProxyConfig::CreateDirect()); |
2090 | 2150 |
2091 // Start another request -- the effective configuration has changed. | 2151 // Start another request -- the effective configuration has changed. |
2092 ProxyInfo info2; | 2152 ProxyInfo info2; |
2093 TestCompletionCallback callback2; | 2153 TestCompletionCallback callback2; |
2094 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, | 2154 rv = service.ResolveProxy(GURL("http://www.google.com"), |
2095 callback2.callback(), NULL, BoundNetLog()); | 2155 &info2, |
| 2156 callback2.callback(), |
| 2157 NULL, |
| 2158 BoundNetLog()); |
2096 EXPECT_EQ(OK, rv); | 2159 EXPECT_EQ(OK, rv); |
2097 | 2160 |
2098 EXPECT_TRUE(info2.is_direct()); | 2161 EXPECT_TRUE(info2.is_direct()); |
2099 } | 2162 } |
2100 | 2163 |
2101 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { | 2164 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { |
2102 MockProxyConfigService* config_service = | 2165 MockProxyConfigService* config_service = |
2103 new MockProxyConfigService("http://foopy/proxy.pac"); | 2166 new MockProxyConfigService("http://foopy/proxy.pac"); |
2104 | 2167 |
2105 MockAsyncProxyResolverExpectsBytes* resolver = | 2168 MockAsyncProxyResolverExpectsBytes* resolver = |
2106 new MockAsyncProxyResolverExpectsBytes; | 2169 new MockAsyncProxyResolverExpectsBytes; |
2107 | 2170 |
2108 CapturingNetLog log; | 2171 CapturingNetLog log; |
2109 | 2172 |
2110 ProxyService service(config_service, resolver, &log); | 2173 ProxyService service(config_service, resolver, &log); |
2111 | 2174 |
2112 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2175 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2113 service.SetProxyScriptFetchers(fetcher, | 2176 service.SetProxyScriptFetchers(fetcher, |
2114 new DoNothingDhcpProxyScriptFetcher()); | 2177 new DoNothingDhcpProxyScriptFetcher()); |
2115 | 2178 |
2116 // Disable the "wait after IP address changes" hack, so this unit-test can | 2179 // Disable the "wait after IP address changes" hack, so this unit-test can |
2117 // complete quickly. | 2180 // complete quickly. |
2118 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); | 2181 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); |
2119 | 2182 |
2120 // Start 1 request. | 2183 // Start 1 request. |
2121 | 2184 |
2122 ProxyInfo info1; | 2185 ProxyInfo info1; |
2123 TestCompletionCallback callback1; | 2186 TestCompletionCallback callback1; |
2124 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 2187 int rv = service.ResolveProxy(GURL("http://request1"), |
2125 callback1.callback(), NULL, BoundNetLog()); | 2188 &info1, |
| 2189 callback1.callback(), |
| 2190 NULL, |
| 2191 BoundNetLog()); |
2126 EXPECT_EQ(ERR_IO_PENDING, rv); | 2192 EXPECT_EQ(ERR_IO_PENDING, rv); |
2127 | 2193 |
2128 // The first request should have triggered initial download of PAC script. | 2194 // The first request should have triggered initial download of PAC script. |
2129 EXPECT_TRUE(fetcher->has_pending_request()); | 2195 EXPECT_TRUE(fetcher->has_pending_request()); |
2130 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2196 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2131 | 2197 |
2132 // Nothing has been sent to the resolver yet. | 2198 // Nothing has been sent to the resolver yet. |
2133 EXPECT_TRUE(resolver->pending_requests().empty()); | 2199 EXPECT_TRUE(resolver->pending_requests().empty()); |
2134 | 2200 |
2135 // At this point the ProxyService should be waiting for the | 2201 // At this point the ProxyService should be waiting for the |
(...skipping 20 matching lines...) Expand all Loading... |
2156 | 2222 |
2157 // Now simluate a change in the network. The ProxyConfigService is still | 2223 // Now simluate a change in the network. The ProxyConfigService is still |
2158 // going to return the same PAC URL as before, but this URL needs to be | 2224 // going to return the same PAC URL as before, but this URL needs to be |
2159 // refetched on the new network. | 2225 // refetched on the new network. |
2160 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 2226 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
2161 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 2227 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. |
2162 | 2228 |
2163 // Start a second request. | 2229 // Start a second request. |
2164 ProxyInfo info2; | 2230 ProxyInfo info2; |
2165 TestCompletionCallback callback2; | 2231 TestCompletionCallback callback2; |
2166 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 2232 rv = service.ResolveProxy(GURL("http://request2"), |
2167 callback2.callback(), NULL, BoundNetLog()); | 2233 &info2, |
| 2234 callback2.callback(), |
| 2235 NULL, |
| 2236 BoundNetLog()); |
2168 EXPECT_EQ(ERR_IO_PENDING, rv); | 2237 EXPECT_EQ(ERR_IO_PENDING, rv); |
2169 | 2238 |
2170 // This second request should have triggered the re-download of the PAC | 2239 // This second request should have triggered the re-download of the PAC |
2171 // script (since we marked the network as having changed). | 2240 // script (since we marked the network as having changed). |
2172 EXPECT_TRUE(fetcher->has_pending_request()); | 2241 EXPECT_TRUE(fetcher->has_pending_request()); |
2173 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2242 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2174 | 2243 |
2175 // Nothing has been sent to the resolver yet. | 2244 // Nothing has been sent to the resolver yet. |
2176 EXPECT_TRUE(resolver->pending_requests().empty()); | 2245 EXPECT_TRUE(resolver->pending_requests().empty()); |
2177 | 2246 |
(...skipping 17 matching lines...) Expand all Loading... |
2195 // Wait for completion callback, and verify that the request ran as expected. | 2264 // Wait for completion callback, and verify that the request ran as expected. |
2196 EXPECT_EQ(OK, callback2.WaitForResult()); | 2265 EXPECT_EQ(OK, callback2.WaitForResult()); |
2197 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2266 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2198 | 2267 |
2199 // Check that the expected events were output to the log stream. In particular | 2268 // Check that the expected events were output to the log stream. In particular |
2200 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial | 2269 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial |
2201 // setup), and NOT a second time when the IP address changed. | 2270 // setup), and NOT a second time when the IP address changed. |
2202 CapturingNetLog::CapturedEntryList entries; | 2271 CapturingNetLog::CapturedEntryList entries; |
2203 log.GetEntries(&entries); | 2272 log.GetEntries(&entries); |
2204 | 2273 |
2205 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, | 2274 EXPECT_TRUE( |
2206 NetLog::TYPE_PROXY_CONFIG_CHANGED)); | 2275 LogContainsEntryWithType(entries, 0, NetLog::TYPE_PROXY_CONFIG_CHANGED)); |
2207 ASSERT_EQ(9u, entries.size()); | 2276 ASSERT_EQ(9u, entries.size()); |
2208 for (size_t i = 1; i < entries.size(); ++i) | 2277 for (size_t i = 1; i < entries.size(); ++i) |
2209 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); | 2278 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); |
2210 } | 2279 } |
2211 | 2280 |
2212 // This test verifies that the PAC script specified by the settings is | 2281 // This test verifies that the PAC script specified by the settings is |
2213 // periodically polled for changes. Specifically, if the initial fetch fails due | 2282 // periodically polled for changes. Specifically, if the initial fetch fails due |
2214 // to a network error, we will eventually re-configure the service to use the | 2283 // to a network error, we will eventually re-configure the service to use the |
2215 // script once it becomes available. | 2284 // script once it becomes available. |
2216 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) { | 2285 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) { |
(...skipping 11 matching lines...) Expand all Loading... |
2228 ProxyService service(config_service, resolver, NULL); | 2297 ProxyService service(config_service, resolver, NULL); |
2229 | 2298 |
2230 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2299 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2231 service.SetProxyScriptFetchers(fetcher, | 2300 service.SetProxyScriptFetchers(fetcher, |
2232 new DoNothingDhcpProxyScriptFetcher()); | 2301 new DoNothingDhcpProxyScriptFetcher()); |
2233 | 2302 |
2234 // Start 1 request. | 2303 // Start 1 request. |
2235 | 2304 |
2236 ProxyInfo info1; | 2305 ProxyInfo info1; |
2237 TestCompletionCallback callback1; | 2306 TestCompletionCallback callback1; |
2238 int rv = service.ResolveProxy( | 2307 int rv = service.ResolveProxy(GURL("http://request1"), |
2239 GURL("http://request1"), &info1, callback1.callback(), | 2308 &info1, |
2240 NULL, BoundNetLog()); | 2309 callback1.callback(), |
| 2310 NULL, |
| 2311 BoundNetLog()); |
2241 EXPECT_EQ(ERR_IO_PENDING, rv); | 2312 EXPECT_EQ(ERR_IO_PENDING, rv); |
2242 | 2313 |
2243 // The first request should have triggered initial download of PAC script. | 2314 // The first request should have triggered initial download of PAC script. |
2244 EXPECT_TRUE(fetcher->has_pending_request()); | 2315 EXPECT_TRUE(fetcher->has_pending_request()); |
2245 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2316 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2246 | 2317 |
2247 // Nothing has been sent to the resolver yet. | 2318 // Nothing has been sent to the resolver yet. |
2248 EXPECT_TRUE(resolver->pending_requests().empty()); | 2319 EXPECT_TRUE(resolver->pending_requests().empty()); |
2249 | 2320 |
2250 // At this point the ProxyService should be waiting for the | 2321 // At this point the ProxyService should be waiting for the |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2289 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 2360 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
2290 | 2361 |
2291 // At this point the ProxyService should have re-configured itself to use the | 2362 // At this point the ProxyService should have re-configured itself to use the |
2292 // PAC script (thereby recovering from the initial fetch failure). We will | 2363 // PAC script (thereby recovering from the initial fetch failure). We will |
2293 // verify that the next Resolve request uses the resolver rather than | 2364 // verify that the next Resolve request uses the resolver rather than |
2294 // DIRECT. | 2365 // DIRECT. |
2295 | 2366 |
2296 // Start a second request. | 2367 // Start a second request. |
2297 ProxyInfo info2; | 2368 ProxyInfo info2; |
2298 TestCompletionCallback callback2; | 2369 TestCompletionCallback callback2; |
2299 rv = service.ResolveProxy( | 2370 rv = service.ResolveProxy(GURL("http://request2"), |
2300 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2371 &info2, |
2301 BoundNetLog()); | 2372 callback2.callback(), |
| 2373 NULL, |
| 2374 BoundNetLog()); |
2302 EXPECT_EQ(ERR_IO_PENDING, rv); | 2375 EXPECT_EQ(ERR_IO_PENDING, rv); |
2303 | 2376 |
2304 // Check that it was sent to the resolver. | 2377 // Check that it was sent to the resolver. |
2305 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2378 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2306 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2379 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2307 | 2380 |
2308 // Complete the pending second request. | 2381 // Complete the pending second request. |
2309 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2382 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2310 resolver->pending_requests()[0]->CompleteNow(OK); | 2383 resolver->pending_requests()[0]->CompleteNow(OK); |
2311 | 2384 |
(...skipping 21 matching lines...) Expand all Loading... |
2333 ProxyService service(config_service, resolver, NULL); | 2406 ProxyService service(config_service, resolver, NULL); |
2334 | 2407 |
2335 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2408 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2336 service.SetProxyScriptFetchers(fetcher, | 2409 service.SetProxyScriptFetchers(fetcher, |
2337 new DoNothingDhcpProxyScriptFetcher()); | 2410 new DoNothingDhcpProxyScriptFetcher()); |
2338 | 2411 |
2339 // Start 1 request. | 2412 // Start 1 request. |
2340 | 2413 |
2341 ProxyInfo info1; | 2414 ProxyInfo info1; |
2342 TestCompletionCallback callback1; | 2415 TestCompletionCallback callback1; |
2343 int rv = service.ResolveProxy( | 2416 int rv = service.ResolveProxy(GURL("http://request1"), |
2344 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2417 &info1, |
2345 BoundNetLog()); | 2418 callback1.callback(), |
| 2419 NULL, |
| 2420 BoundNetLog()); |
2346 EXPECT_EQ(ERR_IO_PENDING, rv); | 2421 EXPECT_EQ(ERR_IO_PENDING, rv); |
2347 | 2422 |
2348 // The first request should have triggered initial download of PAC script. | 2423 // The first request should have triggered initial download of PAC script. |
2349 EXPECT_TRUE(fetcher->has_pending_request()); | 2424 EXPECT_TRUE(fetcher->has_pending_request()); |
2350 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2425 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2351 | 2426 |
2352 // Nothing has been sent to the resolver yet. | 2427 // Nothing has been sent to the resolver yet. |
2353 EXPECT_TRUE(resolver->pending_requests().empty()); | 2428 EXPECT_TRUE(resolver->pending_requests().empty()); |
2354 | 2429 |
2355 // At this point the ProxyService should be waiting for the | 2430 // At this point the ProxyService should be waiting for the |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2399 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | 2474 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
2400 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 2475 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
2401 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 2476 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
2402 | 2477 |
2403 // At this point the ProxyService should have re-configured itself to use the | 2478 // At this point the ProxyService should have re-configured itself to use the |
2404 // new PAC script. | 2479 // new PAC script. |
2405 | 2480 |
2406 // Start a second request. | 2481 // Start a second request. |
2407 ProxyInfo info2; | 2482 ProxyInfo info2; |
2408 TestCompletionCallback callback2; | 2483 TestCompletionCallback callback2; |
2409 rv = service.ResolveProxy( | 2484 rv = service.ResolveProxy(GURL("http://request2"), |
2410 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2485 &info2, |
2411 BoundNetLog()); | 2486 callback2.callback(), |
| 2487 NULL, |
| 2488 BoundNetLog()); |
2412 EXPECT_EQ(ERR_IO_PENDING, rv); | 2489 EXPECT_EQ(ERR_IO_PENDING, rv); |
2413 | 2490 |
2414 // Check that it was sent to the resolver. | 2491 // Check that it was sent to the resolver. |
2415 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2492 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2416 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2493 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2417 | 2494 |
2418 // Complete the pending second request. | 2495 // Complete the pending second request. |
2419 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2496 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2420 resolver->pending_requests()[0]->CompleteNow(OK); | 2497 resolver->pending_requests()[0]->CompleteNow(OK); |
2421 | 2498 |
(...skipping 21 matching lines...) Expand all Loading... |
2443 ProxyService service(config_service, resolver, NULL); | 2520 ProxyService service(config_service, resolver, NULL); |
2444 | 2521 |
2445 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2522 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2446 service.SetProxyScriptFetchers(fetcher, | 2523 service.SetProxyScriptFetchers(fetcher, |
2447 new DoNothingDhcpProxyScriptFetcher()); | 2524 new DoNothingDhcpProxyScriptFetcher()); |
2448 | 2525 |
2449 // Start 1 request. | 2526 // Start 1 request. |
2450 | 2527 |
2451 ProxyInfo info1; | 2528 ProxyInfo info1; |
2452 TestCompletionCallback callback1; | 2529 TestCompletionCallback callback1; |
2453 int rv = service.ResolveProxy( | 2530 int rv = service.ResolveProxy(GURL("http://request1"), |
2454 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2531 &info1, |
2455 BoundNetLog()); | 2532 callback1.callback(), |
| 2533 NULL, |
| 2534 BoundNetLog()); |
2456 EXPECT_EQ(ERR_IO_PENDING, rv); | 2535 EXPECT_EQ(ERR_IO_PENDING, rv); |
2457 | 2536 |
2458 // The first request should have triggered initial download of PAC script. | 2537 // The first request should have triggered initial download of PAC script. |
2459 EXPECT_TRUE(fetcher->has_pending_request()); | 2538 EXPECT_TRUE(fetcher->has_pending_request()); |
2460 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2539 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2461 | 2540 |
2462 // Nothing has been sent to the resolver yet. | 2541 // Nothing has been sent to the resolver yet. |
2463 EXPECT_TRUE(resolver->pending_requests().empty()); | 2542 EXPECT_TRUE(resolver->pending_requests().empty()); |
2464 | 2543 |
2465 // At this point the ProxyService should be waiting for the | 2544 // At this point the ProxyService should be waiting for the |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2505 base::MessageLoop::current()->RunUntilIdle(); | 2584 base::MessageLoop::current()->RunUntilIdle(); |
2506 | 2585 |
2507 ASSERT_FALSE(resolver->has_pending_set_pac_script_request()); | 2586 ASSERT_FALSE(resolver->has_pending_set_pac_script_request()); |
2508 | 2587 |
2509 // At this point the ProxyService is still running the same PAC script as | 2588 // At this point the ProxyService is still running the same PAC script as |
2510 // before. | 2589 // before. |
2511 | 2590 |
2512 // Start a second request. | 2591 // Start a second request. |
2513 ProxyInfo info2; | 2592 ProxyInfo info2; |
2514 TestCompletionCallback callback2; | 2593 TestCompletionCallback callback2; |
2515 rv = service.ResolveProxy( | 2594 rv = service.ResolveProxy(GURL("http://request2"), |
2516 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2595 &info2, |
2517 BoundNetLog()); | 2596 callback2.callback(), |
| 2597 NULL, |
| 2598 BoundNetLog()); |
2518 EXPECT_EQ(ERR_IO_PENDING, rv); | 2599 EXPECT_EQ(ERR_IO_PENDING, rv); |
2519 | 2600 |
2520 // Check that it was sent to the resolver. | 2601 // Check that it was sent to the resolver. |
2521 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2602 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2522 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2603 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2523 | 2604 |
2524 // Complete the pending second request. | 2605 // Complete the pending second request. |
2525 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2606 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2526 resolver->pending_requests()[0]->CompleteNow(OK); | 2607 resolver->pending_requests()[0]->CompleteNow(OK); |
2527 | 2608 |
(...skipping 21 matching lines...) Expand all Loading... |
2549 ProxyService service(config_service, resolver, NULL); | 2630 ProxyService service(config_service, resolver, NULL); |
2550 | 2631 |
2551 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2632 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2552 service.SetProxyScriptFetchers(fetcher, | 2633 service.SetProxyScriptFetchers(fetcher, |
2553 new DoNothingDhcpProxyScriptFetcher()); | 2634 new DoNothingDhcpProxyScriptFetcher()); |
2554 | 2635 |
2555 // Start 1 request. | 2636 // Start 1 request. |
2556 | 2637 |
2557 ProxyInfo info1; | 2638 ProxyInfo info1; |
2558 TestCompletionCallback callback1; | 2639 TestCompletionCallback callback1; |
2559 int rv = service.ResolveProxy( | 2640 int rv = service.ResolveProxy(GURL("http://request1"), |
2560 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2641 &info1, |
2561 BoundNetLog()); | 2642 callback1.callback(), |
| 2643 NULL, |
| 2644 BoundNetLog()); |
2562 EXPECT_EQ(ERR_IO_PENDING, rv); | 2645 EXPECT_EQ(ERR_IO_PENDING, rv); |
2563 | 2646 |
2564 // The first request should have triggered initial download of PAC script. | 2647 // The first request should have triggered initial download of PAC script. |
2565 EXPECT_TRUE(fetcher->has_pending_request()); | 2648 EXPECT_TRUE(fetcher->has_pending_request()); |
2566 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2649 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2567 | 2650 |
2568 // Nothing has been sent to the resolver yet. | 2651 // Nothing has been sent to the resolver yet. |
2569 EXPECT_TRUE(resolver->pending_requests().empty()); | 2652 EXPECT_TRUE(resolver->pending_requests().empty()); |
2570 | 2653 |
2571 // At this point the ProxyService should be waiting for the | 2654 // At this point the ProxyService should be waiting for the |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2609 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2692 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2610 | 2693 |
2611 base::MessageLoop::current()->RunUntilIdle(); | 2694 base::MessageLoop::current()->RunUntilIdle(); |
2612 | 2695 |
2613 // At this point the ProxyService should have re-configured itself to use | 2696 // At this point the ProxyService should have re-configured itself to use |
2614 // DIRECT connections rather than the given proxy resolver. | 2697 // DIRECT connections rather than the given proxy resolver. |
2615 | 2698 |
2616 // Start a second request. | 2699 // Start a second request. |
2617 ProxyInfo info2; | 2700 ProxyInfo info2; |
2618 TestCompletionCallback callback2; | 2701 TestCompletionCallback callback2; |
2619 rv = service.ResolveProxy( | 2702 rv = service.ResolveProxy(GURL("http://request2"), |
2620 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2703 &info2, |
2621 BoundNetLog()); | 2704 callback2.callback(), |
| 2705 NULL, |
| 2706 BoundNetLog()); |
2622 EXPECT_EQ(OK, rv); | 2707 EXPECT_EQ(OK, rv); |
2623 EXPECT_TRUE(info2.is_direct()); | 2708 EXPECT_TRUE(info2.is_direct()); |
2624 } | 2709 } |
2625 | 2710 |
2626 // Tests that the code which decides at what times to poll the PAC | 2711 // Tests that the code which decides at what times to poll the PAC |
2627 // script follows the expected policy. | 2712 // script follows the expected policy. |
2628 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { | 2713 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { |
2629 // Retrieve the internal polling policy implementation used by ProxyService. | 2714 // Retrieve the internal polling policy implementation used by ProxyService. |
2630 scoped_ptr<ProxyService::PacPollPolicy> policy = | 2715 scoped_ptr<ProxyService::PacPollPolicy> policy = |
2631 ProxyService::CreateDefaultPacPollPolicy(); | 2716 ProxyService::CreateDefaultPacPollPolicy(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2701 ProxyService service(config_service, resolver, NULL); | 2786 ProxyService service(config_service, resolver, NULL); |
2702 | 2787 |
2703 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2788 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2704 service.SetProxyScriptFetchers(fetcher, | 2789 service.SetProxyScriptFetchers(fetcher, |
2705 new DoNothingDhcpProxyScriptFetcher()); | 2790 new DoNothingDhcpProxyScriptFetcher()); |
2706 | 2791 |
2707 // Start 1 request. | 2792 // Start 1 request. |
2708 | 2793 |
2709 ProxyInfo info1; | 2794 ProxyInfo info1; |
2710 TestCompletionCallback callback1; | 2795 TestCompletionCallback callback1; |
2711 int rv = service.ResolveProxy( | 2796 int rv = service.ResolveProxy(GURL("http://request1"), |
2712 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2797 &info1, |
2713 BoundNetLog()); | 2798 callback1.callback(), |
| 2799 NULL, |
| 2800 BoundNetLog()); |
2714 EXPECT_EQ(ERR_IO_PENDING, rv); | 2801 EXPECT_EQ(ERR_IO_PENDING, rv); |
2715 | 2802 |
2716 // The first request should have triggered initial download of PAC script. | 2803 // The first request should have triggered initial download of PAC script. |
2717 EXPECT_TRUE(fetcher->has_pending_request()); | 2804 EXPECT_TRUE(fetcher->has_pending_request()); |
2718 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2805 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2719 | 2806 |
2720 // Nothing has been sent to the resolver yet. | 2807 // Nothing has been sent to the resolver yet. |
2721 EXPECT_TRUE(resolver->pending_requests().empty()); | 2808 EXPECT_TRUE(resolver->pending_requests().empty()); |
2722 | 2809 |
2723 // At this point the ProxyService should be waiting for the | 2810 // At this point the ProxyService should be waiting for the |
(...skipping 21 matching lines...) Expand all Loading... |
2745 // At this point we have initialized the proxy service using a PAC script. | 2832 // At this point we have initialized the proxy service using a PAC script. |
2746 // Our PAC poller is set to update ONLY in response to network activity, | 2833 // Our PAC poller is set to update ONLY in response to network activity, |
2747 // (i.e. another call to ResolveProxy()). | 2834 // (i.e. another call to ResolveProxy()). |
2748 | 2835 |
2749 ASSERT_FALSE(fetcher->has_pending_request()); | 2836 ASSERT_FALSE(fetcher->has_pending_request()); |
2750 ASSERT_TRUE(resolver->pending_requests().empty()); | 2837 ASSERT_TRUE(resolver->pending_requests().empty()); |
2751 | 2838 |
2752 // Start a second request. | 2839 // Start a second request. |
2753 ProxyInfo info2; | 2840 ProxyInfo info2; |
2754 TestCompletionCallback callback2; | 2841 TestCompletionCallback callback2; |
2755 rv = service.ResolveProxy( | 2842 rv = service.ResolveProxy(GURL("http://request2"), |
2756 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2843 &info2, |
2757 BoundNetLog()); | 2844 callback2.callback(), |
| 2845 NULL, |
| 2846 BoundNetLog()); |
2758 EXPECT_EQ(ERR_IO_PENDING, rv); | 2847 EXPECT_EQ(ERR_IO_PENDING, rv); |
2759 | 2848 |
2760 // This request should have sent work to the resolver; complete it. | 2849 // This request should have sent work to the resolver; complete it. |
2761 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2850 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2762 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2851 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2763 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2852 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2764 resolver->pending_requests()[0]->CompleteNow(OK); | 2853 resolver->pending_requests()[0]->CompleteNow(OK); |
2765 | 2854 |
2766 EXPECT_EQ(OK, callback2.WaitForResult()); | 2855 EXPECT_EQ(OK, callback2.WaitForResult()); |
2767 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2856 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2768 | 2857 |
2769 // In response to getting that resolve request, the poller should have | 2858 // In response to getting that resolve request, the poller should have |
2770 // started the next poll, and made it as far as to request the download. | 2859 // started the next poll, and made it as far as to request the download. |
2771 | 2860 |
2772 EXPECT_TRUE(fetcher->has_pending_request()); | 2861 EXPECT_TRUE(fetcher->has_pending_request()); |
2773 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2862 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2774 | 2863 |
2775 // This time we will fail the download, to simulate a PAC script change. | 2864 // This time we will fail the download, to simulate a PAC script change. |
2776 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2865 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2777 | 2866 |
2778 // Drain the message loop, so ProxyService is notified of the change | 2867 // Drain the message loop, so ProxyService is notified of the change |
2779 // and has a chance to re-configure itself. | 2868 // and has a chance to re-configure itself. |
2780 base::MessageLoop::current()->RunUntilIdle(); | 2869 base::MessageLoop::current()->RunUntilIdle(); |
2781 | 2870 |
2782 // Start a third request -- this time we expect to get a direct connection | 2871 // Start a third request -- this time we expect to get a direct connection |
2783 // since the PAC script poller experienced a failure. | 2872 // since the PAC script poller experienced a failure. |
2784 ProxyInfo info3; | 2873 ProxyInfo info3; |
2785 TestCompletionCallback callback3; | 2874 TestCompletionCallback callback3; |
2786 rv = service.ResolveProxy( | 2875 rv = service.ResolveProxy(GURL("http://request3"), |
2787 GURL("http://request3"), &info3, callback3.callback(), NULL, | 2876 &info3, |
2788 BoundNetLog()); | 2877 callback3.callback(), |
| 2878 NULL, |
| 2879 BoundNetLog()); |
2789 EXPECT_EQ(OK, rv); | 2880 EXPECT_EQ(OK, rv); |
2790 EXPECT_TRUE(info3.is_direct()); | 2881 EXPECT_TRUE(info3.is_direct()); |
2791 } | 2882 } |
2792 | 2883 |
2793 } // namespace net | 2884 } // namespace net |
OLD | NEW |