OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_DNS_DNS_TEST_UTIL_H_ | 5 #ifndef NET_DNS_DNS_TEST_UTIL_H_ |
6 #define NET_DNS_DNS_TEST_UTIL_H_ | 6 #define NET_DNS_DNS_TEST_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "net/dns/dns_client.h" | |
14 #include "net/dns/dns_config_service.h" | 13 #include "net/dns/dns_config_service.h" |
15 #include "net/dns/dns_protocol.h" | 14 #include "net/dns/dns_protocol.h" |
16 | 15 |
17 namespace net { | 16 namespace net { |
18 | 17 |
19 //----------------------------------------------------------------------------- | 18 //----------------------------------------------------------------------------- |
20 // Query/response set for www.google.com, ID is fixed to 0. | 19 // Query/response set for www.google.com, ID is fixed to 0. |
21 static const char kT0HostName[] = "www.google.com"; | 20 static const char kT0HostName[] = "www.google.com"; |
22 static const uint16 kT0Qtype = dns_protocol::kTypeA; | 21 static const uint16 kT0Qtype = dns_protocol::kTypeA; |
23 static const char kT0DnsName[] = { | 22 static const char kT0DnsName[] = { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 }; | 167 }; |
169 static const char* const kT3IpAddresses[] = { | 168 static const char* const kT3IpAddresses[] = { |
170 "74.125.226.178", "74.125.226.179", "74.125.226.180", | 169 "74.125.226.178", "74.125.226.179", "74.125.226.180", |
171 "74.125.226.176", "74.125.226.177" | 170 "74.125.226.176", "74.125.226.177" |
172 }; | 171 }; |
173 static const char kT3CanonName[] = "www.l.google.com"; | 172 static const char kT3CanonName[] = "www.l.google.com"; |
174 static const int kT3TTL = 0x00000015; | 173 static const int kT3TTL = 0x00000015; |
175 // +2 for the CNAME records, +1 for TXT record. | 174 // +2 for the CNAME records, +1 for TXT record. |
176 static const unsigned kT3RecordCount = arraysize(kT3IpAddresses) + 3; | 175 static const unsigned kT3RecordCount = arraysize(kT3IpAddresses) + 3; |
177 | 176 |
178 class AddressSorter; | |
179 class DnsClient; | 177 class DnsClient; |
180 class MockTransactionFactory; | |
181 | 178 |
182 struct MockDnsClientRule { | 179 struct MockDnsClientRule { |
183 enum Result { | 180 enum Result { |
184 FAIL, // Fail asynchronously with ERR_NAME_NOT_RESOLVED. | 181 FAIL, // Fail asynchronously with ERR_NAME_NOT_RESOLVED. |
185 TIMEOUT, // Fail asynchronously with ERR_DNS_TIMEOUT. | 182 TIMEOUT, // Fail asynchronously with ERR_DNS_TIMEOUT. |
186 EMPTY, // Return an empty response. | 183 EMPTY, // Return an empty response. |
187 OK, // Return a response with loopback address. | 184 OK, // Return a response with loopback address. |
188 }; | 185 }; |
189 | 186 |
190 // If |delay| is true, matching transactions will be delayed until triggered | |
191 // by the consumer. | |
192 MockDnsClientRule(const std::string& prefix_arg, | 187 MockDnsClientRule(const std::string& prefix_arg, |
193 uint16 qtype_arg, | 188 uint16 qtype_arg, |
194 Result result_arg, | 189 Result result_arg) |
195 bool delay) | 190 : result(result_arg), prefix(prefix_arg), qtype(qtype_arg) { } |
196 : result(result_arg), prefix(prefix_arg), qtype(qtype_arg), | |
197 delay(delay) {} | |
198 | 191 |
199 Result result; | 192 Result result; |
200 std::string prefix; | 193 std::string prefix; |
201 uint16 qtype; | 194 uint16 qtype; |
202 bool delay; | |
203 }; | 195 }; |
204 | 196 |
205 typedef std::vector<MockDnsClientRule> MockDnsClientRuleList; | 197 typedef std::vector<MockDnsClientRule> MockDnsClientRuleList; |
206 | 198 |
207 // MockDnsClient provides MockTransactionFactory. | 199 // Creates mock DnsClient for testing HostResolverImpl. |
208 class MockDnsClient : public DnsClient { | 200 scoped_ptr<DnsClient> CreateMockDnsClient(const DnsConfig& config, |
209 public: | 201 const MockDnsClientRuleList& rules); |
210 MockDnsClient(const DnsConfig& config, const MockDnsClientRuleList& rules); | |
211 virtual ~MockDnsClient(); | |
212 | |
213 // DnsClient interface: | |
214 virtual void SetConfig(const DnsConfig& config) OVERRIDE; | |
215 virtual const DnsConfig* GetConfig() const OVERRIDE; | |
216 virtual DnsTransactionFactory* GetTransactionFactory() OVERRIDE; | |
217 virtual AddressSorter* GetAddressSorter() OVERRIDE; | |
218 | |
219 // Completes all DnsTransactions that were delayed by a rule. | |
220 void CompleteDelayedTransactions(); | |
221 | |
222 private: | |
223 DnsConfig config_; | |
224 scoped_ptr<MockTransactionFactory> factory_; | |
225 scoped_ptr<AddressSorter> address_sorter_; | |
226 }; | |
227 | 202 |
228 } // namespace net | 203 } // namespace net |
229 | 204 |
230 #endif // NET_DNS_DNS_TEST_UTIL_H_ | 205 #endif // NET_DNS_DNS_TEST_UTIL_H_ |
OLD | NEW |