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

Unified Diff: net/dns/dns_test_util.cc

Issue 2567623003: Make ERR_ICANN_NAME_COLLISION work for async DNS resolver. (Closed)
Patch Set: address Matt's comments Created 4 years 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
« no previous file with comments | « net/dns/dns_test_util.h ('k') | net/dns/host_resolver_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_test_util.cc
diff --git a/net/dns/dns_test_util.cc b/net/dns/dns_test_util.cc
index 24ce6fbb3755a40468374b355b623a3abe398249..2de2c69bdd4c81f9484114cd75e4fa628f8b3aba 100644
--- a/net/dns/dns_test_util.cc
+++ b/net/dns/dns_test_util.cc
@@ -57,6 +57,13 @@ class MockTransaction : public DnsTransaction,
(hostname.compare(0, prefix.size(), prefix) == 0)) {
result_ = rules[i].result;
delayed_ = rules[i].delay;
+
+ // Fill in an IP address for the result if one was not specified.
+ if (result_.ip.empty() && result_.type == MockDnsClientRule::OK) {
+ result_.ip = qtype_ == dns_protocol::kTypeA
+ ? IPAddress::IPv4Localhost()
+ : IPAddress::IPv6Localhost();
+ }
break;
}
}
@@ -86,7 +93,7 @@ class MockTransaction : public DnsTransaction,
private:
void Finish() {
- switch (result_) {
+ switch (result_.type) {
case MockDnsClientRule::EMPTY:
case MockDnsClientRule::OK: {
std::string qname;
@@ -101,22 +108,21 @@ class MockTransaction : public DnsTransaction,
reinterpret_cast<dns_protocol::Header*>(buffer);
header->flags |= dns_protocol::kFlagResponse;
- if (MockDnsClientRule::OK == result_) {
+ if (MockDnsClientRule::OK == result_.type) {
const uint16_t kPointerToQueryName =
static_cast<uint16_t>(0xc000 | sizeof(*header));
const uint32_t kTTL = 86400; // One day.
// Size of RDATA which is a IPv4 or IPv6 address.
- size_t rdata_size = qtype_ == dns_protocol::kTypeA
- ? IPAddress::kIPv4AddressSize
- : IPAddress::kIPv6AddressSize;
+ EXPECT_TRUE(result_.ip.IsValid());
+ size_t rdata_size = result_.ip.size();
// 12 is the sum of sizes of the compressed name reference, TYPE,
// CLASS, TTL and RDLENGTH.
size_t answer_size = 12 + rdata_size;
- // Write answer with loopback IP address.
+ // Write the answer using the expected IP address.
header->ancount = base::HostToNet16(1);
base::BigEndianWriter writer(buffer + nbytes, answer_size);
writer.WriteU16(kPointerToQueryName);
@@ -124,14 +130,7 @@ class MockTransaction : public DnsTransaction,
writer.WriteU16(dns_protocol::kClassIN);
writer.WriteU32(kTTL);
writer.WriteU16(static_cast<uint16_t>(rdata_size));
- if (qtype_ == dns_protocol::kTypeA) {
- char kIPv4Loopback[] = { 0x7f, 0, 0, 1 };
- writer.WriteBytes(kIPv4Loopback, sizeof(kIPv4Loopback));
- } else {
- char kIPv6Loopback[] = { 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 1 };
- writer.WriteBytes(kIPv6Loopback, sizeof(kIPv6Loopback));
- }
+ writer.WriteBytes(result_.ip.bytes().data(), rdata_size);
nbytes += answer_size;
}
EXPECT_TRUE(response.InitParse(nbytes, query));
« no previous file with comments | « net/dns/dns_test_util.h ('k') | net/dns/host_resolver_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698