OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/base/host_resolver_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 callback_called_ = true; | 252 callback_called_ = true; |
253 callback_result_ = result; | 253 callback_result_ = result; |
254 MessageLoop::current()->Quit(); | 254 MessageLoop::current()->Quit(); |
255 } | 255 } |
256 }; | 256 }; |
257 | 257 |
258 TEST_F(HostResolverImplTest, SynchronousLookup) { | 258 TEST_F(HostResolverImplTest, SynchronousLookup) { |
259 AddressList addrlist; | 259 AddressList addrlist; |
260 const int kPortnum = 80; | 260 const int kPortnum = 80; |
261 | 261 |
262 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = | 262 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
263 new RuleBasedHostResolverProc(NULL); | 263 new RuleBasedHostResolverProc(NULL)); |
264 resolver_proc->AddRule("just.testing", "192.168.1.42"); | 264 resolver_proc->AddRule("just.testing", "192.168.1.42"); |
265 | 265 |
266 scoped_ptr<HostResolver> host_resolver( | 266 scoped_ptr<HostResolver> host_resolver( |
267 CreateHostResolverImpl(resolver_proc)); | 267 CreateHostResolverImpl(resolver_proc)); |
268 | 268 |
269 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); | 269 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); |
270 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 270 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
271 int err = host_resolver->Resolve(info, &addrlist, NULL, NULL, log.bound()); | 271 int err = host_resolver->Resolve(info, &addrlist, NULL, NULL, log.bound()); |
272 EXPECT_EQ(OK, err); | 272 EXPECT_EQ(OK, err); |
273 | 273 |
(...skipping 10 matching lines...) Expand all Loading... |
284 const struct sockaddr* sa = ainfo->ai_addr; | 284 const struct sockaddr* sa = ainfo->ai_addr; |
285 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; | 285 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; |
286 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); | 286 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); |
287 EXPECT_TRUE(htonl(0xc0a8012a) == sa_in->sin_addr.s_addr); | 287 EXPECT_TRUE(htonl(0xc0a8012a) == sa_in->sin_addr.s_addr); |
288 } | 288 } |
289 | 289 |
290 TEST_F(HostResolverImplTest, AsynchronousLookup) { | 290 TEST_F(HostResolverImplTest, AsynchronousLookup) { |
291 AddressList addrlist; | 291 AddressList addrlist; |
292 const int kPortnum = 80; | 292 const int kPortnum = 80; |
293 | 293 |
294 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = | 294 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
295 new RuleBasedHostResolverProc(NULL); | 295 new RuleBasedHostResolverProc(NULL)); |
296 resolver_proc->AddRule("just.testing", "192.168.1.42"); | 296 resolver_proc->AddRule("just.testing", "192.168.1.42"); |
297 | 297 |
298 scoped_ptr<HostResolver> host_resolver( | 298 scoped_ptr<HostResolver> host_resolver( |
299 CreateHostResolverImpl(resolver_proc)); | 299 CreateHostResolverImpl(resolver_proc)); |
300 | 300 |
301 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); | 301 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); |
302 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 302 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
303 int err = host_resolver->Resolve(info, &addrlist, &callback_, NULL, | 303 int err = host_resolver->Resolve(info, &addrlist, &callback_, NULL, |
304 log.bound()); | 304 log.bound()); |
305 EXPECT_EQ(ERR_IO_PENDING, err); | 305 EXPECT_EQ(ERR_IO_PENDING, err); |
(...skipping 15 matching lines...) Expand all Loading... |
321 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); | 321 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); |
322 EXPECT_EQ(sizeof(struct sockaddr_in), ainfo->ai_addrlen); | 322 EXPECT_EQ(sizeof(struct sockaddr_in), ainfo->ai_addrlen); |
323 | 323 |
324 const struct sockaddr* sa = ainfo->ai_addr; | 324 const struct sockaddr* sa = ainfo->ai_addr; |
325 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; | 325 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; |
326 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); | 326 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); |
327 EXPECT_TRUE(htonl(0xc0a8012a) == sa_in->sin_addr.s_addr); | 327 EXPECT_TRUE(htonl(0xc0a8012a) == sa_in->sin_addr.s_addr); |
328 } | 328 } |
329 | 329 |
330 TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { | 330 TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { |
331 scoped_refptr<WaitingHostResolverProc> resolver_proc = | 331 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
332 new WaitingHostResolverProc(NULL); | 332 new WaitingHostResolverProc(NULL)); |
333 | 333 |
334 CapturingNetLog net_log(CapturingNetLog::kUnbounded); | 334 CapturingNetLog net_log(CapturingNetLog::kUnbounded); |
335 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 335 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
336 { | 336 { |
337 scoped_ptr<HostResolver> host_resolver( | 337 scoped_ptr<HostResolver> host_resolver( |
338 new HostResolverImpl(resolver_proc, | 338 new HostResolverImpl(resolver_proc, |
339 CreateDefaultCache(), | 339 CreateDefaultCache(), |
340 kMaxJobs, | 340 kMaxJobs, |
341 &net_log)); | 341 &net_log)); |
342 AddressList addrlist; | 342 AddressList addrlist; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, | 383 net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, |
384 net::NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 384 net::NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, |
385 net::NetLog::PHASE_END); | 385 net::NetLog::PHASE_END); |
386 | 386 |
387 EXPECT_FALSE(callback_called_); | 387 EXPECT_FALSE(callback_called_); |
388 } | 388 } |
389 | 389 |
390 TEST_F(HostResolverImplTest, NumericIPv4Address) { | 390 TEST_F(HostResolverImplTest, NumericIPv4Address) { |
391 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. | 391 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. |
392 | 392 |
393 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = | 393 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
394 new RuleBasedHostResolverProc(NULL); | 394 new RuleBasedHostResolverProc(NULL)); |
395 resolver_proc->AllowDirectLookup("*"); | 395 resolver_proc->AllowDirectLookup("*"); |
396 | 396 |
397 scoped_ptr<HostResolver> host_resolver( | 397 scoped_ptr<HostResolver> host_resolver( |
398 CreateHostResolverImpl(resolver_proc)); | 398 CreateHostResolverImpl(resolver_proc)); |
399 AddressList addrlist; | 399 AddressList addrlist; |
400 const int kPortnum = 5555; | 400 const int kPortnum = 5555; |
401 HostResolver::RequestInfo info(HostPortPair("127.1.2.3", kPortnum)); | 401 HostResolver::RequestInfo info(HostPortPair("127.1.2.3", kPortnum)); |
402 int err = host_resolver->Resolve(info, &addrlist, NULL, NULL, BoundNetLog()); | 402 int err = host_resolver->Resolve(info, &addrlist, NULL, NULL, BoundNetLog()); |
403 EXPECT_EQ(OK, err); | 403 EXPECT_EQ(OK, err); |
404 | 404 |
405 const struct addrinfo* ainfo = addrlist.head(); | 405 const struct addrinfo* ainfo = addrlist.head(); |
406 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); | 406 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); |
407 EXPECT_EQ(sizeof(struct sockaddr_in), ainfo->ai_addrlen); | 407 EXPECT_EQ(sizeof(struct sockaddr_in), ainfo->ai_addrlen); |
408 | 408 |
409 const struct sockaddr* sa = ainfo->ai_addr; | 409 const struct sockaddr* sa = ainfo->ai_addr; |
410 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; | 410 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; |
411 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); | 411 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); |
412 EXPECT_TRUE(htonl(0x7f010203) == sa_in->sin_addr.s_addr); | 412 EXPECT_TRUE(htonl(0x7f010203) == sa_in->sin_addr.s_addr); |
413 } | 413 } |
414 | 414 |
415 TEST_F(HostResolverImplTest, NumericIPv6Address) { | 415 TEST_F(HostResolverImplTest, NumericIPv6Address) { |
416 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = | 416 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
417 new RuleBasedHostResolverProc(NULL); | 417 new RuleBasedHostResolverProc(NULL)); |
418 resolver_proc->AllowDirectLookup("*"); | 418 resolver_proc->AllowDirectLookup("*"); |
419 | 419 |
420 // Resolve a plain IPv6 address. Don't worry about [brackets], because | 420 // Resolve a plain IPv6 address. Don't worry about [brackets], because |
421 // the caller should have removed them. | 421 // the caller should have removed them. |
422 scoped_ptr<HostResolver> host_resolver( | 422 scoped_ptr<HostResolver> host_resolver( |
423 CreateHostResolverImpl(resolver_proc)); | 423 CreateHostResolverImpl(resolver_proc)); |
424 AddressList addrlist; | 424 AddressList addrlist; |
425 const int kPortnum = 5555; | 425 const int kPortnum = 5555; |
426 HostResolver::RequestInfo info(HostPortPair("2001:db8::1", kPortnum)); | 426 HostResolver::RequestInfo info(HostPortPair("2001:db8::1", kPortnum)); |
427 int err = host_resolver->Resolve(info, &addrlist, NULL, NULL, BoundNetLog()); | 427 int err = host_resolver->Resolve(info, &addrlist, NULL, NULL, BoundNetLog()); |
(...skipping 10 matching lines...) Expand all Loading... |
438 const uint8 expect_addr[] = { | 438 const uint8 expect_addr[] = { |
439 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, | 439 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, |
440 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 | 440 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 |
441 }; | 441 }; |
442 for (int i = 0; i < 16; i++) { | 442 for (int i = 0; i < 16; i++) { |
443 EXPECT_EQ(expect_addr[i], sa_in6->sin6_addr.s6_addr[i]); | 443 EXPECT_EQ(expect_addr[i], sa_in6->sin6_addr.s6_addr[i]); |
444 } | 444 } |
445 } | 445 } |
446 | 446 |
447 TEST_F(HostResolverImplTest, EmptyHost) { | 447 TEST_F(HostResolverImplTest, EmptyHost) { |
448 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = | 448 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
449 new RuleBasedHostResolverProc(NULL); | 449 new RuleBasedHostResolverProc(NULL)); |
450 resolver_proc->AllowDirectLookup("*"); | 450 resolver_proc->AllowDirectLookup("*"); |
451 | 451 |
452 scoped_ptr<HostResolver> host_resolver( | 452 scoped_ptr<HostResolver> host_resolver( |
453 CreateHostResolverImpl(resolver_proc)); | 453 CreateHostResolverImpl(resolver_proc)); |
454 AddressList addrlist; | 454 AddressList addrlist; |
455 const int kPortnum = 5555; | 455 const int kPortnum = 5555; |
456 HostResolver::RequestInfo info(HostPortPair("", kPortnum)); | 456 HostResolver::RequestInfo info(HostPortPair("", kPortnum)); |
457 int err = host_resolver->Resolve(info, &addrlist, NULL, NULL, BoundNetLog()); | 457 int err = host_resolver->Resolve(info, &addrlist, NULL, NULL, BoundNetLog()); |
458 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, err); | 458 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, err); |
459 } | 459 } |
460 | 460 |
461 TEST_F(HostResolverImplTest, LongHost) { | 461 TEST_F(HostResolverImplTest, LongHost) { |
462 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = | 462 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
463 new RuleBasedHostResolverProc(NULL); | 463 new RuleBasedHostResolverProc(NULL)); |
464 resolver_proc->AllowDirectLookup("*"); | 464 resolver_proc->AllowDirectLookup("*"); |
465 | 465 |
466 scoped_ptr<HostResolver> host_resolver( | 466 scoped_ptr<HostResolver> host_resolver( |
467 CreateHostResolverImpl(resolver_proc)); | 467 CreateHostResolverImpl(resolver_proc)); |
468 AddressList addrlist; | 468 AddressList addrlist; |
469 const int kPortnum = 5555; | 469 const int kPortnum = 5555; |
470 std::string hostname(4097, 'a'); | 470 std::string hostname(4097, 'a'); |
471 HostResolver::RequestInfo info(HostPortPair(hostname, kPortnum)); | 471 HostResolver::RequestInfo info(HostPortPair(hostname, kPortnum)); |
472 int err = host_resolver->Resolve(info, &addrlist, NULL, NULL, BoundNetLog()); | 472 int err = host_resolver->Resolve(info, &addrlist, NULL, NULL, BoundNetLog()); |
473 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, err); | 473 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, err); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 int count_a_; | 516 int count_a_; |
517 int count_b_; | 517 int count_b_; |
518 CapturingHostResolverProc* resolver_proc_; | 518 CapturingHostResolverProc* resolver_proc_; |
519 | 519 |
520 DISALLOW_COPY_AND_ASSIGN(DeDupeRequestsVerifier); | 520 DISALLOW_COPY_AND_ASSIGN(DeDupeRequestsVerifier); |
521 }; | 521 }; |
522 | 522 |
523 TEST_F(HostResolverImplTest, DeDupeRequests) { | 523 TEST_F(HostResolverImplTest, DeDupeRequests) { |
524 // Use a capturing resolver_proc, since the verifier needs to know what calls | 524 // Use a capturing resolver_proc, since the verifier needs to know what calls |
525 // reached Resolve(). Also, the capturing resolver_proc is initially blocked. | 525 // reached Resolve(). Also, the capturing resolver_proc is initially blocked. |
526 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 526 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
527 new CapturingHostResolverProc(NULL); | 527 new CapturingHostResolverProc(NULL)); |
528 | 528 |
529 scoped_ptr<HostResolver> host_resolver( | 529 scoped_ptr<HostResolver> host_resolver( |
530 CreateHostResolverImpl(resolver_proc)); | 530 CreateHostResolverImpl(resolver_proc)); |
531 | 531 |
532 // The class will receive callbacks for when each resolve completes. It | 532 // The class will receive callbacks for when each resolve completes. It |
533 // checks that the right things happened. | 533 // checks that the right things happened. |
534 DeDupeRequestsVerifier verifier(resolver_proc.get()); | 534 DeDupeRequestsVerifier verifier(resolver_proc.get()); |
535 | 535 |
536 // Start 5 requests, duplicating hosts "a" and "b". Since the resolver_proc is | 536 // Start 5 requests, duplicating hosts "a" and "b". Since the resolver_proc is |
537 // blocked, these should all pile up until we signal it. | 537 // blocked, these should all pile up until we signal it. |
(...skipping 29 matching lines...) Expand all Loading... |
567 } | 567 } |
568 | 568 |
569 private: | 569 private: |
570 DISALLOW_COPY_AND_ASSIGN(CancelMultipleRequestsVerifier); | 570 DISALLOW_COPY_AND_ASSIGN(CancelMultipleRequestsVerifier); |
571 }; | 571 }; |
572 | 572 |
573 TEST_F(HostResolverImplTest, CancelMultipleRequests) { | 573 TEST_F(HostResolverImplTest, CancelMultipleRequests) { |
574 // Use a capturing resolver_proc, since the verifier needs to know what calls | 574 // Use a capturing resolver_proc, since the verifier needs to know what calls |
575 // reached Resolver(). Also, the capturing resolver_proc is initially | 575 // reached Resolver(). Also, the capturing resolver_proc is initially |
576 // blocked. | 576 // blocked. |
577 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 577 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
578 new CapturingHostResolverProc(NULL); | 578 new CapturingHostResolverProc(NULL)); |
579 | 579 |
580 scoped_ptr<HostResolver> host_resolver( | 580 scoped_ptr<HostResolver> host_resolver( |
581 CreateHostResolverImpl(resolver_proc)); | 581 CreateHostResolverImpl(resolver_proc)); |
582 | 582 |
583 // The class will receive callbacks for when each resolve completes. It | 583 // The class will receive callbacks for when each resolve completes. It |
584 // checks that the right things happened. | 584 // checks that the right things happened. |
585 CancelMultipleRequestsVerifier verifier; | 585 CancelMultipleRequestsVerifier verifier; |
586 | 586 |
587 // Start 5 requests, duplicating hosts "a" and "b". Since the resolver_proc is | 587 // Start 5 requests, duplicating hosts "a" and "b". Since the resolver_proc is |
588 // blocked, these should all pile up until we signal it. | 588 // blocked, these should all pile up until we signal it. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 ResolveRequest* req_to_cancel1_; | 654 ResolveRequest* req_to_cancel1_; |
655 ResolveRequest* req_to_cancel2_; | 655 ResolveRequest* req_to_cancel2_; |
656 int num_completions_; | 656 int num_completions_; |
657 DISALLOW_COPY_AND_ASSIGN(CancelWithinCallbackVerifier); | 657 DISALLOW_COPY_AND_ASSIGN(CancelWithinCallbackVerifier); |
658 }; | 658 }; |
659 | 659 |
660 TEST_F(HostResolverImplTest, CancelWithinCallback) { | 660 TEST_F(HostResolverImplTest, CancelWithinCallback) { |
661 // Use a capturing resolver_proc, since the verifier needs to know what calls | 661 // Use a capturing resolver_proc, since the verifier needs to know what calls |
662 // reached Resolver(). Also, the capturing resolver_proc is initially | 662 // reached Resolver(). Also, the capturing resolver_proc is initially |
663 // blocked. | 663 // blocked. |
664 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 664 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
665 new CapturingHostResolverProc(NULL); | 665 new CapturingHostResolverProc(NULL)); |
666 | 666 |
667 scoped_ptr<HostResolver> host_resolver( | 667 scoped_ptr<HostResolver> host_resolver( |
668 CreateHostResolverImpl(resolver_proc)); | 668 CreateHostResolverImpl(resolver_proc)); |
669 | 669 |
670 // The class will receive callbacks for when each resolve completes. It | 670 // The class will receive callbacks for when each resolve completes. It |
671 // checks that the right things happened. | 671 // checks that the right things happened. |
672 CancelWithinCallbackVerifier verifier; | 672 CancelWithinCallbackVerifier verifier; |
673 | 673 |
674 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is | 674 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is |
675 // blocked, these should all pile up until we signal it. | 675 // blocked, these should all pile up until we signal it. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 | 711 |
712 private: | 712 private: |
713 scoped_ptr<HostResolver> host_resolver_; | 713 scoped_ptr<HostResolver> host_resolver_; |
714 DISALLOW_COPY_AND_ASSIGN(DeleteWithinCallbackVerifier); | 714 DISALLOW_COPY_AND_ASSIGN(DeleteWithinCallbackVerifier); |
715 }; | 715 }; |
716 | 716 |
717 TEST_F(HostResolverImplTest, DeleteWithinCallback) { | 717 TEST_F(HostResolverImplTest, DeleteWithinCallback) { |
718 // Use a capturing resolver_proc, since the verifier needs to know what calls | 718 // Use a capturing resolver_proc, since the verifier needs to know what calls |
719 // reached Resolver(). Also, the capturing resolver_proc is initially | 719 // reached Resolver(). Also, the capturing resolver_proc is initially |
720 // blocked. | 720 // blocked. |
721 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 721 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
722 new CapturingHostResolverProc(NULL); | 722 new CapturingHostResolverProc(NULL)); |
723 | 723 |
724 // The class will receive callbacks for when each resolve completes. It | 724 // The class will receive callbacks for when each resolve completes. It |
725 // checks that the right things happened. Note that the verifier holds the | 725 // checks that the right things happened. Note that the verifier holds the |
726 // only reference to |host_resolver|, so it can delete it within callback. | 726 // only reference to |host_resolver|, so it can delete it within callback. |
727 HostResolver* host_resolver = | 727 HostResolver* host_resolver = |
728 CreateHostResolverImpl(resolver_proc); | 728 CreateHostResolverImpl(resolver_proc); |
729 DeleteWithinCallbackVerifier verifier(host_resolver); | 729 DeleteWithinCallbackVerifier verifier(host_resolver); |
730 | 730 |
731 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is | 731 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is |
732 // blocked, these should all pile up until we signal it. | 732 // blocked, these should all pile up until we signal it. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 private: | 766 private: |
767 int num_requests_; | 767 int num_requests_; |
768 scoped_ptr<ResolveRequest> final_request_; | 768 scoped_ptr<ResolveRequest> final_request_; |
769 DISALLOW_COPY_AND_ASSIGN(StartWithinCallbackVerifier); | 769 DISALLOW_COPY_AND_ASSIGN(StartWithinCallbackVerifier); |
770 }; | 770 }; |
771 | 771 |
772 TEST_F(HostResolverImplTest, StartWithinCallback) { | 772 TEST_F(HostResolverImplTest, StartWithinCallback) { |
773 // Use a capturing resolver_proc, since the verifier needs to know what calls | 773 // Use a capturing resolver_proc, since the verifier needs to know what calls |
774 // reached Resolver(). Also, the capturing resolver_proc is initially | 774 // reached Resolver(). Also, the capturing resolver_proc is initially |
775 // blocked. | 775 // blocked. |
776 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 776 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
777 new CapturingHostResolverProc(NULL); | 777 new CapturingHostResolverProc(NULL)); |
778 | 778 |
779 // Turn off caching for this host resolver. | 779 // Turn off caching for this host resolver. |
780 scoped_ptr<HostResolver> host_resolver( | 780 scoped_ptr<HostResolver> host_resolver( |
781 new HostResolverImpl(resolver_proc, NULL, kMaxJobs, NULL)); | 781 new HostResolverImpl(resolver_proc, NULL, kMaxJobs, NULL)); |
782 | 782 |
783 // The class will receive callbacks for when each resolve completes. It | 783 // The class will receive callbacks for when each resolve completes. It |
784 // checks that the right things happened. | 784 // checks that the right things happened. |
785 StartWithinCallbackVerifier verifier; | 785 StartWithinCallbackVerifier verifier; |
786 | 786 |
787 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is | 787 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 | 1098 |
1099 // Resolve "host1" again -- this time it won't be served from cache, so it | 1099 // Resolve "host1" again -- this time it won't be served from cache, so it |
1100 // will complete asynchronously. | 1100 // will complete asynchronously. |
1101 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog()); | 1101 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog()); |
1102 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. | 1102 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. |
1103 EXPECT_EQ(OK, callback.WaitForResult()); | 1103 EXPECT_EQ(OK, callback.WaitForResult()); |
1104 } | 1104 } |
1105 | 1105 |
1106 // Test that IP address changes send ERR_ABORTED to pending requests. | 1106 // Test that IP address changes send ERR_ABORTED to pending requests. |
1107 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { | 1107 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { |
1108 scoped_refptr<WaitingHostResolverProc> resolver_proc = | 1108 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
1109 new WaitingHostResolverProc(NULL); | 1109 new WaitingHostResolverProc(NULL)); |
1110 HostCache* cache = CreateDefaultCache(); | 1110 HostCache* cache = CreateDefaultCache(); |
1111 scoped_ptr<HostResolver> host_resolver( | 1111 scoped_ptr<HostResolver> host_resolver( |
1112 new HostResolverImpl(resolver_proc, cache, kMaxJobs, NULL)); | 1112 new HostResolverImpl(resolver_proc, cache, kMaxJobs, NULL)); |
1113 | 1113 |
1114 // Resolve "host1". | 1114 // Resolve "host1". |
1115 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1115 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
1116 TestCompletionCallback callback; | 1116 TestCompletionCallback callback; |
1117 AddressList addrlist; | 1117 AddressList addrlist; |
1118 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 1118 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, |
1119 BoundNetLog()); | 1119 BoundNetLog()); |
1120 EXPECT_EQ(ERR_IO_PENDING, rv); | 1120 EXPECT_EQ(ERR_IO_PENDING, rv); |
1121 | 1121 |
1122 // Triggering an IP address change. | 1122 // Triggering an IP address change. |
1123 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1123 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
1124 MessageLoop::current()->RunAllPending(); // Notification happens async. | 1124 MessageLoop::current()->RunAllPending(); // Notification happens async. |
1125 resolver_proc->Signal(); | 1125 resolver_proc->Signal(); |
1126 | 1126 |
1127 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); | 1127 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); |
1128 EXPECT_EQ(0u, cache->size()); | 1128 EXPECT_EQ(0u, cache->size()); |
1129 } | 1129 } |
1130 | 1130 |
1131 // Obey pool constraints after IP address has changed. | 1131 // Obey pool constraints after IP address has changed. |
1132 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { | 1132 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { |
1133 scoped_refptr<WaitingHostResolverProc> resolver_proc = | 1133 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
1134 new WaitingHostResolverProc(NULL); | 1134 new WaitingHostResolverProc(NULL)); |
1135 scoped_ptr<MockHostResolver> host_resolver(new MockHostResolver()); | 1135 scoped_ptr<MockHostResolver> host_resolver(new MockHostResolver()); |
1136 host_resolver->Reset(resolver_proc); | 1136 host_resolver->Reset(resolver_proc); |
1137 | 1137 |
1138 const size_t kMaxOutstandingJobs = 1u; | 1138 const size_t kMaxOutstandingJobs = 1u; |
1139 const size_t kMaxPendingRequests = 1000000u; // not relevant. | 1139 const size_t kMaxPendingRequests = 1000000u; // not relevant. |
1140 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, | 1140 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, |
1141 kMaxOutstandingJobs, | 1141 kMaxOutstandingJobs, |
1142 kMaxPendingRequests); | 1142 kMaxPendingRequests); |
1143 | 1143 |
1144 // Resolve "host1". | 1144 // Resolve "host1". |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 | 1195 |
1196 private: | 1196 private: |
1197 MockHostResolver* const host_resolver_; | 1197 MockHostResolver* const host_resolver_; |
1198 const HostResolver::RequestInfo info_; | 1198 const HostResolver::RequestInfo info_; |
1199 AddressList addrlist_; | 1199 AddressList addrlist_; |
1200 TestCompletionCallback callback_; | 1200 TestCompletionCallback callback_; |
1201 TestCompletionCallback nested_callback_; | 1201 TestCompletionCallback nested_callback_; |
1202 }; | 1202 }; |
1203 | 1203 |
1204 TEST_F(HostResolverImplTest, OnlyAbortExistingRequestsOnIPAddressChange) { | 1204 TEST_F(HostResolverImplTest, OnlyAbortExistingRequestsOnIPAddressChange) { |
1205 scoped_refptr<WaitingHostResolverProc> resolver_proc = | 1205 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
1206 new WaitingHostResolverProc(NULL); | 1206 new WaitingHostResolverProc(NULL)); |
1207 scoped_ptr<MockHostResolver> host_resolver(new MockHostResolver()); | 1207 scoped_ptr<MockHostResolver> host_resolver(new MockHostResolver()); |
1208 host_resolver->Reset(resolver_proc); | 1208 host_resolver->Reset(resolver_proc); |
1209 | 1209 |
1210 // Resolve "host1". | 1210 // Resolve "host1". |
1211 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1211 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
1212 ResolveWithinCallback callback(host_resolver.get(), info); | 1212 ResolveWithinCallback callback(host_resolver.get(), info); |
1213 AddressList addrlist; | 1213 AddressList addrlist; |
1214 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 1214 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, |
1215 BoundNetLog()); | 1215 BoundNetLog()); |
1216 EXPECT_EQ(ERR_IO_PENDING, rv); | 1216 EXPECT_EQ(ERR_IO_PENDING, rv); |
1217 | 1217 |
1218 // Triggering an IP address change. | 1218 // Triggering an IP address change. |
1219 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1219 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
1220 MessageLoop::current()->RunAllPending(); // Notification happens async. | 1220 MessageLoop::current()->RunAllPending(); // Notification happens async. |
1221 | 1221 |
1222 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); | 1222 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); |
1223 resolver_proc->Signal(); | 1223 resolver_proc->Signal(); |
1224 EXPECT_EQ(OK, callback.WaitForNestedResult()); | 1224 EXPECT_EQ(OK, callback.WaitForNestedResult()); |
1225 } | 1225 } |
1226 | 1226 |
1227 // Tests that when the maximum threads is set to 1, requests are dequeued | 1227 // Tests that when the maximum threads is set to 1, requests are dequeued |
1228 // in order of priority. | 1228 // in order of priority. |
1229 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { | 1229 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { |
1230 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1230 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
1231 new CapturingHostResolverProc(NULL); | 1231 new CapturingHostResolverProc(NULL)); |
1232 | 1232 |
1233 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1233 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
1234 size_t kMaxJobs = 1u; | 1234 size_t kMaxJobs = 1u; |
1235 scoped_ptr<HostResolver> host_resolver( | 1235 scoped_ptr<HostResolver> host_resolver( |
1236 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, | 1236 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, |
1237 NULL)); | 1237 NULL)); |
1238 | 1238 |
1239 CapturingObserver observer; | 1239 CapturingObserver observer; |
1240 host_resolver->AddObserver(&observer); | 1240 host_resolver->AddObserver(&observer); |
1241 | 1241 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 EXPECT_EQ(LOW, observer.finish_log[3].info.priority()); | 1305 EXPECT_EQ(LOW, observer.finish_log[3].info.priority()); |
1306 | 1306 |
1307 EXPECT_EQ("req1", observer.finish_log[4].info.hostname()); | 1307 EXPECT_EQ("req1", observer.finish_log[4].info.hostname()); |
1308 EXPECT_EQ("req2", observer.finish_log[5].info.hostname()); | 1308 EXPECT_EQ("req2", observer.finish_log[5].info.hostname()); |
1309 EXPECT_EQ("req3", observer.finish_log[6].info.hostname()); | 1309 EXPECT_EQ("req3", observer.finish_log[6].info.hostname()); |
1310 EXPECT_EQ("req6", observer.finish_log[7].info.hostname()); | 1310 EXPECT_EQ("req6", observer.finish_log[7].info.hostname()); |
1311 } | 1311 } |
1312 | 1312 |
1313 // Try cancelling a request which has not been attached to a job yet. | 1313 // Try cancelling a request which has not been attached to a job yet. |
1314 TEST_F(HostResolverImplTest, CancelPendingRequest) { | 1314 TEST_F(HostResolverImplTest, CancelPendingRequest) { |
1315 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1315 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
1316 new CapturingHostResolverProc(NULL); | 1316 new CapturingHostResolverProc(NULL)); |
1317 | 1317 |
1318 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1318 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
1319 const size_t kMaxJobs = 1u; | 1319 const size_t kMaxJobs = 1u; |
1320 scoped_ptr<HostResolver> host_resolver( | 1320 scoped_ptr<HostResolver> host_resolver( |
1321 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, | 1321 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, |
1322 NULL)); | 1322 NULL)); |
1323 | 1323 |
1324 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1324 // Note that at this point the CapturingHostResolverProc is blocked, so any |
1325 // requests we make will not complete. | 1325 // requests we make will not complete. |
1326 | 1326 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 ASSERT_EQ(4u, capture_list.size()); | 1368 ASSERT_EQ(4u, capture_list.size()); |
1369 | 1369 |
1370 EXPECT_EQ("req0", capture_list[0].hostname); | 1370 EXPECT_EQ("req0", capture_list[0].hostname); |
1371 EXPECT_EQ("req2", capture_list[1].hostname); | 1371 EXPECT_EQ("req2", capture_list[1].hostname); |
1372 EXPECT_EQ("req6", capture_list[2].hostname); | 1372 EXPECT_EQ("req6", capture_list[2].hostname); |
1373 EXPECT_EQ("req3", capture_list[3].hostname); | 1373 EXPECT_EQ("req3", capture_list[3].hostname); |
1374 } | 1374 } |
1375 | 1375 |
1376 // Test that when too many requests are enqueued, old ones start to be aborted. | 1376 // Test that when too many requests are enqueued, old ones start to be aborted. |
1377 TEST_F(HostResolverImplTest, QueueOverflow) { | 1377 TEST_F(HostResolverImplTest, QueueOverflow) { |
1378 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1378 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
1379 new CapturingHostResolverProc(NULL); | 1379 new CapturingHostResolverProc(NULL)); |
1380 | 1380 |
1381 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1381 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
1382 const size_t kMaxOutstandingJobs = 1u; | 1382 const size_t kMaxOutstandingJobs = 1u; |
1383 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1383 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
1384 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); | 1384 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); |
1385 | 1385 |
1386 // Only allow up to 3 requests to be enqueued at a time. | 1386 // Only allow up to 3 requests to be enqueued at a time. |
1387 const size_t kMaxPendingRequests = 3u; | 1387 const size_t kMaxPendingRequests = 3u; |
1388 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, | 1388 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, |
1389 kMaxOutstandingJobs, | 1389 kMaxOutstandingJobs, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 | 1446 |
1447 EXPECT_EQ("req0", capture_list[0].hostname); | 1447 EXPECT_EQ("req0", capture_list[0].hostname); |
1448 EXPECT_EQ("req1", capture_list[1].hostname); | 1448 EXPECT_EQ("req1", capture_list[1].hostname); |
1449 EXPECT_EQ("req6", capture_list[2].hostname); | 1449 EXPECT_EQ("req6", capture_list[2].hostname); |
1450 EXPECT_EQ("req7", capture_list[3].hostname); | 1450 EXPECT_EQ("req7", capture_list[3].hostname); |
1451 } | 1451 } |
1452 | 1452 |
1453 // Tests that after changing the default AddressFamily to IPV4, requests | 1453 // Tests that after changing the default AddressFamily to IPV4, requests |
1454 // with UNSPECIFIED address family map to IPV4. | 1454 // with UNSPECIFIED address family map to IPV4. |
1455 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { | 1455 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { |
1456 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1456 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
1457 new CapturingHostResolverProc(new EchoingHostResolverProc); | 1457 new CapturingHostResolverProc(new EchoingHostResolverProc)); |
1458 | 1458 |
1459 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1459 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
1460 const size_t kMaxOutstandingJobs = 1u; | 1460 const size_t kMaxOutstandingJobs = 1u; |
1461 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1461 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
1462 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); | 1462 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); |
1463 | 1463 |
1464 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1464 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
1465 | 1465 |
1466 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1466 // Note that at this point the CapturingHostResolverProc is blocked, so any |
1467 // requests we make will not complete. | 1467 // requests we make will not complete. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 // z = value of address family | 1514 // z = value of address family |
1515 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[0].head())); | 1515 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[0].head())); |
1516 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[1].head())); | 1516 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[1].head())); |
1517 EXPECT_EQ("192.2.104.2", NetAddressToString(addrlist[2].head())); | 1517 EXPECT_EQ("192.2.104.2", NetAddressToString(addrlist[2].head())); |
1518 } | 1518 } |
1519 | 1519 |
1520 // This is the exact same test as SetDefaultAddressFamily_IPv4, except the order | 1520 // This is the exact same test as SetDefaultAddressFamily_IPv4, except the order |
1521 // of requests 0 and 1 is flipped, and the default is set to IPv6 in place of | 1521 // of requests 0 and 1 is flipped, and the default is set to IPv6 in place of |
1522 // IPv4. | 1522 // IPv4. |
1523 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { | 1523 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { |
1524 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1524 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
1525 new CapturingHostResolverProc(new EchoingHostResolverProc); | 1525 new CapturingHostResolverProc(new EchoingHostResolverProc)); |
1526 | 1526 |
1527 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1527 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
1528 const size_t kMaxOutstandingJobs = 1u; | 1528 const size_t kMaxOutstandingJobs = 1u; |
1529 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1529 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
1530 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); | 1530 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); |
1531 | 1531 |
1532 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); | 1532 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); |
1533 | 1533 |
1534 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1534 // Note that at this point the CapturingHostResolverProc is blocked, so any |
1535 // requests we make will not complete. | 1535 // requests we make will not complete. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 // y = ASCII value of hostname[0] | 1581 // y = ASCII value of hostname[0] |
1582 // z = value of address family | 1582 // z = value of address family |
1583 EXPECT_EQ("192.2.104.2", NetAddressToString(addrlist[0].head())); | 1583 EXPECT_EQ("192.2.104.2", NetAddressToString(addrlist[0].head())); |
1584 EXPECT_EQ("192.2.104.2", NetAddressToString(addrlist[1].head())); | 1584 EXPECT_EQ("192.2.104.2", NetAddressToString(addrlist[1].head())); |
1585 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[2].head())); | 1585 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[2].head())); |
1586 } | 1586 } |
1587 | 1587 |
1588 // This tests that the default address family is respected for synchronous | 1588 // This tests that the default address family is respected for synchronous |
1589 // resolutions. | 1589 // resolutions. |
1590 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { | 1590 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { |
1591 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1591 scoped_refptr<CapturingHostResolverProc> resolver_proc( |
1592 new CapturingHostResolverProc(new EchoingHostResolverProc); | 1592 new CapturingHostResolverProc(new EchoingHostResolverProc)); |
1593 | 1593 |
1594 const size_t kMaxOutstandingJobs = 10u; | 1594 const size_t kMaxOutstandingJobs = 10u; |
1595 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1595 scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
1596 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); | 1596 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); |
1597 | 1597 |
1598 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1598 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
1599 | 1599 |
1600 // Unblock the resolver thread so the requests can run. | 1600 // Unblock the resolver thread so the requests can run. |
1601 resolver_proc->Signal(); | 1601 resolver_proc->Signal(); |
1602 | 1602 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1638 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); | 1638 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); |
1639 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); | 1639 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); |
1640 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); | 1640 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); |
1641 } | 1641 } |
1642 | 1642 |
1643 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1643 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
1644 | 1644 |
1645 } // namespace | 1645 } // namespace |
1646 | 1646 |
1647 } // namespace net | 1647 } // namespace net |
OLD | NEW |