Chromium Code Reviews| 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/base/host_resolver_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "base/time.h" | 21 #include "base/time.h" |
| 22 #include "net/base/address_list.h" | 22 #include "net/base/address_list.h" |
| 23 #include "net/base/completion_callback.h" | 23 #include "net/base/completion_callback.h" |
| 24 #include "net/base/host_cache.h" | 24 #include "net/base/host_cache.h" |
| 25 #include "net/base/mock_host_resolver.h" | 25 #include "net/base/mock_host_resolver.h" |
| 26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 27 #include "net/base/net_log_unittest.h" | 27 #include "net/base/net_log_unittest.h" |
| 28 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
| 29 #include "net/base/sys_addrinfo.h" | 29 #include "net/base/sys_addrinfo.h" |
| 30 #include "net/base/test_completion_callback.h" | 30 #include "net/base/test_completion_callback.h" |
| 31 #include "net/dns/dns_client.h" | |
| 32 #include "net/dns/dns_test_util.h" | |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 34 |
| 33 namespace net { | 35 namespace net { |
| 36 namespace { | |
| 34 | 37 |
| 35 using base::TimeDelta; | 38 using base::TimeDelta; |
| 36 using base::TimeTicks; | 39 using base::TimeTicks; |
| 37 | 40 |
| 38 static const size_t kMaxJobs = 10u; | 41 const size_t kMaxJobs = 10u; |
| 39 static const size_t kMaxRetryAttempts = 4u; | 42 const size_t kMaxRetryAttempts = 4u; |
| 40 | 43 |
| 41 PrioritizedDispatcher::Limits DefaultLimits() { | 44 PrioritizedDispatcher::Limits DefaultLimits() { |
| 42 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, kMaxJobs); | 45 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, kMaxJobs); |
| 43 return limits; | 46 return limits; |
| 44 } | 47 } |
| 45 | 48 |
| 46 HostResolverImpl::ProcTaskParams DefaultParams( | 49 HostResolverImpl::ProcTaskParams DefaultParams( |
| 47 HostResolverProc* resolver_proc) { | 50 HostResolverProc* resolver_proc) { |
| 48 return HostResolverImpl::ProcTaskParams(resolver_proc, | 51 return HostResolverImpl::ProcTaskParams(resolver_proc, |
| 49 kMaxRetryAttempts); | 52 kMaxRetryAttempts); |
| 50 } | 53 } |
| 51 | 54 |
| 52 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { | 55 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { |
| 53 return new HostResolverImpl( | 56 return new HostResolverImpl( |
| 54 HostCache::CreateDefaultCache(), | 57 HostCache::CreateDefaultCache(), |
| 55 DefaultLimits(), | 58 DefaultLimits(), |
| 56 DefaultParams(resolver_proc), | 59 DefaultParams(resolver_proc), |
| 57 scoped_ptr<DnsConfigService>(NULL), | 60 scoped_ptr<DnsConfigService>(NULL), |
| 58 NULL); | 61 NULL); |
| 59 } | 62 } |
| 60 | 63 |
| 64 HostResolverImpl* CreateHostResolverImplWithDnsConfig( | |
| 65 HostResolverProc* resolver_proc, | |
| 66 scoped_ptr<DnsConfigService> config_service) { | |
| 67 return new HostResolverImpl( | |
| 68 HostCache::CreateDefaultCache(), | |
| 69 DefaultLimits(), | |
| 70 DefaultParams(resolver_proc), | |
| 71 config_service.Pass(), | |
| 72 NULL); | |
| 73 } | |
| 74 | |
| 61 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 75 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 62 HostResolverImpl* CreateSerialHostResolverImpl( | 76 HostResolverImpl* CreateSerialHostResolverImpl( |
| 63 HostResolverProc* resolver_proc) { | 77 HostResolverProc* resolver_proc) { |
| 64 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc); | 78 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc); |
| 65 params.max_retry_attempts = 0u; | 79 params.max_retry_attempts = 0u; |
| 66 | 80 |
| 67 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); | 81 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); |
| 68 | 82 |
| 69 return new HostResolverImpl(HostCache::CreateDefaultCache(), | 83 return new HostResolverImpl(HostCache::CreateDefaultCache(), |
| 70 limits, | 84 limits, |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 // resolve results by forwarding them to Delegate. | 404 // resolve results by forwarding them to Delegate. |
| 391 class ResolveRequest { | 405 class ResolveRequest { |
| 392 public: | 406 public: |
| 393 // Delegate interface, for notification when the ResolveRequest completes. | 407 // Delegate interface, for notification when the ResolveRequest completes. |
| 394 class Delegate { | 408 class Delegate { |
| 395 public: | 409 public: |
| 396 virtual ~Delegate() {} | 410 virtual ~Delegate() {} |
| 397 virtual void OnCompleted(ResolveRequest* resolve) = 0; | 411 virtual void OnCompleted(ResolveRequest* resolve) = 0; |
| 398 }; | 412 }; |
| 399 | 413 |
| 414 // For asynchronous resolutions. | |
| 400 ResolveRequest(HostResolver* resolver, | 415 ResolveRequest(HostResolver* resolver, |
| 401 const std::string& hostname, | 416 const std::string& hostname, |
| 402 int port, | 417 int port, |
| 403 Delegate* delegate) | 418 Delegate* delegate) |
| 404 : info_(HostPortPair(hostname, port)), | 419 : info_(HostPortPair(hostname, port)), |
| 405 resolver_(resolver), | 420 resolver_(resolver), |
| 406 delegate_(delegate) { | 421 delegate_(delegate) { |
| 407 // Start the request. | 422 // Start the request. |
| 408 int err = resolver->Resolve( | 423 int err = resolver->Resolve( |
| 409 info_, &addrlist_, | 424 info_, &addrlist_, |
| 410 base::Bind(&ResolveRequest::OnLookupFinished, base::Unretained(this)), | 425 base::Bind(&ResolveRequest::OnLookupFinished, base::Unretained(this)), |
| 411 &req_, BoundNetLog()); | 426 &req_, BoundNetLog()); |
| 412 EXPECT_EQ(ERR_IO_PENDING, err); | 427 EXPECT_EQ(ERR_IO_PENDING, err); |
| 413 } | 428 } |
| 414 | 429 |
| 430 // For asynchronous resolutions. | |
| 415 ResolveRequest(HostResolver* resolver, | 431 ResolveRequest(HostResolver* resolver, |
| 416 const HostResolver::RequestInfo& info, | 432 const HostResolver::RequestInfo& info, |
| 417 Delegate* delegate) | 433 Delegate* delegate) |
| 418 : info_(info), resolver_(resolver), delegate_(delegate) { | 434 : info_(info), resolver_(resolver), delegate_(delegate) { |
| 419 // Start the request. | 435 // Start the request. |
| 420 int err = resolver->Resolve( | 436 int err = resolver->Resolve( |
| 421 info, &addrlist_, | 437 info, &addrlist_, |
| 422 base::Bind(&ResolveRequest::OnLookupFinished, | 438 base::Bind(&ResolveRequest::OnLookupFinished, |
| 423 base::Unretained(this)), | 439 base::Unretained(this)), |
| 424 &req_, BoundNetLog()); | 440 &req_, BoundNetLog()); |
| 425 EXPECT_EQ(ERR_IO_PENDING, err); | 441 EXPECT_EQ(ERR_IO_PENDING, err); |
| 426 } | 442 } |
| 427 | 443 |
| 444 // For synchronous resolutions. | |
| 445 ResolveRequest(HostResolver* resolver, | |
| 446 const std::string& hostname, | |
| 447 int port) | |
| 448 : info_(HostPortPair(hostname, port)), | |
| 449 resolver_(resolver), | |
| 450 delegate_(NULL) { | |
| 451 // Start the request. | |
| 452 result_ = resolver->Resolve( | |
| 453 info_, &addrlist_, | |
| 454 base::Bind(&ResolveRequest::OnLookupFinished, base::Unretained(this)), | |
| 455 &req_, BoundNetLog()); | |
| 456 EXPECT_NE(ERR_IO_PENDING, result_); | |
| 457 } | |
| 458 | |
| 459 // For synchronous resolutions. | |
| 460 ResolveRequest(HostResolver* resolver, | |
| 461 const HostResolver::RequestInfo& info) | |
| 462 : info_(info), | |
| 463 resolver_(resolver), | |
| 464 delegate_(NULL) { | |
| 465 // Start the request. | |
| 466 result_ = resolver->Resolve( | |
| 467 info_, &addrlist_, | |
| 468 base::Bind(&ResolveRequest::OnLookupFinished, base::Unretained(this)), | |
| 469 &req_, BoundNetLog()); | |
| 470 EXPECT_NE(ERR_IO_PENDING, result_); | |
| 471 } | |
| 472 | |
| 428 void Cancel() { | 473 void Cancel() { |
| 429 resolver_->CancelRequest(req_); | 474 resolver_->CancelRequest(req_); |
| 430 } | 475 } |
| 431 | 476 |
| 432 const std::string& hostname() const { | 477 const std::string& hostname() const { |
| 433 return info_.hostname(); | 478 return info_.hostname(); |
| 434 } | 479 } |
| 435 | 480 |
| 436 int port() const { | 481 int port() const { |
| 437 return info_.port(); | 482 return info_.port(); |
| 438 } | 483 } |
| 439 | 484 |
| 440 int result() const { | 485 int result() const { |
| 441 return result_; | 486 return result_; |
| 442 } | 487 } |
| 443 | 488 |
| 444 const AddressList& addrlist() const { | 489 const AddressList& addrlist() const { |
| 445 return addrlist_; | 490 return addrlist_; |
| 446 } | 491 } |
| 447 | 492 |
| 448 HostResolver* resolver() const { | 493 HostResolver* resolver() const { |
| 449 return resolver_; | 494 return resolver_; |
| 450 } | 495 } |
| 451 | 496 |
| 452 private: | 497 private: |
| 453 void OnLookupFinished(int result) { | 498 void OnLookupFinished(int result) { |
| 499 EXPECT_TRUE(delegate_ != NULL); | |
| 500 if (delegate_ == NULL) | |
| 501 return; | |
| 454 result_ = result; | 502 result_ = result; |
| 455 delegate_->OnCompleted(this); | 503 delegate_->OnCompleted(this); |
| 456 } | 504 } |
| 457 | 505 |
| 458 // The request details. | 506 // The request details. |
| 459 HostResolver::RequestInfo info_; | 507 HostResolver::RequestInfo info_; |
| 460 HostResolver::RequestHandle req_; | 508 HostResolver::RequestHandle req_; |
| 461 | 509 |
| 462 // The result of the resolve. | 510 // The result of the resolve. |
| 463 int result_; | 511 int result_; |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 req3.Cancel(); | 911 req3.Cancel(); |
| 864 req5.Cancel(); | 912 req5.Cancel(); |
| 865 | 913 |
| 866 // Ready, Set, GO!!! | 914 // Ready, Set, GO!!! |
| 867 resolver_proc->Signal(); | 915 resolver_proc->Signal(); |
| 868 | 916 |
| 869 // |verifier| will send quit message once all the requests have finished. | 917 // |verifier| will send quit message once all the requests have finished. |
| 870 MessageLoop::current()->Run(); | 918 MessageLoop::current()->Run(); |
| 871 } | 919 } |
| 872 | 920 |
| 873 // Helper class used by HostResolverImplTest.CanceledRequestsReleaseJobSlots. | 921 // Delegate which allows to wait for specific number of requests to complete. |
| 922 // Used by HostResolverImplTest.CanceledRequestsReleaseJobSlots and .DnsTask. | |
| 874 class CountingDelegate : public ResolveRequest::Delegate { | 923 class CountingDelegate : public ResolveRequest::Delegate { |
| 875 public: | 924 public: |
| 876 CountingDelegate() : num_completions_(0) {} | 925 CountingDelegate() : num_completions_(0) {} |
| 877 | 926 |
| 878 virtual void OnCompleted(ResolveRequest* resolve) OVERRIDE { | 927 virtual void OnCompleted(ResolveRequest* resolve) OVERRIDE { |
| 879 ++num_completions_; | 928 ++num_completions_; |
| 880 MessageLoop::current()->Quit(); | 929 if (num_completions_ == awaited_num_completions_) |
| 930 MessageLoop::current()->Quit(); | |
| 881 } | 931 } |
| 882 | 932 |
| 883 unsigned num_completions() const { return num_completions_; } | 933 unsigned num_completions() const { return num_completions_; } |
| 884 | 934 |
| 935 void WaitForCompletions(unsigned completions) { | |
| 936 ASSERT_LT(num_completions_, completions); | |
| 937 awaited_num_completions_ = completions; | |
| 938 MessageLoop::current()->Run(); | |
| 939 EXPECT_EQ(completions, num_completions_); | |
| 940 } | |
| 941 | |
| 885 private: | 942 private: |
| 886 unsigned num_completions_; | 943 unsigned num_completions_; |
| 944 unsigned awaited_num_completions_; | |
|
mmenke
2012/03/13 20:31:08
You need to initialize this to 0 in the constructo
szym
2012/03/13 21:17:19
Good catch. Thanks.
| |
| 887 }; | 945 }; |
| 888 | 946 |
| 889 TEST_F(HostResolverImplTest, CanceledRequestsReleaseJobSlots) { | 947 TEST_F(HostResolverImplTest, CanceledRequestsReleaseJobSlots) { |
| 890 scoped_refptr<CountingHostResolverProc> resolver_proc( | 948 scoped_refptr<CountingHostResolverProc> resolver_proc( |
| 891 new CountingHostResolverProc(NULL)); | 949 new CountingHostResolverProc(NULL)); |
| 892 | 950 |
| 893 scoped_ptr<HostResolverImpl> host_resolver( | 951 scoped_ptr<HostResolverImpl> host_resolver( |
| 894 CreateHostResolverImpl(resolver_proc)); | 952 CreateHostResolverImpl(resolver_proc)); |
| 895 | 953 |
| 896 CountingDelegate delegate; | 954 CountingDelegate delegate; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 911 // Cancel all but last two. | 969 // Cancel all but last two. |
| 912 for (unsigned i = 0; i < requests.size() - 2; ++i) { | 970 for (unsigned i = 0; i < requests.size() - 2; ++i) { |
| 913 requests[i]->Cancel(); | 971 requests[i]->Cancel(); |
| 914 } | 972 } |
| 915 | 973 |
| 916 EXPECT_TRUE(resolver_proc->WaitFor(kMaxJobs + 1)); | 974 EXPECT_TRUE(resolver_proc->WaitFor(kMaxJobs + 1)); |
| 917 EXPECT_EQ(0u, delegate.num_completions()); | 975 EXPECT_EQ(0u, delegate.num_completions()); |
| 918 | 976 |
| 919 resolver_proc->SignalAll(); | 977 resolver_proc->SignalAll(); |
| 920 | 978 |
| 921 while (delegate.num_completions() < 2) | 979 delegate.WaitForCompletions(2); |
| 922 MessageLoop::current()->Run(); | |
| 923 | 980 |
| 924 EXPECT_EQ(0u, host_resolver->num_running_jobs_for_tests()); | 981 EXPECT_EQ(0u, host_resolver->num_running_jobs_for_tests()); |
| 925 } | 982 } |
| 926 | 983 |
| 927 // Helper class used by HostResolverImplTest.CancelWithinCallback. | 984 // Helper class used by HostResolverImplTest.CancelWithinCallback. |
| 928 class CancelWithinCallbackVerifier : public ResolveRequest::Delegate { | 985 class CancelWithinCallbackVerifier : public ResolveRequest::Delegate { |
| 929 public: | 986 public: |
| 930 CancelWithinCallbackVerifier() | 987 CancelWithinCallbackVerifier() |
| 931 : req_to_cancel1_(NULL), req_to_cancel2_(NULL), num_completions_(0) { | 988 : req_to_cancel1_(NULL), req_to_cancel2_(NULL), num_completions_(0) { |
| 932 } | 989 } |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1743 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. | 1800 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. |
| 1744 EXPECT_EQ(-4, callback.WaitForResult()); | 1801 EXPECT_EQ(-4, callback.WaitForResult()); |
| 1745 | 1802 |
| 1746 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); | 1803 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); |
| 1747 MessageLoop::current()->RunAllPending(); | 1804 MessageLoop::current()->RunAllPending(); |
| 1748 | 1805 |
| 1749 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); | 1806 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); |
| 1750 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); | 1807 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); |
| 1751 } | 1808 } |
| 1752 | 1809 |
| 1810 DnsConfig CreateValidDnsConfig() { | |
| 1811 IPAddressNumber dns_ip; | |
| 1812 bool rv = ParseIPLiteralToNumber("192.168.1.0", &dns_ip); | |
| 1813 EXPECT_TRUE(rv); | |
| 1814 | |
| 1815 DnsConfig config; | |
| 1816 config.nameservers.push_back(IPEndPoint(dns_ip, | |
| 1817 dns_protocol::kDefaultPort)); | |
| 1818 EXPECT_TRUE(config.IsValid()); | |
| 1819 return config; | |
| 1820 } | |
| 1821 | |
| 1822 // TODO(szym): Test AbortAllInProgressJobs due to DnsConfig change. | |
| 1823 | |
| 1753 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1824 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
| 1754 | 1825 |
| 1826 } // namespace | |
| 1827 | |
| 1828 // Test successful and fallback resolutions in HostResolverImpl::DnsTask. | |
| 1829 TEST_F(HostResolverImplTest, DnsTask) { | |
| 1830 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( | |
| 1831 new RuleBasedHostResolverProc(NULL)); | |
| 1832 scoped_ptr<HostResolverImpl> host_resolver(CreateHostResolverImpl( | |
| 1833 resolver_proc)); | |
| 1834 | |
| 1835 resolver_proc->AddRule("er_succeed", "192.168.1.101"); | |
| 1836 resolver_proc->AddRule("nx_succeed", "192.168.1.102"); | |
| 1837 resolver_proc->AddSimulatedFailure("ok_fail"); | |
| 1838 resolver_proc->AddSimulatedFailure("er_fail"); | |
| 1839 resolver_proc->AddSimulatedFailure("nx_fail"); | |
| 1840 | |
| 1841 CountingDelegate delegate; | |
| 1842 | |
| 1843 // Initially there is no config, so client should not be invoked. | |
| 1844 ResolveRequest req1(host_resolver.get(), "ok_fail", 80, &delegate); | |
| 1845 | |
| 1846 delegate.WaitForCompletions(1); | |
| 1847 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req1.result()); | |
| 1848 | |
| 1849 host_resolver->set_dns_client_for_tests( | |
| 1850 CreateMockDnsClient(CreateValidDnsConfig())); | |
| 1851 | |
| 1852 ResolveRequest req2(host_resolver.get(), "ok_fail", 80, &delegate); | |
| 1853 ResolveRequest req3(host_resolver.get(), "er_fail", 80, &delegate); | |
| 1854 ResolveRequest req4(host_resolver.get(), "nx_fail", 80, &delegate); | |
| 1855 ResolveRequest req5(host_resolver.get(), "er_succeed", 80, &delegate); | |
| 1856 ResolveRequest req6(host_resolver.get(), "nx_succeed", 80, &delegate); | |
| 1857 | |
| 1858 delegate.WaitForCompletions(6); | |
| 1859 EXPECT_EQ(OK, req2.result()); | |
| 1860 // Resolved by MockDnsClient. | |
| 1861 EXPECT_EQ("127.0.0.1", NetAddressToString(req2.addrlist().head())); | |
| 1862 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req3.result()); | |
| 1863 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req4.result()); | |
| 1864 EXPECT_EQ(OK, req5.result()); | |
| 1865 EXPECT_EQ("192.168.1.101", NetAddressToString(req5.addrlist().head())); | |
| 1866 EXPECT_EQ(OK, req6.result()); | |
| 1867 EXPECT_EQ("192.168.1.102", NetAddressToString(req6.addrlist().head())); | |
| 1868 } | |
| 1869 | |
| 1870 TEST_F(HostResolverImplTest, ServeFromHosts) { | |
| 1871 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( | |
| 1872 new RuleBasedHostResolverProc(NULL)); | |
| 1873 MockDnsConfigService* config_service = new MockDnsConfigService(); | |
| 1874 scoped_ptr<HostResolverImpl> host_resolver( | |
| 1875 CreateHostResolverImplWithDnsConfig( | |
| 1876 resolver_proc, | |
| 1877 scoped_ptr<DnsConfigService>(config_service))); | |
| 1878 | |
| 1879 resolver_proc->AddSimulatedFailure("*"); | |
| 1880 | |
| 1881 DnsConfig config = CreateValidDnsConfig(); | |
| 1882 host_resolver->set_dns_client_for_tests(CreateMockDnsClient(config)); | |
| 1883 | |
| 1884 CountingDelegate delegate; | |
| 1885 | |
| 1886 ResolveRequest req1(host_resolver.get(), "er_ipv4", 80, &delegate); | |
| 1887 delegate.WaitForCompletions(1); | |
| 1888 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req1.result()); | |
| 1889 | |
| 1890 IPAddressNumber local_ipv4, local_ipv6; | |
| 1891 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &local_ipv4)); | |
| 1892 ASSERT_TRUE(ParseIPLiteralToNumber("::1", &local_ipv6)); | |
| 1893 | |
| 1894 DnsHosts hosts; | |
| 1895 hosts[DnsHostsKey("er_ipv4", ADDRESS_FAMILY_IPV4)] = local_ipv4; | |
| 1896 hosts[DnsHostsKey("er_ipv6", ADDRESS_FAMILY_IPV6)] = local_ipv6; | |
| 1897 hosts[DnsHostsKey("er_both", ADDRESS_FAMILY_IPV4)] = local_ipv4; | |
| 1898 hosts[DnsHostsKey("er_both", ADDRESS_FAMILY_IPV6)] = local_ipv6; | |
| 1899 | |
| 1900 config_service->ChangeConfig(config); | |
| 1901 config_service->ChangeHosts(hosts); | |
| 1902 | |
| 1903 ResolveRequest req2(host_resolver.get(), "er_ipv4", 80); | |
| 1904 ASSERT_EQ(OK, req2.result()); | |
|
mmenke
2012/03/13 20:31:08
There are still a couple more cases like this in t
szym
2012/03/13 21:17:19
Rather than using ASSERT_EQ to avoid a crash, I ad
mmenke
2012/03/13 21:23:39
Sounds like a better idea to me.
| |
| 1905 EXPECT_EQ("127.0.0.1", NetAddressToString(req2.addrlist().head())); | |
| 1906 | |
| 1907 ResolveRequest req3(host_resolver.get(), "er_ipv6", 80); | |
| 1908 ASSERT_EQ(OK, req3.result()); | |
| 1909 EXPECT_EQ("::1", NetAddressToString(req3.addrlist().head())); | |
| 1910 | |
| 1911 ResolveRequest req4(host_resolver.get(), "er_both", 80); | |
| 1912 ASSERT_EQ(OK, req4.result()); | |
| 1913 // Either result is satisfactory. http://crbug.com/117850 | |
| 1914 const addrinfo* addr = req4.addrlist().head(); | |
| 1915 if (addr->ai_addrlen == sizeof(struct sockaddr_in)) | |
| 1916 EXPECT_EQ("127.0.0.1", NetAddressToString(addr)); | |
| 1917 else | |
| 1918 EXPECT_EQ("::1", NetAddressToString(addr)); | |
| 1919 | |
| 1920 // Requests with specified AddressFamily. | |
| 1921 HostResolver::RequestInfo info(HostPortPair("er_both", 80)); | |
| 1922 info.set_address_family(ADDRESS_FAMILY_IPV4); | |
| 1923 ResolveRequest req5(host_resolver.get(), info); | |
| 1924 ASSERT_EQ(OK, req5.result()); | |
| 1925 EXPECT_EQ("127.0.0.1", NetAddressToString(req5.addrlist().head())); | |
| 1926 | |
| 1927 info.set_address_family(ADDRESS_FAMILY_IPV6); | |
| 1928 ResolveRequest req6(host_resolver.get(), info); | |
| 1929 ASSERT_EQ(OK, req6.result()); | |
| 1930 EXPECT_EQ("::1", NetAddressToString(req6.addrlist().head())); | |
| 1931 } | |
| 1932 | |
| 1755 } // namespace net | 1933 } // namespace net |
| OLD | NEW |