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

Unified Diff: net/dns/dns_client_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/dns_client_unittest.cc
diff --git a/net/dns/dns_client_unittest.cc b/net/dns/dns_client_unittest.cc
index fdbae8f91a3cf817c57d2f60c5c34ec2e67792b7..7f5211c5a6f2e0159355ff47649c18786cc61267 100644
--- a/net/dns/dns_client_unittest.cc
+++ b/net/dns/dns_client_unittest.cc
@@ -15,8 +15,9 @@
#include "net/socket/socket_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
-// TODO(szym): test DnsClient::Request::Start with synchronous failure
-// TODO(szym): test suffix search and server fallback once implemented
+// TODO(szym): test timeout.
+// TODO(szym): test server fallback.
+// TODO(szym): test suffix search.
namespace net {
@@ -24,19 +25,18 @@ namespace {
class DnsClientTest : public testing::Test {
public:
- class TestRequestHelper {
+ class TestHelper {
public:
// If |answer_count| < 0, it is the expected error code.
- TestRequestHelper(const char* name,
- uint16 type,
- const MockWrite& write,
- const MockRead& read,
- int answer_count) {
- // Must include the terminating \x00.
- qname = std::string(name, strlen(name) + 1);
- qtype = type;
- expected_answer_count = answer_count;
- completed = false;
+ TestHelper(const char* name,
+ uint16 type,
+ const MockWrite& write,
+ const MockRead& read,
+ int answer_count)
+ : qname(name),
+ qtype(type),
+ expected_answer_count(answer_count),
+ completed(false) {
writes.push_back(write);
reads.push_back(read);
ReadBigEndian<uint16>(write.data, &transaction_id);
@@ -45,28 +45,27 @@ class DnsClientTest : public testing::Test {
}
void MakeRequest(DnsClient* client) {
- EXPECT_EQ(NULL, request.get());
- request.reset(client->CreateRequest(
+ EXPECT_EQ(NULL, transaction.get());
+ transaction = client->CreateTransaction(
qname,
qtype,
- base::Bind(&TestRequestHelper::OnRequestComplete,
+ base::Bind(&TestHelper::OnTransactionComplete,
base::Unretained(this)),
- BoundNetLog()));
- EXPECT_EQ(qname, request->qname());
- EXPECT_EQ(qtype, request->qtype());
- EXPECT_EQ(ERR_IO_PENDING, request->Start());
+ BoundNetLog());
+ EXPECT_EQ(qname, transaction->GetHostname());
+ EXPECT_EQ(qtype, transaction->GetType());
}
void Cancel() {
- ASSERT_TRUE(request.get() != NULL);
- request.reset(NULL);
+ ASSERT_TRUE(transaction.get() != NULL);
+ transaction.reset(NULL);
}
- void OnRequestComplete(DnsClient::Request* req,
- int rv,
- const DnsResponse* response) {
+ void OnTransactionComplete(DnsTransaction* t,
+ int rv,
+ const DnsResponse* response) {
EXPECT_FALSE(completed);
- EXPECT_EQ(request.get(), req);
+ EXPECT_EQ(transaction.get(), t);
if (expected_answer_count >= 0) {
EXPECT_EQ(OK, rv);
@@ -87,9 +86,9 @@ class DnsClientTest : public testing::Test {
completed = true;
}
- void CancelOnRequestComplete(DnsClient::Request* req,
- int rv,
- const DnsResponse* response) {
+ void CancelOnTransactionComplete(DnsTransaction* req,
+ int rv,
+ const DnsResponse* response) {
EXPECT_FALSE(completed);
Cancel();
}
@@ -100,15 +99,15 @@ class DnsClientTest : public testing::Test {
std::vector<MockRead> reads;
uint16 transaction_id; // Id from first write.
scoped_ptr<StaticSocketDataProvider> data;
- scoped_ptr<DnsClient::Request> request;
+ scoped_ptr<DnsTransaction> transaction;
int expected_answer_count;
bool completed;
};
virtual void SetUp() OVERRIDE {
- helpers_.push_back(new TestRequestHelper(
- kT0DnsName,
+ helpers_.push_back(new TestHelper(
+ kT0HostName,
kT0Qtype,
MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram),
arraysize(kT0QueryDatagram)),
@@ -116,8 +115,8 @@ class DnsClientTest : public testing::Test {
arraysize(kT0ResponseDatagram)),
arraysize(kT0IpAddresses) + 1)); // +1 for CNAME RR
- helpers_.push_back(new TestRequestHelper(
- kT1DnsName,
+ helpers_.push_back(new TestHelper(
+ kT1HostName,
kT1Qtype,
MockWrite(true, reinterpret_cast<const char*>(kT1QueryDatagram),
arraysize(kT1QueryDatagram)),
@@ -125,8 +124,8 @@ class DnsClientTest : public testing::Test {
arraysize(kT1ResponseDatagram)),
arraysize(kT1IpAddresses) + 1)); // +1 for CNAME RR
- helpers_.push_back(new TestRequestHelper(
- kT2DnsName,
+ helpers_.push_back(new TestHelper(
+ kT2HostName,
kT2Qtype,
MockWrite(true, reinterpret_cast<const char*>(kT2QueryDatagram),
arraysize(kT2QueryDatagram)),
@@ -134,8 +133,8 @@ class DnsClientTest : public testing::Test {
arraysize(kT2ResponseDatagram)),
arraysize(kT2IpAddresses) + 1)); // +1 for CNAME RR
- helpers_.push_back(new TestRequestHelper(
- kT3DnsName,
+ helpers_.push_back(new TestHelper(
+ kT3HostName,
kT3Qtype,
MockWrite(true, reinterpret_cast<const char*>(kT3QueryDatagram),
arraysize(kT3QueryDatagram)),
@@ -170,7 +169,7 @@ class DnsClientTest : public testing::Test {
base::Bind(&DnsClientTest::GetNextId, base::Unretained(this)),
NULL /* NetLog */);
- client_.reset(DnsClient::CreateClient(session));
+ client_ = DnsClient::CreateClient(session);
}
virtual void TearDown() OVERRIDE {
@@ -187,7 +186,7 @@ class DnsClientTest : public testing::Test {
}
protected:
- std::vector<TestRequestHelper*> helpers_;
+ std::vector<TestHelper*> helpers_;
std::deque<int> transaction_ids_;
scoped_ptr<DnsClient> client_;
};
@@ -246,13 +245,12 @@ TEST_F(DnsClientTest, DestroyClient) {
TEST_F(DnsClientTest, DestroyRequestFromCallback) {
// Custom callback to cancel the completing request.
- helpers_[0]->request.reset(client_->CreateRequest(
+ helpers_[0]->transaction = client_->CreateTransaction(
helpers_[0]->qname,
helpers_[0]->qtype,
- base::Bind(&TestRequestHelper::CancelOnRequestComplete,
+ base::Bind(&TestHelper::CancelOnTransactionComplete,
base::Unretained(helpers_[0])),
- BoundNetLog()));
- helpers_[0]->request->Start();
+ BoundNetLog());
for (unsigned i = 1; i < helpers_.size(); ++i) {
helpers_[i]->MakeRequest(client_.get());
@@ -269,8 +267,8 @@ TEST_F(DnsClientTest, DestroyRequestFromCallback) {
TEST_F(DnsClientTest, HandleFailure) {
STLDeleteElements(&helpers_);
// Wrong question.
- helpers_.push_back(new TestRequestHelper(
- kT0DnsName,
+ helpers_.push_back(new TestHelper(
+ kT0HostName,
kT0Qtype,
MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram),
arraysize(kT0QueryDatagram)),
@@ -283,8 +281,8 @@ TEST_F(DnsClientTest, HandleFailure) {
memcpy(nxdomain_response, kT0QueryDatagram, arraysize(nxdomain_response));
nxdomain_response[2] &= 0x80; // Response bit.
nxdomain_response[3] &= 0x03; // NXDOMAIN bit.
- helpers_.push_back(new TestRequestHelper(
- kT0DnsName,
+ helpers_.push_back(new TestHelper(
+ kT0HostName,
kT0Qtype,
MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram),
arraysize(kT0QueryDatagram)),

Powered by Google App Engine
This is Rietveld 408576698