| Index: net/dns/async_host_resolver_unittest.cc
|
| diff --git a/net/dns/async_host_resolver_unittest.cc b/net/dns/async_host_resolver_unittest.cc
|
| index 21123bc937bd98caa8b67ad77f472e30dac879a1..442246e96051e794976609b2dab84ce60fb0d827 100644
|
| --- a/net/dns/async_host_resolver_unittest.cc
|
| +++ b/net/dns/async_host_resolver_unittest.cc
|
| @@ -13,10 +13,10 @@
|
| #include "net/base/net_log.h"
|
| #include "net/base/sys_addrinfo.h"
|
| #include "net/base/test_completion_callback.h"
|
| -#include "net/dns/dns_client.h"
|
| #include "net/dns/dns_query.h"
|
| #include "net/dns/dns_response.h"
|
| #include "net/dns/dns_test_util.h"
|
| +#include "net/dns/dns_transaction.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace net {
|
| @@ -48,39 +48,57 @@ void VerifyAddressList(const std::vector<const char*>& ip_addresses,
|
| ASSERT_EQ(static_cast<addrinfo*>(NULL), ainfo);
|
| }
|
|
|
| -class MockDnsClient : public DnsClient,
|
| +class MockDnsClient : public DnsTransactionFactory,
|
| public base::SupportsWeakPtr<MockDnsClient> {
|
| public:
|
| // Using WeakPtr to support cancellation.
|
| // All MockRequests succeed unless canceled or MockDnsClient is destroyed.
|
| - class MockRequest : public DnsClient::Request,
|
| + class MockRequest : public DnsTransaction,
|
| public base::SupportsWeakPtr<MockRequest> {
|
| public:
|
| - MockRequest(const base::StringPiece& qname,
|
| + MockRequest(const std::string& hostname,
|
| uint16 qtype,
|
| - const RequestCallback& callback,
|
| + const DnsTransactionFactory::CallbackType& callback,
|
| const base::WeakPtr<MockDnsClient>& client)
|
| - : Request(qname, qtype, callback), started_(false), client_(client) {
|
| - }
|
| + : hostname_(hostname),
|
| + qtype_(qtype),
|
| + callback_(callback),
|
| + started_(false),
|
| + client_(client) {
|
|
|
| - virtual int Start() OVERRIDE {
|
| EXPECT_FALSE(started_);
|
| started_ = true;
|
| MessageLoop::current()->PostTask(
|
| FROM_HERE,
|
| base::Bind(&MockRequest::Finish, AsWeakPtr()));
|
| + }
|
| +
|
| + virtual const std::string& GetHostname() const OVERRIDE {
|
| + return hostname_;
|
| + }
|
| +
|
| + virtual uint16 GetType() const OVERRIDE {
|
| + return qtype_;
|
| + }
|
| +
|
| + virtual int Start() OVERRIDE {
|
| return ERR_IO_PENDING;
|
| }
|
|
|
| private:
|
| void Finish() {
|
| if (!client_) {
|
| - DoCallback(ERR_DNS_SERVER_FAILED, NULL);
|
| + callback_.Run(this, ERR_DNS_SERVER_FAILED, NULL);
|
| return;
|
| }
|
| - DoCallback(OK, client_->responses[Key(qname(), qtype())]);
|
| + callback_.Run(this,
|
| + OK,
|
| + client_->responses[Key(GetHostname(), GetType())]);
|
| }
|
|
|
| + std::string hostname_;
|
| + uint16 qtype_;
|
| + DnsTransactionFactory::CallbackType callback_;
|
| bool started_;
|
| base::WeakPtr<MockDnsClient> client_;
|
| };
|
| @@ -92,12 +110,14 @@ class MockDnsClient : public DnsClient,
|
| STLDeleteValues(&responses);
|
| }
|
|
|
| - Request* CreateRequest(const base::StringPiece& qname,
|
| - uint16 qtype,
|
| - const RequestCallback& callback,
|
| - const BoundNetLog&) {
|
| + scoped_ptr<DnsTransaction> CreateTransaction(
|
| + const std::string& qname,
|
| + uint16 qtype,
|
| + const DnsTransactionFactory::CallbackType& callback,
|
| + const BoundNetLog&) {
|
| ++num_requests;
|
| - return new MockRequest(qname, qtype, callback, AsWeakPtr());
|
| + return scoped_ptr<DnsTransaction>(
|
| + new MockRequest(qname, qtype, callback, AsWeakPtr()));
|
| }
|
|
|
| int num_requests;
|
| @@ -137,24 +157,24 @@ class AsyncHostResolverTest : public testing::Test {
|
| info2_.set_address_family(ADDRESS_FAMILY_IPV4);
|
| info3_.set_address_family(ADDRESS_FAMILY_IPV4);
|
|
|
| - client_.reset(new MockDnsClient());
|
| + client_ = new MockDnsClient();
|
|
|
| - AddResponse(std::string(kT0DnsName, arraysize(kT0DnsName)), kT0Qtype,
|
| + AddResponse(kT0HostName, kT0Qtype,
|
| new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram),
|
| arraysize(kT0ResponseDatagram),
|
| arraysize(kT0QueryDatagram)));
|
|
|
| - AddResponse(std::string(kT1DnsName, arraysize(kT1DnsName)), kT1Qtype,
|
| + AddResponse(kT1HostName, kT1Qtype,
|
| new DnsResponse(reinterpret_cast<const char*>(kT1ResponseDatagram),
|
| arraysize(kT1ResponseDatagram),
|
| arraysize(kT1QueryDatagram)));
|
|
|
| - AddResponse(std::string(kT2DnsName, arraysize(kT2DnsName)), kT2Qtype,
|
| + AddResponse(kT2HostName, kT2Qtype,
|
| new DnsResponse(reinterpret_cast<const char*>(kT2ResponseDatagram),
|
| arraysize(kT2ResponseDatagram),
|
| arraysize(kT2QueryDatagram)));
|
|
|
| - AddResponse(std::string(kT3DnsName, arraysize(kT3DnsName)), kT3Qtype,
|
| + AddResponse(kT3HostName, kT3Qtype,
|
| new DnsResponse(reinterpret_cast<const char*>(kT3ResponseDatagram),
|
| arraysize(kT3ResponseDatagram),
|
| arraysize(kT3QueryDatagram)));
|
| @@ -162,7 +182,7 @@ class AsyncHostResolverTest : public testing::Test {
|
| resolver_.reset(
|
| new AsyncHostResolver(kMaxTransactions, kMaxPendingRequests,
|
| HostCache::CreateDefaultCache(),
|
| - client_.get(), NULL));
|
| + scoped_ptr<DnsTransactionFactory>(client_), NULL));
|
| }
|
|
|
| void AddResponse(const std::string& name, uint8 type, DnsResponse* response) {
|
| @@ -175,7 +195,7 @@ class AsyncHostResolverTest : public testing::Test {
|
| std::vector<const char*> ip_addresses0_, ip_addresses1_,
|
| ip_addresses2_, ip_addresses3_;
|
| scoped_ptr<HostResolver> resolver_;
|
| - scoped_ptr<MockDnsClient> client_;
|
| + MockDnsClient* client_; // Owned by the AsyncHostResolver.
|
| TestCompletionCallback callback0_, callback1_, callback2_, callback3_;
|
| };
|
|
|
| @@ -225,18 +245,20 @@ TEST_F(AsyncHostResolverTest, CachedLookup) {
|
| VerifyAddressList(ip_addresses0_, kPortNum, addrlist1_);
|
| }
|
|
|
| -TEST_F(AsyncHostResolverTest, InvalidHostNameLookup) {
|
| +// TODO(szym): This tests DnsClient not AsyncHostResolver. Remove or move to
|
| +// dns_client_unittest.cc
|
| +TEST_F(AsyncHostResolverTest, DISABLED_InvalidHostNameLookup) {
|
| const std::string kHostName1(64, 'a');
|
| info0_.set_host_port_pair(HostPortPair(kHostName1, kPortNum));
|
| int rv = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL,
|
| BoundNetLog());
|
| - EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv);
|
| + EXPECT_EQ(ERR_INVALID_ARGUMENT, rv);
|
|
|
| const std::string kHostName2(4097, 'b');
|
| info0_.set_host_port_pair(HostPortPair(kHostName2, kPortNum));
|
| rv = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL,
|
| BoundNetLog());
|
| - EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv);
|
| + EXPECT_EQ(ERR_INVALID_ARGUMENT, rv);
|
| }
|
|
|
| TEST_F(AsyncHostResolverTest, Lookup) {
|
|
|