Chromium Code Reviews| 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..4969ac0c5c69e95d65b99b08f322d8d6d12ce8c6 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,8 @@ 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(), |
| + result_.ip.bytes().size()); |
|
mmenke
2016/12/13 19:24:15
nit: result_.ip.bytes().size() -> size, or remove
eroman
2016/12/13 22:09:04
Done.
|
| nbytes += answer_size; |
| } |
| EXPECT_TRUE(response.InitParse(nbytes, query)); |