| 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 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 |
| 169 // Creates mock DnsClient for testing HostResolverImpl. | 188 // Creates mock DnsClient for testing HostResolverImpl. |
| 170 scoped_ptr<DnsClient> CreateMockDnsClient(const DnsConfig& config); | 189 scoped_ptr<DnsClient> CreateMockDnsClient(const DnsConfig& config, |
| 190 const MockDnsClientRuleList& rules); |
| 171 | 191 |
| 172 class MockDnsConfigService : public DnsConfigService { | 192 class MockDnsConfigService : public DnsConfigService { |
| 173 public: | 193 public: |
| 174 virtual ~MockDnsConfigService(); | 194 virtual ~MockDnsConfigService(); |
| 175 | 195 |
| 176 // NetworkChangeNotifier::DNSObserver: | 196 // NetworkChangeNotifier::DNSObserver: |
| 177 virtual void OnDNSChanged(unsigned detail) OVERRIDE; | 197 virtual void OnDNSChanged(unsigned detail) OVERRIDE; |
| 178 | 198 |
| 179 // Expose the protected methods for tests. | 199 // Expose the protected methods for tests. |
| 180 void ChangeConfig(const DnsConfig& config); | 200 void ChangeConfig(const DnsConfig& config); |
| 181 void ChangeHosts(const DnsHosts& hosts); | 201 void ChangeHosts(const DnsHosts& hosts); |
| 182 }; | 202 }; |
| 183 | 203 |
| 184 | 204 |
| 185 } // namespace net | 205 } // namespace net |
| 186 | 206 |
| 187 #endif // NET_DNS_DNS_TEST_UTIL_H_ | 207 #endif // NET_DNS_DNS_TEST_UTIL_H_ |
| OLD | NEW |