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/dns/host_resolver_impl.h" | 5 #include "net/dns/host_resolver_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "base/test/test_timeouts.h" | 26 #include "base/test/test_timeouts.h" |
27 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
28 #include "base/time/time.h" | 28 #include "base/time/time.h" |
29 #include "net/base/address_list.h" | 29 #include "net/base/address_list.h" |
30 #include "net/base/ip_address.h" | 30 #include "net/base/ip_address.h" |
31 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
32 #include "net/dns/dns_client.h" | 32 #include "net/dns/dns_client.h" |
33 #include "net/dns/dns_test_util.h" | 33 #include "net/dns/dns_test_util.h" |
34 #include "net/dns/mock_host_resolver.h" | 34 #include "net/dns/mock_host_resolver.h" |
35 #include "net/log/test_net_log.h" | 35 #include "net/log/test_net_log.h" |
| 36 #include "net/test/gtest_util.h" |
| 37 #include "testing/gmock/include/gmock/gmock.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
37 | 39 |
| 40 using net::test::IsError; |
| 41 using net::test::IsOk; |
| 42 |
38 namespace net { | 43 namespace net { |
39 | 44 |
40 namespace { | 45 namespace { |
41 | 46 |
42 const size_t kMaxJobs = 10u; | 47 const size_t kMaxJobs = 10u; |
43 const size_t kMaxRetryAttempts = 4u; | 48 const size_t kMaxRetryAttempts = 4u; |
44 | 49 |
45 HostResolver::Options DefaultOptions() { | 50 HostResolver::Options DefaultOptions() { |
46 HostResolver::Options options; | 51 HostResolver::Options options; |
47 options.max_concurrent_resolves = kMaxJobs; | 52 options.max_concurrent_resolves = kMaxJobs; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 DCHECK(!handle_); | 232 DCHECK(!handle_); |
228 list_ = AddressList(); | 233 list_ = AddressList(); |
229 result_ = resolver_->Resolve( | 234 result_ = resolver_->Resolve( |
230 info_, | 235 info_, |
231 priority_, | 236 priority_, |
232 &list_, | 237 &list_, |
233 base::Bind(&Request::OnComplete, base::Unretained(this)), | 238 base::Bind(&Request::OnComplete, base::Unretained(this)), |
234 &handle_, | 239 &handle_, |
235 BoundNetLog()); | 240 BoundNetLog()); |
236 if (!list_.empty()) | 241 if (!list_.empty()) |
237 EXPECT_EQ(OK, result_); | 242 EXPECT_THAT(result_, IsOk()); |
238 return result_; | 243 return result_; |
239 } | 244 } |
240 | 245 |
241 int ResolveFromCache() { | 246 int ResolveFromCache() { |
242 DCHECK(resolver_); | 247 DCHECK(resolver_); |
243 DCHECK(!handle_); | 248 DCHECK(!handle_); |
244 return resolver_->ResolveFromCache(info_, &list_, BoundNetLog()); | 249 return resolver_->ResolveFromCache(info_, &list_, BoundNetLog()); |
245 } | 250 } |
246 | 251 |
247 int ResolveStaleFromCache() { | 252 int ResolveStaleFromCache() { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 closure.Cancel(); | 305 closure.Cancel(); |
301 if (did_quit) | 306 if (did_quit) |
302 return result_; | 307 return result_; |
303 else | 308 else |
304 return ERR_UNEXPECTED; | 309 return ERR_UNEXPECTED; |
305 } | 310 } |
306 | 311 |
307 private: | 312 private: |
308 void OnComplete(int rv) { | 313 void OnComplete(int rv) { |
309 EXPECT_TRUE(pending()); | 314 EXPECT_TRUE(pending()); |
310 EXPECT_EQ(ERR_IO_PENDING, result_); | 315 EXPECT_THAT(result_, IsError(ERR_IO_PENDING)); |
311 EXPECT_NE(ERR_IO_PENDING, rv); | 316 EXPECT_NE(ERR_IO_PENDING, rv); |
312 result_ = rv; | 317 result_ = rv; |
313 handle_ = NULL; | 318 handle_ = NULL; |
314 if (!list_.empty()) { | 319 if (!list_.empty()) { |
315 EXPECT_EQ(OK, result_); | 320 EXPECT_THAT(result_, IsOk()); |
316 EXPECT_EQ(info_.port(), list_.front().port()); | 321 EXPECT_EQ(info_.port(), list_.front().port()); |
317 } | 322 } |
318 if (handler_) | 323 if (handler_) |
319 handler_->Handle(this); | 324 handler_->Handle(this); |
320 if (quit_on_complete_) { | 325 if (quit_on_complete_) { |
321 base::MessageLoop::current()->QuitWhenIdle(); | 326 base::MessageLoop::current()->QuitWhenIdle(); |
322 quit_on_complete_ = false; | 327 quit_on_complete_ = false; |
323 } | 328 } |
324 } | 329 } |
325 | 330 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 std::vector<std::unique_ptr<Request>> requests_; | 629 std::vector<std::unique_ptr<Request>> requests_; |
625 | 630 |
626 std::unique_ptr<Handler> handler_; | 631 std::unique_ptr<Handler> handler_; |
627 }; | 632 }; |
628 | 633 |
629 TEST_F(HostResolverImplTest, AsynchronousLookup) { | 634 TEST_F(HostResolverImplTest, AsynchronousLookup) { |
630 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42"); | 635 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42"); |
631 proc_->SignalMultiple(1u); | 636 proc_->SignalMultiple(1u); |
632 | 637 |
633 Request* req = CreateRequest("just.testing", 80); | 638 Request* req = CreateRequest("just.testing", 80); |
634 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 639 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
635 EXPECT_EQ(OK, req->WaitForResult()); | 640 EXPECT_THAT(req->WaitForResult(), IsOk()); |
636 | 641 |
637 EXPECT_TRUE(req->HasOneAddress("192.168.1.42", 80)); | 642 EXPECT_TRUE(req->HasOneAddress("192.168.1.42", 80)); |
638 | 643 |
639 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname); | 644 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname); |
640 } | 645 } |
641 | 646 |
642 // RFC 6761 localhost names should always resolve to loopback. | 647 // RFC 6761 localhost names should always resolve to loopback. |
643 TEST_F(HostResolverImplTest, LocalhostLookup) { | 648 TEST_F(HostResolverImplTest, LocalhostLookup) { |
644 // Add a rule resolving localhost names to a non-loopback IP and test | 649 // Add a rule resolving localhost names to a non-loopback IP and test |
645 // that they still resolves to loopback. | 650 // that they still resolves to loopback. |
646 proc_->AddRuleForAllFamilies("foo.localhost", "192.168.1.42"); | 651 proc_->AddRuleForAllFamilies("foo.localhost", "192.168.1.42"); |
647 proc_->AddRuleForAllFamilies("localhost", "192.168.1.42"); | 652 proc_->AddRuleForAllFamilies("localhost", "192.168.1.42"); |
648 proc_->AddRuleForAllFamilies("localhost.", "192.168.1.42"); | 653 proc_->AddRuleForAllFamilies("localhost.", "192.168.1.42"); |
649 | 654 |
650 Request* req0 = CreateRequest("foo.localhost", 80); | 655 Request* req0 = CreateRequest("foo.localhost", 80); |
651 EXPECT_EQ(OK, req0->Resolve()); | 656 EXPECT_THAT(req0->Resolve(), IsOk()); |
652 EXPECT_TRUE(req0->HasAddress("127.0.0.1", 80)); | 657 EXPECT_TRUE(req0->HasAddress("127.0.0.1", 80)); |
653 EXPECT_TRUE(req0->HasAddress("::1", 80)); | 658 EXPECT_TRUE(req0->HasAddress("::1", 80)); |
654 | 659 |
655 Request* req1 = CreateRequest("localhost", 80); | 660 Request* req1 = CreateRequest("localhost", 80); |
656 EXPECT_EQ(OK, req1->Resolve()); | 661 EXPECT_THAT(req1->Resolve(), IsOk()); |
657 EXPECT_TRUE(req1->HasAddress("127.0.0.1", 80)); | 662 EXPECT_TRUE(req1->HasAddress("127.0.0.1", 80)); |
658 EXPECT_TRUE(req1->HasAddress("::1", 80)); | 663 EXPECT_TRUE(req1->HasAddress("::1", 80)); |
659 | 664 |
660 Request* req2 = CreateRequest("localhost.", 80); | 665 Request* req2 = CreateRequest("localhost.", 80); |
661 EXPECT_EQ(OK, req2->Resolve()); | 666 EXPECT_THAT(req2->Resolve(), IsOk()); |
662 EXPECT_TRUE(req2->HasAddress("127.0.0.1", 80)); | 667 EXPECT_TRUE(req2->HasAddress("127.0.0.1", 80)); |
663 EXPECT_TRUE(req2->HasAddress("::1", 80)); | 668 EXPECT_TRUE(req2->HasAddress("::1", 80)); |
664 } | 669 } |
665 | 670 |
666 TEST_F(HostResolverImplTest, LocalhostIPV4IPV6Lookup) { | 671 TEST_F(HostResolverImplTest, LocalhostIPV4IPV6Lookup) { |
667 Request* req1 = CreateRequest("localhost6", 80, MEDIUM, ADDRESS_FAMILY_IPV4); | 672 Request* req1 = CreateRequest("localhost6", 80, MEDIUM, ADDRESS_FAMILY_IPV4); |
668 EXPECT_EQ(OK, req1->Resolve()); | 673 EXPECT_THAT(req1->Resolve(), IsOk()); |
669 EXPECT_EQ(0u, req1->NumberOfAddresses()); | 674 EXPECT_EQ(0u, req1->NumberOfAddresses()); |
670 | 675 |
671 Request* req2 = CreateRequest("localhost6", 80, MEDIUM, ADDRESS_FAMILY_IPV6); | 676 Request* req2 = CreateRequest("localhost6", 80, MEDIUM, ADDRESS_FAMILY_IPV6); |
672 EXPECT_EQ(OK, req2->Resolve()); | 677 EXPECT_THAT(req2->Resolve(), IsOk()); |
673 EXPECT_TRUE(req2->HasOneAddress("::1", 80)); | 678 EXPECT_TRUE(req2->HasOneAddress("::1", 80)); |
674 | 679 |
675 Request* req3 = | 680 Request* req3 = |
676 CreateRequest("localhost6", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED); | 681 CreateRequest("localhost6", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED); |
677 EXPECT_EQ(OK, req3->Resolve()); | 682 EXPECT_THAT(req3->Resolve(), IsOk()); |
678 EXPECT_TRUE(req3->HasOneAddress("::1", 80)); | 683 EXPECT_TRUE(req3->HasOneAddress("::1", 80)); |
679 | 684 |
680 Request* req4 = CreateRequest("localhost", 80, MEDIUM, ADDRESS_FAMILY_IPV4); | 685 Request* req4 = CreateRequest("localhost", 80, MEDIUM, ADDRESS_FAMILY_IPV4); |
681 EXPECT_EQ(OK, req4->Resolve()); | 686 EXPECT_THAT(req4->Resolve(), IsOk()); |
682 EXPECT_TRUE(req4->HasOneAddress("127.0.0.1", 80)); | 687 EXPECT_TRUE(req4->HasOneAddress("127.0.0.1", 80)); |
683 | 688 |
684 Request* req5 = CreateRequest("localhost", 80, MEDIUM, ADDRESS_FAMILY_IPV6); | 689 Request* req5 = CreateRequest("localhost", 80, MEDIUM, ADDRESS_FAMILY_IPV6); |
685 EXPECT_EQ(OK, req5->Resolve()); | 690 EXPECT_THAT(req5->Resolve(), IsOk()); |
686 EXPECT_TRUE(req5->HasOneAddress("::1", 80)); | 691 EXPECT_TRUE(req5->HasOneAddress("::1", 80)); |
687 } | 692 } |
688 | 693 |
689 TEST_F(HostResolverImplTest, ResolveIPLiteralWithHostResolverSystemOnly) { | 694 TEST_F(HostResolverImplTest, ResolveIPLiteralWithHostResolverSystemOnly) { |
690 const char kIpLiteral[] = "178.78.32.1"; | 695 const char kIpLiteral[] = "178.78.32.1"; |
691 // Add a mapping to tell if the resolver proc was called (if it was called, | 696 // Add a mapping to tell if the resolver proc was called (if it was called, |
692 // then the result will be the remapped value. Otherwise it will be the IP | 697 // then the result will be the remapped value. Otherwise it will be the IP |
693 // literal). | 698 // literal). |
694 proc_->AddRuleForAllFamilies(kIpLiteral, "183.45.32.1"); | 699 proc_->AddRuleForAllFamilies(kIpLiteral, "183.45.32.1"); |
695 | 700 |
696 HostResolver::RequestInfo info_bypass(HostPortPair(kIpLiteral, 80)); | 701 HostResolver::RequestInfo info_bypass(HostPortPair(kIpLiteral, 80)); |
697 info_bypass.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY); | 702 info_bypass.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY); |
698 | 703 |
699 Request* req = CreateRequest(info_bypass, MEDIUM); | 704 Request* req = CreateRequest(info_bypass, MEDIUM); |
700 EXPECT_EQ(OK, req->Resolve()); | 705 EXPECT_THAT(req->Resolve(), IsOk()); |
701 | 706 |
702 EXPECT_TRUE(req->HasAddress(kIpLiteral, 80)); | 707 EXPECT_TRUE(req->HasAddress(kIpLiteral, 80)); |
703 } | 708 } |
704 | 709 |
705 TEST_F(HostResolverImplTest, EmptyListMeansNameNotResolved) { | 710 TEST_F(HostResolverImplTest, EmptyListMeansNameNotResolved) { |
706 proc_->AddRuleForAllFamilies("just.testing", ""); | 711 proc_->AddRuleForAllFamilies("just.testing", ""); |
707 proc_->SignalMultiple(1u); | 712 proc_->SignalMultiple(1u); |
708 | 713 |
709 Request* req = CreateRequest("just.testing", 80); | 714 Request* req = CreateRequest("just.testing", 80); |
710 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 715 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
711 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->WaitForResult()); | 716 EXPECT_THAT(req->WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
712 EXPECT_EQ(0u, req->NumberOfAddresses()); | 717 EXPECT_EQ(0u, req->NumberOfAddresses()); |
713 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname); | 718 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname); |
714 } | 719 } |
715 | 720 |
716 TEST_F(HostResolverImplTest, FailedAsynchronousLookup) { | 721 TEST_F(HostResolverImplTest, FailedAsynchronousLookup) { |
717 proc_->AddRuleForAllFamilies(std::string(), | 722 proc_->AddRuleForAllFamilies(std::string(), |
718 "0.0.0.0"); // Default to failures. | 723 "0.0.0.0"); // Default to failures. |
719 proc_->SignalMultiple(1u); | 724 proc_->SignalMultiple(1u); |
720 | 725 |
721 Request* req = CreateRequest("just.testing", 80); | 726 Request* req = CreateRequest("just.testing", 80); |
722 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 727 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
723 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->WaitForResult()); | 728 EXPECT_THAT(req->WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
724 | 729 |
725 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname); | 730 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname); |
726 | 731 |
727 // Also test that the error is not cached. | 732 // Also test that the error is not cached. |
728 EXPECT_EQ(ERR_DNS_CACHE_MISS, req->ResolveFromCache()); | 733 EXPECT_THAT(req->ResolveFromCache(), IsError(ERR_DNS_CACHE_MISS)); |
729 } | 734 } |
730 | 735 |
731 TEST_F(HostResolverImplTest, AbortedAsynchronousLookup) { | 736 TEST_F(HostResolverImplTest, AbortedAsynchronousLookup) { |
732 Request* req0 = CreateRequest("just.testing", 80); | 737 Request* req0 = CreateRequest("just.testing", 80); |
733 EXPECT_EQ(ERR_IO_PENDING, req0->Resolve()); | 738 EXPECT_THAT(req0->Resolve(), IsError(ERR_IO_PENDING)); |
734 | 739 |
735 EXPECT_TRUE(proc_->WaitFor(1u)); | 740 EXPECT_TRUE(proc_->WaitFor(1u)); |
736 | 741 |
737 // Resolver is destroyed while job is running on WorkerPool. | 742 // Resolver is destroyed while job is running on WorkerPool. |
738 resolver_.reset(); | 743 resolver_.reset(); |
739 | 744 |
740 proc_->SignalAll(); | 745 proc_->SignalAll(); |
741 | 746 |
742 // To ensure there was no spurious callback, complete with a new resolver. | 747 // To ensure there was no spurious callback, complete with a new resolver. |
743 CreateResolver(); | 748 CreateResolver(); |
744 Request* req1 = CreateRequest("just.testing", 80); | 749 Request* req1 = CreateRequest("just.testing", 80); |
745 EXPECT_EQ(ERR_IO_PENDING, req1->Resolve()); | 750 EXPECT_THAT(req1->Resolve(), IsError(ERR_IO_PENDING)); |
746 | 751 |
747 proc_->SignalMultiple(2u); | 752 proc_->SignalMultiple(2u); |
748 | 753 |
749 EXPECT_EQ(OK, req1->WaitForResult()); | 754 EXPECT_THAT(req1->WaitForResult(), IsOk()); |
750 | 755 |
751 // This request was canceled. | 756 // This request was canceled. |
752 EXPECT_FALSE(req0->completed()); | 757 EXPECT_FALSE(req0->completed()); |
753 } | 758 } |
754 | 759 |
755 #if defined(THREAD_SANITIZER) | 760 #if defined(THREAD_SANITIZER) |
756 // Use of WorkerPool in HostResolverImpl causes a data race. crbug.com/334140 | 761 // Use of WorkerPool in HostResolverImpl causes a data race. crbug.com/334140 |
757 #define MAYBE_NumericIPv4Address DISABLED_NumericIPv4Address | 762 #define MAYBE_NumericIPv4Address DISABLED_NumericIPv4Address |
758 #else | 763 #else |
759 #define MAYBE_NumericIPv4Address NumericIPv4Address | 764 #define MAYBE_NumericIPv4Address NumericIPv4Address |
760 #endif | 765 #endif |
761 TEST_F(HostResolverImplTest, MAYBE_NumericIPv4Address) { | 766 TEST_F(HostResolverImplTest, MAYBE_NumericIPv4Address) { |
762 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. | 767 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. |
763 Request* req = CreateRequest("127.1.2.3", 5555); | 768 Request* req = CreateRequest("127.1.2.3", 5555); |
764 EXPECT_EQ(OK, req->Resolve()); | 769 EXPECT_THAT(req->Resolve(), IsOk()); |
765 | 770 |
766 EXPECT_TRUE(req->HasOneAddress("127.1.2.3", 5555)); | 771 EXPECT_TRUE(req->HasOneAddress("127.1.2.3", 5555)); |
767 } | 772 } |
768 | 773 |
769 #if defined(THREAD_SANITIZER) | 774 #if defined(THREAD_SANITIZER) |
770 // Use of WorkerPool in HostResolverImpl causes a data race. crbug.com/334140 | 775 // Use of WorkerPool in HostResolverImpl causes a data race. crbug.com/334140 |
771 #define MAYBE_NumericIPv6Address DISABLED_NumericIPv6Address | 776 #define MAYBE_NumericIPv6Address DISABLED_NumericIPv6Address |
772 #else | 777 #else |
773 #define MAYBE_NumericIPv6Address NumericIPv6Address | 778 #define MAYBE_NumericIPv6Address NumericIPv6Address |
774 #endif | 779 #endif |
775 TEST_F(HostResolverImplTest, MAYBE_NumericIPv6Address) { | 780 TEST_F(HostResolverImplTest, MAYBE_NumericIPv6Address) { |
776 // Resolve a plain IPv6 address. Don't worry about [brackets], because | 781 // Resolve a plain IPv6 address. Don't worry about [brackets], because |
777 // the caller should have removed them. | 782 // the caller should have removed them. |
778 Request* req = CreateRequest("2001:db8::1", 5555); | 783 Request* req = CreateRequest("2001:db8::1", 5555); |
779 EXPECT_EQ(OK, req->Resolve()); | 784 EXPECT_THAT(req->Resolve(), IsOk()); |
780 | 785 |
781 EXPECT_TRUE(req->HasOneAddress("2001:db8::1", 5555)); | 786 EXPECT_TRUE(req->HasOneAddress("2001:db8::1", 5555)); |
782 } | 787 } |
783 | 788 |
784 #if defined(THREAD_SANITIZER) | 789 #if defined(THREAD_SANITIZER) |
785 // Use of WorkerPool in HostResolverImpl causes a data race. crbug.com/334140 | 790 // Use of WorkerPool in HostResolverImpl causes a data race. crbug.com/334140 |
786 #define MAYBE_EmptyHost DISABLED_EmptyHost | 791 #define MAYBE_EmptyHost DISABLED_EmptyHost |
787 #else | 792 #else |
788 #define MAYBE_EmptyHost EmptyHost | 793 #define MAYBE_EmptyHost EmptyHost |
789 #endif | 794 #endif |
790 TEST_F(HostResolverImplTest, MAYBE_EmptyHost) { | 795 TEST_F(HostResolverImplTest, MAYBE_EmptyHost) { |
791 Request* req = CreateRequest(std::string(), 5555); | 796 Request* req = CreateRequest(std::string(), 5555); |
792 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->Resolve()); | 797 EXPECT_THAT(req->Resolve(), IsError(ERR_NAME_NOT_RESOLVED)); |
793 } | 798 } |
794 | 799 |
795 #if defined(THREAD_SANITIZER) | 800 #if defined(THREAD_SANITIZER) |
796 // There's a data race in this test that may lead to use-after-free. | 801 // There's a data race in this test that may lead to use-after-free. |
797 // If the test starts to crash without ThreadSanitizer it needs to be disabled | 802 // If the test starts to crash without ThreadSanitizer it needs to be disabled |
798 // globally. See http://crbug.com/268946 (stacks for this test in | 803 // globally. See http://crbug.com/268946 (stacks for this test in |
799 // crbug.com/333567). | 804 // crbug.com/333567). |
800 #define MAYBE_EmptyDotsHost DISABLED_EmptyDotsHost | 805 #define MAYBE_EmptyDotsHost DISABLED_EmptyDotsHost |
801 #else | 806 #else |
802 #define MAYBE_EmptyDotsHost EmptyDotsHost | 807 #define MAYBE_EmptyDotsHost EmptyDotsHost |
803 #endif | 808 #endif |
804 TEST_F(HostResolverImplTest, MAYBE_EmptyDotsHost) { | 809 TEST_F(HostResolverImplTest, MAYBE_EmptyDotsHost) { |
805 for (int i = 0; i < 16; ++i) { | 810 for (int i = 0; i < 16; ++i) { |
806 Request* req = CreateRequest(std::string(i, '.'), 5555); | 811 Request* req = CreateRequest(std::string(i, '.'), 5555); |
807 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->Resolve()); | 812 EXPECT_THAT(req->Resolve(), IsError(ERR_NAME_NOT_RESOLVED)); |
808 } | 813 } |
809 } | 814 } |
810 | 815 |
811 #if defined(THREAD_SANITIZER) | 816 #if defined(THREAD_SANITIZER) |
812 // There's a data race in this test that may lead to use-after-free. | 817 // There's a data race in this test that may lead to use-after-free. |
813 // If the test starts to crash without ThreadSanitizer it needs to be disabled | 818 // If the test starts to crash without ThreadSanitizer it needs to be disabled |
814 // globally. See http://crbug.com/268946. | 819 // globally. See http://crbug.com/268946. |
815 #define MAYBE_LongHost DISABLED_LongHost | 820 #define MAYBE_LongHost DISABLED_LongHost |
816 #else | 821 #else |
817 #define MAYBE_LongHost LongHost | 822 #define MAYBE_LongHost LongHost |
818 #endif | 823 #endif |
819 TEST_F(HostResolverImplTest, MAYBE_LongHost) { | 824 TEST_F(HostResolverImplTest, MAYBE_LongHost) { |
820 Request* req = CreateRequest(std::string(4097, 'a'), 5555); | 825 Request* req = CreateRequest(std::string(4097, 'a'), 5555); |
821 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->Resolve()); | 826 EXPECT_THAT(req->Resolve(), IsError(ERR_NAME_NOT_RESOLVED)); |
822 } | 827 } |
823 | 828 |
824 TEST_F(HostResolverImplTest, DeDupeRequests) { | 829 TEST_F(HostResolverImplTest, DeDupeRequests) { |
825 // Start 5 requests, duplicating hosts "a" and "b". Since the resolver_proc is | 830 // Start 5 requests, duplicating hosts "a" and "b". Since the resolver_proc is |
826 // blocked, these should all pile up until we signal it. | 831 // blocked, these should all pile up until we signal it. |
827 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80)->Resolve()); | 832 EXPECT_THAT(CreateRequest("a", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
828 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 80)->Resolve()); | 833 EXPECT_THAT(CreateRequest("b", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
829 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 81)->Resolve()); | 834 EXPECT_THAT(CreateRequest("b", 81)->Resolve(), IsError(ERR_IO_PENDING)); |
830 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 82)->Resolve()); | 835 EXPECT_THAT(CreateRequest("a", 82)->Resolve(), IsError(ERR_IO_PENDING)); |
831 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 83)->Resolve()); | 836 EXPECT_THAT(CreateRequest("b", 83)->Resolve(), IsError(ERR_IO_PENDING)); |
832 | 837 |
833 proc_->SignalMultiple(2u); // One for "a", one for "b". | 838 proc_->SignalMultiple(2u); // One for "a", one for "b". |
834 | 839 |
835 for (size_t i = 0; i < requests_.size(); ++i) { | 840 for (size_t i = 0; i < requests_.size(); ++i) { |
836 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; | 841 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; |
837 } | 842 } |
838 } | 843 } |
839 | 844 |
840 TEST_F(HostResolverImplTest, CancelMultipleRequests) { | 845 TEST_F(HostResolverImplTest, CancelMultipleRequests) { |
841 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80)->Resolve()); | 846 EXPECT_THAT(CreateRequest("a", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
842 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 80)->Resolve()); | 847 EXPECT_THAT(CreateRequest("b", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
843 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 81)->Resolve()); | 848 EXPECT_THAT(CreateRequest("b", 81)->Resolve(), IsError(ERR_IO_PENDING)); |
844 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 82)->Resolve()); | 849 EXPECT_THAT(CreateRequest("a", 82)->Resolve(), IsError(ERR_IO_PENDING)); |
845 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 83)->Resolve()); | 850 EXPECT_THAT(CreateRequest("b", 83)->Resolve(), IsError(ERR_IO_PENDING)); |
846 | 851 |
847 // Cancel everything except request for ("a", 82). | 852 // Cancel everything except request for ("a", 82). |
848 requests_[0]->Cancel(); | 853 requests_[0]->Cancel(); |
849 requests_[1]->Cancel(); | 854 requests_[1]->Cancel(); |
850 requests_[2]->Cancel(); | 855 requests_[2]->Cancel(); |
851 requests_[4]->Cancel(); | 856 requests_[4]->Cancel(); |
852 | 857 |
853 proc_->SignalMultiple(2u); // One for "a", one for "b". | 858 proc_->SignalMultiple(2u); // One for "a", one for "b". |
854 | 859 |
855 EXPECT_EQ(OK, requests_[3]->WaitForResult()); | 860 EXPECT_THAT(requests_[3]->WaitForResult(), IsOk()); |
856 } | 861 } |
857 | 862 |
858 TEST_F(HostResolverImplTest, CanceledRequestsReleaseJobSlots) { | 863 TEST_F(HostResolverImplTest, CanceledRequestsReleaseJobSlots) { |
859 // Fill up the dispatcher and queue. | 864 // Fill up the dispatcher and queue. |
860 for (unsigned i = 0; i < kMaxJobs + 1; ++i) { | 865 for (unsigned i = 0; i < kMaxJobs + 1; ++i) { |
861 std::string hostname = "a_"; | 866 std::string hostname = "a_"; |
862 hostname[1] = 'a' + i; | 867 hostname[1] = 'a' + i; |
863 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(hostname, 80)->Resolve()); | 868 EXPECT_THAT(CreateRequest(hostname, 80)->Resolve(), |
864 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(hostname, 81)->Resolve()); | 869 IsError(ERR_IO_PENDING)); |
| 870 EXPECT_THAT(CreateRequest(hostname, 81)->Resolve(), |
| 871 IsError(ERR_IO_PENDING)); |
865 } | 872 } |
866 | 873 |
867 EXPECT_TRUE(proc_->WaitFor(kMaxJobs)); | 874 EXPECT_TRUE(proc_->WaitFor(kMaxJobs)); |
868 | 875 |
869 // Cancel all but last two. | 876 // Cancel all but last two. |
870 for (unsigned i = 0; i < requests_.size() - 2; ++i) { | 877 for (unsigned i = 0; i < requests_.size() - 2; ++i) { |
871 requests_[i]->Cancel(); | 878 requests_[i]->Cancel(); |
872 } | 879 } |
873 | 880 |
874 EXPECT_TRUE(proc_->WaitFor(kMaxJobs + 1)); | 881 EXPECT_TRUE(proc_->WaitFor(kMaxJobs + 1)); |
875 | 882 |
876 proc_->SignalAll(); | 883 proc_->SignalAll(); |
877 | 884 |
878 size_t num_requests = requests_.size(); | 885 size_t num_requests = requests_.size(); |
879 EXPECT_EQ(OK, requests_[num_requests - 1]->WaitForResult()); | 886 EXPECT_THAT(requests_[num_requests - 1]->WaitForResult(), IsOk()); |
880 EXPECT_EQ(OK, requests_[num_requests - 2]->result()); | 887 EXPECT_THAT(requests_[num_requests - 2]->result(), IsOk()); |
881 } | 888 } |
882 | 889 |
883 TEST_F(HostResolverImplTest, CancelWithinCallback) { | 890 TEST_F(HostResolverImplTest, CancelWithinCallback) { |
884 struct MyHandler : public Handler { | 891 struct MyHandler : public Handler { |
885 void Handle(Request* req) override { | 892 void Handle(Request* req) override { |
886 // Port 80 is the first request that the callback will be invoked for. | 893 // Port 80 is the first request that the callback will be invoked for. |
887 // While we are executing within that callback, cancel the other requests | 894 // While we are executing within that callback, cancel the other requests |
888 // in the job and start another request. | 895 // in the job and start another request. |
889 if (req->index() == 0) { | 896 if (req->index() == 0) { |
890 // Once "a:80" completes, it will cancel "a:81" and "a:82". | 897 // Once "a:80" completes, it will cancel "a:81" and "a:82". |
891 requests()[1]->Cancel(); | 898 requests()[1]->Cancel(); |
892 requests()[2]->Cancel(); | 899 requests()[2]->Cancel(); |
893 } | 900 } |
894 } | 901 } |
895 }; | 902 }; |
896 set_handler(new MyHandler()); | 903 set_handler(new MyHandler()); |
897 | 904 |
898 for (size_t i = 0; i < 4; ++i) { | 905 for (size_t i = 0; i < 4; ++i) { |
899 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; | 906 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; |
900 } | 907 } |
901 | 908 |
902 proc_->SignalMultiple(2u); // One for "a". One for "finalrequest". | 909 proc_->SignalMultiple(2u); // One for "a". One for "finalrequest". |
903 | 910 |
904 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 911 EXPECT_THAT(requests_[0]->WaitForResult(), IsOk()); |
905 | 912 |
906 Request* final_request = CreateRequest("finalrequest", 70); | 913 Request* final_request = CreateRequest("finalrequest", 70); |
907 EXPECT_EQ(ERR_IO_PENDING, final_request->Resolve()); | 914 EXPECT_THAT(final_request->Resolve(), IsError(ERR_IO_PENDING)); |
908 EXPECT_EQ(OK, final_request->WaitForResult()); | 915 EXPECT_THAT(final_request->WaitForResult(), IsOk()); |
909 EXPECT_TRUE(requests_[3]->completed()); | 916 EXPECT_TRUE(requests_[3]->completed()); |
910 } | 917 } |
911 | 918 |
912 TEST_F(HostResolverImplTest, DeleteWithinCallback) { | 919 TEST_F(HostResolverImplTest, DeleteWithinCallback) { |
913 struct MyHandler : public Handler { | 920 struct MyHandler : public Handler { |
914 void Handle(Request* req) override { | 921 void Handle(Request* req) override { |
915 EXPECT_EQ("a", req->info().hostname()); | 922 EXPECT_EQ("a", req->info().hostname()); |
916 EXPECT_EQ(80, req->info().port()); | 923 EXPECT_EQ(80, req->info().port()); |
917 | 924 |
918 DeleteResolver(); | 925 DeleteResolver(); |
(...skipping 26 matching lines...) Expand all Loading... |
945 | 952 |
946 // Quit after returning from OnCompleted (to give it a chance at | 953 // Quit after returning from OnCompleted (to give it a chance at |
947 // incorrectly running the cancelled tasks). | 954 // incorrectly running the cancelled tasks). |
948 base::ThreadTaskRunnerHandle::Get()->PostTask( | 955 base::ThreadTaskRunnerHandle::Get()->PostTask( |
949 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 956 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
950 } | 957 } |
951 }; | 958 }; |
952 set_handler(new MyHandler()); | 959 set_handler(new MyHandler()); |
953 | 960 |
954 // This test assumes that the Jobs will be Aborted in order ["a", "b"] | 961 // This test assumes that the Jobs will be Aborted in order ["a", "b"] |
955 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80)->Resolve()); | 962 EXPECT_THAT(CreateRequest("a", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
956 // HostResolverImpl will be deleted before later Requests can complete. | 963 // HostResolverImpl will be deleted before later Requests can complete. |
957 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 81)->Resolve()); | 964 EXPECT_THAT(CreateRequest("a", 81)->Resolve(), IsError(ERR_IO_PENDING)); |
958 // Job for 'b' will be aborted before it can complete. | 965 // Job for 'b' will be aborted before it can complete. |
959 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 82)->Resolve()); | 966 EXPECT_THAT(CreateRequest("b", 82)->Resolve(), IsError(ERR_IO_PENDING)); |
960 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 83)->Resolve()); | 967 EXPECT_THAT(CreateRequest("b", 83)->Resolve(), IsError(ERR_IO_PENDING)); |
961 | 968 |
962 EXPECT_TRUE(proc_->WaitFor(1u)); | 969 EXPECT_TRUE(proc_->WaitFor(1u)); |
963 | 970 |
964 // Triggering an IP address change. | 971 // Triggering an IP address change. |
965 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 972 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
966 | 973 |
967 // |MyHandler| will send quit message once all the requests have finished. | 974 // |MyHandler| will send quit message once all the requests have finished. |
968 base::RunLoop().Run(); | 975 base::RunLoop().Run(); |
969 | 976 |
970 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->result()); | 977 EXPECT_THAT(requests_[0]->result(), IsError(ERR_NETWORK_CHANGED)); |
971 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->result()); | 978 EXPECT_THAT(requests_[1]->result(), IsError(ERR_IO_PENDING)); |
972 EXPECT_EQ(ERR_IO_PENDING, requests_[2]->result()); | 979 EXPECT_THAT(requests_[2]->result(), IsError(ERR_IO_PENDING)); |
973 EXPECT_EQ(ERR_IO_PENDING, requests_[3]->result()); | 980 EXPECT_THAT(requests_[3]->result(), IsError(ERR_IO_PENDING)); |
974 // Clean up. | 981 // Clean up. |
975 proc_->SignalMultiple(requests_.size()); | 982 proc_->SignalMultiple(requests_.size()); |
976 } | 983 } |
977 | 984 |
978 TEST_F(HostResolverImplTest, StartWithinCallback) { | 985 TEST_F(HostResolverImplTest, StartWithinCallback) { |
979 struct MyHandler : public Handler { | 986 struct MyHandler : public Handler { |
980 void Handle(Request* req) override { | 987 void Handle(Request* req) override { |
981 if (req->index() == 0) { | 988 if (req->index() == 0) { |
982 // On completing the first request, start another request for "a". | 989 // On completing the first request, start another request for "a". |
983 // Since caching is disabled, this will result in another async request. | 990 // Since caching is disabled, this will result in another async request. |
984 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 70)->Resolve()); | 991 EXPECT_THAT(CreateRequest("a", 70)->Resolve(), IsError(ERR_IO_PENDING)); |
985 } | 992 } |
986 } | 993 } |
987 }; | 994 }; |
988 set_handler(new MyHandler()); | 995 set_handler(new MyHandler()); |
989 | 996 |
990 // Turn off caching for this host resolver. | 997 // Turn off caching for this host resolver. |
991 HostResolver::Options options = DefaultOptions(); | 998 HostResolver::Options options = DefaultOptions(); |
992 options.enable_caching = false; | 999 options.enable_caching = false; |
993 resolver_.reset(new TestHostResolverImpl(options, NULL)); | 1000 resolver_.reset(new TestHostResolverImpl(options, NULL)); |
994 resolver_->set_proc_params_for_test(DefaultParams(proc_.get())); | 1001 resolver_->set_proc_params_for_test(DefaultParams(proc_.get())); |
995 | 1002 |
996 for (size_t i = 0; i < 4; ++i) { | 1003 for (size_t i = 0; i < 4; ++i) { |
997 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; | 1004 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; |
998 } | 1005 } |
999 | 1006 |
1000 proc_->SignalMultiple(2u); // One for "a". One for the second "a". | 1007 proc_->SignalMultiple(2u); // One for "a". One for the second "a". |
1001 | 1008 |
1002 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 1009 EXPECT_THAT(requests_[0]->WaitForResult(), IsOk()); |
1003 ASSERT_EQ(5u, requests_.size()); | 1010 ASSERT_EQ(5u, requests_.size()); |
1004 EXPECT_EQ(OK, requests_.back()->WaitForResult()); | 1011 EXPECT_THAT(requests_.back()->WaitForResult(), IsOk()); |
1005 | 1012 |
1006 EXPECT_EQ(2u, proc_->GetCaptureList().size()); | 1013 EXPECT_EQ(2u, proc_->GetCaptureList().size()); |
1007 } | 1014 } |
1008 | 1015 |
1009 TEST_F(HostResolverImplTest, BypassCache) { | 1016 TEST_F(HostResolverImplTest, BypassCache) { |
1010 struct MyHandler : public Handler { | 1017 struct MyHandler : public Handler { |
1011 void Handle(Request* req) override { | 1018 void Handle(Request* req) override { |
1012 if (req->index() == 0) { | 1019 if (req->index() == 0) { |
1013 // On completing the first request, start another request for "a". | 1020 // On completing the first request, start another request for "a". |
1014 // Since caching is enabled, this should complete synchronously. | 1021 // Since caching is enabled, this should complete synchronously. |
1015 std::string hostname = req->info().hostname(); | 1022 std::string hostname = req->info().hostname(); |
1016 EXPECT_EQ(OK, CreateRequest(hostname, 70)->Resolve()); | 1023 EXPECT_THAT(CreateRequest(hostname, 70)->Resolve(), IsOk()); |
1017 EXPECT_EQ(OK, CreateRequest(hostname, 75)->ResolveFromCache()); | 1024 EXPECT_THAT(CreateRequest(hostname, 75)->ResolveFromCache(), IsOk()); |
1018 | 1025 |
1019 // Ok good. Now make sure that if we ask to bypass the cache, it can no | 1026 // Ok good. Now make sure that if we ask to bypass the cache, it can no |
1020 // longer service the request synchronously. | 1027 // longer service the request synchronously. |
1021 HostResolver::RequestInfo info(HostPortPair(hostname, 71)); | 1028 HostResolver::RequestInfo info(HostPortPair(hostname, 71)); |
1022 info.set_allow_cached_response(false); | 1029 info.set_allow_cached_response(false); |
1023 EXPECT_EQ(ERR_IO_PENDING, | 1030 EXPECT_EQ(ERR_IO_PENDING, |
1024 CreateRequest(info, DEFAULT_PRIORITY)->Resolve()); | 1031 CreateRequest(info, DEFAULT_PRIORITY)->Resolve()); |
1025 } else if (71 == req->info().port()) { | 1032 } else if (71 == req->info().port()) { |
1026 // Test is done. | 1033 // Test is done. |
1027 base::MessageLoop::current()->QuitWhenIdle(); | 1034 base::MessageLoop::current()->QuitWhenIdle(); |
1028 } else { | 1035 } else { |
1029 FAIL() << "Unexpected request"; | 1036 FAIL() << "Unexpected request"; |
1030 } | 1037 } |
1031 } | 1038 } |
1032 }; | 1039 }; |
1033 set_handler(new MyHandler()); | 1040 set_handler(new MyHandler()); |
1034 | 1041 |
1035 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80)->Resolve()); | 1042 EXPECT_THAT(CreateRequest("a", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
1036 proc_->SignalMultiple(3u); // Only need two, but be generous. | 1043 proc_->SignalMultiple(3u); // Only need two, but be generous. |
1037 | 1044 |
1038 // |verifier| will send quit message once all the requests have finished. | 1045 // |verifier| will send quit message once all the requests have finished. |
1039 base::RunLoop().Run(); | 1046 base::RunLoop().Run(); |
1040 EXPECT_EQ(2u, proc_->GetCaptureList().size()); | 1047 EXPECT_EQ(2u, proc_->GetCaptureList().size()); |
1041 } | 1048 } |
1042 | 1049 |
1043 // Test that IP address changes flush the cache but initial DNS config reads do | 1050 // Test that IP address changes flush the cache but initial DNS config reads do |
1044 // not. | 1051 // not. |
1045 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { | 1052 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { |
1046 proc_->SignalMultiple(2u); // One before the flush, one after. | 1053 proc_->SignalMultiple(2u); // One before the flush, one after. |
1047 | 1054 |
1048 Request* req = CreateRequest("host1", 70); | 1055 Request* req = CreateRequest("host1", 70); |
1049 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1056 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
1050 EXPECT_EQ(OK, req->WaitForResult()); | 1057 EXPECT_THAT(req->WaitForResult(), IsOk()); |
1051 | 1058 |
1052 req = CreateRequest("host1", 75); | 1059 req = CreateRequest("host1", 75); |
1053 EXPECT_EQ(OK, req->Resolve()); // Should complete synchronously. | 1060 EXPECT_THAT(req->Resolve(), IsOk()); // Should complete synchronously. |
1054 | 1061 |
1055 // Verify initial DNS config read does not flush cache. | 1062 // Verify initial DNS config read does not flush cache. |
1056 NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); | 1063 NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); |
1057 req = CreateRequest("host1", 75); | 1064 req = CreateRequest("host1", 75); |
1058 EXPECT_EQ(OK, req->Resolve()); // Should complete synchronously. | 1065 EXPECT_THAT(req->Resolve(), IsOk()); // Should complete synchronously. |
1059 | 1066 |
1060 // Flush cache by triggering an IP address change. | 1067 // Flush cache by triggering an IP address change. |
1061 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1068 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
1062 base::RunLoop().RunUntilIdle(); // Notification happens async. | 1069 base::RunLoop().RunUntilIdle(); // Notification happens async. |
1063 | 1070 |
1064 // Resolve "host1" again -- this time it won't be served from cache, so it | 1071 // Resolve "host1" again -- this time it won't be served from cache, so it |
1065 // will complete asynchronously. | 1072 // will complete asynchronously. |
1066 req = CreateRequest("host1", 80); | 1073 req = CreateRequest("host1", 80); |
1067 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1074 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
1068 EXPECT_EQ(OK, req->WaitForResult()); | 1075 EXPECT_THAT(req->WaitForResult(), IsOk()); |
1069 } | 1076 } |
1070 | 1077 |
1071 // Test that IP address changes send ERR_NETWORK_CHANGED to pending requests. | 1078 // Test that IP address changes send ERR_NETWORK_CHANGED to pending requests. |
1072 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { | 1079 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { |
1073 Request* req = CreateRequest("host1", 70); | 1080 Request* req = CreateRequest("host1", 70); |
1074 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1081 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
1075 | 1082 |
1076 EXPECT_TRUE(proc_->WaitFor(1u)); | 1083 EXPECT_TRUE(proc_->WaitFor(1u)); |
1077 // Triggering an IP address change. | 1084 // Triggering an IP address change. |
1078 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1085 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
1079 base::RunLoop().RunUntilIdle(); // Notification happens async. | 1086 base::RunLoop().RunUntilIdle(); // Notification happens async. |
1080 proc_->SignalAll(); | 1087 proc_->SignalAll(); |
1081 | 1088 |
1082 EXPECT_EQ(ERR_NETWORK_CHANGED, req->WaitForResult()); | 1089 EXPECT_THAT(req->WaitForResult(), IsError(ERR_NETWORK_CHANGED)); |
1083 EXPECT_EQ(0u, resolver_->GetHostCache()->size()); | 1090 EXPECT_EQ(0u, resolver_->GetHostCache()->size()); |
1084 } | 1091 } |
1085 | 1092 |
1086 // Test that initial DNS config read signals do not abort pending requests. | 1093 // Test that initial DNS config read signals do not abort pending requests. |
1087 TEST_F(HostResolverImplTest, DontAbortOnInitialDNSConfigRead) { | 1094 TEST_F(HostResolverImplTest, DontAbortOnInitialDNSConfigRead) { |
1088 Request* req = CreateRequest("host1", 70); | 1095 Request* req = CreateRequest("host1", 70); |
1089 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1096 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
1090 | 1097 |
1091 EXPECT_TRUE(proc_->WaitFor(1u)); | 1098 EXPECT_TRUE(proc_->WaitFor(1u)); |
1092 // Triggering initial DNS config read signal. | 1099 // Triggering initial DNS config read signal. |
1093 NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); | 1100 NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); |
1094 base::RunLoop().RunUntilIdle(); // Notification happens async. | 1101 base::RunLoop().RunUntilIdle(); // Notification happens async. |
1095 proc_->SignalAll(); | 1102 proc_->SignalAll(); |
1096 | 1103 |
1097 EXPECT_EQ(OK, req->WaitForResult()); | 1104 EXPECT_THAT(req->WaitForResult(), IsOk()); |
1098 } | 1105 } |
1099 | 1106 |
1100 // Obey pool constraints after IP address has changed. | 1107 // Obey pool constraints after IP address has changed. |
1101 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { | 1108 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { |
1102 // Runs at most one job at a time. | 1109 // Runs at most one job at a time. |
1103 CreateSerialResolver(); | 1110 CreateSerialResolver(); |
1104 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a")->Resolve()); | 1111 EXPECT_THAT(CreateRequest("a")->Resolve(), IsError(ERR_IO_PENDING)); |
1105 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b")->Resolve()); | 1112 EXPECT_THAT(CreateRequest("b")->Resolve(), IsError(ERR_IO_PENDING)); |
1106 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("c")->Resolve()); | 1113 EXPECT_THAT(CreateRequest("c")->Resolve(), IsError(ERR_IO_PENDING)); |
1107 | 1114 |
1108 EXPECT_TRUE(proc_->WaitFor(1u)); | 1115 EXPECT_TRUE(proc_->WaitFor(1u)); |
1109 // Triggering an IP address change. | 1116 // Triggering an IP address change. |
1110 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1117 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
1111 base::RunLoop().RunUntilIdle(); // Notification happens async. | 1118 base::RunLoop().RunUntilIdle(); // Notification happens async. |
1112 proc_->SignalMultiple(3u); // Let the false-start go so that we can catch it. | 1119 proc_->SignalMultiple(3u); // Let the false-start go so that we can catch it. |
1113 | 1120 |
1114 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->WaitForResult()); | 1121 EXPECT_THAT(requests_[0]->WaitForResult(), IsError(ERR_NETWORK_CHANGED)); |
1115 | 1122 |
1116 EXPECT_EQ(1u, num_running_dispatcher_jobs()); | 1123 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
1117 | 1124 |
1118 EXPECT_FALSE(requests_[1]->completed()); | 1125 EXPECT_FALSE(requests_[1]->completed()); |
1119 EXPECT_FALSE(requests_[2]->completed()); | 1126 EXPECT_FALSE(requests_[2]->completed()); |
1120 | 1127 |
1121 EXPECT_EQ(OK, requests_[2]->WaitForResult()); | 1128 EXPECT_THAT(requests_[2]->WaitForResult(), IsOk()); |
1122 EXPECT_EQ(OK, requests_[1]->result()); | 1129 EXPECT_THAT(requests_[1]->result(), IsOk()); |
1123 } | 1130 } |
1124 | 1131 |
1125 // Tests that a new Request made from the callback of a previously aborted one | 1132 // Tests that a new Request made from the callback of a previously aborted one |
1126 // will not be aborted. | 1133 // will not be aborted. |
1127 TEST_F(HostResolverImplTest, AbortOnlyExistingRequestsOnIPAddressChange) { | 1134 TEST_F(HostResolverImplTest, AbortOnlyExistingRequestsOnIPAddressChange) { |
1128 struct MyHandler : public Handler { | 1135 struct MyHandler : public Handler { |
1129 void Handle(Request* req) override { | 1136 void Handle(Request* req) override { |
1130 // Start new request for a different hostname to ensure that the order | 1137 // Start new request for a different hostname to ensure that the order |
1131 // of jobs in HostResolverImpl is not stable. | 1138 // of jobs in HostResolverImpl is not stable. |
1132 std::string hostname; | 1139 std::string hostname; |
1133 if (req->index() == 0) | 1140 if (req->index() == 0) |
1134 hostname = "zzz"; | 1141 hostname = "zzz"; |
1135 else if (req->index() == 1) | 1142 else if (req->index() == 1) |
1136 hostname = "aaa"; | 1143 hostname = "aaa"; |
1137 else if (req->index() == 2) | 1144 else if (req->index() == 2) |
1138 hostname = "eee"; | 1145 hostname = "eee"; |
1139 else | 1146 else |
1140 return; // A request started from within MyHandler. | 1147 return; // A request started from within MyHandler. |
1141 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(hostname)->Resolve()) << hostname; | 1148 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(hostname)->Resolve()) << hostname; |
1142 } | 1149 } |
1143 }; | 1150 }; |
1144 set_handler(new MyHandler()); | 1151 set_handler(new MyHandler()); |
1145 | 1152 |
1146 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("bbb")->Resolve()); | 1153 EXPECT_THAT(CreateRequest("bbb")->Resolve(), IsError(ERR_IO_PENDING)); |
1147 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("eee")->Resolve()); | 1154 EXPECT_THAT(CreateRequest("eee")->Resolve(), IsError(ERR_IO_PENDING)); |
1148 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ccc")->Resolve()); | 1155 EXPECT_THAT(CreateRequest("ccc")->Resolve(), IsError(ERR_IO_PENDING)); |
1149 | 1156 |
1150 // Wait until all are blocked; | 1157 // Wait until all are blocked; |
1151 EXPECT_TRUE(proc_->WaitFor(3u)); | 1158 EXPECT_TRUE(proc_->WaitFor(3u)); |
1152 // Trigger an IP address change. | 1159 // Trigger an IP address change. |
1153 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1160 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
1154 // This should abort all running jobs. | 1161 // This should abort all running jobs. |
1155 base::RunLoop().RunUntilIdle(); | 1162 base::RunLoop().RunUntilIdle(); |
1156 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->result()); | 1163 EXPECT_THAT(requests_[0]->result(), IsError(ERR_NETWORK_CHANGED)); |
1157 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[1]->result()); | 1164 EXPECT_THAT(requests_[1]->result(), IsError(ERR_NETWORK_CHANGED)); |
1158 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[2]->result()); | 1165 EXPECT_THAT(requests_[2]->result(), IsError(ERR_NETWORK_CHANGED)); |
1159 ASSERT_EQ(6u, requests_.size()); | 1166 ASSERT_EQ(6u, requests_.size()); |
1160 // Unblock all calls to proc. | 1167 // Unblock all calls to proc. |
1161 proc_->SignalMultiple(requests_.size()); | 1168 proc_->SignalMultiple(requests_.size()); |
1162 // Run until the re-started requests finish. | 1169 // Run until the re-started requests finish. |
1163 EXPECT_EQ(OK, requests_[3]->WaitForResult()); | 1170 EXPECT_THAT(requests_[3]->WaitForResult(), IsOk()); |
1164 EXPECT_EQ(OK, requests_[4]->WaitForResult()); | 1171 EXPECT_THAT(requests_[4]->WaitForResult(), IsOk()); |
1165 EXPECT_EQ(OK, requests_[5]->WaitForResult()); | 1172 EXPECT_THAT(requests_[5]->WaitForResult(), IsOk()); |
1166 // Verify that results of aborted Jobs were not cached. | 1173 // Verify that results of aborted Jobs were not cached. |
1167 EXPECT_EQ(6u, proc_->GetCaptureList().size()); | 1174 EXPECT_EQ(6u, proc_->GetCaptureList().size()); |
1168 EXPECT_EQ(3u, resolver_->GetHostCache()->size()); | 1175 EXPECT_EQ(3u, resolver_->GetHostCache()->size()); |
1169 } | 1176 } |
1170 | 1177 |
1171 // Tests that when the maximum threads is set to 1, requests are dequeued | 1178 // Tests that when the maximum threads is set to 1, requests are dequeued |
1172 // in order of priority. | 1179 // in order of priority. |
1173 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { | 1180 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { |
1174 CreateSerialResolver(); | 1181 CreateSerialResolver(); |
1175 | 1182 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 CreateSerialResolver(); | 1224 CreateSerialResolver(); |
1218 | 1225 |
1219 CreateRequest("req0", 80, MEDIUM); | 1226 CreateRequest("req0", 80, MEDIUM); |
1220 CreateRequest("req1", 80, LOW); | 1227 CreateRequest("req1", 80, LOW); |
1221 CreateRequest("req2", 80, LOWEST); | 1228 CreateRequest("req2", 80, LOWEST); |
1222 | 1229 |
1223 ASSERT_EQ(3u, requests_.size()); | 1230 ASSERT_EQ(3u, requests_.size()); |
1224 | 1231 |
1225 // req0 starts immediately; without ChangePriority, req1 and then req2 should | 1232 // req0 starts immediately; without ChangePriority, req1 and then req2 should |
1226 // run. | 1233 // run. |
1227 EXPECT_EQ(ERR_IO_PENDING, requests_[0]->Resolve()); | 1234 EXPECT_THAT(requests_[0]->Resolve(), IsError(ERR_IO_PENDING)); |
1228 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->Resolve()); | 1235 EXPECT_THAT(requests_[1]->Resolve(), IsError(ERR_IO_PENDING)); |
1229 EXPECT_EQ(ERR_IO_PENDING, requests_[2]->Resolve()); | 1236 EXPECT_THAT(requests_[2]->Resolve(), IsError(ERR_IO_PENDING)); |
1230 | 1237 |
1231 // Changing req2 to HIGH should make it run before req1. | 1238 // Changing req2 to HIGH should make it run before req1. |
1232 // (It can't run before req0, since req0 started immediately.) | 1239 // (It can't run before req0, since req0 started immediately.) |
1233 requests_[2]->ChangePriority(HIGHEST); | 1240 requests_[2]->ChangePriority(HIGHEST); |
1234 | 1241 |
1235 // Let all 3 requests finish. | 1242 // Let all 3 requests finish. |
1236 proc_->SignalMultiple(3u); | 1243 proc_->SignalMultiple(3u); |
1237 | 1244 |
1238 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 1245 EXPECT_THAT(requests_[0]->WaitForResult(), IsOk()); |
1239 EXPECT_EQ(OK, requests_[1]->WaitForResult()); | 1246 EXPECT_THAT(requests_[1]->WaitForResult(), IsOk()); |
1240 EXPECT_EQ(OK, requests_[2]->WaitForResult()); | 1247 EXPECT_THAT(requests_[2]->WaitForResult(), IsOk()); |
1241 | 1248 |
1242 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList(); | 1249 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList(); |
1243 ASSERT_EQ(3u, capture_list.size()); | 1250 ASSERT_EQ(3u, capture_list.size()); |
1244 | 1251 |
1245 EXPECT_EQ("req0", capture_list[0].hostname); | 1252 EXPECT_EQ("req0", capture_list[0].hostname); |
1246 EXPECT_EQ("req2", capture_list[1].hostname); | 1253 EXPECT_EQ("req2", capture_list[1].hostname); |
1247 EXPECT_EQ("req1", capture_list[2].hostname); | 1254 EXPECT_EQ("req1", capture_list[2].hostname); |
1248 } | 1255 } |
1249 | 1256 |
1250 // Try cancelling a job which has not started yet. | 1257 // Try cancelling a job which has not started yet. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 TEST_F(HostResolverImplTest, QueueOverflow) { | 1301 TEST_F(HostResolverImplTest, QueueOverflow) { |
1295 CreateSerialResolver(); | 1302 CreateSerialResolver(); |
1296 | 1303 |
1297 // Allow only 3 queued jobs. | 1304 // Allow only 3 queued jobs. |
1298 const size_t kMaxPendingJobs = 3u; | 1305 const size_t kMaxPendingJobs = 3u; |
1299 resolver_->SetMaxQueuedJobs(kMaxPendingJobs); | 1306 resolver_->SetMaxQueuedJobs(kMaxPendingJobs); |
1300 | 1307 |
1301 // Note that at this point the MockHostResolverProc is blocked, so any | 1308 // Note that at this point the MockHostResolverProc is blocked, so any |
1302 // requests we make will not complete. | 1309 // requests we make will not complete. |
1303 | 1310 |
1304 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("req0", 80, LOWEST)->Resolve()); | 1311 EXPECT_THAT(CreateRequest("req0", 80, LOWEST)->Resolve(), |
1305 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("req1", 80, HIGHEST)->Resolve()); | 1312 IsError(ERR_IO_PENDING)); |
1306 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("req2", 80, MEDIUM)->Resolve()); | 1313 EXPECT_THAT(CreateRequest("req1", 80, HIGHEST)->Resolve(), |
1307 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("req3", 80, MEDIUM)->Resolve()); | 1314 IsError(ERR_IO_PENDING)); |
| 1315 EXPECT_THAT(CreateRequest("req2", 80, MEDIUM)->Resolve(), |
| 1316 IsError(ERR_IO_PENDING)); |
| 1317 EXPECT_THAT(CreateRequest("req3", 80, MEDIUM)->Resolve(), |
| 1318 IsError(ERR_IO_PENDING)); |
1308 | 1319 |
1309 // At this point, there are 3 enqueued jobs. | 1320 // At this point, there are 3 enqueued jobs. |
1310 // Insertion of subsequent requests will cause evictions | 1321 // Insertion of subsequent requests will cause evictions |
1311 // based on priority. | 1322 // based on priority. |
1312 | 1323 |
1313 EXPECT_EQ(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE, | 1324 EXPECT_EQ(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE, |
1314 CreateRequest("req4", 80, LOW)->Resolve()); // Evicts itself! | 1325 CreateRequest("req4", 80, LOW)->Resolve()); // Evicts itself! |
1315 | 1326 |
1316 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("req5", 80, MEDIUM)->Resolve()); | 1327 EXPECT_THAT(CreateRequest("req5", 80, MEDIUM)->Resolve(), |
1317 EXPECT_EQ(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE, requests_[2]->result()); | 1328 IsError(ERR_IO_PENDING)); |
1318 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("req6", 80, HIGHEST)->Resolve()); | 1329 EXPECT_THAT(requests_[2]->result(), |
1319 EXPECT_EQ(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE, requests_[3]->result()); | 1330 IsError(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE)); |
1320 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("req7", 80, MEDIUM)->Resolve()); | 1331 EXPECT_THAT(CreateRequest("req6", 80, HIGHEST)->Resolve(), |
1321 EXPECT_EQ(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE, requests_[5]->result()); | 1332 IsError(ERR_IO_PENDING)); |
| 1333 EXPECT_THAT(requests_[3]->result(), |
| 1334 IsError(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE)); |
| 1335 EXPECT_THAT(CreateRequest("req7", 80, MEDIUM)->Resolve(), |
| 1336 IsError(ERR_IO_PENDING)); |
| 1337 EXPECT_THAT(requests_[5]->result(), |
| 1338 IsError(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE)); |
1322 | 1339 |
1323 // Unblock the resolver thread so the requests can run. | 1340 // Unblock the resolver thread so the requests can run. |
1324 proc_->SignalMultiple(4u); | 1341 proc_->SignalMultiple(4u); |
1325 | 1342 |
1326 // The rest should succeed. | 1343 // The rest should succeed. |
1327 EXPECT_EQ(OK, requests_[7]->WaitForResult()); | 1344 EXPECT_THAT(requests_[7]->WaitForResult(), IsOk()); |
1328 EXPECT_EQ(OK, requests_[0]->result()); | 1345 EXPECT_THAT(requests_[0]->result(), IsOk()); |
1329 EXPECT_EQ(OK, requests_[1]->result()); | 1346 EXPECT_THAT(requests_[1]->result(), IsOk()); |
1330 EXPECT_EQ(OK, requests_[6]->result()); | 1347 EXPECT_THAT(requests_[6]->result(), IsOk()); |
1331 | 1348 |
1332 // Verify that they called out the the resolver proc (which runs on the | 1349 // Verify that they called out the the resolver proc (which runs on the |
1333 // resolver thread) in the expected order. | 1350 // resolver thread) in the expected order. |
1334 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList(); | 1351 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList(); |
1335 ASSERT_EQ(4u, capture_list.size()); | 1352 ASSERT_EQ(4u, capture_list.size()); |
1336 | 1353 |
1337 EXPECT_EQ("req0", capture_list[0].hostname); | 1354 EXPECT_EQ("req0", capture_list[0].hostname); |
1338 EXPECT_EQ("req1", capture_list[1].hostname); | 1355 EXPECT_EQ("req1", capture_list[1].hostname); |
1339 EXPECT_EQ("req6", capture_list[2].hostname); | 1356 EXPECT_EQ("req6", capture_list[2].hostname); |
1340 EXPECT_EQ("req7", capture_list[3].hostname); | 1357 EXPECT_EQ("req7", capture_list[3].hostname); |
1341 | 1358 |
1342 // Verify that the evicted (incomplete) requests were not cached. | 1359 // Verify that the evicted (incomplete) requests were not cached. |
1343 EXPECT_EQ(4u, resolver_->GetHostCache()->size()); | 1360 EXPECT_EQ(4u, resolver_->GetHostCache()->size()); |
1344 | 1361 |
1345 for (size_t i = 0; i < requests_.size(); ++i) { | 1362 for (size_t i = 0; i < requests_.size(); ++i) { |
1346 EXPECT_TRUE(requests_[i]->completed()) << i; | 1363 EXPECT_TRUE(requests_[i]->completed()) << i; |
1347 } | 1364 } |
1348 } | 1365 } |
1349 | 1366 |
1350 // Make sure that the address family parameter is respected when raw IPs are | 1367 // Make sure that the address family parameter is respected when raw IPs are |
1351 // passed in. | 1368 // passed in. |
1352 TEST_F(HostResolverImplTest, AddressFamilyWithRawIPs) { | 1369 TEST_F(HostResolverImplTest, AddressFamilyWithRawIPs) { |
1353 Request* request = | 1370 Request* request = |
1354 CreateRequest("127.0.0.1", 80, MEDIUM, ADDRESS_FAMILY_IPV4); | 1371 CreateRequest("127.0.0.1", 80, MEDIUM, ADDRESS_FAMILY_IPV4); |
1355 EXPECT_EQ(OK, request->Resolve()); | 1372 EXPECT_THAT(request->Resolve(), IsOk()); |
1356 EXPECT_TRUE(request->HasOneAddress("127.0.0.1", 80)); | 1373 EXPECT_TRUE(request->HasOneAddress("127.0.0.1", 80)); |
1357 | 1374 |
1358 request = CreateRequest("127.0.0.1", 80, MEDIUM, ADDRESS_FAMILY_IPV6); | 1375 request = CreateRequest("127.0.0.1", 80, MEDIUM, ADDRESS_FAMILY_IPV6); |
1359 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, request->Resolve()); | 1376 EXPECT_THAT(request->Resolve(), IsError(ERR_NAME_NOT_RESOLVED)); |
1360 | 1377 |
1361 request = CreateRequest("127.0.0.1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED); | 1378 request = CreateRequest("127.0.0.1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED); |
1362 EXPECT_EQ(OK, request->Resolve()); | 1379 EXPECT_THAT(request->Resolve(), IsOk()); |
1363 EXPECT_TRUE(request->HasOneAddress("127.0.0.1", 80)); | 1380 EXPECT_TRUE(request->HasOneAddress("127.0.0.1", 80)); |
1364 | 1381 |
1365 request = CreateRequest("::1", 80, MEDIUM, ADDRESS_FAMILY_IPV4); | 1382 request = CreateRequest("::1", 80, MEDIUM, ADDRESS_FAMILY_IPV4); |
1366 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, request->Resolve()); | 1383 EXPECT_THAT(request->Resolve(), IsError(ERR_NAME_NOT_RESOLVED)); |
1367 | 1384 |
1368 request = CreateRequest("::1", 80, MEDIUM, ADDRESS_FAMILY_IPV6); | 1385 request = CreateRequest("::1", 80, MEDIUM, ADDRESS_FAMILY_IPV6); |
1369 EXPECT_EQ(OK, request->Resolve()); | 1386 EXPECT_THAT(request->Resolve(), IsOk()); |
1370 EXPECT_TRUE(request->HasOneAddress("::1", 80)); | 1387 EXPECT_TRUE(request->HasOneAddress("::1", 80)); |
1371 | 1388 |
1372 request = CreateRequest("::1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED); | 1389 request = CreateRequest("::1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED); |
1373 EXPECT_EQ(OK, request->Resolve()); | 1390 EXPECT_THAT(request->Resolve(), IsOk()); |
1374 EXPECT_TRUE(request->HasOneAddress("::1", 80)); | 1391 EXPECT_TRUE(request->HasOneAddress("::1", 80)); |
1375 } | 1392 } |
1376 | 1393 |
1377 TEST_F(HostResolverImplTest, ResolveFromCache) { | 1394 TEST_F(HostResolverImplTest, ResolveFromCache) { |
1378 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42"); | 1395 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42"); |
1379 proc_->SignalMultiple(1u); // Need only one. | 1396 proc_->SignalMultiple(1u); // Need only one. |
1380 | 1397 |
1381 HostResolver::RequestInfo info(HostPortPair("just.testing", 80)); | 1398 HostResolver::RequestInfo info(HostPortPair("just.testing", 80)); |
1382 | 1399 |
1383 // First hit will miss the cache. | 1400 // First hit will miss the cache. |
1384 EXPECT_EQ(ERR_DNS_CACHE_MISS, | 1401 EXPECT_EQ(ERR_DNS_CACHE_MISS, |
1385 CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache()); | 1402 CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache()); |
1386 | 1403 |
1387 // This time, we fetch normally. | 1404 // This time, we fetch normally. |
1388 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(info, DEFAULT_PRIORITY)->Resolve()); | 1405 EXPECT_THAT(CreateRequest(info, DEFAULT_PRIORITY)->Resolve(), |
1389 EXPECT_EQ(OK, requests_[1]->WaitForResult()); | 1406 IsError(ERR_IO_PENDING)); |
| 1407 EXPECT_THAT(requests_[1]->WaitForResult(), IsOk()); |
1390 | 1408 |
1391 // Now we should be able to fetch from the cache. | 1409 // Now we should be able to fetch from the cache. |
1392 EXPECT_EQ(OK, CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache()); | 1410 EXPECT_THAT(CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache(), |
| 1411 IsOk()); |
1393 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.1.42", 80)); | 1412 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.1.42", 80)); |
1394 } | 1413 } |
1395 | 1414 |
1396 TEST_F(HostResolverImplTest, ResolveStaleFromCache) { | 1415 TEST_F(HostResolverImplTest, ResolveStaleFromCache) { |
1397 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42"); | 1416 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42"); |
1398 proc_->SignalMultiple(1u); // Need only one. | 1417 proc_->SignalMultiple(1u); // Need only one. |
1399 | 1418 |
1400 HostResolver::RequestInfo info(HostPortPair("just.testing", 80)); | 1419 HostResolver::RequestInfo info(HostPortPair("just.testing", 80)); |
1401 | 1420 |
1402 // First hit will miss the cache. | 1421 // First hit will miss the cache. |
1403 EXPECT_EQ(ERR_DNS_CACHE_MISS, | 1422 EXPECT_EQ(ERR_DNS_CACHE_MISS, |
1404 CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache()); | 1423 CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache()); |
1405 | 1424 |
1406 // This time, we fetch normally. | 1425 // This time, we fetch normally. |
1407 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(info, DEFAULT_PRIORITY)->Resolve()); | 1426 EXPECT_THAT(CreateRequest(info, DEFAULT_PRIORITY)->Resolve(), |
1408 EXPECT_EQ(OK, requests_[1]->WaitForResult()); | 1427 IsError(ERR_IO_PENDING)); |
| 1428 EXPECT_THAT(requests_[1]->WaitForResult(), IsOk()); |
1409 | 1429 |
1410 // Now we should be able to fetch from the cache. | 1430 // Now we should be able to fetch from the cache. |
1411 EXPECT_EQ(OK, CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache()); | 1431 EXPECT_THAT(CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache(), |
| 1432 IsOk()); |
1412 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.1.42", 80)); | 1433 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.1.42", 80)); |
1413 EXPECT_EQ(OK, CreateRequest(info, DEFAULT_PRIORITY)->ResolveStaleFromCache()); | 1434 EXPECT_THAT(CreateRequest(info, DEFAULT_PRIORITY)->ResolveStaleFromCache(), |
| 1435 IsOk()); |
1414 EXPECT_TRUE(requests_[3]->HasOneAddress("192.168.1.42", 80)); | 1436 EXPECT_TRUE(requests_[3]->HasOneAddress("192.168.1.42", 80)); |
1415 EXPECT_FALSE(requests_[3]->staleness().is_stale()); | 1437 EXPECT_FALSE(requests_[3]->staleness().is_stale()); |
1416 | 1438 |
1417 MakeCacheStale(); | 1439 MakeCacheStale(); |
1418 | 1440 |
1419 // Now we should be able to fetch from the cache only if we use | 1441 // Now we should be able to fetch from the cache only if we use |
1420 // ResolveStaleFromCache. | 1442 // ResolveStaleFromCache. |
1421 EXPECT_EQ(ERR_DNS_CACHE_MISS, | 1443 EXPECT_EQ(ERR_DNS_CACHE_MISS, |
1422 CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache()); | 1444 CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache()); |
1423 EXPECT_EQ(OK, CreateRequest(info, DEFAULT_PRIORITY)->ResolveStaleFromCache()); | 1445 EXPECT_THAT(CreateRequest(info, DEFAULT_PRIORITY)->ResolveStaleFromCache(), |
| 1446 IsOk()); |
1424 EXPECT_TRUE(requests_[5]->HasOneAddress("192.168.1.42", 80)); | 1447 EXPECT_TRUE(requests_[5]->HasOneAddress("192.168.1.42", 80)); |
1425 EXPECT_TRUE(requests_[5]->staleness().is_stale()); | 1448 EXPECT_TRUE(requests_[5]->staleness().is_stale()); |
1426 } | 1449 } |
1427 | 1450 |
1428 // Test the retry attempts simulating host resolver proc that takes too long. | 1451 // Test the retry attempts simulating host resolver proc that takes too long. |
1429 TEST_F(HostResolverImplTest, MultipleAttempts) { | 1452 TEST_F(HostResolverImplTest, MultipleAttempts) { |
1430 // Total number of attempts would be 3 and we want the 3rd attempt to resolve | 1453 // Total number of attempts would be 3 and we want the 3rd attempt to resolve |
1431 // the host. First and second attempt will be forced to sleep until they get | 1454 // the host. First and second attempt will be forced to sleep until they get |
1432 // word that a resolution has completed. The 3rd resolution attempt will try | 1455 // word that a resolution has completed. The 3rd resolution attempt will try |
1433 // to get done ASAP, and won't sleep.. | 1456 // to get done ASAP, and won't sleep.. |
(...skipping 10 matching lines...) Expand all Loading... |
1444 // that unit test runs faster. For example, this test finishes in 1.5 secs | 1467 // that unit test runs faster. For example, this test finishes in 1.5 secs |
1445 // (500ms * 3). | 1468 // (500ms * 3). |
1446 params.unresponsive_delay = base::TimeDelta::FromMilliseconds(500); | 1469 params.unresponsive_delay = base::TimeDelta::FromMilliseconds(500); |
1447 | 1470 |
1448 resolver_.reset(new TestHostResolverImpl(DefaultOptions(), NULL)); | 1471 resolver_.reset(new TestHostResolverImpl(DefaultOptions(), NULL)); |
1449 resolver_->set_proc_params_for_test(params); | 1472 resolver_->set_proc_params_for_test(params); |
1450 | 1473 |
1451 // Resolve "host1". | 1474 // Resolve "host1". |
1452 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1475 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
1453 Request* req = CreateRequest(info, DEFAULT_PRIORITY); | 1476 Request* req = CreateRequest(info, DEFAULT_PRIORITY); |
1454 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1477 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
1455 | 1478 |
1456 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. | 1479 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. |
1457 EXPECT_EQ(-4, req->WaitForResult()); | 1480 EXPECT_EQ(-4, req->WaitForResult()); |
1458 | 1481 |
1459 resolver_proc->WaitForAllAttemptsToFinish( | 1482 resolver_proc->WaitForAllAttemptsToFinish( |
1460 base::TimeDelta::FromMilliseconds(60000)); | 1483 base::TimeDelta::FromMilliseconds(60000)); |
1461 base::RunLoop().RunUntilIdle(); | 1484 base::RunLoop().RunUntilIdle(); |
1462 | 1485 |
1463 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); | 1486 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); |
1464 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); | 1487 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); |
1465 } | 1488 } |
1466 | 1489 |
1467 // If a host resolves to a list that includes 127.0.53.53, this is treated as | 1490 // If a host resolves to a list that includes 127.0.53.53, this is treated as |
1468 // an error. 127.0.53.53 is a localhost address, however it has been given a | 1491 // an error. 127.0.53.53 is a localhost address, however it has been given a |
1469 // special significance by ICANN to help surfance name collision resulting from | 1492 // special significance by ICANN to help surfance name collision resulting from |
1470 // the new gTLDs. | 1493 // the new gTLDs. |
1471 TEST_F(HostResolverImplTest, NameCollision127_0_53_53) { | 1494 TEST_F(HostResolverImplTest, NameCollision127_0_53_53) { |
1472 proc_->AddRuleForAllFamilies("single", "127.0.53.53"); | 1495 proc_->AddRuleForAllFamilies("single", "127.0.53.53"); |
1473 proc_->AddRuleForAllFamilies("multiple", "127.0.0.1,127.0.53.53"); | 1496 proc_->AddRuleForAllFamilies("multiple", "127.0.0.1,127.0.53.53"); |
1474 proc_->AddRuleForAllFamilies("ipv6", "::127.0.53.53"); | 1497 proc_->AddRuleForAllFamilies("ipv6", "::127.0.53.53"); |
1475 proc_->AddRuleForAllFamilies("not_reserved1", "53.53.0.127"); | 1498 proc_->AddRuleForAllFamilies("not_reserved1", "53.53.0.127"); |
1476 proc_->AddRuleForAllFamilies("not_reserved2", "127.0.53.54"); | 1499 proc_->AddRuleForAllFamilies("not_reserved2", "127.0.53.54"); |
1477 proc_->AddRuleForAllFamilies("not_reserved3", "10.0.53.53"); | 1500 proc_->AddRuleForAllFamilies("not_reserved3", "10.0.53.53"); |
1478 proc_->SignalMultiple(6u); | 1501 proc_->SignalMultiple(6u); |
1479 | 1502 |
1480 Request* request; | 1503 Request* request; |
1481 | 1504 |
1482 request = CreateRequest("single"); | 1505 request = CreateRequest("single"); |
1483 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); | 1506 EXPECT_THAT(request->Resolve(), IsError(ERR_IO_PENDING)); |
1484 EXPECT_EQ(ERR_ICANN_NAME_COLLISION, request->WaitForResult()); | 1507 EXPECT_THAT(request->WaitForResult(), IsError(ERR_ICANN_NAME_COLLISION)); |
1485 | 1508 |
1486 request = CreateRequest("multiple"); | 1509 request = CreateRequest("multiple"); |
1487 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); | 1510 EXPECT_THAT(request->Resolve(), IsError(ERR_IO_PENDING)); |
1488 EXPECT_EQ(ERR_ICANN_NAME_COLLISION, request->WaitForResult()); | 1511 EXPECT_THAT(request->WaitForResult(), IsError(ERR_ICANN_NAME_COLLISION)); |
1489 | 1512 |
1490 // Resolving an IP literal of 127.0.53.53 however is allowed. | 1513 // Resolving an IP literal of 127.0.53.53 however is allowed. |
1491 EXPECT_EQ(OK, CreateRequest("127.0.53.53")->Resolve()); | 1514 EXPECT_THAT(CreateRequest("127.0.53.53")->Resolve(), IsOk()); |
1492 | 1515 |
1493 // Moreover the address should not be recognized when embedded in an IPv6 | 1516 // Moreover the address should not be recognized when embedded in an IPv6 |
1494 // address. | 1517 // address. |
1495 request = CreateRequest("ipv6"); | 1518 request = CreateRequest("ipv6"); |
1496 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); | 1519 EXPECT_THAT(request->Resolve(), IsError(ERR_IO_PENDING)); |
1497 EXPECT_EQ(OK, request->WaitForResult()); | 1520 EXPECT_THAT(request->WaitForResult(), IsOk()); |
1498 | 1521 |
1499 // Try some other IPs which are similar, but NOT an exact match on | 1522 // Try some other IPs which are similar, but NOT an exact match on |
1500 // 127.0.53.53. | 1523 // 127.0.53.53. |
1501 request = CreateRequest("not_reserved1"); | 1524 request = CreateRequest("not_reserved1"); |
1502 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); | 1525 EXPECT_THAT(request->Resolve(), IsError(ERR_IO_PENDING)); |
1503 EXPECT_EQ(OK, request->WaitForResult()); | 1526 EXPECT_THAT(request->WaitForResult(), IsOk()); |
1504 | 1527 |
1505 request = CreateRequest("not_reserved2"); | 1528 request = CreateRequest("not_reserved2"); |
1506 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); | 1529 EXPECT_THAT(request->Resolve(), IsError(ERR_IO_PENDING)); |
1507 EXPECT_EQ(OK, request->WaitForResult()); | 1530 EXPECT_THAT(request->WaitForResult(), IsOk()); |
1508 | 1531 |
1509 request = CreateRequest("not_reserved3"); | 1532 request = CreateRequest("not_reserved3"); |
1510 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); | 1533 EXPECT_THAT(request->Resolve(), IsError(ERR_IO_PENDING)); |
1511 EXPECT_EQ(OK, request->WaitForResult()); | 1534 EXPECT_THAT(request->WaitForResult(), IsOk()); |
1512 } | 1535 } |
1513 | 1536 |
1514 TEST_F(HostResolverImplTest, IsIPv6Reachable) { | 1537 TEST_F(HostResolverImplTest, IsIPv6Reachable) { |
1515 // The real HostResolverImpl is needed since TestHostResolverImpl will | 1538 // The real HostResolverImpl is needed since TestHostResolverImpl will |
1516 // bypass the IPv6 reachability tests. | 1539 // bypass the IPv6 reachability tests. |
1517 resolver_.reset(new HostResolverImpl(DefaultOptions(), nullptr)); | 1540 resolver_.reset(new HostResolverImpl(DefaultOptions(), nullptr)); |
1518 | 1541 |
1519 // Verify that two consecutive calls return the same value. | 1542 // Verify that two consecutive calls return the same value. |
1520 TestNetLog net_log; | 1543 TestNetLog net_log; |
1521 BoundNetLog bound_net_log = BoundNetLog::Make(&net_log, NetLog::SOURCE_NONE); | 1544 BoundNetLog bound_net_log = BoundNetLog::Make(&net_log, NetLog::SOURCE_NONE); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1630 // TODO(szym): Test AbortAllInProgressJobs due to DnsConfig change. | 1653 // TODO(szym): Test AbortAllInProgressJobs due to DnsConfig change. |
1631 | 1654 |
1632 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1655 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
1633 | 1656 |
1634 // Test successful and fallback resolutions in HostResolverImpl::DnsTask. | 1657 // Test successful and fallback resolutions in HostResolverImpl::DnsTask. |
1635 TEST_F(HostResolverImplDnsTest, DnsTask) { | 1658 TEST_F(HostResolverImplDnsTest, DnsTask) { |
1636 proc_->AddRuleForAllFamilies("nx_succeed", "192.168.1.102"); | 1659 proc_->AddRuleForAllFamilies("nx_succeed", "192.168.1.102"); |
1637 // All other hostnames will fail in proc_. | 1660 // All other hostnames will fail in proc_. |
1638 | 1661 |
1639 // Initially there is no config, so client should not be invoked. | 1662 // Initially there is no config, so client should not be invoked. |
1640 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve()); | 1663 EXPECT_THAT(CreateRequest("ok_fail", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
1641 proc_->SignalMultiple(requests_.size()); | 1664 proc_->SignalMultiple(requests_.size()); |
1642 | 1665 |
1643 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[0]->WaitForResult()); | 1666 EXPECT_THAT(requests_[0]->WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
1644 | 1667 |
1645 ChangeDnsConfig(CreateValidDnsConfig()); | 1668 ChangeDnsConfig(CreateValidDnsConfig()); |
1646 | 1669 |
1647 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80, MEDIUM, | 1670 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80, MEDIUM, |
1648 ADDRESS_FAMILY_IPV4)->Resolve()); | 1671 ADDRESS_FAMILY_IPV4)->Resolve()); |
1649 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_fail", 80, MEDIUM, | 1672 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_fail", 80, MEDIUM, |
1650 ADDRESS_FAMILY_IPV4)->Resolve()); | 1673 ADDRESS_FAMILY_IPV4)->Resolve()); |
1651 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_succeed", 80, MEDIUM, | 1674 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_succeed", 80, MEDIUM, |
1652 ADDRESS_FAMILY_IPV4)->Resolve()); | 1675 ADDRESS_FAMILY_IPV4)->Resolve()); |
1653 | 1676 |
1654 proc_->SignalMultiple(requests_.size()); | 1677 proc_->SignalMultiple(requests_.size()); |
1655 | 1678 |
1656 for (size_t i = 1; i < requests_.size(); ++i) | 1679 for (size_t i = 1; i < requests_.size(); ++i) |
1657 EXPECT_NE(ERR_UNEXPECTED, requests_[i]->WaitForResult()) << i; | 1680 EXPECT_NE(ERR_UNEXPECTED, requests_[i]->WaitForResult()) << i; |
1658 | 1681 |
1659 EXPECT_EQ(OK, requests_[1]->result()); | 1682 EXPECT_THAT(requests_[1]->result(), IsOk()); |
1660 // Resolved by MockDnsClient. | 1683 // Resolved by MockDnsClient. |
1661 EXPECT_TRUE(requests_[1]->HasOneAddress("127.0.0.1", 80)); | 1684 EXPECT_TRUE(requests_[1]->HasOneAddress("127.0.0.1", 80)); |
1662 // Fallback to ProcTask. | 1685 // Fallback to ProcTask. |
1663 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[2]->result()); | 1686 EXPECT_THAT(requests_[2]->result(), IsError(ERR_NAME_NOT_RESOLVED)); |
1664 EXPECT_EQ(OK, requests_[3]->result()); | 1687 EXPECT_THAT(requests_[3]->result(), IsOk()); |
1665 EXPECT_TRUE(requests_[3]->HasOneAddress("192.168.1.102", 80)); | 1688 EXPECT_TRUE(requests_[3]->HasOneAddress("192.168.1.102", 80)); |
1666 } | 1689 } |
1667 | 1690 |
1668 // Test successful and failing resolutions in HostResolverImpl::DnsTask when | 1691 // Test successful and failing resolutions in HostResolverImpl::DnsTask when |
1669 // fallback to ProcTask is disabled. | 1692 // fallback to ProcTask is disabled. |
1670 TEST_F(HostResolverImplDnsTest, NoFallbackToProcTask) { | 1693 TEST_F(HostResolverImplDnsTest, NoFallbackToProcTask) { |
1671 set_fallback_to_proctask(false); | 1694 set_fallback_to_proctask(false); |
1672 | 1695 |
1673 proc_->AddRuleForAllFamilies("nx_succeed", "192.168.1.102"); | 1696 proc_->AddRuleForAllFamilies("nx_succeed", "192.168.1.102"); |
1674 // All other hostnames will fail in proc_. | 1697 // All other hostnames will fail in proc_. |
1675 | 1698 |
1676 // Set empty DnsConfig. | 1699 // Set empty DnsConfig. |
1677 ChangeDnsConfig(DnsConfig()); | 1700 ChangeDnsConfig(DnsConfig()); |
1678 // Initially there is no config, so client should not be invoked. | 1701 // Initially there is no config, so client should not be invoked. |
1679 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve()); | 1702 EXPECT_THAT(CreateRequest("ok_fail", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
1680 // There is no config, so fallback to ProcTask must work. | 1703 // There is no config, so fallback to ProcTask must work. |
1681 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_succeed", 80)->Resolve()); | 1704 EXPECT_THAT(CreateRequest("nx_succeed", 80)->Resolve(), |
| 1705 IsError(ERR_IO_PENDING)); |
1682 proc_->SignalMultiple(requests_.size()); | 1706 proc_->SignalMultiple(requests_.size()); |
1683 | 1707 |
1684 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[0]->WaitForResult()); | 1708 EXPECT_THAT(requests_[0]->WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
1685 EXPECT_EQ(OK, requests_[1]->WaitForResult()); | 1709 EXPECT_THAT(requests_[1]->WaitForResult(), IsOk()); |
1686 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.1.102", 80)); | 1710 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.1.102", 80)); |
1687 | 1711 |
1688 ChangeDnsConfig(CreateValidDnsConfig()); | 1712 ChangeDnsConfig(CreateValidDnsConfig()); |
1689 | 1713 |
1690 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_abort", 80, MEDIUM, | 1714 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_abort", 80, MEDIUM, |
1691 ADDRESS_FAMILY_IPV4)->Resolve()); | 1715 ADDRESS_FAMILY_IPV4)->Resolve()); |
1692 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80, MEDIUM, | 1716 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80, MEDIUM, |
1693 ADDRESS_FAMILY_IPV4)->Resolve()); | 1717 ADDRESS_FAMILY_IPV4)->Resolve()); |
1694 | 1718 |
1695 // Simulate the case when the preference or policy has disabled the DNS client | 1719 // Simulate the case when the preference or policy has disabled the DNS client |
1696 // causing AbortDnsTasks. | 1720 // causing AbortDnsTasks. |
1697 resolver_->SetDnsClient( | 1721 resolver_->SetDnsClient( |
1698 std::unique_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_))); | 1722 std::unique_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_))); |
1699 ChangeDnsConfig(CreateValidDnsConfig()); | 1723 ChangeDnsConfig(CreateValidDnsConfig()); |
1700 | 1724 |
1701 // First request is resolved by MockDnsClient, others should fail due to | 1725 // First request is resolved by MockDnsClient, others should fail due to |
1702 // disabled fallback to ProcTask. | 1726 // disabled fallback to ProcTask. |
1703 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80, MEDIUM, | 1727 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80, MEDIUM, |
1704 ADDRESS_FAMILY_IPV4)->Resolve()); | 1728 ADDRESS_FAMILY_IPV4)->Resolve()); |
1705 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_fail", 80, MEDIUM, | 1729 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_fail", 80, MEDIUM, |
1706 ADDRESS_FAMILY_IPV4)->Resolve()); | 1730 ADDRESS_FAMILY_IPV4)->Resolve()); |
1707 proc_->SignalMultiple(requests_.size()); | 1731 proc_->SignalMultiple(requests_.size()); |
1708 | 1732 |
1709 // Aborted due to Network Change. | 1733 // Aborted due to Network Change. |
1710 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[2]->WaitForResult()); | 1734 EXPECT_THAT(requests_[2]->WaitForResult(), IsError(ERR_NETWORK_CHANGED)); |
1711 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[3]->WaitForResult()); | 1735 EXPECT_THAT(requests_[3]->WaitForResult(), IsError(ERR_NETWORK_CHANGED)); |
1712 // Resolved by MockDnsClient. | 1736 // Resolved by MockDnsClient. |
1713 EXPECT_EQ(OK, requests_[4]->WaitForResult()); | 1737 EXPECT_THAT(requests_[4]->WaitForResult(), IsOk()); |
1714 EXPECT_TRUE(requests_[4]->HasOneAddress("127.0.0.1", 80)); | 1738 EXPECT_TRUE(requests_[4]->HasOneAddress("127.0.0.1", 80)); |
1715 // Fallback to ProcTask is disabled. | 1739 // Fallback to ProcTask is disabled. |
1716 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[5]->WaitForResult()); | 1740 EXPECT_THAT(requests_[5]->WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
1717 } | 1741 } |
1718 | 1742 |
1719 // Test behavior of OnDnsTaskFailure when Job is aborted. | 1743 // Test behavior of OnDnsTaskFailure when Job is aborted. |
1720 TEST_F(HostResolverImplDnsTest, OnDnsTaskFailureAbortedJob) { | 1744 TEST_F(HostResolverImplDnsTest, OnDnsTaskFailureAbortedJob) { |
1721 ChangeDnsConfig(CreateValidDnsConfig()); | 1745 ChangeDnsConfig(CreateValidDnsConfig()); |
1722 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); | 1746 EXPECT_THAT(CreateRequest("nx_abort", 80)->Resolve(), |
| 1747 IsError(ERR_IO_PENDING)); |
1723 // Abort all jobs here. | 1748 // Abort all jobs here. |
1724 CreateResolver(); | 1749 CreateResolver(); |
1725 proc_->SignalMultiple(requests_.size()); | 1750 proc_->SignalMultiple(requests_.size()); |
1726 // Run to completion. | 1751 // Run to completion. |
1727 base::RunLoop().RunUntilIdle(); // Notification happens async. | 1752 base::RunLoop().RunUntilIdle(); // Notification happens async. |
1728 // It shouldn't crash during OnDnsTaskFailure callbacks. | 1753 // It shouldn't crash during OnDnsTaskFailure callbacks. |
1729 EXPECT_EQ(ERR_IO_PENDING, requests_[0]->result()); | 1754 EXPECT_THAT(requests_[0]->result(), IsError(ERR_IO_PENDING)); |
1730 | 1755 |
1731 // Repeat test with Fallback to ProcTask disabled | 1756 // Repeat test with Fallback to ProcTask disabled |
1732 set_fallback_to_proctask(false); | 1757 set_fallback_to_proctask(false); |
1733 ChangeDnsConfig(CreateValidDnsConfig()); | 1758 ChangeDnsConfig(CreateValidDnsConfig()); |
1734 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); | 1759 EXPECT_THAT(CreateRequest("nx_abort", 80)->Resolve(), |
| 1760 IsError(ERR_IO_PENDING)); |
1735 // Abort all jobs here. | 1761 // Abort all jobs here. |
1736 CreateResolver(); | 1762 CreateResolver(); |
1737 // Run to completion. | 1763 // Run to completion. |
1738 base::RunLoop().RunUntilIdle(); // Notification happens async. | 1764 base::RunLoop().RunUntilIdle(); // Notification happens async. |
1739 // It shouldn't crash during OnDnsTaskFailure callbacks. | 1765 // It shouldn't crash during OnDnsTaskFailure callbacks. |
1740 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->result()); | 1766 EXPECT_THAT(requests_[1]->result(), IsError(ERR_IO_PENDING)); |
1741 } | 1767 } |
1742 | 1768 |
1743 TEST_F(HostResolverImplDnsTest, DnsTaskUnspec) { | 1769 TEST_F(HostResolverImplDnsTest, DnsTaskUnspec) { |
1744 ChangeDnsConfig(CreateValidDnsConfig()); | 1770 ChangeDnsConfig(CreateValidDnsConfig()); |
1745 | 1771 |
1746 proc_->AddRuleForAllFamilies("4nx", "192.168.1.101"); | 1772 proc_->AddRuleForAllFamilies("4nx", "192.168.1.101"); |
1747 // All other hostnames will fail in proc_. | 1773 // All other hostnames will fail in proc_. |
1748 | 1774 |
1749 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); | 1775 EXPECT_THAT(CreateRequest("ok", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
1750 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4ok", 80)->Resolve()); | 1776 EXPECT_THAT(CreateRequest("4ok", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
1751 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("6ok", 80)->Resolve()); | 1777 EXPECT_THAT(CreateRequest("6ok", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
1752 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4nx", 80)->Resolve()); | 1778 EXPECT_THAT(CreateRequest("4nx", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
1753 | 1779 |
1754 proc_->SignalMultiple(requests_.size()); | 1780 proc_->SignalMultiple(requests_.size()); |
1755 | 1781 |
1756 for (size_t i = 0; i < requests_.size(); ++i) | 1782 for (size_t i = 0; i < requests_.size(); ++i) |
1757 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; | 1783 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; |
1758 | 1784 |
1759 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); | 1785 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); |
1760 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); | 1786 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); |
1761 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); | 1787 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); |
1762 EXPECT_EQ(1u, requests_[1]->NumberOfAddresses()); | 1788 EXPECT_EQ(1u, requests_[1]->NumberOfAddresses()); |
1763 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80)); | 1789 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80)); |
1764 EXPECT_EQ(1u, requests_[2]->NumberOfAddresses()); | 1790 EXPECT_EQ(1u, requests_[2]->NumberOfAddresses()); |
1765 EXPECT_TRUE(requests_[2]->HasAddress("::1", 80)); | 1791 EXPECT_TRUE(requests_[2]->HasAddress("::1", 80)); |
1766 EXPECT_EQ(1u, requests_[3]->NumberOfAddresses()); | 1792 EXPECT_EQ(1u, requests_[3]->NumberOfAddresses()); |
1767 EXPECT_TRUE(requests_[3]->HasAddress("192.168.1.101", 80)); | 1793 EXPECT_TRUE(requests_[3]->HasAddress("192.168.1.101", 80)); |
1768 } | 1794 } |
1769 | 1795 |
1770 TEST_F(HostResolverImplDnsTest, ServeFromHosts) { | 1796 TEST_F(HostResolverImplDnsTest, ServeFromHosts) { |
1771 // Initially, use empty HOSTS file. | 1797 // Initially, use empty HOSTS file. |
1772 DnsConfig config = CreateValidDnsConfig(); | 1798 DnsConfig config = CreateValidDnsConfig(); |
1773 ChangeDnsConfig(config); | 1799 ChangeDnsConfig(config); |
1774 | 1800 |
1775 proc_->AddRuleForAllFamilies(std::string(), | 1801 proc_->AddRuleForAllFamilies(std::string(), |
1776 std::string()); // Default to failures. | 1802 std::string()); // Default to failures. |
1777 proc_->SignalMultiple(1u); // For the first request which misses. | 1803 proc_->SignalMultiple(1u); // For the first request which misses. |
1778 | 1804 |
1779 Request* req0 = CreateRequest("nx_ipv4", 80); | 1805 Request* req0 = CreateRequest("nx_ipv4", 80); |
1780 EXPECT_EQ(ERR_IO_PENDING, req0->Resolve()); | 1806 EXPECT_THAT(req0->Resolve(), IsError(ERR_IO_PENDING)); |
1781 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req0->WaitForResult()); | 1807 EXPECT_THAT(req0->WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
1782 | 1808 |
1783 IPAddress local_ipv4 = IPAddress::IPv4Localhost(); | 1809 IPAddress local_ipv4 = IPAddress::IPv4Localhost(); |
1784 IPAddress local_ipv6 = IPAddress::IPv6Localhost(); | 1810 IPAddress local_ipv6 = IPAddress::IPv6Localhost(); |
1785 | 1811 |
1786 DnsHosts hosts; | 1812 DnsHosts hosts; |
1787 hosts[DnsHostsKey("nx_ipv4", ADDRESS_FAMILY_IPV4)] = local_ipv4; | 1813 hosts[DnsHostsKey("nx_ipv4", ADDRESS_FAMILY_IPV4)] = local_ipv4; |
1788 hosts[DnsHostsKey("nx_ipv6", ADDRESS_FAMILY_IPV6)] = local_ipv6; | 1814 hosts[DnsHostsKey("nx_ipv6", ADDRESS_FAMILY_IPV6)] = local_ipv6; |
1789 hosts[DnsHostsKey("nx_both", ADDRESS_FAMILY_IPV4)] = local_ipv4; | 1815 hosts[DnsHostsKey("nx_both", ADDRESS_FAMILY_IPV4)] = local_ipv4; |
1790 hosts[DnsHostsKey("nx_both", ADDRESS_FAMILY_IPV6)] = local_ipv6; | 1816 hosts[DnsHostsKey("nx_both", ADDRESS_FAMILY_IPV6)] = local_ipv6; |
1791 | 1817 |
1792 // Update HOSTS file. | 1818 // Update HOSTS file. |
1793 config.hosts = hosts; | 1819 config.hosts = hosts; |
1794 ChangeDnsConfig(config); | 1820 ChangeDnsConfig(config); |
1795 | 1821 |
1796 Request* req1 = CreateRequest("nx_ipv4", 80); | 1822 Request* req1 = CreateRequest("nx_ipv4", 80); |
1797 EXPECT_EQ(OK, req1->Resolve()); | 1823 EXPECT_THAT(req1->Resolve(), IsOk()); |
1798 EXPECT_TRUE(req1->HasOneAddress("127.0.0.1", 80)); | 1824 EXPECT_TRUE(req1->HasOneAddress("127.0.0.1", 80)); |
1799 | 1825 |
1800 Request* req2 = CreateRequest("nx_ipv6", 80); | 1826 Request* req2 = CreateRequest("nx_ipv6", 80); |
1801 EXPECT_EQ(OK, req2->Resolve()); | 1827 EXPECT_THAT(req2->Resolve(), IsOk()); |
1802 EXPECT_TRUE(req2->HasOneAddress("::1", 80)); | 1828 EXPECT_TRUE(req2->HasOneAddress("::1", 80)); |
1803 | 1829 |
1804 Request* req3 = CreateRequest("nx_both", 80); | 1830 Request* req3 = CreateRequest("nx_both", 80); |
1805 EXPECT_EQ(OK, req3->Resolve()); | 1831 EXPECT_THAT(req3->Resolve(), IsOk()); |
1806 EXPECT_TRUE(req3->HasAddress("127.0.0.1", 80) && | 1832 EXPECT_TRUE(req3->HasAddress("127.0.0.1", 80) && |
1807 req3->HasAddress("::1", 80)); | 1833 req3->HasAddress("::1", 80)); |
1808 | 1834 |
1809 // Requests with specified AddressFamily. | 1835 // Requests with specified AddressFamily. |
1810 Request* req4 = CreateRequest("nx_ipv4", 80, MEDIUM, ADDRESS_FAMILY_IPV4); | 1836 Request* req4 = CreateRequest("nx_ipv4", 80, MEDIUM, ADDRESS_FAMILY_IPV4); |
1811 EXPECT_EQ(OK, req4->Resolve()); | 1837 EXPECT_THAT(req4->Resolve(), IsOk()); |
1812 EXPECT_TRUE(req4->HasOneAddress("127.0.0.1", 80)); | 1838 EXPECT_TRUE(req4->HasOneAddress("127.0.0.1", 80)); |
1813 | 1839 |
1814 Request* req5 = CreateRequest("nx_ipv6", 80, MEDIUM, ADDRESS_FAMILY_IPV6); | 1840 Request* req5 = CreateRequest("nx_ipv6", 80, MEDIUM, ADDRESS_FAMILY_IPV6); |
1815 EXPECT_EQ(OK, req5->Resolve()); | 1841 EXPECT_THAT(req5->Resolve(), IsOk()); |
1816 EXPECT_TRUE(req5->HasOneAddress("::1", 80)); | 1842 EXPECT_TRUE(req5->HasOneAddress("::1", 80)); |
1817 | 1843 |
1818 // Request with upper case. | 1844 // Request with upper case. |
1819 Request* req6 = CreateRequest("nx_IPV4", 80); | 1845 Request* req6 = CreateRequest("nx_IPV4", 80); |
1820 EXPECT_EQ(OK, req6->Resolve()); | 1846 EXPECT_THAT(req6->Resolve(), IsOk()); |
1821 EXPECT_TRUE(req6->HasOneAddress("127.0.0.1", 80)); | 1847 EXPECT_TRUE(req6->HasOneAddress("127.0.0.1", 80)); |
1822 } | 1848 } |
1823 | 1849 |
1824 TEST_F(HostResolverImplDnsTest, BypassDnsTask) { | 1850 TEST_F(HostResolverImplDnsTest, BypassDnsTask) { |
1825 ChangeDnsConfig(CreateValidDnsConfig()); | 1851 ChangeDnsConfig(CreateValidDnsConfig()); |
1826 | 1852 |
1827 proc_->AddRuleForAllFamilies(std::string(), | 1853 proc_->AddRuleForAllFamilies(std::string(), |
1828 std::string()); // Default to failures. | 1854 std::string()); // Default to failures. |
1829 | 1855 |
1830 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok.local", 80)->Resolve()); | 1856 EXPECT_THAT(CreateRequest("ok.local", 80)->Resolve(), |
1831 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok.local.", 80)->Resolve()); | 1857 IsError(ERR_IO_PENDING)); |
1832 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("oklocal", 80)->Resolve()); | 1858 EXPECT_THAT(CreateRequest("ok.local.", 80)->Resolve(), |
1833 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("oklocal.", 80)->Resolve()); | 1859 IsError(ERR_IO_PENDING)); |
1834 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); | 1860 EXPECT_THAT(CreateRequest("oklocal", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
| 1861 EXPECT_THAT(CreateRequest("oklocal.", 80)->Resolve(), |
| 1862 IsError(ERR_IO_PENDING)); |
| 1863 EXPECT_THAT(CreateRequest("ok", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
1835 | 1864 |
1836 proc_->SignalMultiple(requests_.size()); | 1865 proc_->SignalMultiple(requests_.size()); |
1837 | 1866 |
1838 for (size_t i = 0; i < 2; ++i) | 1867 for (size_t i = 0; i < 2; ++i) |
1839 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[i]->WaitForResult()) << i; | 1868 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[i]->WaitForResult()) << i; |
1840 | 1869 |
1841 for (size_t i = 2; i < requests_.size(); ++i) | 1870 for (size_t i = 2; i < requests_.size(); ++i) |
1842 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; | 1871 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; |
1843 } | 1872 } |
1844 | 1873 |
1845 TEST_F(HostResolverImplDnsTest, SystemOnlyBypassesDnsTask) { | 1874 TEST_F(HostResolverImplDnsTest, SystemOnlyBypassesDnsTask) { |
1846 ChangeDnsConfig(CreateValidDnsConfig()); | 1875 ChangeDnsConfig(CreateValidDnsConfig()); |
1847 | 1876 |
1848 proc_->AddRuleForAllFamilies(std::string(), std::string()); | 1877 proc_->AddRuleForAllFamilies(std::string(), std::string()); |
1849 | 1878 |
1850 HostResolver::RequestInfo info_bypass(HostPortPair("ok", 80)); | 1879 HostResolver::RequestInfo info_bypass(HostPortPair("ok", 80)); |
1851 info_bypass.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY); | 1880 info_bypass.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY); |
1852 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(info_bypass, MEDIUM)->Resolve()); | 1881 EXPECT_THAT(CreateRequest(info_bypass, MEDIUM)->Resolve(), |
| 1882 IsError(ERR_IO_PENDING)); |
1853 | 1883 |
1854 HostResolver::RequestInfo info(HostPortPair("ok", 80)); | 1884 HostResolver::RequestInfo info(HostPortPair("ok", 80)); |
1855 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(info, MEDIUM)->Resolve()); | 1885 EXPECT_THAT(CreateRequest(info, MEDIUM)->Resolve(), IsError(ERR_IO_PENDING)); |
1856 | 1886 |
1857 proc_->SignalMultiple(requests_.size()); | 1887 proc_->SignalMultiple(requests_.size()); |
1858 | 1888 |
1859 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[0]->WaitForResult()); | 1889 EXPECT_THAT(requests_[0]->WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
1860 EXPECT_EQ(OK, requests_[1]->WaitForResult()); | 1890 EXPECT_THAT(requests_[1]->WaitForResult(), IsOk()); |
1861 } | 1891 } |
1862 | 1892 |
1863 TEST_F(HostResolverImplDnsTest, DisableDnsClientOnPersistentFailure) { | 1893 TEST_F(HostResolverImplDnsTest, DisableDnsClientOnPersistentFailure) { |
1864 ChangeDnsConfig(CreateValidDnsConfig()); | 1894 ChangeDnsConfig(CreateValidDnsConfig()); |
1865 | 1895 |
1866 proc_->AddRuleForAllFamilies(std::string(), | 1896 proc_->AddRuleForAllFamilies(std::string(), |
1867 std::string()); // Default to failures. | 1897 std::string()); // Default to failures. |
1868 | 1898 |
1869 // Check that DnsTask works. | 1899 // Check that DnsTask works. |
1870 Request* req = CreateRequest("ok_1", 80); | 1900 Request* req = CreateRequest("ok_1", 80); |
1871 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1901 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
1872 EXPECT_EQ(OK, req->WaitForResult()); | 1902 EXPECT_THAT(req->WaitForResult(), IsOk()); |
1873 | 1903 |
1874 for (unsigned i = 0; i < maximum_dns_failures(); ++i) { | 1904 for (unsigned i = 0; i < maximum_dns_failures(); ++i) { |
1875 // Use custom names to require separate Jobs. | 1905 // Use custom names to require separate Jobs. |
1876 std::string hostname = base::StringPrintf("nx_%u", i); | 1906 std::string hostname = base::StringPrintf("nx_%u", i); |
1877 // Ensure fallback to ProcTask succeeds. | 1907 // Ensure fallback to ProcTask succeeds. |
1878 proc_->AddRuleForAllFamilies(hostname, "192.168.1.101"); | 1908 proc_->AddRuleForAllFamilies(hostname, "192.168.1.101"); |
1879 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(hostname, 80)->Resolve()) << i; | 1909 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(hostname, 80)->Resolve()) << i; |
1880 } | 1910 } |
1881 | 1911 |
1882 proc_->SignalMultiple(requests_.size()); | 1912 proc_->SignalMultiple(requests_.size()); |
1883 | 1913 |
1884 for (size_t i = 0; i < requests_.size(); ++i) | 1914 for (size_t i = 0; i < requests_.size(); ++i) |
1885 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; | 1915 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; |
1886 | 1916 |
1887 ASSERT_FALSE(proc_->HasBlockedRequests()); | 1917 ASSERT_FALSE(proc_->HasBlockedRequests()); |
1888 | 1918 |
1889 // DnsTask should be disabled by now. | 1919 // DnsTask should be disabled by now. |
1890 req = CreateRequest("ok_2", 80); | 1920 req = CreateRequest("ok_2", 80); |
1891 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1921 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
1892 proc_->SignalMultiple(1u); | 1922 proc_->SignalMultiple(1u); |
1893 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->WaitForResult()); | 1923 EXPECT_THAT(req->WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
1894 | 1924 |
1895 // Check that it is re-enabled after DNS change. | 1925 // Check that it is re-enabled after DNS change. |
1896 ChangeDnsConfig(CreateValidDnsConfig()); | 1926 ChangeDnsConfig(CreateValidDnsConfig()); |
1897 req = CreateRequest("ok_3", 80); | 1927 req = CreateRequest("ok_3", 80); |
1898 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1928 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
1899 EXPECT_EQ(OK, req->WaitForResult()); | 1929 EXPECT_THAT(req->WaitForResult(), IsOk()); |
1900 } | 1930 } |
1901 | 1931 |
1902 TEST_F(HostResolverImplDnsTest, DontDisableDnsClientOnSporadicFailure) { | 1932 TEST_F(HostResolverImplDnsTest, DontDisableDnsClientOnSporadicFailure) { |
1903 ChangeDnsConfig(CreateValidDnsConfig()); | 1933 ChangeDnsConfig(CreateValidDnsConfig()); |
1904 | 1934 |
1905 // |proc_| defaults to successes. | 1935 // |proc_| defaults to successes. |
1906 | 1936 |
1907 // 20 failures interleaved with 20 successes. | 1937 // 20 failures interleaved with 20 successes. |
1908 for (unsigned i = 0; i < 40; ++i) { | 1938 for (unsigned i = 0; i < 40; ++i) { |
1909 // Use custom names to require separate Jobs. | 1939 // Use custom names to require separate Jobs. |
1910 std::string hostname = (i % 2) == 0 ? base::StringPrintf("nx_%u", i) | 1940 std::string hostname = (i % 2) == 0 ? base::StringPrintf("nx_%u", i) |
1911 : base::StringPrintf("ok_%u", i); | 1941 : base::StringPrintf("ok_%u", i); |
1912 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(hostname, 80)->Resolve()) << i; | 1942 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(hostname, 80)->Resolve()) << i; |
1913 } | 1943 } |
1914 | 1944 |
1915 proc_->SignalMultiple(requests_.size()); | 1945 proc_->SignalMultiple(requests_.size()); |
1916 | 1946 |
1917 for (size_t i = 0; i < requests_.size(); ++i) | 1947 for (size_t i = 0; i < requests_.size(); ++i) |
1918 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; | 1948 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; |
1919 | 1949 |
1920 // Make |proc_| default to failures. | 1950 // Make |proc_| default to failures. |
1921 proc_->AddRuleForAllFamilies(std::string(), std::string()); | 1951 proc_->AddRuleForAllFamilies(std::string(), std::string()); |
1922 | 1952 |
1923 // DnsTask should still be enabled. | 1953 // DnsTask should still be enabled. |
1924 Request* req = CreateRequest("ok_last", 80); | 1954 Request* req = CreateRequest("ok_last", 80); |
1925 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1955 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); |
1926 EXPECT_EQ(OK, req->WaitForResult()); | 1956 EXPECT_THAT(req->WaitForResult(), IsOk()); |
1927 } | 1957 } |
1928 | 1958 |
1929 // Confirm that resolving "localhost" is unrestricted even if there are no | 1959 // Confirm that resolving "localhost" is unrestricted even if there are no |
1930 // global IPv6 address. See SystemHostResolverCall for rationale. | 1960 // global IPv6 address. See SystemHostResolverCall for rationale. |
1931 // Test both the DnsClient and system host resolver paths. | 1961 // Test both the DnsClient and system host resolver paths. |
1932 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) { | 1962 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) { |
1933 // Use regular SystemHostResolverCall! | 1963 // Use regular SystemHostResolverCall! |
1934 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc()); | 1964 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc()); |
1935 resolver_.reset(new TestHostResolverImpl(DefaultOptions(), NULL, false)); | 1965 resolver_.reset(new TestHostResolverImpl(DefaultOptions(), NULL, false)); |
1936 resolver_->set_proc_params_for_test(DefaultParams(proc.get())); | 1966 resolver_->set_proc_params_for_test(DefaultParams(proc.get())); |
(...skipping 18 matching lines...) Expand all Loading... |
1955 | 1985 |
1956 // Try without DnsClient. | 1986 // Try without DnsClient. |
1957 DnsConfig config = CreateValidDnsConfig(); | 1987 DnsConfig config = CreateValidDnsConfig(); |
1958 config.use_local_ipv6 = false; | 1988 config.use_local_ipv6 = false; |
1959 ChangeDnsConfig(config); | 1989 ChangeDnsConfig(config); |
1960 HostResolver::RequestInfo info_proc(HostPortPair("localhost", 80)); | 1990 HostResolver::RequestInfo info_proc(HostPortPair("localhost", 80)); |
1961 info_proc.set_address_family(ADDRESS_FAMILY_UNSPECIFIED); | 1991 info_proc.set_address_family(ADDRESS_FAMILY_UNSPECIFIED); |
1962 info_proc.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY); | 1992 info_proc.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY); |
1963 Request* req = CreateRequest(info_proc, DEFAULT_PRIORITY); | 1993 Request* req = CreateRequest(info_proc, DEFAULT_PRIORITY); |
1964 | 1994 |
1965 EXPECT_EQ(OK, req->Resolve()); | 1995 EXPECT_THAT(req->Resolve(), IsOk()); |
1966 | 1996 |
1967 EXPECT_TRUE(req->HasAddress("127.0.0.1", 80)); | 1997 EXPECT_TRUE(req->HasAddress("127.0.0.1", 80)); |
1968 EXPECT_TRUE(req->HasAddress("::1", 80)); | 1998 EXPECT_TRUE(req->HasAddress("::1", 80)); |
1969 | 1999 |
1970 // Configure DnsClient with dual-host HOSTS file. | 2000 // Configure DnsClient with dual-host HOSTS file. |
1971 DnsConfig config_hosts = CreateValidDnsConfig(); | 2001 DnsConfig config_hosts = CreateValidDnsConfig(); |
1972 DnsHosts hosts; | 2002 DnsHosts hosts; |
1973 IPAddress local_ipv4 = IPAddress::IPv4Localhost(); | 2003 IPAddress local_ipv4 = IPAddress::IPv4Localhost(); |
1974 IPAddress local_ipv6 = IPAddress::IPv6Localhost(); | 2004 IPAddress local_ipv6 = IPAddress::IPv6Localhost(); |
1975 if (saw_ipv4) | 2005 if (saw_ipv4) |
1976 hosts[DnsHostsKey("localhost", ADDRESS_FAMILY_IPV4)] = local_ipv4; | 2006 hosts[DnsHostsKey("localhost", ADDRESS_FAMILY_IPV4)] = local_ipv4; |
1977 if (saw_ipv6) | 2007 if (saw_ipv6) |
1978 hosts[DnsHostsKey("localhost", ADDRESS_FAMILY_IPV6)] = local_ipv6; | 2008 hosts[DnsHostsKey("localhost", ADDRESS_FAMILY_IPV6)] = local_ipv6; |
1979 config_hosts.hosts = hosts; | 2009 config_hosts.hosts = hosts; |
1980 | 2010 |
1981 ChangeDnsConfig(config_hosts); | 2011 ChangeDnsConfig(config_hosts); |
1982 HostResolver::RequestInfo info_hosts(HostPortPair("localhost", 80)); | 2012 HostResolver::RequestInfo info_hosts(HostPortPair("localhost", 80)); |
1983 info_hosts.set_address_family(ADDRESS_FAMILY_UNSPECIFIED); | 2013 info_hosts.set_address_family(ADDRESS_FAMILY_UNSPECIFIED); |
1984 req = CreateRequest(info_hosts, DEFAULT_PRIORITY); | 2014 req = CreateRequest(info_hosts, DEFAULT_PRIORITY); |
1985 // Expect synchronous resolution from DnsHosts. | 2015 // Expect synchronous resolution from DnsHosts. |
1986 EXPECT_EQ(OK, req->Resolve()); | 2016 EXPECT_THAT(req->Resolve(), IsOk()); |
1987 | 2017 |
1988 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80)); | 2018 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80)); |
1989 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80)); | 2019 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80)); |
1990 } | 2020 } |
1991 | 2021 |
1992 // Cancel a request with a single DNS transaction active. | 2022 // Cancel a request with a single DNS transaction active. |
1993 TEST_F(HostResolverImplDnsTest, CancelWithOneTransactionActive) { | 2023 TEST_F(HostResolverImplDnsTest, CancelWithOneTransactionActive) { |
1994 ChangeDnsConfig(CreateValidDnsConfig()); | 2024 ChangeDnsConfig(CreateValidDnsConfig()); |
1995 | 2025 |
1996 EXPECT_EQ(ERR_IO_PENDING, | 2026 EXPECT_EQ(ERR_IO_PENDING, |
1997 CreateRequest("ok", 80, MEDIUM, ADDRESS_FAMILY_IPV4)->Resolve()); | 2027 CreateRequest("ok", 80, MEDIUM, ADDRESS_FAMILY_IPV4)->Resolve()); |
1998 EXPECT_EQ(1u, num_running_dispatcher_jobs()); | 2028 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
1999 requests_[0]->Cancel(); | 2029 requests_[0]->Cancel(); |
2000 | 2030 |
2001 // Dispatcher state checked in TearDown. | 2031 // Dispatcher state checked in TearDown. |
2002 } | 2032 } |
2003 | 2033 |
2004 // Cancel a request with a single DNS transaction active and another pending. | 2034 // Cancel a request with a single DNS transaction active and another pending. |
2005 TEST_F(HostResolverImplDnsTest, CancelWithOneTransactionActiveOnePending) { | 2035 TEST_F(HostResolverImplDnsTest, CancelWithOneTransactionActiveOnePending) { |
2006 CreateSerialResolver(); | 2036 CreateSerialResolver(); |
2007 ChangeDnsConfig(CreateValidDnsConfig()); | 2037 ChangeDnsConfig(CreateValidDnsConfig()); |
2008 | 2038 |
2009 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); | 2039 EXPECT_THAT(CreateRequest("ok", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
2010 EXPECT_EQ(1u, num_running_dispatcher_jobs()); | 2040 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
2011 requests_[0]->Cancel(); | 2041 requests_[0]->Cancel(); |
2012 | 2042 |
2013 // Dispatcher state checked in TearDown. | 2043 // Dispatcher state checked in TearDown. |
2014 } | 2044 } |
2015 | 2045 |
2016 // Cancel a request with two DNS transactions active. | 2046 // Cancel a request with two DNS transactions active. |
2017 TEST_F(HostResolverImplDnsTest, CancelWithTwoTransactionsActive) { | 2047 TEST_F(HostResolverImplDnsTest, CancelWithTwoTransactionsActive) { |
2018 ChangeDnsConfig(CreateValidDnsConfig()); | 2048 ChangeDnsConfig(CreateValidDnsConfig()); |
2019 | 2049 |
2020 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); | 2050 EXPECT_THAT(CreateRequest("ok", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
2021 EXPECT_EQ(2u, num_running_dispatcher_jobs()); | 2051 EXPECT_EQ(2u, num_running_dispatcher_jobs()); |
2022 requests_[0]->Cancel(); | 2052 requests_[0]->Cancel(); |
2023 | 2053 |
2024 // Dispatcher state checked in TearDown. | 2054 // Dispatcher state checked in TearDown. |
2025 } | 2055 } |
2026 | 2056 |
2027 // Delete a resolver with some active requests and some queued requests. | 2057 // Delete a resolver with some active requests and some queued requests. |
2028 TEST_F(HostResolverImplDnsTest, DeleteWithActiveTransactions) { | 2058 TEST_F(HostResolverImplDnsTest, DeleteWithActiveTransactions) { |
2029 // At most 10 Jobs active at once. | 2059 // At most 10 Jobs active at once. |
2030 CreateResolverWithLimitsAndParams(10u, DefaultParams(proc_.get())); | 2060 CreateResolverWithLimitsAndParams(10u, DefaultParams(proc_.get())); |
(...skipping 13 matching lines...) Expand all Loading... |
2044 } | 2074 } |
2045 EXPECT_EQ(10u, num_running_dispatcher_jobs()); | 2075 EXPECT_EQ(10u, num_running_dispatcher_jobs()); |
2046 | 2076 |
2047 resolver_.reset(); | 2077 resolver_.reset(); |
2048 } | 2078 } |
2049 | 2079 |
2050 // Cancel a request with only the IPv6 transaction active. | 2080 // Cancel a request with only the IPv6 transaction active. |
2051 TEST_F(HostResolverImplDnsTest, CancelWithIPv6TransactionActive) { | 2081 TEST_F(HostResolverImplDnsTest, CancelWithIPv6TransactionActive) { |
2052 ChangeDnsConfig(CreateValidDnsConfig()); | 2082 ChangeDnsConfig(CreateValidDnsConfig()); |
2053 | 2083 |
2054 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("6slow_ok", 80)->Resolve()); | 2084 EXPECT_THAT(CreateRequest("6slow_ok", 80)->Resolve(), |
| 2085 IsError(ERR_IO_PENDING)); |
2055 EXPECT_EQ(2u, num_running_dispatcher_jobs()); | 2086 EXPECT_EQ(2u, num_running_dispatcher_jobs()); |
2056 | 2087 |
2057 // The IPv4 request should complete, the IPv6 request is still pending. | 2088 // The IPv4 request should complete, the IPv6 request is still pending. |
2058 base::RunLoop().RunUntilIdle(); | 2089 base::RunLoop().RunUntilIdle(); |
2059 EXPECT_EQ(1u, num_running_dispatcher_jobs()); | 2090 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
2060 requests_[0]->Cancel(); | 2091 requests_[0]->Cancel(); |
2061 | 2092 |
2062 // Dispatcher state checked in TearDown. | 2093 // Dispatcher state checked in TearDown. |
2063 } | 2094 } |
2064 | 2095 |
2065 // Cancel a request with only the IPv4 transaction pending. | 2096 // Cancel a request with only the IPv4 transaction pending. |
2066 TEST_F(HostResolverImplDnsTest, CancelWithIPv4TransactionPending) { | 2097 TEST_F(HostResolverImplDnsTest, CancelWithIPv4TransactionPending) { |
2067 set_fallback_to_proctask(false); | 2098 set_fallback_to_proctask(false); |
2068 ChangeDnsConfig(CreateValidDnsConfig()); | 2099 ChangeDnsConfig(CreateValidDnsConfig()); |
2069 | 2100 |
2070 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80)->Resolve()); | 2101 EXPECT_THAT(CreateRequest("4slow_ok", 80)->Resolve(), |
| 2102 IsError(ERR_IO_PENDING)); |
2071 EXPECT_EQ(2u, num_running_dispatcher_jobs()); | 2103 EXPECT_EQ(2u, num_running_dispatcher_jobs()); |
2072 | 2104 |
2073 // The IPv6 request should complete, the IPv4 request is still pending. | 2105 // The IPv6 request should complete, the IPv4 request is still pending. |
2074 base::RunLoop().RunUntilIdle(); | 2106 base::RunLoop().RunUntilIdle(); |
2075 EXPECT_EQ(1u, num_running_dispatcher_jobs()); | 2107 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
2076 | 2108 |
2077 requests_[0]->Cancel(); | 2109 requests_[0]->Cancel(); |
2078 } | 2110 } |
2079 | 2111 |
2080 // Test cases where AAAA completes first. | 2112 // Test cases where AAAA completes first. |
2081 TEST_F(HostResolverImplDnsTest, AAAACompletesFirst) { | 2113 TEST_F(HostResolverImplDnsTest, AAAACompletesFirst) { |
2082 set_fallback_to_proctask(false); | 2114 set_fallback_to_proctask(false); |
2083 ChangeDnsConfig(CreateValidDnsConfig()); | 2115 ChangeDnsConfig(CreateValidDnsConfig()); |
2084 | 2116 |
2085 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80)->Resolve()); | 2117 EXPECT_THAT(CreateRequest("4slow_ok", 80)->Resolve(), |
2086 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_4ok", 80)->Resolve()); | 2118 IsError(ERR_IO_PENDING)); |
2087 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_4timeout", 80)->Resolve()); | 2119 EXPECT_THAT(CreateRequest("4slow_4ok", 80)->Resolve(), |
2088 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_6timeout", 80)->Resolve()); | 2120 IsError(ERR_IO_PENDING)); |
| 2121 EXPECT_THAT(CreateRequest("4slow_4timeout", 80)->Resolve(), |
| 2122 IsError(ERR_IO_PENDING)); |
| 2123 EXPECT_THAT(CreateRequest("4slow_6timeout", 80)->Resolve(), |
| 2124 IsError(ERR_IO_PENDING)); |
2089 | 2125 |
2090 base::RunLoop().RunUntilIdle(); | 2126 base::RunLoop().RunUntilIdle(); |
2091 EXPECT_FALSE(requests_[0]->completed()); | 2127 EXPECT_FALSE(requests_[0]->completed()); |
2092 EXPECT_FALSE(requests_[1]->completed()); | 2128 EXPECT_FALSE(requests_[1]->completed()); |
2093 EXPECT_FALSE(requests_[2]->completed()); | 2129 EXPECT_FALSE(requests_[2]->completed()); |
2094 // The IPv6 of the third request should have failed and resulted in cancelling | 2130 // The IPv6 of the third request should have failed and resulted in cancelling |
2095 // the IPv4 request. | 2131 // the IPv4 request. |
2096 EXPECT_TRUE(requests_[3]->completed()); | 2132 EXPECT_TRUE(requests_[3]->completed()); |
2097 EXPECT_EQ(ERR_DNS_TIMED_OUT, requests_[3]->result()); | 2133 EXPECT_THAT(requests_[3]->result(), IsError(ERR_DNS_TIMED_OUT)); |
2098 EXPECT_EQ(3u, num_running_dispatcher_jobs()); | 2134 EXPECT_EQ(3u, num_running_dispatcher_jobs()); |
2099 | 2135 |
2100 dns_client_->CompleteDelayedTransactions(); | 2136 dns_client_->CompleteDelayedTransactions(); |
2101 EXPECT_TRUE(requests_[0]->completed()); | 2137 EXPECT_TRUE(requests_[0]->completed()); |
2102 EXPECT_EQ(OK, requests_[0]->result()); | 2138 EXPECT_THAT(requests_[0]->result(), IsOk()); |
2103 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); | 2139 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); |
2104 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); | 2140 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); |
2105 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); | 2141 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); |
2106 | 2142 |
2107 EXPECT_TRUE(requests_[1]->completed()); | 2143 EXPECT_TRUE(requests_[1]->completed()); |
2108 EXPECT_EQ(OK, requests_[1]->result()); | 2144 EXPECT_THAT(requests_[1]->result(), IsOk()); |
2109 EXPECT_EQ(1u, requests_[1]->NumberOfAddresses()); | 2145 EXPECT_EQ(1u, requests_[1]->NumberOfAddresses()); |
2110 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80)); | 2146 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80)); |
2111 | 2147 |
2112 EXPECT_TRUE(requests_[2]->completed()); | 2148 EXPECT_TRUE(requests_[2]->completed()); |
2113 EXPECT_EQ(ERR_DNS_TIMED_OUT, requests_[2]->result()); | 2149 EXPECT_THAT(requests_[2]->result(), IsError(ERR_DNS_TIMED_OUT)); |
2114 } | 2150 } |
2115 | 2151 |
2116 // Test the case where only a single transaction slot is available. | 2152 // Test the case where only a single transaction slot is available. |
2117 TEST_F(HostResolverImplDnsTest, SerialResolver) { | 2153 TEST_F(HostResolverImplDnsTest, SerialResolver) { |
2118 CreateSerialResolver(); | 2154 CreateSerialResolver(); |
2119 set_fallback_to_proctask(false); | 2155 set_fallback_to_proctask(false); |
2120 ChangeDnsConfig(CreateValidDnsConfig()); | 2156 ChangeDnsConfig(CreateValidDnsConfig()); |
2121 | 2157 |
2122 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); | 2158 EXPECT_THAT(CreateRequest("ok", 80)->Resolve(), IsError(ERR_IO_PENDING)); |
2123 EXPECT_EQ(1u, num_running_dispatcher_jobs()); | 2159 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
2124 | 2160 |
2125 base::RunLoop().RunUntilIdle(); | 2161 base::RunLoop().RunUntilIdle(); |
2126 EXPECT_TRUE(requests_[0]->completed()); | 2162 EXPECT_TRUE(requests_[0]->completed()); |
2127 EXPECT_EQ(OK, requests_[0]->result()); | 2163 EXPECT_THAT(requests_[0]->result(), IsOk()); |
2128 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); | 2164 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); |
2129 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); | 2165 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); |
2130 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); | 2166 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); |
2131 } | 2167 } |
2132 | 2168 |
2133 // Test the case where the AAAA query is started when another transaction | 2169 // Test the case where the AAAA query is started when another transaction |
2134 // completes. | 2170 // completes. |
2135 TEST_F(HostResolverImplDnsTest, AAAAStartsAfterOtherJobFinishes) { | 2171 TEST_F(HostResolverImplDnsTest, AAAAStartsAfterOtherJobFinishes) { |
2136 CreateResolverWithLimitsAndParams(2u, DefaultParams(proc_.get())); | 2172 CreateResolverWithLimitsAndParams(2u, DefaultParams(proc_.get())); |
2137 set_fallback_to_proctask(false); | 2173 set_fallback_to_proctask(false); |
2138 ChangeDnsConfig(CreateValidDnsConfig()); | 2174 ChangeDnsConfig(CreateValidDnsConfig()); |
2139 | 2175 |
2140 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM, | 2176 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM, |
2141 ADDRESS_FAMILY_IPV4)->Resolve()); | 2177 ADDRESS_FAMILY_IPV4)->Resolve()); |
2142 EXPECT_EQ(ERR_IO_PENDING, | 2178 EXPECT_EQ(ERR_IO_PENDING, |
2143 CreateRequest("4slow_ok", 80, MEDIUM)->Resolve()); | 2179 CreateRequest("4slow_ok", 80, MEDIUM)->Resolve()); |
2144 // An IPv4 request should have been started pending for each job. | 2180 // An IPv4 request should have been started pending for each job. |
2145 EXPECT_EQ(2u, num_running_dispatcher_jobs()); | 2181 EXPECT_EQ(2u, num_running_dispatcher_jobs()); |
2146 | 2182 |
2147 // Request 0's IPv4 request should complete, starting Request 1's IPv6 | 2183 // Request 0's IPv4 request should complete, starting Request 1's IPv6 |
2148 // request, which should also complete. | 2184 // request, which should also complete. |
2149 base::RunLoop().RunUntilIdle(); | 2185 base::RunLoop().RunUntilIdle(); |
2150 EXPECT_EQ(1u, num_running_dispatcher_jobs()); | 2186 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
2151 EXPECT_TRUE(requests_[0]->completed()); | 2187 EXPECT_TRUE(requests_[0]->completed()); |
2152 EXPECT_FALSE(requests_[1]->completed()); | 2188 EXPECT_FALSE(requests_[1]->completed()); |
2153 | 2189 |
2154 dns_client_->CompleteDelayedTransactions(); | 2190 dns_client_->CompleteDelayedTransactions(); |
2155 EXPECT_TRUE(requests_[1]->completed()); | 2191 EXPECT_TRUE(requests_[1]->completed()); |
2156 EXPECT_EQ(OK, requests_[1]->result()); | 2192 EXPECT_THAT(requests_[1]->result(), IsOk()); |
2157 EXPECT_EQ(2u, requests_[1]->NumberOfAddresses()); | 2193 EXPECT_EQ(2u, requests_[1]->NumberOfAddresses()); |
2158 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80)); | 2194 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80)); |
2159 EXPECT_TRUE(requests_[1]->HasAddress("::1", 80)); | 2195 EXPECT_TRUE(requests_[1]->HasAddress("::1", 80)); |
2160 } | 2196 } |
2161 | 2197 |
2162 // Tests the case that a Job with a single transaction receives an empty address | 2198 // Tests the case that a Job with a single transaction receives an empty address |
2163 // list, triggering fallback to ProcTask. | 2199 // list, triggering fallback to ProcTask. |
2164 TEST_F(HostResolverImplDnsTest, IPv4EmptyFallback) { | 2200 TEST_F(HostResolverImplDnsTest, IPv4EmptyFallback) { |
2165 ChangeDnsConfig(CreateValidDnsConfig()); | 2201 ChangeDnsConfig(CreateValidDnsConfig()); |
2166 proc_->AddRuleForAllFamilies("empty_fallback", "192.168.0.1"); | 2202 proc_->AddRuleForAllFamilies("empty_fallback", "192.168.0.1"); |
2167 proc_->SignalMultiple(1u); | 2203 proc_->SignalMultiple(1u); |
2168 EXPECT_EQ(ERR_IO_PENDING, | 2204 EXPECT_EQ(ERR_IO_PENDING, |
2169 CreateRequest("empty_fallback", 80, MEDIUM, | 2205 CreateRequest("empty_fallback", 80, MEDIUM, |
2170 ADDRESS_FAMILY_IPV4)->Resolve()); | 2206 ADDRESS_FAMILY_IPV4)->Resolve()); |
2171 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 2207 EXPECT_THAT(requests_[0]->WaitForResult(), IsOk()); |
2172 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); | 2208 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); |
2173 } | 2209 } |
2174 | 2210 |
2175 // Tests the case that a Job with two transactions receives two empty address | 2211 // Tests the case that a Job with two transactions receives two empty address |
2176 // lists, triggering fallback to ProcTask. | 2212 // lists, triggering fallback to ProcTask. |
2177 TEST_F(HostResolverImplDnsTest, UnspecEmptyFallback) { | 2213 TEST_F(HostResolverImplDnsTest, UnspecEmptyFallback) { |
2178 ChangeDnsConfig(CreateValidDnsConfig()); | 2214 ChangeDnsConfig(CreateValidDnsConfig()); |
2179 proc_->AddRuleForAllFamilies("empty_fallback", "192.168.0.1"); | 2215 proc_->AddRuleForAllFamilies("empty_fallback", "192.168.0.1"); |
2180 proc_->SignalMultiple(1u); | 2216 proc_->SignalMultiple(1u); |
2181 EXPECT_EQ(ERR_IO_PENDING, | 2217 EXPECT_EQ(ERR_IO_PENDING, |
2182 CreateRequest("empty_fallback", 80, MEDIUM, | 2218 CreateRequest("empty_fallback", 80, MEDIUM, |
2183 ADDRESS_FAMILY_UNSPECIFIED)->Resolve()); | 2219 ADDRESS_FAMILY_UNSPECIFIED)->Resolve()); |
2184 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 2220 EXPECT_THAT(requests_[0]->WaitForResult(), IsOk()); |
2185 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); | 2221 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); |
2186 } | 2222 } |
2187 | 2223 |
2188 // Tests getting a new invalid DnsConfig while there are active DnsTasks. | 2224 // Tests getting a new invalid DnsConfig while there are active DnsTasks. |
2189 TEST_F(HostResolverImplDnsTest, InvalidDnsConfigWithPendingRequests) { | 2225 TEST_F(HostResolverImplDnsTest, InvalidDnsConfigWithPendingRequests) { |
2190 // At most 3 jobs active at once. This number is important, since we want to | 2226 // At most 3 jobs active at once. This number is important, since we want to |
2191 // make sure that aborting the first HostResolverImpl::Job does not trigger | 2227 // make sure that aborting the first HostResolverImpl::Job does not trigger |
2192 // another DnsTransaction on the second Job when it releases its second | 2228 // another DnsTransaction on the second Job when it releases its second |
2193 // prioritized dispatcher slot. | 2229 // prioritized dispatcher slot. |
2194 CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get())); | 2230 CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get())); |
2195 | 2231 |
2196 ChangeDnsConfig(CreateValidDnsConfig()); | 2232 ChangeDnsConfig(CreateValidDnsConfig()); |
2197 | 2233 |
2198 proc_->AddRuleForAllFamilies("slow_nx1", "192.168.0.1"); | 2234 proc_->AddRuleForAllFamilies("slow_nx1", "192.168.0.1"); |
2199 proc_->AddRuleForAllFamilies("slow_nx2", "192.168.0.2"); | 2235 proc_->AddRuleForAllFamilies("slow_nx2", "192.168.0.2"); |
2200 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); | 2236 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); |
2201 | 2237 |
2202 // First active job gets two slots. | 2238 // First active job gets two slots. |
2203 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_nx1")->Resolve()); | 2239 EXPECT_THAT(CreateRequest("slow_nx1")->Resolve(), IsError(ERR_IO_PENDING)); |
2204 // Next job gets one slot, and waits on another. | 2240 // Next job gets one slot, and waits on another. |
2205 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_nx2")->Resolve()); | 2241 EXPECT_THAT(CreateRequest("slow_nx2")->Resolve(), IsError(ERR_IO_PENDING)); |
2206 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok")->Resolve()); | 2242 EXPECT_THAT(CreateRequest("ok")->Resolve(), IsError(ERR_IO_PENDING)); |
2207 | 2243 |
2208 EXPECT_EQ(3u, num_running_dispatcher_jobs()); | 2244 EXPECT_EQ(3u, num_running_dispatcher_jobs()); |
2209 | 2245 |
2210 // Clear DNS config. Two in-progress jobs should be aborted, and the next one | 2246 // Clear DNS config. Two in-progress jobs should be aborted, and the next one |
2211 // should use a ProcTask. | 2247 // should use a ProcTask. |
2212 ChangeDnsConfig(DnsConfig()); | 2248 ChangeDnsConfig(DnsConfig()); |
2213 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->WaitForResult()); | 2249 EXPECT_THAT(requests_[0]->WaitForResult(), IsError(ERR_NETWORK_CHANGED)); |
2214 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[1]->WaitForResult()); | 2250 EXPECT_THAT(requests_[1]->WaitForResult(), IsError(ERR_NETWORK_CHANGED)); |
2215 | 2251 |
2216 // Finish up the third job. Should bypass the DnsClient, and get its results | 2252 // Finish up the third job. Should bypass the DnsClient, and get its results |
2217 // from MockHostResolverProc. | 2253 // from MockHostResolverProc. |
2218 EXPECT_FALSE(requests_[2]->completed()); | 2254 EXPECT_FALSE(requests_[2]->completed()); |
2219 proc_->SignalMultiple(1u); | 2255 proc_->SignalMultiple(1u); |
2220 EXPECT_EQ(OK, requests_[2]->WaitForResult()); | 2256 EXPECT_THAT(requests_[2]->WaitForResult(), IsOk()); |
2221 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); | 2257 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); |
2222 } | 2258 } |
2223 | 2259 |
2224 // Tests the case that DnsClient is automatically disabled due to failures | 2260 // Tests the case that DnsClient is automatically disabled due to failures |
2225 // while there are active DnsTasks. | 2261 // while there are active DnsTasks. |
2226 TEST_F(HostResolverImplDnsTest, | 2262 TEST_F(HostResolverImplDnsTest, |
2227 AutomaticallyDisableDnsClientWithPendingRequests) { | 2263 AutomaticallyDisableDnsClientWithPendingRequests) { |
2228 // Trying different limits is important for this test: Different limits | 2264 // Trying different limits is important for this test: Different limits |
2229 // result in different behavior when aborting in-progress DnsTasks. Having | 2265 // result in different behavior when aborting in-progress DnsTasks. Having |
2230 // a DnsTask that has one job active and one in the queue when another job | 2266 // a DnsTask that has one job active and one in the queue when another job |
2231 // occupying two slots has its DnsTask aborted is the case most likely to run | 2267 // occupying two slots has its DnsTask aborted is the case most likely to run |
2232 // into problems. | 2268 // into problems. |
2233 for (size_t limit = 1u; limit < 6u; ++limit) { | 2269 for (size_t limit = 1u; limit < 6u; ++limit) { |
2234 CreateResolverWithLimitsAndParams(limit, DefaultParams(proc_.get())); | 2270 CreateResolverWithLimitsAndParams(limit, DefaultParams(proc_.get())); |
2235 | 2271 |
2236 ChangeDnsConfig(CreateValidDnsConfig()); | 2272 ChangeDnsConfig(CreateValidDnsConfig()); |
2237 | 2273 |
2238 // Queue up enough failures to disable DnsTasks. These will all fall back | 2274 // Queue up enough failures to disable DnsTasks. These will all fall back |
2239 // to ProcTasks, and succeed there. | 2275 // to ProcTasks, and succeed there. |
2240 for (unsigned i = 0u; i < maximum_dns_failures(); ++i) { | 2276 for (unsigned i = 0u; i < maximum_dns_failures(); ++i) { |
2241 std::string host = base::StringPrintf("nx%u", i); | 2277 std::string host = base::StringPrintf("nx%u", i); |
2242 proc_->AddRuleForAllFamilies(host, "192.168.0.1"); | 2278 proc_->AddRuleForAllFamilies(host, "192.168.0.1"); |
2243 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(host)->Resolve()); | 2279 EXPECT_THAT(CreateRequest(host)->Resolve(), IsError(ERR_IO_PENDING)); |
2244 } | 2280 } |
2245 | 2281 |
2246 // These requests should all bypass DnsTasks, due to the above failures, | 2282 // These requests should all bypass DnsTasks, due to the above failures, |
2247 // so should end up using ProcTasks. | 2283 // so should end up using ProcTasks. |
2248 proc_->AddRuleForAllFamilies("slow_ok1", "192.168.0.2"); | 2284 proc_->AddRuleForAllFamilies("slow_ok1", "192.168.0.2"); |
2249 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok1")->Resolve()); | 2285 EXPECT_THAT(CreateRequest("slow_ok1")->Resolve(), IsError(ERR_IO_PENDING)); |
2250 proc_->AddRuleForAllFamilies("slow_ok2", "192.168.0.3"); | 2286 proc_->AddRuleForAllFamilies("slow_ok2", "192.168.0.3"); |
2251 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok2")->Resolve()); | 2287 EXPECT_THAT(CreateRequest("slow_ok2")->Resolve(), IsError(ERR_IO_PENDING)); |
2252 proc_->AddRuleForAllFamilies("slow_ok3", "192.168.0.4"); | 2288 proc_->AddRuleForAllFamilies("slow_ok3", "192.168.0.4"); |
2253 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok3")->Resolve()); | 2289 EXPECT_THAT(CreateRequest("slow_ok3")->Resolve(), IsError(ERR_IO_PENDING)); |
2254 proc_->SignalMultiple(maximum_dns_failures() + 3); | 2290 proc_->SignalMultiple(maximum_dns_failures() + 3); |
2255 | 2291 |
2256 for (size_t i = 0u; i < maximum_dns_failures(); ++i) { | 2292 for (size_t i = 0u; i < maximum_dns_failures(); ++i) { |
2257 EXPECT_EQ(OK, requests_[i]->WaitForResult()); | 2293 EXPECT_THAT(requests_[i]->WaitForResult(), IsOk()); |
2258 EXPECT_TRUE(requests_[i]->HasOneAddress("192.168.0.1", 80)); | 2294 EXPECT_TRUE(requests_[i]->HasOneAddress("192.168.0.1", 80)); |
2259 } | 2295 } |
2260 | 2296 |
2261 EXPECT_EQ(OK, requests_[maximum_dns_failures()]->WaitForResult()); | 2297 EXPECT_THAT(requests_[maximum_dns_failures()]->WaitForResult(), IsOk()); |
2262 EXPECT_TRUE(requests_[maximum_dns_failures()]->HasOneAddress( | 2298 EXPECT_TRUE(requests_[maximum_dns_failures()]->HasOneAddress( |
2263 "192.168.0.2", 80)); | 2299 "192.168.0.2", 80)); |
2264 EXPECT_EQ(OK, requests_[maximum_dns_failures() + 1]->WaitForResult()); | 2300 EXPECT_THAT(requests_[maximum_dns_failures() + 1]->WaitForResult(), IsOk()); |
2265 EXPECT_TRUE(requests_[maximum_dns_failures() + 1]->HasOneAddress( | 2301 EXPECT_TRUE(requests_[maximum_dns_failures() + 1]->HasOneAddress( |
2266 "192.168.0.3", 80)); | 2302 "192.168.0.3", 80)); |
2267 EXPECT_EQ(OK, requests_[maximum_dns_failures() + 2]->WaitForResult()); | 2303 EXPECT_THAT(requests_[maximum_dns_failures() + 2]->WaitForResult(), IsOk()); |
2268 EXPECT_TRUE(requests_[maximum_dns_failures() + 2]->HasOneAddress( | 2304 EXPECT_TRUE(requests_[maximum_dns_failures() + 2]->HasOneAddress( |
2269 "192.168.0.4", 80)); | 2305 "192.168.0.4", 80)); |
2270 requests_.clear(); | 2306 requests_.clear(); |
2271 } | 2307 } |
2272 } | 2308 } |
2273 | 2309 |
2274 // Tests a call to SetDnsClient while there are active DnsTasks. | 2310 // Tests a call to SetDnsClient while there are active DnsTasks. |
2275 TEST_F(HostResolverImplDnsTest, ManuallyDisableDnsClientWithPendingRequests) { | 2311 TEST_F(HostResolverImplDnsTest, ManuallyDisableDnsClientWithPendingRequests) { |
2276 // At most 3 jobs active at once. This number is important, since we want to | 2312 // At most 3 jobs active at once. This number is important, since we want to |
2277 // make sure that aborting the first HostResolverImpl::Job does not trigger | 2313 // make sure that aborting the first HostResolverImpl::Job does not trigger |
2278 // another DnsTransaction on the second Job when it releases its second | 2314 // another DnsTransaction on the second Job when it releases its second |
2279 // prioritized dispatcher slot. | 2315 // prioritized dispatcher slot. |
2280 CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get())); | 2316 CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get())); |
2281 | 2317 |
2282 ChangeDnsConfig(CreateValidDnsConfig()); | 2318 ChangeDnsConfig(CreateValidDnsConfig()); |
2283 | 2319 |
2284 proc_->AddRuleForAllFamilies("slow_ok1", "192.168.0.1"); | 2320 proc_->AddRuleForAllFamilies("slow_ok1", "192.168.0.1"); |
2285 proc_->AddRuleForAllFamilies("slow_ok2", "192.168.0.2"); | 2321 proc_->AddRuleForAllFamilies("slow_ok2", "192.168.0.2"); |
2286 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); | 2322 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); |
2287 | 2323 |
2288 // First active job gets two slots. | 2324 // First active job gets two slots. |
2289 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok1")->Resolve()); | 2325 EXPECT_THAT(CreateRequest("slow_ok1")->Resolve(), IsError(ERR_IO_PENDING)); |
2290 // Next job gets one slot, and waits on another. | 2326 // Next job gets one slot, and waits on another. |
2291 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok2")->Resolve()); | 2327 EXPECT_THAT(CreateRequest("slow_ok2")->Resolve(), IsError(ERR_IO_PENDING)); |
2292 // Next one is queued. | 2328 // Next one is queued. |
2293 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok")->Resolve()); | 2329 EXPECT_THAT(CreateRequest("ok")->Resolve(), IsError(ERR_IO_PENDING)); |
2294 | 2330 |
2295 EXPECT_EQ(3u, num_running_dispatcher_jobs()); | 2331 EXPECT_EQ(3u, num_running_dispatcher_jobs()); |
2296 | 2332 |
2297 // Clear DnsClient. The two in-progress jobs should fall back to a ProcTask, | 2333 // Clear DnsClient. The two in-progress jobs should fall back to a ProcTask, |
2298 // and the next one should be started with a ProcTask. | 2334 // and the next one should be started with a ProcTask. |
2299 resolver_->SetDnsClient(std::unique_ptr<DnsClient>()); | 2335 resolver_->SetDnsClient(std::unique_ptr<DnsClient>()); |
2300 | 2336 |
2301 // All three in-progress requests should now be running a ProcTask. | 2337 // All three in-progress requests should now be running a ProcTask. |
2302 EXPECT_EQ(3u, num_running_dispatcher_jobs()); | 2338 EXPECT_EQ(3u, num_running_dispatcher_jobs()); |
2303 proc_->SignalMultiple(3u); | 2339 proc_->SignalMultiple(3u); |
2304 | 2340 |
2305 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 2341 EXPECT_THAT(requests_[0]->WaitForResult(), IsOk()); |
2306 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); | 2342 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); |
2307 EXPECT_EQ(OK, requests_[1]->WaitForResult()); | 2343 EXPECT_THAT(requests_[1]->WaitForResult(), IsOk()); |
2308 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); | 2344 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); |
2309 EXPECT_EQ(OK, requests_[2]->WaitForResult()); | 2345 EXPECT_THAT(requests_[2]->WaitForResult(), IsOk()); |
2310 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); | 2346 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); |
2311 } | 2347 } |
2312 | 2348 |
2313 TEST_F(HostResolverImplTest, ResolveLocalHostname) { | 2349 TEST_F(HostResolverImplTest, ResolveLocalHostname) { |
2314 AddressList addresses; | 2350 AddressList addresses; |
2315 | 2351 |
2316 TestBothLoopbackIPs("localhost"); | 2352 TestBothLoopbackIPs("localhost"); |
2317 TestBothLoopbackIPs("localhoST"); | 2353 TestBothLoopbackIPs("localhoST"); |
2318 TestBothLoopbackIPs("localhost."); | 2354 TestBothLoopbackIPs("localhost."); |
2319 TestBothLoopbackIPs("localhoST."); | 2355 TestBothLoopbackIPs("localhoST."); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2362 EXPECT_FALSE(ResolveLocalHostname("::1:1", kLocalhostLookupPort, &addresses)); | 2398 EXPECT_FALSE(ResolveLocalHostname("::1:1", kLocalhostLookupPort, &addresses)); |
2363 EXPECT_FALSE(ResolveLocalHostname("0:0:0:0:0:0:0:0:1", kLocalhostLookupPort, | 2399 EXPECT_FALSE(ResolveLocalHostname("0:0:0:0:0:0:0:0:1", kLocalhostLookupPort, |
2364 &addresses)); | 2400 &addresses)); |
2365 EXPECT_FALSE(ResolveLocalHostname("foo.localhost.com", kLocalhostLookupPort, | 2401 EXPECT_FALSE(ResolveLocalHostname("foo.localhost.com", kLocalhostLookupPort, |
2366 &addresses)); | 2402 &addresses)); |
2367 EXPECT_FALSE( | 2403 EXPECT_FALSE( |
2368 ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses)); | 2404 ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses)); |
2369 } | 2405 } |
2370 | 2406 |
2371 } // namespace net | 2407 } // namespace net |
OLD | NEW |