diff options
author | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-14 22:36:36 +0000 |
---|---|---|
committer | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-14 22:36:36 +0000 |
commit | 6c41190e39d8ecdc0dbcc50bd87125f39c39a101 (patch) | |
tree | 80be44493d34177ca8eb0e1c0f0fe00eaeac1845 /net/base/host_resolver_impl_unittest.cc | |
parent | 5d4b7adcca413109257be1a72a18d883480c3cc0 (diff) | |
download | chromium_src-6c41190e39d8ecdc0dbcc50bd87125f39c39a101.zip chromium_src-6c41190e39d8ecdc0dbcc50bd87125f39c39a101.tar.gz chromium_src-6c41190e39d8ecdc0dbcc50bd87125f39c39a101.tar.bz2 |
[net/dns] Resolve AF_UNSPEC on dual-stacked systems. Sort addresses according to RFC3484.
BUG=113993
TEST=./net_unittests --gtest_filter=AddressSorter*:HostResolverImplDnsTest.DnsTaskUnspec
Review URL: https://chromiumcodereview.appspot.com/10442098
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151586 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/host_resolver_impl_unittest.cc')
-rw-r--r-- | net/base/host_resolver_impl_unittest.cc | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc index 91236b3..6571c46 100644 --- a/net/base/host_resolver_impl_unittest.cc +++ b/net/base/host_resolver_impl_unittest.cc @@ -1236,21 +1236,46 @@ DnsConfig CreateValidDnsConfig() { class HostResolverImplDnsTest : public HostResolverImplTest { protected: virtual void SetUp() OVERRIDE { + AddDnsRule("er", dns_protocol::kTypeA, MockDnsClientRule::FAIL_SYNC); + AddDnsRule("er", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL_SYNC); + AddDnsRule("nx", dns_protocol::kTypeA, MockDnsClientRule::FAIL_ASYNC); + AddDnsRule("nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL_ASYNC); + AddDnsRule("ok", dns_protocol::kTypeA, MockDnsClientRule::OK); + AddDnsRule("ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK); + AddDnsRule("4ok", dns_protocol::kTypeA, MockDnsClientRule::OK); + AddDnsRule("4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY); + AddDnsRule("6ok", dns_protocol::kTypeA, MockDnsClientRule::EMPTY); + AddDnsRule("6ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK); + AddDnsRule("4nx", dns_protocol::kTypeA, MockDnsClientRule::OK); + AddDnsRule("4nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL_ASYNC); + CreateResolver(); + } + + void CreateResolver() { config_service_ = new MockDnsConfigService(); resolver_.reset(new HostResolverImpl( HostCache::CreateDefaultCache(), DefaultLimits(), DefaultParams(proc_), scoped_ptr<DnsConfigService>(config_service_), - CreateMockDnsClient(DnsConfig()), + CreateMockDnsClient(DnsConfig(), dns_rules_), NULL)); } + // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply. + void AddDnsRule(const std::string& prefix, + uint16 qtype, + MockDnsClientRule::Result result) { + MockDnsClientRule rule = { prefix, qtype, result }; + dns_rules_.push_back(rule); + } + void ChangeDnsConfig(const DnsConfig& config) { config_service_->ChangeConfig(config); config_service_->ChangeHosts(config.hosts); } + MockDnsClientRuleList dns_rules_; // Owned by |resolver_|. MockDnsConfigService* config_service_; }; @@ -1298,11 +1323,38 @@ TEST_F(HostResolverImplDnsTest, DnsTask) { EXPECT_TRUE(requests_[5]->HasOneAddress("192.168.1.102", 80)); } +TEST_F(HostResolverImplDnsTest, DnsTaskUnspec) { + ChangeDnsConfig(CreateValidDnsConfig()); + + proc_->AddRuleForAllFamilies("4nx", "192.168.1.101"); + // All other hostnames will fail in proc_. + + EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); + EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4ok", 80)->Resolve()); + EXPECT_EQ(ERR_IO_PENDING, CreateRequest("6ok", 80)->Resolve()); + EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4nx", 80)->Resolve()); + + proc_->SignalMultiple(requests_.size()); + + for (size_t i = 0; i < requests_.size(); ++i) + EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; + + EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); + EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); + EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); + EXPECT_EQ(1u, requests_[1]->NumberOfAddresses()); + EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80)); + EXPECT_EQ(1u, requests_[2]->NumberOfAddresses()); + EXPECT_TRUE(requests_[2]->HasAddress("::1", 80)); + EXPECT_EQ(1u, requests_[3]->NumberOfAddresses()); + EXPECT_TRUE(requests_[3]->HasAddress("192.168.1.101", 80)); +} + TEST_F(HostResolverImplDnsTest, ServeFromHosts) { // Initially, use empty HOSTS file. ChangeDnsConfig(CreateValidDnsConfig()); - proc_->AddRuleForAllFamilies("", "0.0.0.0"); // Default to failures. + proc_->AddRuleForAllFamilies("", ""); // Default to failures. proc_->SignalMultiple(1u); // For the first request which misses. Request* req0 = CreateRequest("er_ipv4", 80); @@ -1353,7 +1405,7 @@ TEST_F(HostResolverImplDnsTest, ServeFromHosts) { TEST_F(HostResolverImplDnsTest, BypassDnsTask) { ChangeDnsConfig(CreateValidDnsConfig()); - proc_->AddRuleForAllFamilies("", "0.0.0.0"); // Default to failures. + proc_->AddRuleForAllFamilies("", ""); // Default to failures. EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok.local", 80)->Resolve()); EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok.local.", 80)->Resolve()); |