| Index: net/dns/host_resolver_impl_unittest.cc
|
| diff --git a/net/dns/host_resolver_impl_unittest.cc b/net/dns/host_resolver_impl_unittest.cc
|
| index 0b4807a98518d049d388ef428a1c668e6e10400d..ce5776a91b62c26cae990404bf7a9af018b4d123 100644
|
| --- a/net/dns/host_resolver_impl_unittest.cc
|
| +++ b/net/dns/host_resolver_impl_unittest.cc
|
| @@ -2522,4 +2522,98 @@ TEST_F(HostResolverImplTest, CacheHitCallback) {
|
| EXPECT_EQ(1, count2);
|
| }
|
|
|
| +// Tests that after changing the default AddressFamily to IPV4, requests
|
| +// with UNSPECIFIED address family map to IPV4.
|
| +TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) {
|
| + CreateSerialResolver(); // To guarantee order of resolutions.
|
| +
|
| + proc_->AddRule("h1", ADDRESS_FAMILY_IPV4, "1.0.0.1");
|
| + proc_->AddRule("h1", ADDRESS_FAMILY_IPV6, "::2");
|
| +
|
| + resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
|
| +
|
| + CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED);
|
| + CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
|
| + CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
|
| +
|
| + // Start all of the requests.
|
| + for (size_t i = 0; i < requests_.size(); ++i) {
|
| + EXPECT_EQ(ERR_IO_PENDING, requests_[i]->Resolve()) << i;
|
| + }
|
| +
|
| + proc_->SignalMultiple(requests_.size());
|
| +
|
| + // Wait for all the requests to complete.
|
| + for (size_t i = 0u; i < requests_.size(); ++i) {
|
| + EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i;
|
| + }
|
| +
|
| + // Since the requests all had the same priority and we limited the thread
|
| + // count to 1, they should have completed in the same order as they were
|
| + // requested. Moreover, request0 and request1 will have been serviced by
|
| + // the same job.
|
| +
|
| + MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList();
|
| + ASSERT_EQ(2u, capture_list.size());
|
| +
|
| + EXPECT_EQ("h1", capture_list[0].hostname);
|
| + EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[0].address_family);
|
| +
|
| + EXPECT_EQ("h1", capture_list[1].hostname);
|
| + EXPECT_EQ(ADDRESS_FAMILY_IPV6, capture_list[1].address_family);
|
| +
|
| + // Now check that the correct resolved IP addresses were returned.
|
| + EXPECT_TRUE(requests_[0]->HasOneAddress("1.0.0.1", 80));
|
| + EXPECT_TRUE(requests_[1]->HasOneAddress("1.0.0.1", 80));
|
| + EXPECT_TRUE(requests_[2]->HasOneAddress("::2", 80));
|
| +}
|
| +
|
| +// This is the exact same test as SetDefaultAddressFamily_IPv4, except the
|
| +// default family is set to IPv6 and the family of requests is flipped where
|
| +// specified.
|
| +TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) {
|
| + CreateSerialResolver(); // To guarantee order of resolutions.
|
| +
|
| + // Don't use IPv6 replacements here since some systems don't support it.
|
| + proc_->AddRule("h1", ADDRESS_FAMILY_IPV4, "1.0.0.1");
|
| + proc_->AddRule("h1", ADDRESS_FAMILY_IPV6, "::2");
|
| +
|
| + resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6);
|
| +
|
| + CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED);
|
| + CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
|
| + CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
|
| +
|
| + // Start all of the requests.
|
| + for (size_t i = 0; i < requests_.size(); ++i) {
|
| + EXPECT_EQ(ERR_IO_PENDING, requests_[i]->Resolve()) << i;
|
| + }
|
| +
|
| + proc_->SignalMultiple(requests_.size());
|
| +
|
| + // Wait for all the requests to complete.
|
| + for (size_t i = 0u; i < requests_.size(); ++i) {
|
| + EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i;
|
| + }
|
| +
|
| + // Since the requests all had the same priority and we limited the thread
|
| + // count to 1, they should have completed in the same order as they were
|
| + // requested. Moreover, request0 and request1 will have been serviced by
|
| + // the same job.
|
| +
|
| + MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList();
|
| + ASSERT_EQ(2u, capture_list.size());
|
| +
|
| + EXPECT_EQ("h1", capture_list[0].hostname);
|
| + EXPECT_EQ(ADDRESS_FAMILY_IPV6, capture_list[0].address_family);
|
| +
|
| + EXPECT_EQ("h1", capture_list[1].hostname);
|
| + EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[1].address_family);
|
| +
|
| + // Now check that the correct resolved IP addresses were returned.
|
| + EXPECT_TRUE(requests_[0]->HasOneAddress("::2", 80));
|
| + EXPECT_TRUE(requests_[1]->HasOneAddress("::2", 80));
|
| + EXPECT_TRUE(requests_[2]->HasOneAddress("1.0.0.1", 80));
|
| +}
|
| +
|
| } // namespace net
|
|
|