Read HTTPS responses in HostResolverManager

Converted GetIntegrityResultsForTesting() into a shared
GetExperimentalResultsForTesting().  HTTPS records result in a `true`
experimental result if successfully parsed.  Records parsable enough to
recognize as HTTPS but without parsable rdatas result in a `false`
experimental result.

In order to determine up the stack if Chrome receives HTTPS records
with unparsable rdatas (as opposed to completely unparsable responses),
created a new MalformedHttpsRecordRdata type. This is minimally added
into HttpsRecordRdata because the plan is to remove it again once we
have completed initial query experiments.

Note: Discovered that all the HostResolverManagerDnsTest.*_WrongType
tests were not actually testing what we thought they were because they
all queried the wrong name.  Oops! Fixed them, and their mocked
responses, and had to slightly adjust DnsResponse to allow creating
those mocked responses.

Bug: 1138620
Change-Id: I9f95d659b2d044b4e702e6db965acd14a86c0848
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2508337
Reviewed-by: Dan McArdle <[email protected]>
Commit-Queue: Eric Orth <[email protected]>
Cr-Commit-Position: refs/heads/master@{#823862}
diff --git a/net/dns/dns_test_util.cc b/net/dns/dns_test_util.cc
index 28a6333..0de0f38 100644
--- a/net/dns/dns_test_util.cc
+++ b/net/dns/dns_test_util.cc
@@ -99,6 +99,55 @@
       net::IPAddressToPackedString(ip), ttl);
 }
 
+DnsResourceRecord BuildTestHttpsAliasRecord(std::string name,
+                                            base::StringPiece alias_name,
+                                            base::TimeDelta ttl) {
+  DCHECK(!name.empty());
+
+  std::string rdata("\000\000", 2);
+
+  std::string alias_domain;
+  CHECK(DNSDomainFromDot(alias_name, &alias_domain));
+  rdata.append(alias_domain);
+
+  return BuildTestDnsRecord(std::move(name), dns_protocol::kTypeHttps,
+                            std::move(rdata), ttl);
+}
+
+DnsResourceRecord BuildTestHttpsServiceRecord(
+    std::string name,
+    uint16_t priority,
+    base::StringPiece service_name,
+    const std::map<uint16_t, std::string>& params,
+    base::TimeDelta ttl) {
+  DCHECK(!name.empty());
+  DCHECK_NE(priority, 0);
+
+  std::string rdata;
+
+  char num_buffer[2];
+  base::WriteBigEndian(num_buffer, priority);
+  rdata.append(num_buffer, 2);
+
+  std::string service_domain;
+  CHECK(DNSDomainFromDot(service_name, &service_domain));
+  rdata.append(service_domain);
+
+  for (auto& param : params) {
+    base::WriteBigEndian(num_buffer, param.first);
+    rdata.append(num_buffer, 2);
+
+    base::WriteBigEndian(num_buffer,
+                         base::checked_cast<uint16_t>(param.second.size()));
+    rdata.append(num_buffer, 2);
+
+    rdata.append(param.second);
+  }
+
+  return BuildTestDnsRecord(std::move(name), dns_protocol::kTypeHttps,
+                            std::move(rdata), ttl);
+}
+
 DnsResponse BuildTestDnsResponse(
     std::string name,
     uint16_t type,
@@ -111,7 +160,8 @@
   base::Optional<DnsQuery> query(base::in_place, 0, std::move(dns_name), type);
   return DnsResponse(0, true /* is_authoritative */, answers,
                      {} /* authority_records */, {} /* additional_records */,
-                     query);
+                     query, dns_protocol::kRcodeNOERROR /* rcode */,
+                     false /* validate_answers_match_query */);
 }
 
 DnsResponse BuildTestDnsAddressResponse(std::string name,