Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: net/dns/dns_test_util.h

Issue 22909037: [net/dns] Reland of 218616 (Simultaneous A/AAAA queries). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix printing unsigned Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/priority_queue_unittest.cc ('k') | net/dns/dns_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
13 #include "net/dns/dns_config_service.h" 14 #include "net/dns/dns_config_service.h"
14 #include "net/dns/dns_protocol.h" 15 #include "net/dns/dns_protocol.h"
15 16
16 namespace net { 17 namespace net {
17 18
18 //----------------------------------------------------------------------------- 19 //-----------------------------------------------------------------------------
19 // Query/response set for www.google.com, ID is fixed to 0. 20 // Query/response set for www.google.com, ID is fixed to 0.
20 static const char kT0HostName[] = "www.google.com"; 21 static const char kT0HostName[] = "www.google.com";
21 static const uint16 kT0Qtype = dns_protocol::kTypeA; 22 static const uint16 kT0Qtype = dns_protocol::kTypeA;
22 static const char kT0DnsName[] = { 23 static const char kT0DnsName[] = {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 }; 168 };
168 static const char* const kT3IpAddresses[] = { 169 static const char* const kT3IpAddresses[] = {
169 "74.125.226.178", "74.125.226.179", "74.125.226.180", 170 "74.125.226.178", "74.125.226.179", "74.125.226.180",
170 "74.125.226.176", "74.125.226.177" 171 "74.125.226.176", "74.125.226.177"
171 }; 172 };
172 static const char kT3CanonName[] = "www.l.google.com"; 173 static const char kT3CanonName[] = "www.l.google.com";
173 static const int kT3TTL = 0x00000015; 174 static const int kT3TTL = 0x00000015;
174 // +2 for the CNAME records, +1 for TXT record. 175 // +2 for the CNAME records, +1 for TXT record.
175 static const unsigned kT3RecordCount = arraysize(kT3IpAddresses) + 3; 176 static const unsigned kT3RecordCount = arraysize(kT3IpAddresses) + 3;
176 177
178 class AddressSorter;
177 class DnsClient; 179 class DnsClient;
180 class MockTransactionFactory;
178 181
179 struct MockDnsClientRule { 182 struct MockDnsClientRule {
180 enum Result { 183 enum Result {
181 FAIL, // Fail asynchronously with ERR_NAME_NOT_RESOLVED. 184 FAIL, // Fail asynchronously with ERR_NAME_NOT_RESOLVED.
182 TIMEOUT, // Fail asynchronously with ERR_DNS_TIMEOUT. 185 TIMEOUT, // Fail asynchronously with ERR_DNS_TIMEOUT.
183 EMPTY, // Return an empty response. 186 EMPTY, // Return an empty response.
184 OK, // Return a response with loopback address. 187 OK, // Return a response with loopback address.
185 }; 188 };
186 189
190 // If |delay| is true, matching transactions will be delayed until triggered
191 // by the consumer.
187 MockDnsClientRule(const std::string& prefix_arg, 192 MockDnsClientRule(const std::string& prefix_arg,
188 uint16 qtype_arg, 193 uint16 qtype_arg,
189 Result result_arg) 194 Result result_arg,
190 : result(result_arg), prefix(prefix_arg), qtype(qtype_arg) { } 195 bool delay)
196 : result(result_arg), prefix(prefix_arg), qtype(qtype_arg),
197 delay(delay) {}
191 198
192 Result result; 199 Result result;
193 std::string prefix; 200 std::string prefix;
194 uint16 qtype; 201 uint16 qtype;
202 bool delay;
195 }; 203 };
196 204
197 typedef std::vector<MockDnsClientRule> MockDnsClientRuleList; 205 typedef std::vector<MockDnsClientRule> MockDnsClientRuleList;
198 206
199 // Creates mock DnsClient for testing HostResolverImpl. 207 // MockDnsClient provides MockTransactionFactory.
200 scoped_ptr<DnsClient> CreateMockDnsClient(const DnsConfig& config, 208 class MockDnsClient : public DnsClient {
201 const MockDnsClientRuleList& rules); 209 public:
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 };
202 227
203 } // namespace net 228 } // namespace net
204 229
205 #endif // NET_DNS_DNS_TEST_UTIL_H_ 230 #endif // NET_DNS_DNS_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/base/priority_queue_unittest.cc ('k') | net/dns/dns_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698