xref: /aosp_15_r20/external/cronet/net/dns/host_resolver_internal_result_test_util.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_DNS_HOST_RESOLVER_INTERNAL_RESULT_TEST_UTIL_H_
6 #define NET_DNS_HOST_RESOLVER_INTERNAL_RESULT_TEST_UTIL_H_
7 
8 #include <map>
9 #include <optional>
10 #include <ostream>
11 #include <string>
12 #include <vector>
13 
14 #include "base/time/time.h"
15 #include "net/base/connection_endpoint_metadata.h"
16 #include "net/base/host_port_pair.h"
17 #include "net/base/ip_endpoint.h"
18 #include "net/dns/host_resolver_internal_result.h"
19 #include "net/dns/https_record_rdata.h"
20 #include "net/dns/public/dns_query_type.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 
24 namespace net {
25 
26 testing::Matcher<const HostResolverInternalResult&>
27 ExpectHostResolverInternalDataResult(
28     std::string expected_domain_name,
29     DnsQueryType expected_query_type,
30     HostResolverInternalResult::Source expected_source,
31     testing::Matcher<std::optional<base::TimeTicks>> expiration_matcher,
32     testing::Matcher<std::optional<base::Time>> timed_expiration_matcher,
33     testing::Matcher<std::vector<IPEndPoint>> endpoints_matcher =
34         testing::IsEmpty(),
35     testing::Matcher<std::vector<std::string>> strings_matcher =
36         testing::IsEmpty(),
37     testing::Matcher<std::vector<HostPortPair>> hosts_matcher =
38         testing::IsEmpty());
39 
40 testing::Matcher<const HostResolverInternalResult&>
41 ExpectHostResolverInternalMetadataResult(
42     std::string expected_domain_name,
43     DnsQueryType expected_query_type,
44     HostResolverInternalResult::Source expected_source,
45     testing::Matcher<std::optional<base::TimeTicks>> expiration_matcher,
46     testing::Matcher<std::optional<base::Time>> timed_expiration_matcher,
47     testing::Matcher<
48         std::multimap<HttpsRecordPriority, ConnectionEndpointMetadata>>
49         metadatas_matcher = testing::IsEmpty());
50 
51 testing::Matcher<const HostResolverInternalResult&>
52 ExpectHostResolverInternalErrorResult(
53     std::string expected_domain_name,
54     DnsQueryType expected_query_type,
55     HostResolverInternalResult::Source expected_source,
56     testing::Matcher<std::optional<base::TimeTicks>> expiration_matcher,
57     testing::Matcher<std::optional<base::Time>> timed_expiration_matcher,
58     int expected_error);
59 
60 testing::Matcher<const HostResolverInternalResult&>
61 ExpectHostResolverInternalAliasResult(
62     std::string expected_domain_name,
63     DnsQueryType expected_query_type,
64     HostResolverInternalResult::Source expected_source,
65     testing::Matcher<std::optional<base::TimeTicks>> expiration_matcher,
66     testing::Matcher<std::optional<base::Time>> timed_expiration_matcher,
67     std::string expected_alias_target);
68 
69 std::ostream& operator<<(std::ostream& os,
70                          const HostResolverInternalResult& result);
71 
72 }  // namespace net
73 
74 #endif  // NET_DNS_HOST_RESOLVER_INTERNAL_RESULT_TEST_UTIL_H_
75