TXT HostResolver support.

When ResolveHostParameters::dns_query_type is set to TXT, a relevant
DNS/MDNS query will be made with text record results in
ResolveHostRequest::GetTextResults().  Will always use DNS or MDNS
resolver as the System/Proc resolver only supports address queries.

Lots of necessary changes to MockDnsClient.  Rules now allow specifying
a full DnsResponse rather than just IPAddresses, and added a couple
helper methods to create such response objects.  Rewrote and cleaned up
all the response generation code to support the changes.

Bug: 846423
Change-Id: I7298c73e7293ed4415eaa57c8d750111295dfbda
Reviewed-on: https://chromium-review.googlesource.com/c/1352529
Reviewed-by: Tom Sepez <[email protected]>
Reviewed-by: Asanka Herath <[email protected]>
Commit-Queue: Eric Orth <[email protected]>
Cr-Commit-Position: refs/heads/master@{#615941}
diff --git a/net/dns/host_resolver_mdns_task.cc b/net/dns/host_resolver_mdns_task.cc
index 6e0f2f6..af5b795 100644
--- a/net/dns/host_resolver_mdns_task.cc
+++ b/net/dns/host_resolver_mdns_task.cc
@@ -8,6 +8,7 @@
 #include <utility>
 
 #include "base/logging.h"
+#include "base/strings/string_util.h"
 #include "net/base/ip_endpoint.h"
 #include "net/base/net_errors.h"
 #include "net/dns/public/dns_protocol.h"
@@ -86,7 +87,16 @@
     }
 
     if (error == net::OK) {
+      // Expected to be validated by MDnsClient.
+      DCHECK_EQ(DnsQueryTypeToQtype(query_type_), parsed->type());
+      DCHECK(
+          base::EqualsCaseInsensitiveASCII(task_->hostname_, parsed->name()));
+
       switch (query_type_) {
+        case DnsQueryType::UNSPECIFIED:
+          // Should create two separate transactions with specified type.
+          NOTREACHED();
+          break;
         case DnsQueryType::A:
           results_ = HostCache::Entry(
               OK,
@@ -101,9 +111,11 @@
                   parsed->rdata<net::AAAARecordRdata>()->address(), 0)),
               HostCache::Entry::SOURCE_UNKNOWN);
           break;
-        default:
-          // TODO(crbug.com/846423): Add result parsing for non-address types.
-          NOTIMPLEMENTED();
+        case DnsQueryType::TXT:
+          results_ = HostCache::Entry(
+              OK, parsed->rdata<net::TxtRecordRdata>()->texts(),
+              HostCache::Entry::SOURCE_UNKNOWN);
+          break;
       }
     } else {
       results_ = HostCache::Entry(error, HostCache::Entry::SOURCE_UNKNOWN);