| 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 efb63e849dec34cdb28abaeac223768c4cad21de..d2173374122f8a93cfd6a9e5341f0c668e70e176 100644
|
| --- a/net/dns/host_resolver_impl_unittest.cc
|
| +++ b/net/dns/host_resolver_impl_unittest.cc
|
| @@ -56,7 +56,8 @@ class MockHostResolverProc : public HostResolverProc {
|
| : hostname(hostname), address_family(address_family) {}
|
| bool operator<(const ResolveKey& other) const {
|
| return address_family < other.address_family ||
|
| - (address_family == other.address_family && hostname < other.hostname);
|
| + (address_family == other.address_family &&
|
| + hostname < other.hostname);
|
| }
|
| std::string hostname;
|
| AddressFamily address_family;
|
| @@ -69,8 +70,7 @@ class MockHostResolverProc : public HostResolverProc {
|
| num_requests_waiting_(0),
|
| num_slots_available_(0),
|
| requests_waiting_(&lock_),
|
| - slots_available_(&lock_) {
|
| - }
|
| + slots_available_(&lock_) {}
|
|
|
| // Waits until |count| calls to |Resolve| are blocked. Returns false when
|
| // timed out.
|
| @@ -99,13 +99,15 @@ class MockHostResolverProc : public HostResolverProc {
|
| slots_available_.Broadcast();
|
| }
|
|
|
| - void AddRule(const std::string& hostname, AddressFamily family,
|
| + void AddRule(const std::string& hostname,
|
| + AddressFamily family,
|
| const AddressList& result) {
|
| base::AutoLock lock(lock_);
|
| rules_[ResolveKey(hostname, family)] = result;
|
| }
|
|
|
| - void AddRule(const std::string& hostname, AddressFamily family,
|
| + void AddRule(const std::string& hostname,
|
| + AddressFamily family,
|
| const std::string& ip_list) {
|
| AddressList result;
|
| int rv = ParseAddressList(ip_list, std::string(), &result);
|
| @@ -178,14 +180,14 @@ class MockHostResolverProc : public HostResolverProc {
|
| DISALLOW_COPY_AND_ASSIGN(MockHostResolverProc);
|
| };
|
|
|
| -bool AddressListContains(const AddressList& list, const std::string& address,
|
| +bool AddressListContains(const AddressList& list,
|
| + const std::string& address,
|
| int port) {
|
| IPAddressNumber ip;
|
| bool rv = ParseIPLiteralToNumber(address, &ip);
|
| DCHECK(rv);
|
| - return std::find(list.begin(),
|
| - list.end(),
|
| - IPEndPoint(ip, port)) != list.end();
|
| + return std::find(list.begin(), list.end(), IPEndPoint(ip, port)) !=
|
| + list.end();
|
| }
|
|
|
| // A wrapper for requests to a HostResolver.
|
| @@ -252,9 +254,7 @@ class Request {
|
| }
|
|
|
| // Returns the number of addresses in |list_|.
|
| - unsigned NumberOfAddresses() const {
|
| - return list_.size();
|
| - }
|
| + unsigned NumberOfAddresses() const { return list_.size(); }
|
|
|
| bool HasOneAddress(const std::string& address, int port) const {
|
| return HasAddress(address, port) && (NumberOfAddresses() == 1u);
|
| @@ -324,8 +324,7 @@ class LookupAttemptHostResolverProc : public HostResolverProc {
|
| total_attempts_(total_attempts),
|
| total_attempts_resolved_(0),
|
| resolved_attempt_number_(0),
|
| - all_done_(&lock_) {
|
| - }
|
| + all_done_(&lock_) {}
|
|
|
| // Test harness will wait for all attempts to finish before checking the
|
| // results.
|
| @@ -334,7 +333,7 @@ class LookupAttemptHostResolverProc : public HostResolverProc {
|
| {
|
| base::AutoLock auto_lock(lock_);
|
| while (total_attempts_resolved_ != total_attempts_ &&
|
| - base::TimeTicks::Now() < end_time) {
|
| + base::TimeTicks::Now() < end_time) {
|
| all_done_.TimedWait(end_time - base::TimeTicks::Now());
|
| }
|
| }
|
| @@ -378,8 +377,8 @@ class LookupAttemptHostResolverProc : public HostResolverProc {
|
| // Wait for the attempt_number_to_resolve_ attempt to resolve.
|
| WaitForAnAttemptToComplete();
|
|
|
| - int result = ResolveUsingPrevious(host, address_family, host_resolver_flags,
|
| - addrlist, os_error);
|
| + int result = ResolveUsingPrevious(
|
| + host, address_family, host_resolver_flags, addrlist, os_error);
|
|
|
| {
|
| base::AutoLock auto_lock(lock_);
|
| @@ -459,9 +458,7 @@ class HostResolverImplTest : public testing::Test {
|
| };
|
|
|
| // testing::Test implementation:
|
| - virtual void SetUp() OVERRIDE {
|
| - CreateResolver();
|
| - }
|
| + virtual void SetUp() OVERRIDE { CreateResolver(); }
|
|
|
| virtual void TearDown() OVERRIDE {
|
| if (resolver_.get())
|
| @@ -472,8 +469,8 @@ class HostResolverImplTest : public testing::Test {
|
| virtual void CreateResolverWithLimitsAndParams(
|
| const PrioritizedDispatcher::Limits& limits,
|
| const HostResolverImpl::ProcTaskParams& params) {
|
| - resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(),
|
| - limits, params, NULL));
|
| + resolver_.reset(new HostResolverImpl(
|
| + HostCache::CreateDefaultCache(), limits, params, NULL));
|
| }
|
|
|
| // The Request will not be made until a call to |Resolve()|, and the Job will
|
| @@ -1272,11 +1269,8 @@ TEST_F(HostResolverImplTest, MultipleAttempts) {
|
| // (500ms * 3).
|
| params.unresponsive_delay = base::TimeDelta::FromMilliseconds(500);
|
|
|
| - resolver_.reset(
|
| - new HostResolverImpl(HostCache::CreateDefaultCache(),
|
| - DefaultLimits(),
|
| - params,
|
| - NULL));
|
| + resolver_.reset(new HostResolverImpl(
|
| + HostCache::CreateDefaultCache(), DefaultLimits(), params, NULL));
|
|
|
| // Resolve "host1".
|
| HostResolver::RequestInfo info(HostPortPair("host1", 70));
|
| @@ -1324,30 +1318,36 @@ class HostResolverImplDnsTest : public HostResolverImplTest {
|
| AddDnsRule("4nx", dns_protocol::kTypeA, MockDnsClientRule::OK, false);
|
| AddDnsRule("4nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL, false);
|
| AddDnsRule("empty", dns_protocol::kTypeA, MockDnsClientRule::EMPTY, false);
|
| - AddDnsRule("empty", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY,
|
| - false);
|
| + AddDnsRule(
|
| + "empty", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY, false);
|
|
|
| AddDnsRule("slow_nx", dns_protocol::kTypeA, MockDnsClientRule::FAIL, true);
|
| - AddDnsRule("slow_nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL,
|
| - true);
|
| + AddDnsRule(
|
| + "slow_nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL, true);
|
|
|
| AddDnsRule("4slow_ok", dns_protocol::kTypeA, MockDnsClientRule::OK, true);
|
| - AddDnsRule("4slow_ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK,
|
| - false);
|
| + AddDnsRule(
|
| + "4slow_ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK, false);
|
| AddDnsRule("6slow_ok", dns_protocol::kTypeA, MockDnsClientRule::OK, false);
|
| - AddDnsRule("6slow_ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK,
|
| - true);
|
| + AddDnsRule(
|
| + "6slow_ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK, true);
|
| AddDnsRule("4slow_4ok", dns_protocol::kTypeA, MockDnsClientRule::OK, true);
|
| - AddDnsRule("4slow_4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY,
|
| + AddDnsRule(
|
| + "4slow_4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY, false);
|
| + AddDnsRule("4slow_4timeout",
|
| + dns_protocol::kTypeA,
|
| + MockDnsClientRule::TIMEOUT,
|
| + true);
|
| + AddDnsRule("4slow_4timeout",
|
| + dns_protocol::kTypeAAAA,
|
| + MockDnsClientRule::OK,
|
| false);
|
| - AddDnsRule("4slow_4timeout", dns_protocol::kTypeA,
|
| - MockDnsClientRule::TIMEOUT, true);
|
| - AddDnsRule("4slow_4timeout", dns_protocol::kTypeAAAA, MockDnsClientRule::OK,
|
| + AddDnsRule(
|
| + "4slow_6timeout", dns_protocol::kTypeA, MockDnsClientRule::OK, true);
|
| + AddDnsRule("4slow_6timeout",
|
| + dns_protocol::kTypeAAAA,
|
| + MockDnsClientRule::TIMEOUT,
|
| false);
|
| - AddDnsRule("4slow_6timeout", dns_protocol::kTypeA,
|
| - MockDnsClientRule::OK, true);
|
| - AddDnsRule("4slow_6timeout", dns_protocol::kTypeAAAA,
|
| - MockDnsClientRule::TIMEOUT, false);
|
| CreateResolver();
|
| }
|
|
|
| @@ -1355,10 +1355,8 @@ class HostResolverImplDnsTest : public HostResolverImplTest {
|
| virtual void CreateResolverWithLimitsAndParams(
|
| const PrioritizedDispatcher::Limits& limits,
|
| const HostResolverImpl::ProcTaskParams& params) OVERRIDE {
|
| - resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(),
|
| - limits,
|
| - params,
|
| - NULL));
|
| + resolver_.reset(new HostResolverImpl(
|
| + HostCache::CreateDefaultCache(), limits, params, NULL));
|
| // Disable IPv6 support probing.
|
| resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
|
| dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_);
|
| @@ -1559,8 +1557,7 @@ TEST_F(HostResolverImplDnsTest, ServeFromHosts) {
|
|
|
| Request* req3 = CreateRequest("nx_both", 80);
|
| EXPECT_EQ(OK, req3->Resolve());
|
| - EXPECT_TRUE(req3->HasAddress("127.0.0.1", 80) &&
|
| - req3->HasAddress("::1", 80));
|
| + EXPECT_TRUE(req3->HasAddress("127.0.0.1", 80) && req3->HasAddress("::1", 80));
|
|
|
| // Requests with specified AddressFamily.
|
| Request* req4 = CreateRequest("nx_ipv4", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
|
| @@ -1698,8 +1695,8 @@ TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) {
|
|
|
| // Get the expected output.
|
| AddressList addrlist;
|
| - int rv = proc->Resolve("localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist,
|
| - NULL);
|
| + int rv = proc->Resolve(
|
| + "localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist, NULL);
|
| if (rv != OK)
|
| return;
|
|
|
| @@ -1794,15 +1791,15 @@ TEST_F(HostResolverImplDnsTest, DeleteWithActiveTransactions) {
|
| ChangeDnsConfig(CreateValidDnsConfig());
|
|
|
| // First active job is an IPv4 request.
|
| - EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM,
|
| - ADDRESS_FAMILY_IPV4)->Resolve());
|
| + EXPECT_EQ(ERR_IO_PENDING,
|
| + CreateRequest("ok", 80, MEDIUM, ADDRESS_FAMILY_IPV4)->Resolve());
|
|
|
| // Add 10 more DNS lookups for different hostnames. First 4 should have two
|
| // active jobs, next one has a single active job, and one pending. Others
|
| // should all be queued.
|
| for (int i = 0; i < 10; ++i) {
|
| - EXPECT_EQ(ERR_IO_PENDING, CreateRequest(
|
| - base::StringPrintf("ok%i", i))->Resolve());
|
| + EXPECT_EQ(ERR_IO_PENDING,
|
| + CreateRequest(base::StringPrintf("ok%i", i))->Resolve());
|
| }
|
| EXPECT_EQ(10u, num_running_dispatcher_jobs());
|
|
|
| @@ -1906,10 +1903,9 @@ TEST_F(HostResolverImplDnsTest, AAAAStartsAfterOtherJobFinishes) {
|
| resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
|
| ChangeDnsConfig(CreateValidDnsConfig());
|
|
|
| - EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM,
|
| - ADDRESS_FAMILY_IPV4)->Resolve());
|
| EXPECT_EQ(ERR_IO_PENDING,
|
| - CreateRequest("4slow_ok", 80, MEDIUM)->Resolve());
|
| + CreateRequest("ok", 80, MEDIUM, ADDRESS_FAMILY_IPV4)->Resolve());
|
| + EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80, MEDIUM)->Resolve());
|
| // An IPv4 request should have been started pending for each job.
|
| EXPECT_EQ(2u, num_running_dispatcher_jobs());
|
|
|
| @@ -1935,8 +1931,8 @@ TEST_F(HostResolverImplDnsTest, IPv4EmptyFallback) {
|
| proc_->AddRuleForAllFamilies("empty_fallback", "192.168.0.1");
|
| proc_->SignalMultiple(1u);
|
| EXPECT_EQ(ERR_IO_PENDING,
|
| - CreateRequest("empty_fallback", 80, MEDIUM,
|
| - ADDRESS_FAMILY_IPV4)->Resolve());
|
| + CreateRequest("empty_fallback", 80, MEDIUM, ADDRESS_FAMILY_IPV4)
|
| + ->Resolve());
|
| EXPECT_EQ(OK, requests_[0]->WaitForResult());
|
| EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80));
|
| }
|
| @@ -1947,9 +1943,10 @@ TEST_F(HostResolverImplDnsTest, UnspecEmptyFallback) {
|
| ChangeDnsConfig(CreateValidDnsConfig());
|
| proc_->AddRuleForAllFamilies("empty_fallback", "192.168.0.1");
|
| proc_->SignalMultiple(1u);
|
| - EXPECT_EQ(ERR_IO_PENDING,
|
| - CreateRequest("empty_fallback", 80, MEDIUM,
|
| - ADDRESS_FAMILY_UNSPECIFIED)->Resolve());
|
| + EXPECT_EQ(
|
| + ERR_IO_PENDING,
|
| + CreateRequest("empty_fallback", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED)
|
| + ->Resolve());
|
| EXPECT_EQ(OK, requests_[0]->WaitForResult());
|
| EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80));
|
| }
|
| @@ -2034,14 +2031,14 @@ TEST_F(HostResolverImplDnsTest,
|
| }
|
|
|
| EXPECT_EQ(OK, requests_[maximum_dns_failures()]->WaitForResult());
|
| - EXPECT_TRUE(requests_[maximum_dns_failures()]->HasOneAddress(
|
| - "192.168.0.2", 80));
|
| + EXPECT_TRUE(
|
| + requests_[maximum_dns_failures()]->HasOneAddress("192.168.0.2", 80));
|
| EXPECT_EQ(OK, requests_[maximum_dns_failures() + 1]->WaitForResult());
|
| EXPECT_TRUE(requests_[maximum_dns_failures() + 1]->HasOneAddress(
|
| - "192.168.0.3", 80));
|
| + "192.168.0.3", 80));
|
| EXPECT_EQ(OK, requests_[maximum_dns_failures() + 2]->WaitForResult());
|
| EXPECT_TRUE(requests_[maximum_dns_failures() + 2]->HasOneAddress(
|
| - "192.168.0.4", 80));
|
| + "192.168.0.4", 80));
|
| requests_.clear();
|
| }
|
| }
|
|
|