Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: net/dns/async_host_resolver_unittest.cc

Issue 9190031: DnsClient refactoring + features (timeout, suffix search, server rotation). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added comments. Fixed tests. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..088c14eba6f24bd8fcf85c234fd6d7df40ed8a49 100644
--- a/net/dns/async_host_resolver_unittest.cc
+++ b/net/dns/async_host_resolver_unittest.cc
@@ -53,34 +53,48 @@ class MockDnsClient : public DnsClient,
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 DnsClient::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()));
- return ERR_IO_PENDING;
+ }
+
+ virtual const std::string& GetHostname() const OVERRIDE {
+ return hostname_;
+ }
+
+ virtual uint16 GetType() const OVERRIDE {
+ return qtype_;
}
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_;
+ DnsClient::CallbackType callback_;
bool started_;
base::WeakPtr<MockDnsClient> client_;
};
@@ -92,12 +106,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 DnsClient::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 +153,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 +178,7 @@ class AsyncHostResolverTest : public testing::Test {
resolver_.reset(
new AsyncHostResolver(kMaxTransactions, kMaxPendingRequests,
HostCache::CreateDefaultCache(),
- client_.get(), NULL));
+ scoped_ptr<DnsClient>(client_), NULL));
}
void AddResponse(const std::string& name, uint8 type, DnsResponse* response) {
@@ -175,7 +191,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 +241,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) {

Powered by Google App Engine
This is Rietveld 408576698