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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/base/net_log.h" | 14 #include "net/base/net_log.h" |
15 #include "net/base/net_log_unittest.h" | 15 #include "net/base/net_log_unittest.h" |
16 #include "net/base/network_delegate.h" | |
16 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
17 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 18 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
18 #include "net/proxy/mock_proxy_resolver.h" | 19 #include "net/proxy/mock_proxy_resolver.h" |
19 #include "net/proxy/mock_proxy_script_fetcher.h" | 20 #include "net/proxy/mock_proxy_script_fetcher.h" |
20 #include "net/proxy/proxy_config_service.h" | 21 #include "net/proxy/proxy_config_service.h" |
21 #include "net/proxy/proxy_resolver.h" | 22 #include "net/proxy/proxy_resolver.h" |
22 #include "net/proxy/proxy_script_fetcher.h" | 23 #include "net/proxy/proxy_script_fetcher.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
25 | 26 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 FOR_EACH_OBSERVER(Observer, observers_, | 147 FOR_EACH_OBSERVER(Observer, observers_, |
147 OnProxyConfigChanged(config_, availability_)); | 148 OnProxyConfigChanged(config_, availability_)); |
148 } | 149 } |
149 | 150 |
150 private: | 151 private: |
151 ConfigAvailability availability_; | 152 ConfigAvailability availability_; |
152 ProxyConfig config_; | 153 ProxyConfig config_; |
153 ObserverList<Observer, true> observers_; | 154 ObserverList<Observer, true> observers_; |
154 }; | 155 }; |
155 | 156 |
157 // A test network delegate that exercises the OnResolveProxy callback. | |
158 class TestResolveProxyNetworkDelegate : public NetworkDelegate { | |
159 public: | |
160 TestResolveProxyNetworkDelegate() | |
161 : NetworkDelegate(), on_resolve_proxy_called(false) { | |
162 } | |
163 | |
164 virtual void OnResolveProxy( | |
165 const GURL& url, int load_flags, ProxyInfo* result) { | |
166 on_resolve_proxy_called = true; | |
167 } | |
168 | |
169 bool on_resolve_proxy_called; | |
170 }; | |
171 | |
156 } // namespace | 172 } // namespace |
157 | 173 |
158 TEST_F(ProxyServiceTest, Direct) { | 174 TEST_F(ProxyServiceTest, Direct) { |
159 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 175 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
160 ProxyService service(new MockProxyConfigService( | 176 ProxyService service(new MockProxyConfigService( |
161 ProxyConfig::CreateDirect()), resolver, NULL); | 177 ProxyConfig::CreateDirect()), resolver, NULL); |
162 | 178 |
163 GURL url("http://www.google.com/"); | 179 GURL url("http://www.google.com/"); |
164 | 180 |
165 ProxyInfo info; | 181 ProxyInfo info; |
166 TestCompletionCallback callback; | 182 TestCompletionCallback callback; |
167 CapturingBoundNetLog log; | 183 CapturingBoundNetLog log; |
168 int rv = service.ResolveProxy( | 184 int rv = service.ResolveProxy( |
169 url, &info, callback.callback(), NULL, log.bound()); | 185 url, 0, &info, callback.callback(), NULL, NULL, log.bound()); |
170 EXPECT_EQ(OK, rv); | 186 EXPECT_EQ(OK, rv); |
171 EXPECT_TRUE(resolver->pending_requests().empty()); | 187 EXPECT_TRUE(resolver->pending_requests().empty()); |
172 | 188 |
173 EXPECT_TRUE(info.is_direct()); | 189 EXPECT_TRUE(info.is_direct()); |
174 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); | 190 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); |
175 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); | 191 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); |
176 | 192 |
177 // Check the NetLog was filled correctly. | 193 // Check the NetLog was filled correctly. |
178 CapturingNetLog::CapturedEntryList entries; | 194 CapturingNetLog::CapturedEntryList entries; |
179 log.GetEntries(&entries); | 195 log.GetEntries(&entries); |
180 | 196 |
181 EXPECT_EQ(3u, entries.size()); | 197 EXPECT_EQ(3u, entries.size()); |
182 EXPECT_TRUE(LogContainsBeginEvent( | 198 EXPECT_TRUE(LogContainsBeginEvent( |
183 entries, 0, NetLog::TYPE_PROXY_SERVICE)); | 199 entries, 0, NetLog::TYPE_PROXY_SERVICE)); |
184 EXPECT_TRUE(LogContainsEvent( | 200 EXPECT_TRUE(LogContainsEvent( |
185 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 201 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, |
186 NetLog::PHASE_NONE)); | 202 NetLog::PHASE_NONE)); |
187 EXPECT_TRUE(LogContainsEndEvent( | 203 EXPECT_TRUE(LogContainsEndEvent( |
188 entries, 2, NetLog::TYPE_PROXY_SERVICE)); | 204 entries, 2, NetLog::TYPE_PROXY_SERVICE)); |
205 | |
206 // Verify that network delegate is invoked. | |
207 TestResolveProxyNetworkDelegate delegate; | |
208 rv = service.ResolveProxy( | |
209 url, 0, &info, callback.callback(), NULL, &delegate, log.bound()); | |
210 EXPECT_TRUE(delegate.on_resolve_proxy_called); | |
mmenke
2014/07/01 19:45:12
Should have the delegate modify the list, both by
rcs
2014/07/02 00:56:20
Wrote a test, but it seems vaguely odd to me: it's
| |
189 } | 211 } |
190 | 212 |
191 TEST_F(ProxyServiceTest, PAC) { | 213 TEST_F(ProxyServiceTest, PAC) { |
192 MockProxyConfigService* config_service = | 214 MockProxyConfigService* config_service = |
193 new MockProxyConfigService("http://foopy/proxy.pac"); | 215 new MockProxyConfigService("http://foopy/proxy.pac"); |
194 | 216 |
195 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 217 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
196 | 218 |
197 ProxyService service(config_service, resolver, NULL); | 219 ProxyService service(config_service, resolver, NULL); |
198 | 220 |
199 GURL url("http://www.google.com/"); | 221 GURL url("http://www.google.com/"); |
200 | 222 |
201 ProxyInfo info; | 223 ProxyInfo info; |
202 TestCompletionCallback callback; | 224 TestCompletionCallback callback; |
203 ProxyService::PacRequest* request; | 225 ProxyService::PacRequest* request; |
204 CapturingBoundNetLog log; | 226 CapturingBoundNetLog log; |
205 | 227 |
206 int rv = service.ResolveProxy( | 228 int rv = service.ResolveProxy( |
207 url, &info, callback.callback(), &request, log.bound()); | 229 url, 0, &info, callback.callback(), &request, NULL, log.bound()); |
mmenke
2014/07/01 19:45:12
These should all use LOAD_NORMAL.
rcs
2014/07/02 00:56:20
Done.
| |
208 EXPECT_EQ(ERR_IO_PENDING, rv); | 230 EXPECT_EQ(ERR_IO_PENDING, rv); |
209 | 231 |
210 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); | 232 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); |
211 | 233 |
212 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 234 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
213 resolver->pending_set_pac_script_request()->script_data()->url()); | 235 resolver->pending_set_pac_script_request()->script_data()->url()); |
214 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 236 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
215 | 237 |
216 ASSERT_EQ(1u, resolver->pending_requests().size()); | 238 ASSERT_EQ(1u, resolver->pending_requests().size()); |
217 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 239 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 | 274 |
253 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 275 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
254 | 276 |
255 ProxyService service(config_service, resolver, NULL); | 277 ProxyService service(config_service, resolver, NULL); |
256 | 278 |
257 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 279 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
258 | 280 |
259 ProxyInfo info; | 281 ProxyInfo info; |
260 TestCompletionCallback callback; | 282 TestCompletionCallback callback; |
261 int rv = service.ResolveProxy( | 283 int rv = service.ResolveProxy( |
262 url, &info, callback.callback(), NULL, BoundNetLog()); | 284 url, 0, &info, callback.callback(), NULL, NULL, BoundNetLog()); |
263 EXPECT_EQ(ERR_IO_PENDING, rv); | 285 EXPECT_EQ(ERR_IO_PENDING, rv); |
264 | 286 |
265 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 287 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
266 resolver->pending_set_pac_script_request()->script_data()->url()); | 288 resolver->pending_set_pac_script_request()->script_data()->url()); |
267 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 289 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
268 | 290 |
269 ASSERT_EQ(1u, resolver->pending_requests().size()); | 291 ASSERT_EQ(1u, resolver->pending_requests().size()); |
270 // The URL should have been simplified, stripping the username/password/hash. | 292 // The URL should have been simplified, stripping the username/password/hash. |
271 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 293 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
272 resolver->pending_requests()[0]->url()); | 294 resolver->pending_requests()[0]->url()); |
273 | 295 |
274 // We end here without ever completing the request -- destruction of | 296 // We end here without ever completing the request -- destruction of |
275 // ProxyService will cancel the outstanding request. | 297 // ProxyService will cancel the outstanding request. |
276 } | 298 } |
277 | 299 |
278 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { | 300 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
279 MockProxyConfigService* config_service = | 301 MockProxyConfigService* config_service = |
280 new MockProxyConfigService("http://foopy/proxy.pac"); | 302 new MockProxyConfigService("http://foopy/proxy.pac"); |
281 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 303 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
282 | 304 |
283 ProxyService service(config_service, resolver, NULL); | 305 ProxyService service(config_service, resolver, NULL); |
284 | 306 |
285 GURL url("http://www.google.com/"); | 307 GURL url("http://www.google.com/"); |
286 | 308 |
287 ProxyInfo info; | 309 ProxyInfo info; |
288 TestCompletionCallback callback1; | 310 TestCompletionCallback callback1; |
289 int rv = service.ResolveProxy( | 311 int rv = service.ResolveProxy( |
290 url, &info, callback1.callback(), NULL, BoundNetLog()); | 312 url, 0, &info, callback1.callback(), NULL, NULL, BoundNetLog()); |
291 EXPECT_EQ(ERR_IO_PENDING, rv); | 313 EXPECT_EQ(ERR_IO_PENDING, rv); |
292 | 314 |
293 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 315 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
294 resolver->pending_set_pac_script_request()->script_data()->url()); | 316 resolver->pending_set_pac_script_request()->script_data()->url()); |
295 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 317 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
296 | 318 |
297 ASSERT_EQ(1u, resolver->pending_requests().size()); | 319 ASSERT_EQ(1u, resolver->pending_requests().size()); |
298 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 320 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
299 | 321 |
300 // Set the result in proxy resolver. | 322 // Set the result in proxy resolver. |
(...skipping 28 matching lines...) Expand all Loading... | |
329 new MockProxyConfigService("http://foopy/proxy.pac"); | 351 new MockProxyConfigService("http://foopy/proxy.pac"); |
330 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 352 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
331 | 353 |
332 ProxyService service(config_service, resolver, NULL); | 354 ProxyService service(config_service, resolver, NULL); |
333 | 355 |
334 GURL url("http://this-causes-js-error/"); | 356 GURL url("http://this-causes-js-error/"); |
335 | 357 |
336 ProxyInfo info; | 358 ProxyInfo info; |
337 TestCompletionCallback callback1; | 359 TestCompletionCallback callback1; |
338 int rv = service.ResolveProxy( | 360 int rv = service.ResolveProxy( |
339 url, &info, callback1.callback(), NULL, BoundNetLog()); | 361 url, 0, &info, callback1.callback(), NULL, NULL, BoundNetLog()); |
340 EXPECT_EQ(ERR_IO_PENDING, rv); | 362 EXPECT_EQ(ERR_IO_PENDING, rv); |
341 | 363 |
342 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 364 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
343 resolver->pending_set_pac_script_request()->script_data()->url()); | 365 resolver->pending_set_pac_script_request()->script_data()->url()); |
344 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 366 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
345 | 367 |
346 ASSERT_EQ(1u, resolver->pending_requests().size()); | 368 ASSERT_EQ(1u, resolver->pending_requests().size()); |
347 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 369 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
348 | 370 |
349 // Simulate a failure in the PAC executor. | 371 // Simulate a failure in the PAC executor. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 new MockProxyConfigService("http://foopy/proxy.pac"); | 406 new MockProxyConfigService("http://foopy/proxy.pac"); |
385 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 407 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
386 | 408 |
387 ProxyService service(config_service, resolver, NULL); | 409 ProxyService service(config_service, resolver, NULL); |
388 | 410 |
389 GURL url("http://www.google.com/"); | 411 GURL url("http://www.google.com/"); |
390 | 412 |
391 ProxyInfo info; | 413 ProxyInfo info; |
392 TestCompletionCallback callback1; | 414 TestCompletionCallback callback1; |
393 int rv = service.ResolveProxy( | 415 int rv = service.ResolveProxy( |
394 url, &info, callback1.callback(), NULL, BoundNetLog()); | 416 url, 0, &info, callback1.callback(), NULL, NULL, BoundNetLog()); |
395 EXPECT_EQ(ERR_IO_PENDING, rv); | 417 EXPECT_EQ(ERR_IO_PENDING, rv); |
396 | 418 |
397 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 419 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
398 resolver->pending_set_pac_script_request()->script_data()->url()); | 420 resolver->pending_set_pac_script_request()->script_data()->url()); |
399 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 421 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
400 | 422 |
401 ASSERT_EQ(1u, resolver->pending_requests().size()); | 423 ASSERT_EQ(1u, resolver->pending_requests().size()); |
402 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 424 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
403 | 425 |
404 // Set the result in proxy resolver. | 426 // Set the result in proxy resolver. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 | 475 |
454 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 476 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
455 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 477 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
456 ProxyService service(config_service, resolver, NULL); | 478 ProxyService service(config_service, resolver, NULL); |
457 | 479 |
458 // Resolve something. | 480 // Resolve something. |
459 GURL url("http://www.google.com/"); | 481 GURL url("http://www.google.com/"); |
460 ProxyInfo info; | 482 ProxyInfo info; |
461 TestCompletionCallback callback; | 483 TestCompletionCallback callback; |
462 int rv = service.ResolveProxy( | 484 int rv = service.ResolveProxy( |
463 url, &info, callback.callback(), NULL, BoundNetLog()); | 485 url, 0, &info, callback.callback(), NULL, NULL, BoundNetLog()); |
464 ASSERT_EQ(ERR_IO_PENDING, rv); | 486 ASSERT_EQ(ERR_IO_PENDING, rv); |
465 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 487 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
466 ASSERT_EQ(1u, resolver->pending_requests().size()); | 488 ASSERT_EQ(1u, resolver->pending_requests().size()); |
467 | 489 |
468 // Set the result in proxy resolver. | 490 // Set the result in proxy resolver. |
469 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); | 491 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); |
470 resolver->pending_requests()[0]->CompleteNow(OK); | 492 resolver->pending_requests()[0]->CompleteNow(OK); |
471 | 493 |
472 EXPECT_EQ(OK, callback.WaitForResult()); | 494 EXPECT_EQ(OK, callback.WaitForResult()); |
473 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 495 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
(...skipping 14 matching lines...) Expand all Loading... | |
488 | 510 |
489 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 511 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
490 | 512 |
491 ProxyService service(config_service, resolver, NULL); | 513 ProxyService service(config_service, resolver, NULL); |
492 | 514 |
493 // Start first resolve request. | 515 // Start first resolve request. |
494 GURL url("http://www.google.com/"); | 516 GURL url("http://www.google.com/"); |
495 ProxyInfo info; | 517 ProxyInfo info; |
496 TestCompletionCallback callback1; | 518 TestCompletionCallback callback1; |
497 int rv = service.ResolveProxy( | 519 int rv = service.ResolveProxy( |
498 url, &info, callback1.callback(), NULL, BoundNetLog()); | 520 url, 0, &info, callback1.callback(), NULL, NULL, BoundNetLog()); |
499 EXPECT_EQ(ERR_IO_PENDING, rv); | 521 EXPECT_EQ(ERR_IO_PENDING, rv); |
500 | 522 |
501 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 523 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
502 resolver->pending_set_pac_script_request()->script_data()->url()); | 524 resolver->pending_set_pac_script_request()->script_data()->url()); |
503 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 525 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
504 | 526 |
505 ASSERT_EQ(1u, resolver->pending_requests().size()); | 527 ASSERT_EQ(1u, resolver->pending_requests().size()); |
506 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 528 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
507 | 529 |
508 // Fail the first resolve request in MockAsyncProxyResolver. | 530 // Fail the first resolve request in MockAsyncProxyResolver. |
509 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 531 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
510 | 532 |
511 // Although the proxy resolver failed the request, ProxyService implicitly | 533 // Although the proxy resolver failed the request, ProxyService implicitly |
512 // falls-back to DIRECT. | 534 // falls-back to DIRECT. |
513 EXPECT_EQ(OK, callback1.WaitForResult()); | 535 EXPECT_EQ(OK, callback1.WaitForResult()); |
514 EXPECT_TRUE(info.is_direct()); | 536 EXPECT_TRUE(info.is_direct()); |
515 | 537 |
516 // Failed PAC executions still have proxy resolution times. | 538 // Failed PAC executions still have proxy resolution times. |
517 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 539 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
518 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 540 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
519 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 541 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
520 | 542 |
521 // The second resolve request will try to run through the proxy resolver, | 543 // The second resolve request will try to run through the proxy resolver, |
522 // regardless of whether the first request failed in it. | 544 // regardless of whether the first request failed in it. |
523 TestCompletionCallback callback2; | 545 TestCompletionCallback callback2; |
524 rv = service.ResolveProxy( | 546 rv = service.ResolveProxy( |
525 url, &info, callback2.callback(), NULL, BoundNetLog()); | 547 url, 0, &info, callback2.callback(), NULL, NULL, BoundNetLog()); |
526 EXPECT_EQ(ERR_IO_PENDING, rv); | 548 EXPECT_EQ(ERR_IO_PENDING, rv); |
527 | 549 |
528 ASSERT_EQ(1u, resolver->pending_requests().size()); | 550 ASSERT_EQ(1u, resolver->pending_requests().size()); |
529 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 551 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
530 | 552 |
531 // This time we will have the resolver succeed (perhaps the PAC script has | 553 // This time we will have the resolver succeed (perhaps the PAC script has |
532 // a dependency on the current time). | 554 // a dependency on the current time). |
533 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 555 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
534 resolver->pending_requests()[0]->CompleteNow(OK); | 556 resolver->pending_requests()[0]->CompleteNow(OK); |
535 | 557 |
(...skipping 14 matching lines...) Expand all Loading... | |
550 | 572 |
551 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 573 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
552 | 574 |
553 ProxyService service(config_service, resolver, NULL); | 575 ProxyService service(config_service, resolver, NULL); |
554 | 576 |
555 // Start first resolve request. | 577 // Start first resolve request. |
556 GURL url("http://www.google.com/"); | 578 GURL url("http://www.google.com/"); |
557 ProxyInfo info; | 579 ProxyInfo info; |
558 TestCompletionCallback callback1; | 580 TestCompletionCallback callback1; |
559 int rv = service.ResolveProxy( | 581 int rv = service.ResolveProxy( |
560 url, &info, callback1.callback(), NULL, BoundNetLog()); | 582 url, 0, &info, callback1.callback(), NULL, NULL, BoundNetLog()); |
561 EXPECT_EQ(ERR_IO_PENDING, rv); | 583 EXPECT_EQ(ERR_IO_PENDING, rv); |
562 | 584 |
563 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 585 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
564 resolver->pending_set_pac_script_request()->script_data()->url()); | 586 resolver->pending_set_pac_script_request()->script_data()->url()); |
565 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); | 587 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); |
566 | 588 |
567 ASSERT_EQ(0u, resolver->pending_requests().size()); | 589 ASSERT_EQ(0u, resolver->pending_requests().size()); |
568 | 590 |
569 // As the proxy resolver failed the request and is configured for a mandatory | 591 // As the proxy resolver failed the request and is configured for a mandatory |
570 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 592 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
571 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 593 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
572 callback1.WaitForResult()); | 594 callback1.WaitForResult()); |
573 EXPECT_FALSE(info.is_direct()); | 595 EXPECT_FALSE(info.is_direct()); |
574 | 596 |
575 // As the proxy resolver failed the request and is configured for a mandatory | 597 // As the proxy resolver failed the request and is configured for a mandatory |
576 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 598 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
577 TestCompletionCallback callback2; | 599 TestCompletionCallback callback2; |
578 rv = service.ResolveProxy( | 600 rv = service.ResolveProxy( |
579 url, &info, callback2.callback(), NULL, BoundNetLog()); | 601 url, 0, &info, callback2.callback(), NULL, NULL, BoundNetLog()); |
580 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); | 602 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); |
581 EXPECT_FALSE(info.is_direct()); | 603 EXPECT_FALSE(info.is_direct()); |
582 } | 604 } |
583 | 605 |
584 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { | 606 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { |
585 // Test what happens when the ProxyResolver fails that is configured to use a | 607 // Test what happens when the ProxyResolver fails that is configured to use a |
586 // mandatory PAC script. The download of the PAC script has already | 608 // mandatory PAC script. The download of the PAC script has already |
587 // succeeded but the PAC script contains no valid javascript. | 609 // succeeded but the PAC script contains no valid javascript. |
588 | 610 |
589 ProxyConfig config( | 611 ProxyConfig config( |
590 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 612 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
591 config.set_pac_mandatory(true); | 613 config.set_pac_mandatory(true); |
592 | 614 |
593 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 615 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
594 | 616 |
595 MockAsyncProxyResolverExpectsBytes* resolver = | 617 MockAsyncProxyResolverExpectsBytes* resolver = |
596 new MockAsyncProxyResolverExpectsBytes; | 618 new MockAsyncProxyResolverExpectsBytes; |
597 | 619 |
598 ProxyService service(config_service, resolver, NULL); | 620 ProxyService service(config_service, resolver, NULL); |
599 | 621 |
600 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 622 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
601 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); | 623 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); |
602 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); | 624 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); |
603 | 625 |
604 // Start resolve request. | 626 // Start resolve request. |
605 GURL url("http://www.google.com/"); | 627 GURL url("http://www.google.com/"); |
606 ProxyInfo info; | 628 ProxyInfo info; |
607 TestCompletionCallback callback; | 629 TestCompletionCallback callback; |
608 int rv = service.ResolveProxy( | 630 int rv = service.ResolveProxy( |
609 url, &info, callback.callback(), NULL, BoundNetLog()); | 631 url, 0, &info, callback.callback(), NULL, NULL, BoundNetLog()); |
610 EXPECT_EQ(ERR_IO_PENDING, rv); | 632 EXPECT_EQ(ERR_IO_PENDING, rv); |
611 | 633 |
612 // Check that nothing has been sent to the proxy resolver yet. | 634 // Check that nothing has been sent to the proxy resolver yet. |
613 ASSERT_EQ(0u, resolver->pending_requests().size()); | 635 ASSERT_EQ(0u, resolver->pending_requests().size()); |
614 | 636 |
615 // Downloading the PAC script succeeds. | 637 // Downloading the PAC script succeeds. |
616 EXPECT_TRUE(fetcher->has_pending_request()); | 638 EXPECT_TRUE(fetcher->has_pending_request()); |
617 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 639 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
618 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 640 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
619 | 641 |
(...skipping 22 matching lines...) Expand all Loading... | |
642 | 664 |
643 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 665 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
644 | 666 |
645 ProxyService service(config_service, resolver, NULL); | 667 ProxyService service(config_service, resolver, NULL); |
646 | 668 |
647 // Start first resolve request. | 669 // Start first resolve request. |
648 GURL url("http://www.google.com/"); | 670 GURL url("http://www.google.com/"); |
649 ProxyInfo info; | 671 ProxyInfo info; |
650 TestCompletionCallback callback1; | 672 TestCompletionCallback callback1; |
651 int rv = service.ResolveProxy( | 673 int rv = service.ResolveProxy( |
652 url, &info, callback1.callback(), NULL, BoundNetLog()); | 674 url, 0, &info, callback1.callback(), NULL, NULL, BoundNetLog()); |
653 EXPECT_EQ(ERR_IO_PENDING, rv); | 675 EXPECT_EQ(ERR_IO_PENDING, rv); |
654 | 676 |
655 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 677 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
656 resolver->pending_set_pac_script_request()->script_data()->url()); | 678 resolver->pending_set_pac_script_request()->script_data()->url()); |
657 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 679 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
658 | 680 |
659 ASSERT_EQ(1u, resolver->pending_requests().size()); | 681 ASSERT_EQ(1u, resolver->pending_requests().size()); |
660 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 682 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
661 | 683 |
662 // Fail the first resolve request in MockAsyncProxyResolver. | 684 // Fail the first resolve request in MockAsyncProxyResolver. |
663 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 685 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
664 | 686 |
665 // As the proxy resolver failed the request and is configured for a mandatory | 687 // As the proxy resolver failed the request and is configured for a mandatory |
666 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 688 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
667 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 689 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
668 callback1.WaitForResult()); | 690 callback1.WaitForResult()); |
669 EXPECT_FALSE(info.is_direct()); | 691 EXPECT_FALSE(info.is_direct()); |
670 | 692 |
671 // The second resolve request will try to run through the proxy resolver, | 693 // The second resolve request will try to run through the proxy resolver, |
672 // regardless of whether the first request failed in it. | 694 // regardless of whether the first request failed in it. |
673 TestCompletionCallback callback2; | 695 TestCompletionCallback callback2; |
674 rv = service.ResolveProxy( | 696 rv = service.ResolveProxy( |
675 url, &info, callback2.callback(), NULL, BoundNetLog()); | 697 url, 0, &info, callback2.callback(), NULL, NULL, BoundNetLog()); |
676 EXPECT_EQ(ERR_IO_PENDING, rv); | 698 EXPECT_EQ(ERR_IO_PENDING, rv); |
677 | 699 |
678 ASSERT_EQ(1u, resolver->pending_requests().size()); | 700 ASSERT_EQ(1u, resolver->pending_requests().size()); |
679 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 701 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
680 | 702 |
681 // This time we will have the resolver succeed (perhaps the PAC script has | 703 // This time we will have the resolver succeed (perhaps the PAC script has |
682 // a dependency on the current time). | 704 // a dependency on the current time). |
683 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 705 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
684 resolver->pending_requests()[0]->CompleteNow(OK); | 706 resolver->pending_requests()[0]->CompleteNow(OK); |
685 | 707 |
(...skipping 12 matching lines...) Expand all Loading... | |
698 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 720 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
699 | 721 |
700 ProxyService service(config_service, resolver, NULL); | 722 ProxyService service(config_service, resolver, NULL); |
701 | 723 |
702 GURL url("http://www.google.com/"); | 724 GURL url("http://www.google.com/"); |
703 | 725 |
704 // Get the proxy information. | 726 // Get the proxy information. |
705 ProxyInfo info; | 727 ProxyInfo info; |
706 TestCompletionCallback callback1; | 728 TestCompletionCallback callback1; |
707 int rv = service.ResolveProxy( | 729 int rv = service.ResolveProxy( |
708 url, &info, callback1.callback(), NULL, BoundNetLog()); | 730 url, 0, &info, callback1.callback(), NULL, NULL, BoundNetLog()); |
709 EXPECT_EQ(ERR_IO_PENDING, rv); | 731 EXPECT_EQ(ERR_IO_PENDING, rv); |
710 | 732 |
711 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 733 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
712 resolver->pending_set_pac_script_request()->script_data()->url()); | 734 resolver->pending_set_pac_script_request()->script_data()->url()); |
713 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 735 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
714 | 736 |
715 ASSERT_EQ(1u, resolver->pending_requests().size()); | 737 ASSERT_EQ(1u, resolver->pending_requests().size()); |
716 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 738 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
717 | 739 |
718 // Set the result in proxy resolver. | 740 // Set the result in proxy resolver. |
(...skipping 24 matching lines...) Expand all Loading... | |
743 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 765 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
744 | 766 |
745 // The second proxy should be specified. | 767 // The second proxy should be specified. |
746 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 768 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
747 // Report back that the second proxy worked. This will globally mark the | 769 // Report back that the second proxy worked. This will globally mark the |
748 // first proxy as bad. | 770 // first proxy as bad. |
749 service.ReportSuccess(info); | 771 service.ReportSuccess(info); |
750 | 772 |
751 TestCompletionCallback callback3; | 773 TestCompletionCallback callback3; |
752 rv = service.ResolveProxy( | 774 rv = service.ResolveProxy( |
753 url, &info, callback3.callback(), NULL, BoundNetLog()); | 775 url, 0, &info, callback3.callback(), NULL, NULL, BoundNetLog()); |
754 EXPECT_EQ(ERR_IO_PENDING, rv); | 776 EXPECT_EQ(ERR_IO_PENDING, rv); |
755 | 777 |
756 ASSERT_EQ(1u, resolver->pending_requests().size()); | 778 ASSERT_EQ(1u, resolver->pending_requests().size()); |
757 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 779 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
758 | 780 |
759 // Set the result in proxy resolver -- the second result is already known | 781 // Set the result in proxy resolver -- the second result is already known |
760 // to be bad, so we will not try to use it initially. | 782 // to be bad, so we will not try to use it initially. |
761 resolver->pending_requests()[0]->results()->UseNamedProxy( | 783 resolver->pending_requests()[0]->results()->UseNamedProxy( |
762 "foopy3:7070;foopy1:8080;foopy2:9090"); | 784 "foopy3:7070;foopy1:8080;foopy2:9090"); |
763 resolver->pending_requests()[0]->CompleteNow(OK); | 785 resolver->pending_requests()[0]->CompleteNow(OK); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 EXPECT_EQ(ERR_FAILED, rv); | 823 EXPECT_EQ(ERR_FAILED, rv); |
802 EXPECT_FALSE(info.is_direct()); | 824 EXPECT_FALSE(info.is_direct()); |
803 EXPECT_TRUE(info.is_empty()); | 825 EXPECT_TRUE(info.is_empty()); |
804 | 826 |
805 // Proxy times should not have been modified by fallback. | 827 // Proxy times should not have been modified by fallback. |
806 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 828 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
807 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 829 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
808 | 830 |
809 // Look up proxies again | 831 // Look up proxies again |
810 TestCompletionCallback callback7; | 832 TestCompletionCallback callback7; |
811 rv = service.ResolveProxy(url, &info, callback7.callback(), NULL, | 833 rv = service.ResolveProxy(url, 0, &info, callback7.callback(), NULL, |
812 BoundNetLog()); | 834 NULL, BoundNetLog()); |
813 EXPECT_EQ(ERR_IO_PENDING, rv); | 835 EXPECT_EQ(ERR_IO_PENDING, rv); |
814 | 836 |
815 ASSERT_EQ(1u, resolver->pending_requests().size()); | 837 ASSERT_EQ(1u, resolver->pending_requests().size()); |
816 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 838 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
817 | 839 |
818 // This time, the first 3 results have been found to be bad, but only the | 840 // This time, the first 3 results have been found to be bad, but only the |
819 // first proxy has been confirmed ... | 841 // first proxy has been confirmed ... |
820 resolver->pending_requests()[0]->results()->UseNamedProxy( | 842 resolver->pending_requests()[0]->results()->UseNamedProxy( |
821 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); | 843 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); |
822 resolver->pending_requests()[0]->CompleteNow(OK); | 844 resolver->pending_requests()[0]->CompleteNow(OK); |
(...skipping 18 matching lines...) Expand all Loading... | |
841 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 863 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
842 | 864 |
843 ProxyService service(config_service, resolver, NULL); | 865 ProxyService service(config_service, resolver, NULL); |
844 | 866 |
845 GURL url("http://www.google.com/"); | 867 GURL url("http://www.google.com/"); |
846 | 868 |
847 // Get the proxy information. | 869 // Get the proxy information. |
848 ProxyInfo info; | 870 ProxyInfo info; |
849 TestCompletionCallback callback1; | 871 TestCompletionCallback callback1; |
850 int rv = service.ResolveProxy( | 872 int rv = service.ResolveProxy( |
851 url, &info, callback1.callback(), NULL, BoundNetLog()); | 873 url, 0, &info, callback1.callback(), NULL, NULL, BoundNetLog()); |
852 EXPECT_EQ(ERR_IO_PENDING, rv); | 874 EXPECT_EQ(ERR_IO_PENDING, rv); |
853 | 875 |
854 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 876 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
855 resolver->pending_set_pac_script_request()->script_data()->url()); | 877 resolver->pending_set_pac_script_request()->script_data()->url()); |
856 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 878 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
857 | 879 |
858 ASSERT_EQ(1u, resolver->pending_requests().size()); | 880 ASSERT_EQ(1u, resolver->pending_requests().size()); |
859 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 881 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
860 | 882 |
861 // Set the result in proxy resolver. | 883 // Set the result in proxy resolver. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
911 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 933 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
912 | 934 |
913 ProxyService service(config_service, resolver, NULL); | 935 ProxyService service(config_service, resolver, NULL); |
914 | 936 |
915 GURL url("http://www.google.com/"); | 937 GURL url("http://www.google.com/"); |
916 | 938 |
917 // Get the proxy information. | 939 // Get the proxy information. |
918 ProxyInfo info; | 940 ProxyInfo info; |
919 TestCompletionCallback callback1; | 941 TestCompletionCallback callback1; |
920 int rv = service.ResolveProxy( | 942 int rv = service.ResolveProxy( |
921 url, &info, callback1.callback(), NULL, BoundNetLog()); | 943 url, 0, &info, callback1.callback(), NULL, NULL, BoundNetLog()); |
922 EXPECT_EQ(ERR_IO_PENDING, rv); | 944 EXPECT_EQ(ERR_IO_PENDING, rv); |
923 | 945 |
924 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 946 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
925 resolver->pending_set_pac_script_request()->script_data()->url()); | 947 resolver->pending_set_pac_script_request()->script_data()->url()); |
926 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 948 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
927 | 949 |
928 ASSERT_EQ(1u, resolver->pending_requests().size()); | 950 ASSERT_EQ(1u, resolver->pending_requests().size()); |
929 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 951 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
930 | 952 |
931 // Set the result in proxy resolver. | 953 // Set the result in proxy resolver. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1011 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1033 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1012 | 1034 |
1013 ProxyService service(config_service, resolver, NULL); | 1035 ProxyService service(config_service, resolver, NULL); |
1014 | 1036 |
1015 GURL url("http://www.google.com/"); | 1037 GURL url("http://www.google.com/"); |
1016 | 1038 |
1017 // Get the proxy information. | 1039 // Get the proxy information. |
1018 ProxyInfo info; | 1040 ProxyInfo info; |
1019 TestCompletionCallback callback1; | 1041 TestCompletionCallback callback1; |
1020 int rv = service.ResolveProxy( | 1042 int rv = service.ResolveProxy( |
1021 url, &info, callback1.callback(), NULL, BoundNetLog()); | 1043 url, 0, &info, callback1.callback(), NULL, NULL, BoundNetLog()); |
1022 EXPECT_EQ(ERR_IO_PENDING, rv); | 1044 EXPECT_EQ(ERR_IO_PENDING, rv); |
1023 | 1045 |
1024 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1046 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1025 resolver->pending_set_pac_script_request()->script_data()->url()); | 1047 resolver->pending_set_pac_script_request()->script_data()->url()); |
1026 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1048 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1027 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1049 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1028 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1050 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1029 | 1051 |
1030 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1052 resolver->pending_requests()[0]->results()->UseNamedProxy( |
1031 "foopy1:8080;foopy2:9090"); | 1053 "foopy1:8080;foopy2:9090"); |
(...skipping 12 matching lines...) Expand all Loading... | |
1044 EXPECT_EQ(OK, rv); | 1066 EXPECT_EQ(OK, rv); |
1045 | 1067 |
1046 // The first proxy is ignored, and the second one is selected. | 1068 // The first proxy is ignored, and the second one is selected. |
1047 EXPECT_FALSE(info.is_direct()); | 1069 EXPECT_FALSE(info.is_direct()); |
1048 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1070 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1049 | 1071 |
1050 // Fake a PAC failure. | 1072 // Fake a PAC failure. |
1051 ProxyInfo info2; | 1073 ProxyInfo info2; |
1052 TestCompletionCallback callback3; | 1074 TestCompletionCallback callback3; |
1053 rv = service.ResolveProxy( | 1075 rv = service.ResolveProxy( |
1054 url, &info2, callback3.callback(), NULL, BoundNetLog()); | 1076 url, 0, &info2, callback3.callback(), NULL, NULL, BoundNetLog()); |
1055 EXPECT_EQ(ERR_IO_PENDING, rv); | 1077 EXPECT_EQ(ERR_IO_PENDING, rv); |
1056 | 1078 |
1057 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1079 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1058 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1080 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1059 | 1081 |
1060 // This simulates a javascript runtime error in the PAC script. | 1082 // This simulates a javascript runtime error in the PAC script. |
1061 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 1083 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
1062 | 1084 |
1063 // Although the resolver failed, the ProxyService will implicitly fall-back | 1085 // Although the resolver failed, the ProxyService will implicitly fall-back |
1064 // to a DIRECT connection. | 1086 // to a DIRECT connection. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1106 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1128 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1107 | 1129 |
1108 ProxyService service(config_service, resolver, NULL); | 1130 ProxyService service(config_service, resolver, NULL); |
1109 | 1131 |
1110 GURL url("http://www.google.com/"); | 1132 GURL url("http://www.google.com/"); |
1111 | 1133 |
1112 // Get the proxy information. | 1134 // Get the proxy information. |
1113 ProxyInfo info; | 1135 ProxyInfo info; |
1114 TestCompletionCallback callback1; | 1136 TestCompletionCallback callback1; |
1115 int rv = service.ResolveProxy( | 1137 int rv = service.ResolveProxy( |
1116 url, &info, callback1.callback(), NULL, BoundNetLog()); | 1138 url, 0, &info, callback1.callback(), NULL, NULL, BoundNetLog()); |
1117 EXPECT_EQ(ERR_IO_PENDING, rv); | 1139 EXPECT_EQ(ERR_IO_PENDING, rv); |
1118 | 1140 |
1119 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1141 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1120 resolver->pending_set_pac_script_request()->script_data()->url()); | 1142 resolver->pending_set_pac_script_request()->script_data()->url()); |
1121 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1143 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1122 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1144 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1123 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1145 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1124 | 1146 |
1125 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1147 resolver->pending_requests()[0]->results()->UseNamedProxy( |
1126 "foopy1:8080;foopy2:9090"); | 1148 "foopy1:8080;foopy2:9090"); |
(...skipping 12 matching lines...) Expand all Loading... | |
1139 EXPECT_EQ(OK, rv); | 1161 EXPECT_EQ(OK, rv); |
1140 | 1162 |
1141 // The first proxy is ignored, and the second one is selected. | 1163 // The first proxy is ignored, and the second one is selected. |
1142 EXPECT_FALSE(info.is_direct()); | 1164 EXPECT_FALSE(info.is_direct()); |
1143 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1165 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1144 | 1166 |
1145 // Fake a PAC failure. | 1167 // Fake a PAC failure. |
1146 ProxyInfo info2; | 1168 ProxyInfo info2; |
1147 TestCompletionCallback callback3; | 1169 TestCompletionCallback callback3; |
1148 rv = service.ResolveProxy( | 1170 rv = service.ResolveProxy( |
1149 url, &info2, callback3.callback(), NULL, BoundNetLog()); | 1171 url, 0, &info2, callback3.callback(), NULL, NULL, BoundNetLog()); |
1150 EXPECT_EQ(ERR_IO_PENDING, rv); | 1172 EXPECT_EQ(ERR_IO_PENDING, rv); |
1151 | 1173 |
1152 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1174 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1153 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1175 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1154 | 1176 |
1155 // This simulates a javascript runtime error in the PAC script. | 1177 // This simulates a javascript runtime error in the PAC script. |
1156 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 1178 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
1157 | 1179 |
1158 // Although the resolver failed, the ProxyService will NOT fall-back | 1180 // Although the resolver failed, the ProxyService will NOT fall-back |
1159 // to a DIRECT connection as it is configured as mandatory. | 1181 // to a DIRECT connection as it is configured as mandatory. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1198 | 1220 |
1199 ProxyService service( | 1221 ProxyService service( |
1200 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1222 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1201 | 1223 |
1202 int rv; | 1224 int rv; |
1203 GURL url1("http://www.webkit.org"); | 1225 GURL url1("http://www.webkit.org"); |
1204 GURL url2("http://www.webkit.com"); | 1226 GURL url2("http://www.webkit.com"); |
1205 | 1227 |
1206 // Request for a .org domain should bypass proxy. | 1228 // Request for a .org domain should bypass proxy. |
1207 rv = service.ResolveProxy( | 1229 rv = service.ResolveProxy( |
1208 url1, &info[0], callback[0].callback(), NULL, BoundNetLog()); | 1230 url1, 0, &info[0], callback[0].callback(), NULL, NULL, BoundNetLog()); |
1209 EXPECT_EQ(OK, rv); | 1231 EXPECT_EQ(OK, rv); |
1210 EXPECT_TRUE(info[0].is_direct()); | 1232 EXPECT_TRUE(info[0].is_direct()); |
1211 | 1233 |
1212 // Request for a .com domain hits the proxy. | 1234 // Request for a .com domain hits the proxy. |
1213 rv = service.ResolveProxy( | 1235 rv = service.ResolveProxy( |
1214 url2, &info[1], callback[1].callback(), NULL, BoundNetLog()); | 1236 url2, 0, &info[1], callback[1].callback(), NULL, NULL, BoundNetLog()); |
1215 EXPECT_EQ(OK, rv); | 1237 EXPECT_EQ(OK, rv); |
1216 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); | 1238 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); |
1217 } | 1239 } |
1218 | 1240 |
1219 | 1241 |
1220 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { | 1242 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { |
1221 ProxyConfig config; | 1243 ProxyConfig config; |
1222 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); | 1244 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); |
1223 config.set_auto_detect(false); | 1245 config.set_auto_detect(false); |
1224 { | 1246 { |
1225 ProxyService service( | 1247 ProxyService service( |
1226 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1248 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1227 GURL test_url("http://www.msn.com"); | 1249 GURL test_url("http://www.msn.com"); |
1228 ProxyInfo info; | 1250 ProxyInfo info; |
1229 TestCompletionCallback callback; | 1251 TestCompletionCallback callback; |
1230 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1252 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1231 BoundNetLog()); | 1253 NULL, BoundNetLog()); |
1232 EXPECT_EQ(OK, rv); | 1254 EXPECT_EQ(OK, rv); |
1233 EXPECT_FALSE(info.is_direct()); | 1255 EXPECT_FALSE(info.is_direct()); |
1234 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1256 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1235 } | 1257 } |
1236 { | 1258 { |
1237 ProxyService service( | 1259 ProxyService service( |
1238 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1260 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1239 GURL test_url("ftp://ftp.google.com"); | 1261 GURL test_url("ftp://ftp.google.com"); |
1240 ProxyInfo info; | 1262 ProxyInfo info; |
1241 TestCompletionCallback callback; | 1263 TestCompletionCallback callback; |
1242 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1264 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1243 BoundNetLog()); | 1265 NULL, BoundNetLog()); |
1244 EXPECT_EQ(OK, rv); | 1266 EXPECT_EQ(OK, rv); |
1245 EXPECT_TRUE(info.is_direct()); | 1267 EXPECT_TRUE(info.is_direct()); |
1246 EXPECT_EQ("direct://", info.proxy_server().ToURI()); | 1268 EXPECT_EQ("direct://", info.proxy_server().ToURI()); |
1247 } | 1269 } |
1248 { | 1270 { |
1249 ProxyService service( | 1271 ProxyService service( |
1250 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1272 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1251 GURL test_url("https://webbranch.techcu.com"); | 1273 GURL test_url("https://webbranch.techcu.com"); |
1252 ProxyInfo info; | 1274 ProxyInfo info; |
1253 TestCompletionCallback callback; | 1275 TestCompletionCallback callback; |
1254 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1276 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1255 BoundNetLog()); | 1277 NULL, BoundNetLog()); |
1256 EXPECT_EQ(OK, rv); | 1278 EXPECT_EQ(OK, rv); |
1257 EXPECT_FALSE(info.is_direct()); | 1279 EXPECT_FALSE(info.is_direct()); |
1258 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1280 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
1259 } | 1281 } |
1260 { | 1282 { |
1261 config.proxy_rules().ParseFromString("foopy1:8080"); | 1283 config.proxy_rules().ParseFromString("foopy1:8080"); |
1262 ProxyService service( | 1284 ProxyService service( |
1263 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1285 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1264 GURL test_url("http://www.microsoft.com"); | 1286 GURL test_url("http://www.microsoft.com"); |
1265 ProxyInfo info; | 1287 ProxyInfo info; |
1266 TestCompletionCallback callback; | 1288 TestCompletionCallback callback; |
1267 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1289 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1268 BoundNetLog()); | 1290 NULL, BoundNetLog()); |
1269 EXPECT_EQ(OK, rv); | 1291 EXPECT_EQ(OK, rv); |
1270 EXPECT_FALSE(info.is_direct()); | 1292 EXPECT_FALSE(info.is_direct()); |
1271 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1293 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1272 } | 1294 } |
1273 } | 1295 } |
1274 | 1296 |
1275 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { | 1297 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { |
1276 // Test that the proxy config source is set correctly when resolving proxies | 1298 // Test that the proxy config source is set correctly when resolving proxies |
1277 // using manual proxy rules. Namely, the config source should only be set if | 1299 // using manual proxy rules. Namely, the config source should only be set if |
1278 // any of the rules were applied. | 1300 // any of the rules were applied. |
1279 { | 1301 { |
1280 ProxyConfig config; | 1302 ProxyConfig config; |
1281 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1303 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1282 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1304 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1283 ProxyService service( | 1305 ProxyService service( |
1284 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1306 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1285 GURL test_url("http://www.google.com"); | 1307 GURL test_url("http://www.google.com"); |
1286 ProxyInfo info; | 1308 ProxyInfo info; |
1287 TestCompletionCallback callback; | 1309 TestCompletionCallback callback; |
1288 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1310 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1289 BoundNetLog()); | 1311 NULL, BoundNetLog()); |
1290 ASSERT_EQ(OK, rv); | 1312 ASSERT_EQ(OK, rv); |
1291 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. | 1313 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. |
1292 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1314 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1293 } | 1315 } |
1294 { | 1316 { |
1295 ProxyConfig config; | 1317 ProxyConfig config; |
1296 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1318 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1297 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1319 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1298 ProxyService service( | 1320 ProxyService service( |
1299 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1321 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1300 GURL test_url("https://www.google.com"); | 1322 GURL test_url("https://www.google.com"); |
1301 ProxyInfo info; | 1323 ProxyInfo info; |
1302 TestCompletionCallback callback; | 1324 TestCompletionCallback callback; |
1303 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1325 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1304 BoundNetLog()); | 1326 NULL, BoundNetLog()); |
1305 ASSERT_EQ(OK, rv); | 1327 ASSERT_EQ(OK, rv); |
1306 // Used the HTTPS proxy. So source should be TEST. | 1328 // Used the HTTPS proxy. So source should be TEST. |
1307 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1329 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1308 } | 1330 } |
1309 { | 1331 { |
1310 ProxyConfig config; | 1332 ProxyConfig config; |
1311 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1333 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1312 ProxyService service( | 1334 ProxyService service( |
1313 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1335 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1314 GURL test_url("http://www.google.com"); | 1336 GURL test_url("http://www.google.com"); |
1315 ProxyInfo info; | 1337 ProxyInfo info; |
1316 TestCompletionCallback callback; | 1338 TestCompletionCallback callback; |
1317 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1339 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1318 BoundNetLog()); | 1340 NULL, BoundNetLog()); |
1319 ASSERT_EQ(OK, rv); | 1341 ASSERT_EQ(OK, rv); |
1320 // ProxyConfig is empty. Source should still be TEST. | 1342 // ProxyConfig is empty. Source should still be TEST. |
1321 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1343 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1322 } | 1344 } |
1323 } | 1345 } |
1324 | 1346 |
1325 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries | 1347 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries |
1326 // fall back to the SOCKS proxy. | 1348 // fall back to the SOCKS proxy. |
1327 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { | 1349 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { |
1328 ProxyConfig config; | 1350 ProxyConfig config; |
1329 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); | 1351 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); |
1330 config.set_auto_detect(false); | 1352 config.set_auto_detect(false); |
1331 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 1353 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
1332 config.proxy_rules().type); | 1354 config.proxy_rules().type); |
1333 | 1355 |
1334 { | 1356 { |
1335 ProxyService service( | 1357 ProxyService service( |
1336 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1358 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1337 GURL test_url("http://www.msn.com"); | 1359 GURL test_url("http://www.msn.com"); |
1338 ProxyInfo info; | 1360 ProxyInfo info; |
1339 TestCompletionCallback callback; | 1361 TestCompletionCallback callback; |
1340 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1362 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1341 BoundNetLog()); | 1363 NULL, BoundNetLog()); |
1342 EXPECT_EQ(OK, rv); | 1364 EXPECT_EQ(OK, rv); |
1343 EXPECT_FALSE(info.is_direct()); | 1365 EXPECT_FALSE(info.is_direct()); |
1344 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1366 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1345 } | 1367 } |
1346 { | 1368 { |
1347 ProxyService service( | 1369 ProxyService service( |
1348 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1370 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1349 GURL test_url("ftp://ftp.google.com"); | 1371 GURL test_url("ftp://ftp.google.com"); |
1350 ProxyInfo info; | 1372 ProxyInfo info; |
1351 TestCompletionCallback callback; | 1373 TestCompletionCallback callback; |
1352 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1374 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1353 BoundNetLog()); | 1375 NULL, BoundNetLog()); |
1354 EXPECT_EQ(OK, rv); | 1376 EXPECT_EQ(OK, rv); |
1355 EXPECT_FALSE(info.is_direct()); | 1377 EXPECT_FALSE(info.is_direct()); |
1356 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1378 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1357 } | 1379 } |
1358 { | 1380 { |
1359 ProxyService service( | 1381 ProxyService service( |
1360 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1382 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1361 GURL test_url("https://webbranch.techcu.com"); | 1383 GURL test_url("https://webbranch.techcu.com"); |
1362 ProxyInfo info; | 1384 ProxyInfo info; |
1363 TestCompletionCallback callback; | 1385 TestCompletionCallback callback; |
1364 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1386 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1365 BoundNetLog()); | 1387 NULL, BoundNetLog()); |
1366 EXPECT_EQ(OK, rv); | 1388 EXPECT_EQ(OK, rv); |
1367 EXPECT_FALSE(info.is_direct()); | 1389 EXPECT_FALSE(info.is_direct()); |
1368 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1390 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1369 } | 1391 } |
1370 { | 1392 { |
1371 ProxyService service( | 1393 ProxyService service( |
1372 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1394 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1373 GURL test_url("unknown://www.microsoft.com"); | 1395 GURL test_url("unknown://www.microsoft.com"); |
1374 ProxyInfo info; | 1396 ProxyInfo info; |
1375 TestCompletionCallback callback; | 1397 TestCompletionCallback callback; |
1376 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1398 int rv = service.ResolveProxy(test_url, 0, &info, callback.callback(), NULL, |
1377 BoundNetLog()); | 1399 NULL, BoundNetLog()); |
1378 EXPECT_EQ(OK, rv); | 1400 EXPECT_EQ(OK, rv); |
1379 EXPECT_FALSE(info.is_direct()); | 1401 EXPECT_FALSE(info.is_direct()); |
1380 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1402 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1381 } | 1403 } |
1382 } | 1404 } |
1383 | 1405 |
1384 // Test cancellation of an in-progress request. | 1406 // Test cancellation of an in-progress request. |
1385 TEST_F(ProxyServiceTest, CancelInProgressRequest) { | 1407 TEST_F(ProxyServiceTest, CancelInProgressRequest) { |
1386 MockProxyConfigService* config_service = | 1408 MockProxyConfigService* config_service = |
1387 new MockProxyConfigService("http://foopy/proxy.pac"); | 1409 new MockProxyConfigService("http://foopy/proxy.pac"); |
1388 | 1410 |
1389 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1411 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1390 | 1412 |
1391 ProxyService service(config_service, resolver, NULL); | 1413 ProxyService service(config_service, resolver, NULL); |
1392 | 1414 |
1393 // Start 3 requests. | 1415 // Start 3 requests. |
1394 | 1416 |
1395 ProxyInfo info1; | 1417 ProxyInfo info1; |
1396 TestCompletionCallback callback1; | 1418 TestCompletionCallback callback1; |
1397 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1419 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1398 callback1.callback(), NULL, BoundNetLog()); | 1420 callback1.callback(), NULL, NULL, |
1421 BoundNetLog()); | |
1399 EXPECT_EQ(ERR_IO_PENDING, rv); | 1422 EXPECT_EQ(ERR_IO_PENDING, rv); |
1400 | 1423 |
1401 // Nothing has been sent to the proxy resolver yet, since the proxy | 1424 // Nothing has been sent to the proxy resolver yet, since the proxy |
1402 // resolver has not been configured yet. | 1425 // resolver has not been configured yet. |
1403 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1426 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1404 | 1427 |
1405 // Successfully initialize the PAC script. | 1428 // Successfully initialize the PAC script. |
1406 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1429 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1407 resolver->pending_set_pac_script_request()->script_data()->url()); | 1430 resolver->pending_set_pac_script_request()->script_data()->url()); |
1408 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1431 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1409 | 1432 |
1410 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1433 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1411 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1434 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
1412 | 1435 |
1413 ProxyInfo info2; | 1436 ProxyInfo info2; |
1414 TestCompletionCallback callback2; | 1437 TestCompletionCallback callback2; |
1415 ProxyService::PacRequest* request2; | 1438 ProxyService::PacRequest* request2; |
1416 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1439 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1417 callback2.callback(), &request2, BoundNetLog()); | 1440 callback2.callback(), &request2, NULL, |
1441 BoundNetLog()); | |
1418 EXPECT_EQ(ERR_IO_PENDING, rv); | 1442 EXPECT_EQ(ERR_IO_PENDING, rv); |
1419 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1443 ASSERT_EQ(2u, resolver->pending_requests().size()); |
1420 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1444 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
1421 | 1445 |
1422 ProxyInfo info3; | 1446 ProxyInfo info3; |
1423 TestCompletionCallback callback3; | 1447 TestCompletionCallback callback3; |
1424 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1448 rv = service.ResolveProxy(GURL("http://request3"), 0, &info3, |
1425 callback3.callback(), NULL, BoundNetLog()); | 1449 callback3.callback(), NULL, NULL, BoundNetLog()); |
1426 EXPECT_EQ(ERR_IO_PENDING, rv); | 1450 EXPECT_EQ(ERR_IO_PENDING, rv); |
1427 ASSERT_EQ(3u, resolver->pending_requests().size()); | 1451 ASSERT_EQ(3u, resolver->pending_requests().size()); |
1428 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); | 1452 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); |
1429 | 1453 |
1430 // Cancel the second request | 1454 // Cancel the second request |
1431 service.CancelPacRequest(request2); | 1455 service.CancelPacRequest(request2); |
1432 | 1456 |
1433 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1457 ASSERT_EQ(2u, resolver->pending_requests().size()); |
1434 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1458 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
1435 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); | 1459 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); |
(...skipping 30 matching lines...) Expand all Loading... | |
1466 | 1490 |
1467 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1491 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1468 service.SetProxyScriptFetchers(fetcher, | 1492 service.SetProxyScriptFetchers(fetcher, |
1469 new DoNothingDhcpProxyScriptFetcher()); | 1493 new DoNothingDhcpProxyScriptFetcher()); |
1470 | 1494 |
1471 // Start 3 requests. | 1495 // Start 3 requests. |
1472 | 1496 |
1473 ProxyInfo info1; | 1497 ProxyInfo info1; |
1474 TestCompletionCallback callback1; | 1498 TestCompletionCallback callback1; |
1475 ProxyService::PacRequest* request1; | 1499 ProxyService::PacRequest* request1; |
1476 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1500 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1477 callback1.callback(), &request1, BoundNetLog()); | 1501 callback1.callback(), &request1, NULL, |
1502 BoundNetLog()); | |
1478 EXPECT_EQ(ERR_IO_PENDING, rv); | 1503 EXPECT_EQ(ERR_IO_PENDING, rv); |
1479 | 1504 |
1480 // The first request should have triggered download of PAC script. | 1505 // The first request should have triggered download of PAC script. |
1481 EXPECT_TRUE(fetcher->has_pending_request()); | 1506 EXPECT_TRUE(fetcher->has_pending_request()); |
1482 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1507 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1483 | 1508 |
1484 ProxyInfo info2; | 1509 ProxyInfo info2; |
1485 TestCompletionCallback callback2; | 1510 TestCompletionCallback callback2; |
1486 ProxyService::PacRequest* request2; | 1511 ProxyService::PacRequest* request2; |
1487 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1512 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1488 callback2.callback(), &request2, BoundNetLog()); | 1513 callback2.callback(), &request2, NULL, |
1514 BoundNetLog()); | |
1489 EXPECT_EQ(ERR_IO_PENDING, rv); | 1515 EXPECT_EQ(ERR_IO_PENDING, rv); |
1490 | 1516 |
1491 ProxyInfo info3; | 1517 ProxyInfo info3; |
1492 TestCompletionCallback callback3; | 1518 TestCompletionCallback callback3; |
1493 ProxyService::PacRequest* request3; | 1519 ProxyService::PacRequest* request3; |
1494 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1520 rv = service.ResolveProxy(GURL("http://request3"), 0, &info3, |
1495 callback3.callback(), &request3, BoundNetLog()); | 1521 callback3.callback(), &request3, NULL, |
1522 BoundNetLog()); | |
1496 EXPECT_EQ(ERR_IO_PENDING, rv); | 1523 EXPECT_EQ(ERR_IO_PENDING, rv); |
1497 | 1524 |
1498 // Nothing has been sent to the resolver yet. | 1525 // Nothing has been sent to the resolver yet. |
1499 EXPECT_TRUE(resolver->pending_requests().empty()); | 1526 EXPECT_TRUE(resolver->pending_requests().empty()); |
1500 | 1527 |
1501 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1528 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
1502 service.GetLoadState(request1)); | 1529 service.GetLoadState(request1)); |
1503 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1530 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
1504 service.GetLoadState(request2)); | 1531 service.GetLoadState(request2)); |
1505 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1532 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1568 ProxyService service(config_service, resolver, NULL); | 1595 ProxyService service(config_service, resolver, NULL); |
1569 | 1596 |
1570 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1597 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1571 service.SetProxyScriptFetchers(fetcher, | 1598 service.SetProxyScriptFetchers(fetcher, |
1572 new DoNothingDhcpProxyScriptFetcher()); | 1599 new DoNothingDhcpProxyScriptFetcher()); |
1573 | 1600 |
1574 // Start 2 requests. | 1601 // Start 2 requests. |
1575 | 1602 |
1576 ProxyInfo info1; | 1603 ProxyInfo info1; |
1577 TestCompletionCallback callback1; | 1604 TestCompletionCallback callback1; |
1578 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1605 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1579 callback1.callback(), NULL, BoundNetLog()); | 1606 callback1.callback(), NULL, NULL, |
1607 BoundNetLog()); | |
1580 EXPECT_EQ(ERR_IO_PENDING, rv); | 1608 EXPECT_EQ(ERR_IO_PENDING, rv); |
1581 | 1609 |
1582 // The first request should have triggered download of PAC script. | 1610 // The first request should have triggered download of PAC script. |
1583 EXPECT_TRUE(fetcher->has_pending_request()); | 1611 EXPECT_TRUE(fetcher->has_pending_request()); |
1584 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1612 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1585 | 1613 |
1586 ProxyInfo info2; | 1614 ProxyInfo info2; |
1587 TestCompletionCallback callback2; | 1615 TestCompletionCallback callback2; |
1588 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1616 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1589 callback2.callback(), NULL, BoundNetLog()); | 1617 callback2.callback(), NULL, NULL, BoundNetLog()); |
1590 EXPECT_EQ(ERR_IO_PENDING, rv); | 1618 EXPECT_EQ(ERR_IO_PENDING, rv); |
1591 | 1619 |
1592 // At this point the ProxyService should be waiting for the | 1620 // At this point the ProxyService should be waiting for the |
1593 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1621 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
1594 // PAC script download completion. | 1622 // PAC script download completion. |
1595 | 1623 |
1596 // We now change out the ProxyService's script fetcher. We should restart | 1624 // We now change out the ProxyService's script fetcher. We should restart |
1597 // the initialization with the new fetcher. | 1625 // the initialization with the new fetcher. |
1598 | 1626 |
1599 fetcher = new MockProxyScriptFetcher; | 1627 fetcher = new MockProxyScriptFetcher; |
(...skipping 28 matching lines...) Expand all Loading... | |
1628 | 1656 |
1629 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1657 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1630 service.SetProxyScriptFetchers(fetcher, | 1658 service.SetProxyScriptFetchers(fetcher, |
1631 new DoNothingDhcpProxyScriptFetcher()); | 1659 new DoNothingDhcpProxyScriptFetcher()); |
1632 | 1660 |
1633 // Start 3 requests. | 1661 // Start 3 requests. |
1634 ProxyInfo info1; | 1662 ProxyInfo info1; |
1635 TestCompletionCallback callback1; | 1663 TestCompletionCallback callback1; |
1636 ProxyService::PacRequest* request1; | 1664 ProxyService::PacRequest* request1; |
1637 CapturingBoundNetLog log1; | 1665 CapturingBoundNetLog log1; |
1638 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1666 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1639 callback1.callback(), &request1, log1.bound()); | 1667 callback1.callback(), &request1, NULL, |
1668 log1.bound()); | |
1640 EXPECT_EQ(ERR_IO_PENDING, rv); | 1669 EXPECT_EQ(ERR_IO_PENDING, rv); |
1641 | 1670 |
1642 // The first request should have triggered download of PAC script. | 1671 // The first request should have triggered download of PAC script. |
1643 EXPECT_TRUE(fetcher->has_pending_request()); | 1672 EXPECT_TRUE(fetcher->has_pending_request()); |
1644 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1673 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1645 | 1674 |
1646 ProxyInfo info2; | 1675 ProxyInfo info2; |
1647 TestCompletionCallback callback2; | 1676 TestCompletionCallback callback2; |
1648 ProxyService::PacRequest* request2; | 1677 ProxyService::PacRequest* request2; |
1649 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1678 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1650 callback2.callback(), &request2, BoundNetLog()); | 1679 callback2.callback(), &request2, NULL, |
1680 BoundNetLog()); | |
1651 EXPECT_EQ(ERR_IO_PENDING, rv); | 1681 EXPECT_EQ(ERR_IO_PENDING, rv); |
1652 | 1682 |
1653 ProxyInfo info3; | 1683 ProxyInfo info3; |
1654 TestCompletionCallback callback3; | 1684 TestCompletionCallback callback3; |
1655 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1685 rv = service.ResolveProxy(GURL("http://request3"), 0, &info3, |
1656 callback3.callback(), NULL, BoundNetLog()); | 1686 callback3.callback(), NULL, NULL, BoundNetLog()); |
1657 EXPECT_EQ(ERR_IO_PENDING, rv); | 1687 EXPECT_EQ(ERR_IO_PENDING, rv); |
1658 | 1688 |
1659 // Nothing has been sent to the resolver yet. | 1689 // Nothing has been sent to the resolver yet. |
1660 EXPECT_TRUE(resolver->pending_requests().empty()); | 1690 EXPECT_TRUE(resolver->pending_requests().empty()); |
1661 | 1691 |
1662 // Cancel the first 2 requests. | 1692 // Cancel the first 2 requests. |
1663 service.CancelPacRequest(request1); | 1693 service.CancelPacRequest(request1); |
1664 service.CancelPacRequest(request2); | 1694 service.CancelPacRequest(request2); |
1665 | 1695 |
1666 // At this point the ProxyService should be waiting for the | 1696 // At this point the ProxyService should be waiting for the |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1719 ProxyService service(config_service, resolver, NULL); | 1749 ProxyService service(config_service, resolver, NULL); |
1720 | 1750 |
1721 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1751 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1722 service.SetProxyScriptFetchers(fetcher, | 1752 service.SetProxyScriptFetchers(fetcher, |
1723 new DoNothingDhcpProxyScriptFetcher()); | 1753 new DoNothingDhcpProxyScriptFetcher()); |
1724 | 1754 |
1725 // Start 2 requests. | 1755 // Start 2 requests. |
1726 | 1756 |
1727 ProxyInfo info1; | 1757 ProxyInfo info1; |
1728 TestCompletionCallback callback1; | 1758 TestCompletionCallback callback1; |
1729 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1759 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1730 callback1.callback(), NULL, BoundNetLog()); | 1760 callback1.callback(), NULL, NULL, |
1761 BoundNetLog()); | |
1731 EXPECT_EQ(ERR_IO_PENDING, rv); | 1762 EXPECT_EQ(ERR_IO_PENDING, rv); |
1732 | 1763 |
1733 ProxyInfo info2; | 1764 ProxyInfo info2; |
1734 TestCompletionCallback callback2; | 1765 TestCompletionCallback callback2; |
1735 ProxyService::PacRequest* request2; | 1766 ProxyService::PacRequest* request2; |
1736 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1767 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1737 callback2.callback(), &request2, BoundNetLog()); | 1768 callback2.callback(), &request2, NULL, |
1769 BoundNetLog()); | |
1738 EXPECT_EQ(ERR_IO_PENDING, rv); | 1770 EXPECT_EQ(ERR_IO_PENDING, rv); |
1739 | 1771 |
1740 // Check that nothing has been sent to the proxy resolver yet. | 1772 // Check that nothing has been sent to the proxy resolver yet. |
1741 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1773 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1742 | 1774 |
1743 // It should be trying to auto-detect first -- FAIL the autodetect during | 1775 // It should be trying to auto-detect first -- FAIL the autodetect during |
1744 // the script download. | 1776 // the script download. |
1745 EXPECT_TRUE(fetcher->has_pending_request()); | 1777 EXPECT_TRUE(fetcher->has_pending_request()); |
1746 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1778 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1747 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 1779 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1796 ProxyService service(config_service, resolver, NULL); | 1828 ProxyService service(config_service, resolver, NULL); |
1797 | 1829 |
1798 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1830 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1799 service.SetProxyScriptFetchers(fetcher, | 1831 service.SetProxyScriptFetchers(fetcher, |
1800 new DoNothingDhcpProxyScriptFetcher()); | 1832 new DoNothingDhcpProxyScriptFetcher()); |
1801 | 1833 |
1802 // Start 2 requests. | 1834 // Start 2 requests. |
1803 | 1835 |
1804 ProxyInfo info1; | 1836 ProxyInfo info1; |
1805 TestCompletionCallback callback1; | 1837 TestCompletionCallback callback1; |
1806 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1838 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1807 callback1.callback(), NULL, BoundNetLog()); | 1839 callback1.callback(), NULL, NULL, |
1840 BoundNetLog()); | |
1808 EXPECT_EQ(ERR_IO_PENDING, rv); | 1841 EXPECT_EQ(ERR_IO_PENDING, rv); |
1809 | 1842 |
1810 ProxyInfo info2; | 1843 ProxyInfo info2; |
1811 TestCompletionCallback callback2; | 1844 TestCompletionCallback callback2; |
1812 ProxyService::PacRequest* request2; | 1845 ProxyService::PacRequest* request2; |
1813 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1846 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1814 callback2.callback(), &request2, BoundNetLog()); | 1847 callback2.callback(), &request2, NULL, |
1848 BoundNetLog()); | |
1815 EXPECT_EQ(ERR_IO_PENDING, rv); | 1849 EXPECT_EQ(ERR_IO_PENDING, rv); |
1816 | 1850 |
1817 // Check that nothing has been sent to the proxy resolver yet. | 1851 // Check that nothing has been sent to the proxy resolver yet. |
1818 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1852 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1819 | 1853 |
1820 // It should be trying to auto-detect first -- succeed the download. | 1854 // It should be trying to auto-detect first -- succeed the download. |
1821 EXPECT_TRUE(fetcher->has_pending_request()); | 1855 EXPECT_TRUE(fetcher->has_pending_request()); |
1822 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1856 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1823 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 1857 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
1824 | 1858 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1869 ProxyService service(config_service, resolver, NULL); | 1903 ProxyService service(config_service, resolver, NULL); |
1870 | 1904 |
1871 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1905 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1872 service.SetProxyScriptFetchers(fetcher, | 1906 service.SetProxyScriptFetchers(fetcher, |
1873 new DoNothingDhcpProxyScriptFetcher()); | 1907 new DoNothingDhcpProxyScriptFetcher()); |
1874 | 1908 |
1875 // Start 2 requests. | 1909 // Start 2 requests. |
1876 | 1910 |
1877 ProxyInfo info1; | 1911 ProxyInfo info1; |
1878 TestCompletionCallback callback1; | 1912 TestCompletionCallback callback1; |
1879 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1913 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
1880 callback1.callback(), NULL, BoundNetLog()); | 1914 callback1.callback(), NULL, NULL, |
1915 BoundNetLog()); | |
1881 EXPECT_EQ(ERR_IO_PENDING, rv); | 1916 EXPECT_EQ(ERR_IO_PENDING, rv); |
1882 | 1917 |
1883 ProxyInfo info2; | 1918 ProxyInfo info2; |
1884 TestCompletionCallback callback2; | 1919 TestCompletionCallback callback2; |
1885 ProxyService::PacRequest* request2; | 1920 ProxyService::PacRequest* request2; |
1886 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1921 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
1887 callback2.callback(), &request2, BoundNetLog()); | 1922 callback2.callback(), &request2, NULL, |
1923 BoundNetLog()); | |
1888 EXPECT_EQ(ERR_IO_PENDING, rv); | 1924 EXPECT_EQ(ERR_IO_PENDING, rv); |
1889 | 1925 |
1890 // Check that nothing has been sent to the proxy resolver yet. | 1926 // Check that nothing has been sent to the proxy resolver yet. |
1891 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1927 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1892 | 1928 |
1893 // It should be trying to auto-detect first -- fail the download. | 1929 // It should be trying to auto-detect first -- fail the download. |
1894 EXPECT_TRUE(fetcher->has_pending_request()); | 1930 EXPECT_TRUE(fetcher->has_pending_request()); |
1895 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1931 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1896 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 1932 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
1897 | 1933 |
(...skipping 30 matching lines...) Expand all Loading... | |
1928 | 1964 |
1929 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1965 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1930 service.SetProxyScriptFetchers(fetcher, | 1966 service.SetProxyScriptFetchers(fetcher, |
1931 new DoNothingDhcpProxyScriptFetcher()); | 1967 new DoNothingDhcpProxyScriptFetcher()); |
1932 | 1968 |
1933 // Start 1 requests. | 1969 // Start 1 requests. |
1934 | 1970 |
1935 ProxyInfo info1; | 1971 ProxyInfo info1; |
1936 TestCompletionCallback callback1; | 1972 TestCompletionCallback callback1; |
1937 int rv = service.ResolveProxy( | 1973 int rv = service.ResolveProxy( |
1938 GURL("http://www.google.com"), &info1, callback1.callback(), NULL, | 1974 GURL("http://www.google.com"), 0, &info1, callback1.callback(), NULL, |
1939 BoundNetLog()); | 1975 NULL, BoundNetLog()); |
1940 EXPECT_EQ(ERR_IO_PENDING, rv); | 1976 EXPECT_EQ(ERR_IO_PENDING, rv); |
1941 | 1977 |
1942 // Check that nothing has been sent to the proxy resolver yet. | 1978 // Check that nothing has been sent to the proxy resolver yet. |
1943 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1979 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1944 | 1980 |
1945 // It should be trying to auto-detect first -- succeed the download. | 1981 // It should be trying to auto-detect first -- succeed the download. |
1946 EXPECT_TRUE(fetcher->has_pending_request()); | 1982 EXPECT_TRUE(fetcher->has_pending_request()); |
1947 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1983 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1948 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 1984 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
1949 | 1985 |
1950 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 1986 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
1951 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 1987 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
1952 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1988 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1953 | 1989 |
1954 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1990 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1955 EXPECT_EQ(GURL("http://www.google.com"), | 1991 EXPECT_EQ(GURL("http://www.google.com"), |
1956 resolver->pending_requests()[0]->url()); | 1992 resolver->pending_requests()[0]->url()); |
1957 | 1993 |
1958 // Complete the pending request. | 1994 // Complete the pending request. |
1959 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 1995 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
1960 resolver->pending_requests()[0]->CompleteNow(OK); | 1996 resolver->pending_requests()[0]->CompleteNow(OK); |
1961 | 1997 |
1962 // Verify that request ran as expected. | 1998 // Verify that request ran as expected. |
1963 EXPECT_EQ(OK, callback1.WaitForResult()); | 1999 EXPECT_EQ(OK, callback1.WaitForResult()); |
1964 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2000 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
1965 | 2001 |
1966 // Start another request, it should pickup the bypass item. | 2002 // Start another request, it should pickup the bypass item. |
1967 ProxyInfo info2; | 2003 ProxyInfo info2; |
1968 TestCompletionCallback callback2; | 2004 TestCompletionCallback callback2; |
1969 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, | 2005 rv = service.ResolveProxy(GURL("http://www.google.com"), 0, &info2, |
1970 callback2.callback(), NULL, BoundNetLog()); | 2006 callback2.callback(), NULL, NULL, BoundNetLog()); |
1971 EXPECT_EQ(ERR_IO_PENDING, rv); | 2007 EXPECT_EQ(ERR_IO_PENDING, rv); |
1972 | 2008 |
1973 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2009 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1974 EXPECT_EQ(GURL("http://www.google.com"), | 2010 EXPECT_EQ(GURL("http://www.google.com"), |
1975 resolver->pending_requests()[0]->url()); | 2011 resolver->pending_requests()[0]->url()); |
1976 | 2012 |
1977 // Complete the pending request. | 2013 // Complete the pending request. |
1978 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2014 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
1979 resolver->pending_requests()[0]->CompleteNow(OK); | 2015 resolver->pending_requests()[0]->CompleteNow(OK); |
1980 | 2016 |
(...skipping 15 matching lines...) Expand all Loading... | |
1996 ProxyService service(config_service, resolver, NULL); | 2032 ProxyService service(config_service, resolver, NULL); |
1997 | 2033 |
1998 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2034 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1999 service.SetProxyScriptFetchers(fetcher, | 2035 service.SetProxyScriptFetchers(fetcher, |
2000 new DoNothingDhcpProxyScriptFetcher()); | 2036 new DoNothingDhcpProxyScriptFetcher()); |
2001 | 2037 |
2002 // Start 1 request. | 2038 // Start 1 request. |
2003 | 2039 |
2004 ProxyInfo info1; | 2040 ProxyInfo info1; |
2005 TestCompletionCallback callback1; | 2041 TestCompletionCallback callback1; |
2006 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, | 2042 int rv = service.ResolveProxy(GURL("http://www.google.com"), 0, &info1, |
2007 callback1.callback(), NULL, BoundNetLog()); | 2043 callback1.callback(), NULL, NULL, |
2044 BoundNetLog()); | |
2008 EXPECT_EQ(ERR_IO_PENDING, rv); | 2045 EXPECT_EQ(ERR_IO_PENDING, rv); |
2009 | 2046 |
2010 // Check that nothing has been sent to the proxy resolver yet. | 2047 // Check that nothing has been sent to the proxy resolver yet. |
2011 ASSERT_EQ(0u, resolver->pending_requests().size()); | 2048 ASSERT_EQ(0u, resolver->pending_requests().size()); |
2012 | 2049 |
2013 // InitProxyResolver should have issued a request to the ProxyScriptFetcher | 2050 // InitProxyResolver should have issued a request to the ProxyScriptFetcher |
2014 // and be waiting on that to complete. | 2051 // and be waiting on that to complete. |
2015 EXPECT_TRUE(fetcher->has_pending_request()); | 2052 EXPECT_TRUE(fetcher->has_pending_request()); |
2016 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2053 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2017 } | 2054 } |
2018 | 2055 |
2019 // Delete the ProxyService while InitProxyResolver has an outstanding | 2056 // Delete the ProxyService while InitProxyResolver has an outstanding |
2020 // request to the proxy resolver. When run under valgrind, should not | 2057 // request to the proxy resolver. When run under valgrind, should not |
2021 // have any memory errors (used to be that the ProxyResolver was | 2058 // have any memory errors (used to be that the ProxyResolver was |
2022 // being deleted prior to the InitProxyResolver). | 2059 // being deleted prior to the InitProxyResolver). |
2023 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { | 2060 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { |
2024 MockProxyConfigService* config_service = | 2061 MockProxyConfigService* config_service = |
2025 new MockProxyConfigService("http://foopy/proxy.pac"); | 2062 new MockProxyConfigService("http://foopy/proxy.pac"); |
2026 | 2063 |
2027 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 2064 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
2028 | 2065 |
2029 ProxyService service(config_service, resolver, NULL); | 2066 ProxyService service(config_service, resolver, NULL); |
2030 | 2067 |
2031 GURL url("http://www.google.com/"); | 2068 GURL url("http://www.google.com/"); |
2032 | 2069 |
2033 ProxyInfo info; | 2070 ProxyInfo info; |
2034 TestCompletionCallback callback; | 2071 TestCompletionCallback callback; |
2035 int rv = service.ResolveProxy( | 2072 int rv = service.ResolveProxy( |
2036 url, &info, callback.callback(), NULL, BoundNetLog()); | 2073 url, 0, &info, callback.callback(), NULL, NULL, BoundNetLog()); |
2037 EXPECT_EQ(ERR_IO_PENDING, rv); | 2074 EXPECT_EQ(ERR_IO_PENDING, rv); |
2038 | 2075 |
2039 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 2076 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
2040 resolver->pending_set_pac_script_request()->script_data()->url()); | 2077 resolver->pending_set_pac_script_request()->script_data()->url()); |
2041 } | 2078 } |
2042 | 2079 |
2043 TEST_F(ProxyServiceTest, ResetProxyConfigService) { | 2080 TEST_F(ProxyServiceTest, ResetProxyConfigService) { |
2044 ProxyConfig config1; | 2081 ProxyConfig config1; |
2045 config1.proxy_rules().ParseFromString("foopy1:8080"); | 2082 config1.proxy_rules().ParseFromString("foopy1:8080"); |
2046 config1.set_auto_detect(false); | 2083 config1.set_auto_detect(false); |
2047 ProxyService service( | 2084 ProxyService service( |
2048 new MockProxyConfigService(config1), | 2085 new MockProxyConfigService(config1), |
2049 new MockAsyncProxyResolverExpectsBytes, NULL); | 2086 new MockAsyncProxyResolverExpectsBytes, NULL); |
2050 | 2087 |
2051 ProxyInfo info; | 2088 ProxyInfo info; |
2052 TestCompletionCallback callback1; | 2089 TestCompletionCallback callback1; |
2053 int rv = service.ResolveProxy(GURL("http://request1"), &info, | 2090 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info, |
2054 callback1.callback(), NULL, BoundNetLog()); | 2091 callback1.callback(), NULL, NULL, |
2092 BoundNetLog()); | |
2055 EXPECT_EQ(OK, rv); | 2093 EXPECT_EQ(OK, rv); |
2056 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 2094 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
2057 | 2095 |
2058 ProxyConfig config2; | 2096 ProxyConfig config2; |
2059 config2.proxy_rules().ParseFromString("foopy2:8080"); | 2097 config2.proxy_rules().ParseFromString("foopy2:8080"); |
2060 config2.set_auto_detect(false); | 2098 config2.set_auto_detect(false); |
2061 service.ResetConfigService(new MockProxyConfigService(config2)); | 2099 service.ResetConfigService(new MockProxyConfigService(config2)); |
2062 TestCompletionCallback callback2; | 2100 TestCompletionCallback callback2; |
2063 rv = service.ResolveProxy(GURL("http://request2"), &info, | 2101 rv = service.ResolveProxy(GURL("http://request2"), 0, &info, |
2064 callback2.callback(), NULL, BoundNetLog()); | 2102 callback2.callback(), NULL, NULL, BoundNetLog()); |
2065 EXPECT_EQ(OK, rv); | 2103 EXPECT_EQ(OK, rv); |
2066 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 2104 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
2067 } | 2105 } |
2068 | 2106 |
2069 // 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 |
2070 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 2108 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
2071 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 2109 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
2072 ProxyConfig config = ProxyConfig::CreateAutoDetect(); | 2110 ProxyConfig config = ProxyConfig::CreateAutoDetect(); |
2073 | 2111 |
2074 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2112 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2075 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 2113 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
2076 ProxyService service(config_service, resolver, NULL); | 2114 ProxyService service(config_service, resolver, NULL); |
2077 | 2115 |
2078 // Start 1 request. | 2116 // Start 1 request. |
2079 | 2117 |
2080 ProxyInfo info1; | 2118 ProxyInfo info1; |
2081 TestCompletionCallback callback1; | 2119 TestCompletionCallback callback1; |
2082 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, | 2120 int rv = service.ResolveProxy(GURL("http://www.google.com"), 0, &info1, |
2083 callback1.callback(), NULL, BoundNetLog()); | 2121 callback1.callback(), NULL, NULL, |
2122 BoundNetLog()); | |
2084 EXPECT_EQ(ERR_IO_PENDING, rv); | 2123 EXPECT_EQ(ERR_IO_PENDING, rv); |
2085 | 2124 |
2086 // Check that nothing has been sent to the proxy resolver yet. | 2125 // Check that nothing has been sent to the proxy resolver yet. |
2087 ASSERT_EQ(0u, resolver->pending_requests().size()); | 2126 ASSERT_EQ(0u, resolver->pending_requests().size()); |
2088 | 2127 |
2089 // Successfully set the autodetect script. | 2128 // Successfully set the autodetect script. |
2090 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 2129 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
2091 resolver->pending_set_pac_script_request()->script_data()->type()); | 2130 resolver->pending_set_pac_script_request()->script_data()->type()); |
2092 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 2131 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
2093 | 2132 |
2094 // Complete the pending request. | 2133 // Complete the pending request. |
2095 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2134 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2096 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2135 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2097 resolver->pending_requests()[0]->CompleteNow(OK); | 2136 resolver->pending_requests()[0]->CompleteNow(OK); |
2098 | 2137 |
2099 // Verify that request ran as expected. | 2138 // Verify that request ran as expected. |
2100 EXPECT_EQ(OK, callback1.WaitForResult()); | 2139 EXPECT_EQ(OK, callback1.WaitForResult()); |
2101 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2140 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2102 | 2141 |
2103 // Force the ProxyService to pull down a new proxy configuration. | 2142 // Force the ProxyService to pull down a new proxy configuration. |
2104 // (Even though the configuration isn't old/bad). | 2143 // (Even though the configuration isn't old/bad). |
2105 // | 2144 // |
2106 // This new configuration no longer has auto_detect set, so | 2145 // This new configuration no longer has auto_detect set, so |
2107 // requests should complete synchronously now as direct-connect. | 2146 // requests should complete synchronously now as direct-connect. |
2108 config_service->SetConfig(ProxyConfig::CreateDirect()); | 2147 config_service->SetConfig(ProxyConfig::CreateDirect()); |
2109 | 2148 |
2110 // Start another request -- the effective configuration has changed. | 2149 // Start another request -- the effective configuration has changed. |
2111 ProxyInfo info2; | 2150 ProxyInfo info2; |
2112 TestCompletionCallback callback2; | 2151 TestCompletionCallback callback2; |
2113 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, | 2152 rv = service.ResolveProxy(GURL("http://www.google.com"), 0, &info2, |
2114 callback2.callback(), NULL, BoundNetLog()); | 2153 callback2.callback(), NULL, NULL, BoundNetLog()); |
2115 EXPECT_EQ(OK, rv); | 2154 EXPECT_EQ(OK, rv); |
2116 | 2155 |
2117 EXPECT_TRUE(info2.is_direct()); | 2156 EXPECT_TRUE(info2.is_direct()); |
2118 } | 2157 } |
2119 | 2158 |
2120 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { | 2159 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { |
2121 MockProxyConfigService* config_service = | 2160 MockProxyConfigService* config_service = |
2122 new MockProxyConfigService("http://foopy/proxy.pac"); | 2161 new MockProxyConfigService("http://foopy/proxy.pac"); |
2123 | 2162 |
2124 MockAsyncProxyResolverExpectsBytes* resolver = | 2163 MockAsyncProxyResolverExpectsBytes* resolver = |
2125 new MockAsyncProxyResolverExpectsBytes; | 2164 new MockAsyncProxyResolverExpectsBytes; |
2126 | 2165 |
2127 CapturingNetLog log; | 2166 CapturingNetLog log; |
2128 | 2167 |
2129 ProxyService service(config_service, resolver, &log); | 2168 ProxyService service(config_service, resolver, &log); |
2130 | 2169 |
2131 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2170 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2132 service.SetProxyScriptFetchers(fetcher, | 2171 service.SetProxyScriptFetchers(fetcher, |
2133 new DoNothingDhcpProxyScriptFetcher()); | 2172 new DoNothingDhcpProxyScriptFetcher()); |
2134 | 2173 |
2135 // Disable the "wait after IP address changes" hack, so this unit-test can | 2174 // Disable the "wait after IP address changes" hack, so this unit-test can |
2136 // complete quickly. | 2175 // complete quickly. |
2137 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); | 2176 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); |
2138 | 2177 |
2139 // Start 1 request. | 2178 // Start 1 request. |
2140 | 2179 |
2141 ProxyInfo info1; | 2180 ProxyInfo info1; |
2142 TestCompletionCallback callback1; | 2181 TestCompletionCallback callback1; |
2143 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 2182 int rv = service.ResolveProxy(GURL("http://request1"), 0, &info1, |
2144 callback1.callback(), NULL, BoundNetLog()); | 2183 callback1.callback(), NULL, NULL, |
2184 BoundNetLog()); | |
2145 EXPECT_EQ(ERR_IO_PENDING, rv); | 2185 EXPECT_EQ(ERR_IO_PENDING, rv); |
2146 | 2186 |
2147 // The first request should have triggered initial download of PAC script. | 2187 // The first request should have triggered initial download of PAC script. |
2148 EXPECT_TRUE(fetcher->has_pending_request()); | 2188 EXPECT_TRUE(fetcher->has_pending_request()); |
2149 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2189 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2150 | 2190 |
2151 // Nothing has been sent to the resolver yet. | 2191 // Nothing has been sent to the resolver yet. |
2152 EXPECT_TRUE(resolver->pending_requests().empty()); | 2192 EXPECT_TRUE(resolver->pending_requests().empty()); |
2153 | 2193 |
2154 // At this point the ProxyService should be waiting for the | 2194 // At this point the ProxyService should be waiting for the |
(...skipping 20 matching lines...) Expand all Loading... | |
2175 | 2215 |
2176 // Now simluate a change in the network. The ProxyConfigService is still | 2216 // Now simluate a change in the network. The ProxyConfigService is still |
2177 // going to return the same PAC URL as before, but this URL needs to be | 2217 // going to return the same PAC URL as before, but this URL needs to be |
2178 // refetched on the new network. | 2218 // refetched on the new network. |
2179 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 2219 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
2180 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 2220 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. |
2181 | 2221 |
2182 // Start a second request. | 2222 // Start a second request. |
2183 ProxyInfo info2; | 2223 ProxyInfo info2; |
2184 TestCompletionCallback callback2; | 2224 TestCompletionCallback callback2; |
2185 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 2225 rv = service.ResolveProxy(GURL("http://request2"), 0, &info2, |
2186 callback2.callback(), NULL, BoundNetLog()); | 2226 callback2.callback(), NULL, NULL, BoundNetLog()); |
2187 EXPECT_EQ(ERR_IO_PENDING, rv); | 2227 EXPECT_EQ(ERR_IO_PENDING, rv); |
2188 | 2228 |
2189 // This second request should have triggered the re-download of the PAC | 2229 // This second request should have triggered the re-download of the PAC |
2190 // script (since we marked the network as having changed). | 2230 // script (since we marked the network as having changed). |
2191 EXPECT_TRUE(fetcher->has_pending_request()); | 2231 EXPECT_TRUE(fetcher->has_pending_request()); |
2192 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2232 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2193 | 2233 |
2194 // Nothing has been sent to the resolver yet. | 2234 // Nothing has been sent to the resolver yet. |
2195 EXPECT_TRUE(resolver->pending_requests().empty()); | 2235 EXPECT_TRUE(resolver->pending_requests().empty()); |
2196 | 2236 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2248 | 2288 |
2249 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2289 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2250 service.SetProxyScriptFetchers(fetcher, | 2290 service.SetProxyScriptFetchers(fetcher, |
2251 new DoNothingDhcpProxyScriptFetcher()); | 2291 new DoNothingDhcpProxyScriptFetcher()); |
2252 | 2292 |
2253 // Start 1 request. | 2293 // Start 1 request. |
2254 | 2294 |
2255 ProxyInfo info1; | 2295 ProxyInfo info1; |
2256 TestCompletionCallback callback1; | 2296 TestCompletionCallback callback1; |
2257 int rv = service.ResolveProxy( | 2297 int rv = service.ResolveProxy( |
2258 GURL("http://request1"), &info1, callback1.callback(), | 2298 GURL("http://request1"), 0, &info1, callback1.callback(), |
2259 NULL, BoundNetLog()); | 2299 NULL, NULL, BoundNetLog()); |
2260 EXPECT_EQ(ERR_IO_PENDING, rv); | 2300 EXPECT_EQ(ERR_IO_PENDING, rv); |
2261 | 2301 |
2262 // The first request should have triggered initial download of PAC script. | 2302 // The first request should have triggered initial download of PAC script. |
2263 EXPECT_TRUE(fetcher->has_pending_request()); | 2303 EXPECT_TRUE(fetcher->has_pending_request()); |
2264 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2304 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2265 | 2305 |
2266 // Nothing has been sent to the resolver yet. | 2306 // Nothing has been sent to the resolver yet. |
2267 EXPECT_TRUE(resolver->pending_requests().empty()); | 2307 EXPECT_TRUE(resolver->pending_requests().empty()); |
2268 | 2308 |
2269 // At this point the ProxyService should be waiting for the | 2309 // At this point the ProxyService should be waiting for the |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2309 | 2349 |
2310 // At this point the ProxyService should have re-configured itself to use the | 2350 // At this point the ProxyService should have re-configured itself to use the |
2311 // PAC script (thereby recovering from the initial fetch failure). We will | 2351 // PAC script (thereby recovering from the initial fetch failure). We will |
2312 // verify that the next Resolve request uses the resolver rather than | 2352 // verify that the next Resolve request uses the resolver rather than |
2313 // DIRECT. | 2353 // DIRECT. |
2314 | 2354 |
2315 // Start a second request. | 2355 // Start a second request. |
2316 ProxyInfo info2; | 2356 ProxyInfo info2; |
2317 TestCompletionCallback callback2; | 2357 TestCompletionCallback callback2; |
2318 rv = service.ResolveProxy( | 2358 rv = service.ResolveProxy( |
2319 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2359 GURL("http://request2"), 0, &info2, callback2.callback(), NULL, |
2320 BoundNetLog()); | 2360 NULL, BoundNetLog()); |
2321 EXPECT_EQ(ERR_IO_PENDING, rv); | 2361 EXPECT_EQ(ERR_IO_PENDING, rv); |
2322 | 2362 |
2323 // Check that it was sent to the resolver. | 2363 // Check that it was sent to the resolver. |
2324 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2364 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2325 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2365 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2326 | 2366 |
2327 // Complete the pending second request. | 2367 // Complete the pending second request. |
2328 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2368 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2329 resolver->pending_requests()[0]->CompleteNow(OK); | 2369 resolver->pending_requests()[0]->CompleteNow(OK); |
2330 | 2370 |
(...skipping 22 matching lines...) Expand all Loading... | |
2353 | 2393 |
2354 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2394 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2355 service.SetProxyScriptFetchers(fetcher, | 2395 service.SetProxyScriptFetchers(fetcher, |
2356 new DoNothingDhcpProxyScriptFetcher()); | 2396 new DoNothingDhcpProxyScriptFetcher()); |
2357 | 2397 |
2358 // Start 1 request. | 2398 // Start 1 request. |
2359 | 2399 |
2360 ProxyInfo info1; | 2400 ProxyInfo info1; |
2361 TestCompletionCallback callback1; | 2401 TestCompletionCallback callback1; |
2362 int rv = service.ResolveProxy( | 2402 int rv = service.ResolveProxy( |
2363 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2403 GURL("http://request1"), 0, &info1, callback1.callback(), NULL, |
2364 BoundNetLog()); | 2404 NULL, BoundNetLog()); |
2365 EXPECT_EQ(ERR_IO_PENDING, rv); | 2405 EXPECT_EQ(ERR_IO_PENDING, rv); |
2366 | 2406 |
2367 // The first request should have triggered initial download of PAC script. | 2407 // The first request should have triggered initial download of PAC script. |
2368 EXPECT_TRUE(fetcher->has_pending_request()); | 2408 EXPECT_TRUE(fetcher->has_pending_request()); |
2369 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2409 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2370 | 2410 |
2371 // Nothing has been sent to the resolver yet. | 2411 // Nothing has been sent to the resolver yet. |
2372 EXPECT_TRUE(resolver->pending_requests().empty()); | 2412 EXPECT_TRUE(resolver->pending_requests().empty()); |
2373 | 2413 |
2374 // At this point the ProxyService should be waiting for the | 2414 // At this point the ProxyService should be waiting for the |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2419 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 2459 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
2420 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 2460 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
2421 | 2461 |
2422 // At this point the ProxyService should have re-configured itself to use the | 2462 // At this point the ProxyService should have re-configured itself to use the |
2423 // new PAC script. | 2463 // new PAC script. |
2424 | 2464 |
2425 // Start a second request. | 2465 // Start a second request. |
2426 ProxyInfo info2; | 2466 ProxyInfo info2; |
2427 TestCompletionCallback callback2; | 2467 TestCompletionCallback callback2; |
2428 rv = service.ResolveProxy( | 2468 rv = service.ResolveProxy( |
2429 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2469 GURL("http://request2"), 0, &info2, callback2.callback(), NULL, |
2430 BoundNetLog()); | 2470 NULL, BoundNetLog()); |
2431 EXPECT_EQ(ERR_IO_PENDING, rv); | 2471 EXPECT_EQ(ERR_IO_PENDING, rv); |
2432 | 2472 |
2433 // Check that it was sent to the resolver. | 2473 // Check that it was sent to the resolver. |
2434 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2474 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2435 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2475 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2436 | 2476 |
2437 // Complete the pending second request. | 2477 // Complete the pending second request. |
2438 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2478 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2439 resolver->pending_requests()[0]->CompleteNow(OK); | 2479 resolver->pending_requests()[0]->CompleteNow(OK); |
2440 | 2480 |
(...skipping 22 matching lines...) Expand all Loading... | |
2463 | 2503 |
2464 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2504 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2465 service.SetProxyScriptFetchers(fetcher, | 2505 service.SetProxyScriptFetchers(fetcher, |
2466 new DoNothingDhcpProxyScriptFetcher()); | 2506 new DoNothingDhcpProxyScriptFetcher()); |
2467 | 2507 |
2468 // Start 1 request. | 2508 // Start 1 request. |
2469 | 2509 |
2470 ProxyInfo info1; | 2510 ProxyInfo info1; |
2471 TestCompletionCallback callback1; | 2511 TestCompletionCallback callback1; |
2472 int rv = service.ResolveProxy( | 2512 int rv = service.ResolveProxy( |
2473 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2513 GURL("http://request1"), 0, &info1, callback1.callback(), NULL, |
2474 BoundNetLog()); | 2514 NULL, BoundNetLog()); |
2475 EXPECT_EQ(ERR_IO_PENDING, rv); | 2515 EXPECT_EQ(ERR_IO_PENDING, rv); |
2476 | 2516 |
2477 // The first request should have triggered initial download of PAC script. | 2517 // The first request should have triggered initial download of PAC script. |
2478 EXPECT_TRUE(fetcher->has_pending_request()); | 2518 EXPECT_TRUE(fetcher->has_pending_request()); |
2479 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2519 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2480 | 2520 |
2481 // Nothing has been sent to the resolver yet. | 2521 // Nothing has been sent to the resolver yet. |
2482 EXPECT_TRUE(resolver->pending_requests().empty()); | 2522 EXPECT_TRUE(resolver->pending_requests().empty()); |
2483 | 2523 |
2484 // At this point the ProxyService should be waiting for the | 2524 // At this point the ProxyService should be waiting for the |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2525 | 2565 |
2526 ASSERT_FALSE(resolver->has_pending_set_pac_script_request()); | 2566 ASSERT_FALSE(resolver->has_pending_set_pac_script_request()); |
2527 | 2567 |
2528 // At this point the ProxyService is still running the same PAC script as | 2568 // At this point the ProxyService is still running the same PAC script as |
2529 // before. | 2569 // before. |
2530 | 2570 |
2531 // Start a second request. | 2571 // Start a second request. |
2532 ProxyInfo info2; | 2572 ProxyInfo info2; |
2533 TestCompletionCallback callback2; | 2573 TestCompletionCallback callback2; |
2534 rv = service.ResolveProxy( | 2574 rv = service.ResolveProxy( |
2535 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2575 GURL("http://request2"), 0, &info2, callback2.callback(), NULL, |
2536 BoundNetLog()); | 2576 NULL, BoundNetLog()); |
2537 EXPECT_EQ(ERR_IO_PENDING, rv); | 2577 EXPECT_EQ(ERR_IO_PENDING, rv); |
2538 | 2578 |
2539 // Check that it was sent to the resolver. | 2579 // Check that it was sent to the resolver. |
2540 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2580 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2541 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2581 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2542 | 2582 |
2543 // Complete the pending second request. | 2583 // Complete the pending second request. |
2544 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2584 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2545 resolver->pending_requests()[0]->CompleteNow(OK); | 2585 resolver->pending_requests()[0]->CompleteNow(OK); |
2546 | 2586 |
(...skipping 22 matching lines...) Expand all Loading... | |
2569 | 2609 |
2570 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2610 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2571 service.SetProxyScriptFetchers(fetcher, | 2611 service.SetProxyScriptFetchers(fetcher, |
2572 new DoNothingDhcpProxyScriptFetcher()); | 2612 new DoNothingDhcpProxyScriptFetcher()); |
2573 | 2613 |
2574 // Start 1 request. | 2614 // Start 1 request. |
2575 | 2615 |
2576 ProxyInfo info1; | 2616 ProxyInfo info1; |
2577 TestCompletionCallback callback1; | 2617 TestCompletionCallback callback1; |
2578 int rv = service.ResolveProxy( | 2618 int rv = service.ResolveProxy( |
2579 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2619 GURL("http://request1"), 0, &info1, callback1.callback(), NULL, |
2580 BoundNetLog()); | 2620 NULL, BoundNetLog()); |
2581 EXPECT_EQ(ERR_IO_PENDING, rv); | 2621 EXPECT_EQ(ERR_IO_PENDING, rv); |
2582 | 2622 |
2583 // The first request should have triggered initial download of PAC script. | 2623 // The first request should have triggered initial download of PAC script. |
2584 EXPECT_TRUE(fetcher->has_pending_request()); | 2624 EXPECT_TRUE(fetcher->has_pending_request()); |
2585 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2625 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2586 | 2626 |
2587 // Nothing has been sent to the resolver yet. | 2627 // Nothing has been sent to the resolver yet. |
2588 EXPECT_TRUE(resolver->pending_requests().empty()); | 2628 EXPECT_TRUE(resolver->pending_requests().empty()); |
2589 | 2629 |
2590 // At this point the ProxyService should be waiting for the | 2630 // At this point the ProxyService should be waiting for the |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2629 | 2669 |
2630 base::MessageLoop::current()->RunUntilIdle(); | 2670 base::MessageLoop::current()->RunUntilIdle(); |
2631 | 2671 |
2632 // At this point the ProxyService should have re-configured itself to use | 2672 // At this point the ProxyService should have re-configured itself to use |
2633 // DIRECT connections rather than the given proxy resolver. | 2673 // DIRECT connections rather than the given proxy resolver. |
2634 | 2674 |
2635 // Start a second request. | 2675 // Start a second request. |
2636 ProxyInfo info2; | 2676 ProxyInfo info2; |
2637 TestCompletionCallback callback2; | 2677 TestCompletionCallback callback2; |
2638 rv = service.ResolveProxy( | 2678 rv = service.ResolveProxy( |
2639 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2679 GURL("http://request2"), 0, &info2, callback2.callback(), NULL, |
2640 BoundNetLog()); | 2680 NULL, BoundNetLog()); |
2641 EXPECT_EQ(OK, rv); | 2681 EXPECT_EQ(OK, rv); |
2642 EXPECT_TRUE(info2.is_direct()); | 2682 EXPECT_TRUE(info2.is_direct()); |
2643 } | 2683 } |
2644 | 2684 |
2645 // Tests that the code which decides at what times to poll the PAC | 2685 // Tests that the code which decides at what times to poll the PAC |
2646 // script follows the expected policy. | 2686 // script follows the expected policy. |
2647 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { | 2687 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { |
2648 // Retrieve the internal polling policy implementation used by ProxyService. | 2688 // Retrieve the internal polling policy implementation used by ProxyService. |
2649 scoped_ptr<ProxyService::PacPollPolicy> policy = | 2689 scoped_ptr<ProxyService::PacPollPolicy> policy = |
2650 ProxyService::CreateDefaultPacPollPolicy(); | 2690 ProxyService::CreateDefaultPacPollPolicy(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2721 | 2761 |
2722 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2762 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2723 service.SetProxyScriptFetchers(fetcher, | 2763 service.SetProxyScriptFetchers(fetcher, |
2724 new DoNothingDhcpProxyScriptFetcher()); | 2764 new DoNothingDhcpProxyScriptFetcher()); |
2725 | 2765 |
2726 // Start 1 request. | 2766 // Start 1 request. |
2727 | 2767 |
2728 ProxyInfo info1; | 2768 ProxyInfo info1; |
2729 TestCompletionCallback callback1; | 2769 TestCompletionCallback callback1; |
2730 int rv = service.ResolveProxy( | 2770 int rv = service.ResolveProxy( |
2731 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2771 GURL("http://request1"), 0, &info1, callback1.callback(), NULL, |
2732 BoundNetLog()); | 2772 NULL, BoundNetLog()); |
2733 EXPECT_EQ(ERR_IO_PENDING, rv); | 2773 EXPECT_EQ(ERR_IO_PENDING, rv); |
2734 | 2774 |
2735 // The first request should have triggered initial download of PAC script. | 2775 // The first request should have triggered initial download of PAC script. |
2736 EXPECT_TRUE(fetcher->has_pending_request()); | 2776 EXPECT_TRUE(fetcher->has_pending_request()); |
2737 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2777 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2738 | 2778 |
2739 // Nothing has been sent to the resolver yet. | 2779 // Nothing has been sent to the resolver yet. |
2740 EXPECT_TRUE(resolver->pending_requests().empty()); | 2780 EXPECT_TRUE(resolver->pending_requests().empty()); |
2741 | 2781 |
2742 // At this point the ProxyService should be waiting for the | 2782 // At this point the ProxyService should be waiting for the |
(...skipping 22 matching lines...) Expand all Loading... | |
2765 // Our PAC poller is set to update ONLY in response to network activity, | 2805 // Our PAC poller is set to update ONLY in response to network activity, |
2766 // (i.e. another call to ResolveProxy()). | 2806 // (i.e. another call to ResolveProxy()). |
2767 | 2807 |
2768 ASSERT_FALSE(fetcher->has_pending_request()); | 2808 ASSERT_FALSE(fetcher->has_pending_request()); |
2769 ASSERT_TRUE(resolver->pending_requests().empty()); | 2809 ASSERT_TRUE(resolver->pending_requests().empty()); |
2770 | 2810 |
2771 // Start a second request. | 2811 // Start a second request. |
2772 ProxyInfo info2; | 2812 ProxyInfo info2; |
2773 TestCompletionCallback callback2; | 2813 TestCompletionCallback callback2; |
2774 rv = service.ResolveProxy( | 2814 rv = service.ResolveProxy( |
2775 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2815 GURL("http://request2"), 0, &info2, callback2.callback(), NULL, |
2776 BoundNetLog()); | 2816 NULL, BoundNetLog()); |
2777 EXPECT_EQ(ERR_IO_PENDING, rv); | 2817 EXPECT_EQ(ERR_IO_PENDING, rv); |
2778 | 2818 |
2779 // This request should have sent work to the resolver; complete it. | 2819 // This request should have sent work to the resolver; complete it. |
2780 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2820 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2781 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2821 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2782 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2822 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2783 resolver->pending_requests()[0]->CompleteNow(OK); | 2823 resolver->pending_requests()[0]->CompleteNow(OK); |
2784 | 2824 |
2785 EXPECT_EQ(OK, callback2.WaitForResult()); | 2825 EXPECT_EQ(OK, callback2.WaitForResult()); |
2786 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2826 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2787 | 2827 |
2788 // In response to getting that resolve request, the poller should have | 2828 // In response to getting that resolve request, the poller should have |
2789 // started the next poll, and made it as far as to request the download. | 2829 // started the next poll, and made it as far as to request the download. |
2790 | 2830 |
2791 EXPECT_TRUE(fetcher->has_pending_request()); | 2831 EXPECT_TRUE(fetcher->has_pending_request()); |
2792 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2832 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2793 | 2833 |
2794 // This time we will fail the download, to simulate a PAC script change. | 2834 // This time we will fail the download, to simulate a PAC script change. |
2795 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2835 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2796 | 2836 |
2797 // Drain the message loop, so ProxyService is notified of the change | 2837 // Drain the message loop, so ProxyService is notified of the change |
2798 // and has a chance to re-configure itself. | 2838 // and has a chance to re-configure itself. |
2799 base::MessageLoop::current()->RunUntilIdle(); | 2839 base::MessageLoop::current()->RunUntilIdle(); |
2800 | 2840 |
2801 // Start a third request -- this time we expect to get a direct connection | 2841 // Start a third request -- this time we expect to get a direct connection |
2802 // since the PAC script poller experienced a failure. | 2842 // since the PAC script poller experienced a failure. |
2803 ProxyInfo info3; | 2843 ProxyInfo info3; |
2804 TestCompletionCallback callback3; | 2844 TestCompletionCallback callback3; |
2805 rv = service.ResolveProxy( | 2845 rv = service.ResolveProxy( |
2806 GURL("http://request3"), &info3, callback3.callback(), NULL, | 2846 GURL("http://request3"), 0, &info3, callback3.callback(), NULL, |
2807 BoundNetLog()); | 2847 NULL, BoundNetLog()); |
2808 EXPECT_EQ(OK, rv); | 2848 EXPECT_EQ(OK, rv); |
2809 EXPECT_TRUE(info3.is_direct()); | 2849 EXPECT_TRUE(info3.is_direct()); |
2810 } | 2850 } |
2811 | 2851 |
2812 } // namespace net | 2852 } // namespace net |
OLD | NEW |