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> |
| 9 #include <vector> |
| 10 |
8 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
10 #include "net/dns/dns_config_service.h" | 13 #include "net/dns/dns_config_service.h" |
11 #include "net/dns/dns_protocol.h" | 14 #include "net/dns/dns_protocol.h" |
12 | 15 |
13 namespace net { | 16 namespace net { |
14 | 17 |
15 //----------------------------------------------------------------------------- | 18 //----------------------------------------------------------------------------- |
16 // 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. |
17 static const char kT0HostName[] = "www.google.com"; | 20 static const char kT0HostName[] = "www.google.com"; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 static const char* const kT3IpAddresses[] = { | 162 static const char* const kT3IpAddresses[] = { |
160 "74.125.226.178", "74.125.226.179", "74.125.226.180", | 163 "74.125.226.178", "74.125.226.179", "74.125.226.180", |
161 "74.125.226.176", "74.125.226.177" | 164 "74.125.226.176", "74.125.226.177" |
162 }; | 165 }; |
163 static const char kT3CanonName[] = "www.l.google.com"; | 166 static const char kT3CanonName[] = "www.l.google.com"; |
164 static const int kT3TTL = 0x00000015; | 167 static const int kT3TTL = 0x00000015; |
165 // +2 for the CNAME records. | 168 // +2 for the CNAME records. |
166 static const unsigned kT3RecordCount = arraysize(kT3IpAddresses) + 2; | 169 static const unsigned kT3RecordCount = arraysize(kT3IpAddresses) + 2; |
167 | 170 |
168 class DnsClient; | 171 class DnsClient; |
| 172 |
| 173 struct MockDnsClientRule { |
| 174 std::string prefix; |
| 175 uint16 qtype; |
| 176 enum Result { |
| 177 FAIL_SYNC, // Fail synchronously with ERR_NAME_NOT_RESOLVED. |
| 178 FAIL_ASYNC, // Fail asynchronously with ERR_NAME_NOT_RESOLVED. |
| 179 EMPTY, // Return an empty response. |
| 180 OK, // Return a response with loopback address. |
| 181 } result; |
| 182 }; |
| 183 |
| 184 typedef std::vector<MockDnsClientRule> MockDnsClientRuleList; |
| 185 |
169 // Creates mock DnsClient for testing HostResolverImpl. | 186 // Creates mock DnsClient for testing HostResolverImpl. |
170 scoped_ptr<DnsClient> CreateMockDnsClient(const DnsConfig& config); | 187 scoped_ptr<DnsClient> CreateMockDnsClient(const DnsConfig& config, |
| 188 const MockDnsClientRuleList& rules); |
171 | 189 |
172 class MockDnsConfigService : public DnsConfigService { | 190 class MockDnsConfigService : public DnsConfigService { |
173 public: | 191 public: |
174 virtual ~MockDnsConfigService(); | 192 virtual ~MockDnsConfigService(); |
175 | 193 |
176 // NetworkChangeNotifier::DNSObserver: | 194 // NetworkChangeNotifier::DNSObserver: |
177 virtual void OnDNSChanged(unsigned detail) OVERRIDE; | 195 virtual void OnDNSChanged(unsigned detail) OVERRIDE; |
178 | 196 |
179 // Expose the protected methods for tests. | 197 // Expose the protected methods for tests. |
180 void ChangeConfig(const DnsConfig& config); | 198 void ChangeConfig(const DnsConfig& config); |
181 void ChangeHosts(const DnsHosts& hosts); | 199 void ChangeHosts(const DnsHosts& hosts); |
182 }; | 200 }; |
183 | 201 |
184 | 202 |
185 } // namespace net | 203 } // namespace net |
186 | 204 |
187 #endif // NET_DNS_DNS_TEST_UTIL_H_ | 205 #endif // NET_DNS_DNS_TEST_UTIL_H_ |
OLD | NEW |