[email protected] | d0d49dd8 | 2012-01-26 00:03:59 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 4b0112ab | 2011-07-22 15:58:20 | [diff] [blame] | 5 | #ifndef NET_DNS_DNS_TEST_UTIL_H_ |
| 6 | #define NET_DNS_DNS_TEST_UTIL_H_ |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 7 | |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame^] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | d0d49dd8 | 2012-01-26 00:03:59 | [diff] [blame] | 11 | #include "base/basictypes.h" |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 12 | #include "base/memory/scoped_ptr.h" |
| 13 | #include "net/dns/dns_config_service.h" |
[email protected] | 7556ea2 | 2011-12-08 19:29:15 | [diff] [blame] | 14 | #include "net/dns/dns_protocol.h" |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 15 | |
| 16 | namespace net { |
| 17 | |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 18 | //----------------------------------------------------------------------------- |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 19 | // Query/response set for www.google.com, ID is fixed to 0. |
| 20 | static const char kT0HostName[] = "www.google.com"; |
[email protected] | 7556ea2 | 2011-12-08 19:29:15 | [diff] [blame] | 21 | static const uint16 kT0Qtype = dns_protocol::kTypeA; |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 22 | static const char kT0DnsName[] = { |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 23 | 0x03, 'w', 'w', 'w', |
| 24 | 0x06, 'g', 'o', 'o', 'g', 'l', 'e', |
| 25 | 0x03, 'c', 'o', 'm', |
| 26 | 0x00 |
| 27 | }; |
[email protected] | b3601bc2 | 2012-02-21 21:23:20 | [diff] [blame] | 28 | static const size_t kT0QuerySize = 32; |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 29 | static const uint8 kT0ResponseDatagram[] = { |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 30 | // response contains one CNAME for www.l.google.com and the following |
| 31 | // IP addresses: 74.125.226.{179,180,176,177,178} |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 32 | 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x06, |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 33 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, |
| 34 | 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, |
| 35 | 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01, |
| 36 | 0xc0, 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, |
| 37 | 0x4d, 0x13, 0x00, 0x08, 0x03, 0x77, 0x77, 0x77, |
| 38 | 0x01, 0x6c, 0xc0, 0x10, 0xc0, 0x2c, 0x00, 0x01, |
| 39 | 0x00, 0x01, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x04, |
| 40 | 0x4a, 0x7d, 0xe2, 0xb3, 0xc0, 0x2c, 0x00, 0x01, |
| 41 | 0x00, 0x01, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x04, |
| 42 | 0x4a, 0x7d, 0xe2, 0xb4, 0xc0, 0x2c, 0x00, 0x01, |
| 43 | 0x00, 0x01, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x04, |
| 44 | 0x4a, 0x7d, 0xe2, 0xb0, 0xc0, 0x2c, 0x00, 0x01, |
| 45 | 0x00, 0x01, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x04, |
| 46 | 0x4a, 0x7d, 0xe2, 0xb1, 0xc0, 0x2c, 0x00, 0x01, |
| 47 | 0x00, 0x01, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x04, |
| 48 | 0x4a, 0x7d, 0xe2, 0xb2 |
| 49 | }; |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 50 | static const char* const kT0IpAddresses[] = { |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 51 | "74.125.226.179", "74.125.226.180", "74.125.226.176", |
| 52 | "74.125.226.177", "74.125.226.178" |
| 53 | }; |
[email protected] | b3601bc2 | 2012-02-21 21:23:20 | [diff] [blame] | 54 | static const char kT0CanonName[] = "www.l.google.com"; |
| 55 | static const int kT0TTL = 0x000000e4; |
[email protected] | 9d22312b | 2012-04-07 10:09:54 | [diff] [blame] | 56 | // +1 for the CNAME record. |
| 57 | static const unsigned kT0RecordCount = arraysize(kT0IpAddresses) + 1; |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 58 | |
| 59 | //----------------------------------------------------------------------------- |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 60 | // Query/response set for codereview.chromium.org, ID is fixed to 1. |
| 61 | static const char kT1HostName[] = "codereview.chromium.org"; |
[email protected] | 7556ea2 | 2011-12-08 19:29:15 | [diff] [blame] | 62 | static const uint16 kT1Qtype = dns_protocol::kTypeA; |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 63 | static const char kT1DnsName[] = { |
[email protected] | 7556ea2 | 2011-12-08 19:29:15 | [diff] [blame] | 64 | 0x0a, 'c', 'o', 'd', 'e', 'r', 'e', 'v', 'i', 'e', 'w', |
| 65 | 0x08, 'c', 'h', 'r', 'o', 'm', 'i', 'u', 'm', |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 66 | 0x03, 'o', 'r', 'g', |
| 67 | 0x00 |
| 68 | }; |
[email protected] | b3601bc2 | 2012-02-21 21:23:20 | [diff] [blame] | 69 | static const size_t kT1QuerySize = 41; |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 70 | static const uint8 kT1ResponseDatagram[] = { |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 71 | // response contains one CNAME for ghs.l.google.com and the following |
| 72 | // IP address: 64.233.169.121 |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 73 | 0x00, 0x01, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 74 | 0x00, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x6f, 0x64, |
| 75 | 0x65, 0x72, 0x65, 0x76, 0x69, 0x65, 0x77, 0x08, |
| 76 | 0x63, 0x68, 0x72, 0x6f, 0x6d, 0x69, 0x75, 0x6d, |
| 77 | 0x03, 0x6f, 0x72, 0x67, 0x00, 0x00, 0x01, 0x00, |
| 78 | 0x01, 0xc0, 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, |
| 79 | 0x01, 0x41, 0x75, 0x00, 0x12, 0x03, 0x67, 0x68, |
| 80 | 0x73, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f, 0x67, |
| 81 | 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0xc0, |
| 82 | 0x35, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, |
| 83 | 0x0b, 0x00, 0x04, 0x40, 0xe9, 0xa9, 0x79 |
| 84 | }; |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 85 | static const char* const kT1IpAddresses[] = { |
| 86 | "64.233.169.121" |
| 87 | }; |
[email protected] | b3601bc2 | 2012-02-21 21:23:20 | [diff] [blame] | 88 | static const char kT1CanonName[] = "ghs.l.google.com"; |
| 89 | static const int kT1TTL = 0x0000010b; |
[email protected] | 9d22312b | 2012-04-07 10:09:54 | [diff] [blame] | 90 | // +1 for the CNAME record. |
| 91 | static const unsigned kT1RecordCount = arraysize(kT1IpAddresses) + 1; |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 92 | |
| 93 | //----------------------------------------------------------------------------- |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 94 | // Query/response set for www.ccs.neu.edu, ID is fixed to 2. |
| 95 | static const char kT2HostName[] = "www.ccs.neu.edu"; |
[email protected] | 7556ea2 | 2011-12-08 19:29:15 | [diff] [blame] | 96 | static const uint16 kT2Qtype = dns_protocol::kTypeA; |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 97 | static const char kT2DnsName[] = { |
| 98 | 0x03, 'w', 'w', 'w', |
[email protected] | 7556ea2 | 2011-12-08 19:29:15 | [diff] [blame] | 99 | 0x03, 'c', 'c', 's', |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 100 | 0x03, 'n', 'e', 'u', |
| 101 | 0x03, 'e', 'd', 'u', |
| 102 | 0x00 |
| 103 | }; |
[email protected] | b3601bc2 | 2012-02-21 21:23:20 | [diff] [blame] | 104 | static const size_t kT2QuerySize = 33; |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 105 | static const uint8 kT2ResponseDatagram[] = { |
| 106 | // response contains one CNAME for vulcan.ccs.neu.edu and the following |
| 107 | // IP address: 129.10.116.81 |
| 108 | 0x00, 0x02, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, |
| 109 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, |
| 110 | 0x03, 0x63, 0x63, 0x73, 0x03, 0x6e, 0x65, 0x75, |
| 111 | 0x03, 0x65, 0x64, 0x75, 0x00, 0x00, 0x01, 0x00, |
| 112 | 0x01, 0xc0, 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, |
| 113 | 0x00, 0x01, 0x2c, 0x00, 0x09, 0x06, 0x76, 0x75, |
| 114 | 0x6c, 0x63, 0x61, 0x6e, 0xc0, 0x10, 0xc0, 0x2d, |
| 115 | 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x2c, |
| 116 | 0x00, 0x04, 0x81, 0x0a, 0x74, 0x51 |
| 117 | }; |
| 118 | static const char* const kT2IpAddresses[] = { |
| 119 | "129.10.116.81" |
| 120 | }; |
[email protected] | b3601bc2 | 2012-02-21 21:23:20 | [diff] [blame] | 121 | static const char kT2CanonName[] = "vulcan.ccs.neu.edu"; |
| 122 | static const int kT2TTL = 0x0000012c; |
[email protected] | 9d22312b | 2012-04-07 10:09:54 | [diff] [blame] | 123 | // +1 for the CNAME record. |
| 124 | static const unsigned kT2RecordCount = arraysize(kT2IpAddresses) + 1; |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 125 | |
| 126 | //----------------------------------------------------------------------------- |
| 127 | // Query/response set for www.google.az, ID is fixed to 3. |
| 128 | static const char kT3HostName[] = "www.google.az"; |
[email protected] | 7556ea2 | 2011-12-08 19:29:15 | [diff] [blame] | 129 | static const uint16 kT3Qtype = dns_protocol::kTypeA; |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 130 | static const char kT3DnsName[] = { |
| 131 | 0x03, 'w', 'w', 'w', |
| 132 | 0x06, 'g', 'o', 'o', 'g', 'l', 'e', |
| 133 | 0x02, 'a', 'z', |
| 134 | 0x00 |
| 135 | }; |
[email protected] | b3601bc2 | 2012-02-21 21:23:20 | [diff] [blame] | 136 | static const size_t kT3QuerySize = 31; |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 137 | static const uint8 kT3ResponseDatagram[] = { |
| 138 | // response contains www.google.com as CNAME for www.google.az and |
| 139 | // www.l.google.com as CNAME for www.google.com and the following |
| 140 | // IP addresses: 74.125.226.{178,179,180,176,177} |
| 141 | 0x00, 0x03, 0x81, 0x80, 0x00, 0x01, 0x00, 0x07, |
| 142 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77, |
| 143 | 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x02, |
| 144 | 0x61, 0x7a, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0, |
| 145 | 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, 0x50, |
| 146 | 0x99, 0x00, 0x10, 0x03, 0x77, 0x77, 0x77, 0x06, |
| 147 | 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, |
| 148 | 0x6f, 0x6d, 0x00, 0xc0, 0x2b, 0x00, 0x05, 0x00, |
| 149 | 0x01, 0x00, 0x01, 0x50, 0x99, 0x00, 0x08, 0x03, |
| 150 | 0x77, 0x77, 0x77, 0x01, 0x6c, 0xc0, 0x2f, 0xc0, |
| 151 | 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 152 | 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb2, 0xc0, |
| 153 | 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 154 | 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb3, 0xc0, |
| 155 | 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 156 | 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb4, 0xc0, |
| 157 | 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 158 | 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb0, 0xc0, |
| 159 | 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 160 | 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb1 |
| 161 | }; |
| 162 | static const char* const kT3IpAddresses[] = { |
| 163 | "74.125.226.178", "74.125.226.179", "74.125.226.180", |
| 164 | "74.125.226.176", "74.125.226.177" |
| 165 | }; |
[email protected] | b3601bc2 | 2012-02-21 21:23:20 | [diff] [blame] | 166 | static const char kT3CanonName[] = "www.l.google.com"; |
| 167 | static const int kT3TTL = 0x00000015; |
[email protected] | 9d22312b | 2012-04-07 10:09:54 | [diff] [blame] | 168 | // +2 for the CNAME records. |
| 169 | static const unsigned kT3RecordCount = arraysize(kT3IpAddresses) + 2; |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 170 | |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 171 | class DnsClient; |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame^] | 172 | |
| 173 | struct MockDnsClientRule { |
| 174 | enum Result { |
| 175 | FAIL_SYNC, // Fail synchronously with ERR_NAME_NOT_RESOLVED. |
| 176 | FAIL_ASYNC, // Fail asynchronously with ERR_NAME_NOT_RESOLVED. |
| 177 | EMPTY, // Return an empty response. |
| 178 | OK, // Return a response with loopback address. |
| 179 | }; |
| 180 | |
| 181 | std::string prefix; |
| 182 | uint16 qtype; |
| 183 | Result result; |
| 184 | }; |
| 185 | |
| 186 | typedef std::vector<MockDnsClientRule> MockDnsClientRuleList; |
| 187 | |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 188 | // Creates mock DnsClient for testing HostResolverImpl. |
[email protected] | 0adcb2b | 2012-08-15 21:30:46 | [diff] [blame^] | 189 | scoped_ptr<DnsClient> CreateMockDnsClient(const DnsConfig& config, |
| 190 | const MockDnsClientRuleList& rules); |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 191 | |
| 192 | class MockDnsConfigService : public DnsConfigService { |
| 193 | public: |
[email protected] | 05aad32d | 2012-05-16 18:10:53 | [diff] [blame] | 194 | virtual ~MockDnsConfigService(); |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 195 | |
[email protected] | 05aad32d | 2012-05-16 18:10:53 | [diff] [blame] | 196 | // NetworkChangeNotifier::DNSObserver: |
| 197 | virtual void OnDNSChanged(unsigned detail) OVERRIDE; |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 198 | |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 199 | // Expose the protected methods for tests. |
[email protected] | 05aad32d | 2012-05-16 18:10:53 | [diff] [blame] | 200 | void ChangeConfig(const DnsConfig& config); |
| 201 | void ChangeHosts(const DnsHosts& hosts); |
[email protected] | 78eac2a | 2012-03-14 19:09:27 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | |
[email protected] | d391116 | 2011-07-18 15:12:46 | [diff] [blame] | 205 | } // namespace net |
| 206 | |
[email protected] | 4b0112ab | 2011-07-22 15:58:20 | [diff] [blame] | 207 | #endif // NET_DNS_DNS_TEST_UTIL_H_ |