OLD | NEW |
1 // Copyright (c) 2011 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 #include "net/dns/async_host_resolver.h" | 5 #include "net/dns/async_host_resolver.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "net/base/host_cache.h" | 11 #include "net/base/host_cache.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/base/net_log.h" | 13 #include "net/base/net_log.h" |
14 #include "net/base/sys_addrinfo.h" | 14 #include "net/base/sys_addrinfo.h" |
15 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
16 #include "net/dns/dns_client.h" | |
17 #include "net/dns/dns_query.h" | 16 #include "net/dns/dns_query.h" |
18 #include "net/dns/dns_response.h" | 17 #include "net/dns/dns_response.h" |
19 #include "net/dns/dns_test_util.h" | 18 #include "net/dns/dns_test_util.h" |
| 19 #include "net/dns/dns_transaction.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const int kPortNum = 80; | 26 const int kPortNum = 80; |
27 const size_t kMaxTransactions = 2; | 27 const size_t kMaxTransactions = 2; |
28 const size_t kMaxPendingRequests = 1; | 28 const size_t kMaxPendingRequests = 1; |
29 | 29 |
(...skipping 11 matching lines...) Expand all Loading... |
41 EXPECT_EQ(sizeof(struct sockaddr_in), ainfo->ai_addrlen); | 41 EXPECT_EQ(sizeof(struct sockaddr_in), ainfo->ai_addrlen); |
42 | 42 |
43 const struct sockaddr* sa = ainfo->ai_addr; | 43 const struct sockaddr* sa = ainfo->ai_addr; |
44 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; | 44 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; |
45 EXPECT_TRUE(htons(port) == sa_in->sin_port); | 45 EXPECT_TRUE(htons(port) == sa_in->sin_port); |
46 EXPECT_STREQ(*i, NetAddressToString(sa, ainfo->ai_addrlen).c_str()); | 46 EXPECT_STREQ(*i, NetAddressToString(sa, ainfo->ai_addrlen).c_str()); |
47 } | 47 } |
48 ASSERT_EQ(static_cast<addrinfo*>(NULL), ainfo); | 48 ASSERT_EQ(static_cast<addrinfo*>(NULL), ainfo); |
49 } | 49 } |
50 | 50 |
51 class MockDnsClient : public DnsClient, | 51 class MockTransactionFactory : public DnsTransactionFactory, |
52 public base::SupportsWeakPtr<MockDnsClient> { | 52 public base::SupportsWeakPtr<MockTransactionFactory> { |
53 public: | 53 public: |
54 // Using WeakPtr to support cancellation. | 54 // Using WeakPtr to support cancellation. All MockTransactions succeed unless |
55 // All MockRequests succeed unless canceled or MockDnsClient is destroyed. | 55 // cancelled or MockTransactionFactory is destroyed. |
56 class MockRequest : public DnsClient::Request, | 56 class MockTransaction : public DnsTransaction, |
57 public base::SupportsWeakPtr<MockRequest> { | 57 public base::SupportsWeakPtr<MockTransaction> { |
58 public: | 58 public: |
59 MockRequest(const base::StringPiece& qname, | 59 MockTransaction(const std::string& hostname, |
60 uint16 qtype, | 60 uint16 qtype, |
61 const RequestCallback& callback, | 61 const DnsTransactionFactory::CallbackType& callback, |
62 const base::WeakPtr<MockDnsClient>& client) | 62 const base::WeakPtr<MockTransactionFactory>& factory) |
63 : Request(qname, qtype, callback), started_(false), client_(client) { | 63 : hostname_(hostname), |
64 } | 64 qtype_(qtype), |
65 | 65 callback_(callback), |
66 virtual int Start() OVERRIDE { | 66 started_(false), |
| 67 factory_(factory) { |
67 EXPECT_FALSE(started_); | 68 EXPECT_FALSE(started_); |
68 started_ = true; | 69 started_ = true; |
69 MessageLoop::current()->PostTask( | 70 MessageLoop::current()->PostTask( |
70 FROM_HERE, | 71 FROM_HERE, |
71 base::Bind(&MockRequest::Finish, AsWeakPtr())); | 72 base::Bind(&MockTransaction::Finish, AsWeakPtr())); |
| 73 } |
| 74 |
| 75 virtual const std::string& GetHostname() const OVERRIDE { |
| 76 return hostname_; |
| 77 } |
| 78 |
| 79 virtual uint16 GetType() const OVERRIDE { |
| 80 return qtype_; |
| 81 } |
| 82 |
| 83 virtual int Start() OVERRIDE { |
72 return ERR_IO_PENDING; | 84 return ERR_IO_PENDING; |
73 } | 85 } |
74 | 86 |
75 private: | 87 private: |
76 void Finish() { | 88 void Finish() { |
77 if (!client_) { | 89 if (!factory_) { |
78 DoCallback(ERR_DNS_SERVER_FAILED, NULL); | 90 callback_.Run(this, ERR_DNS_SERVER_FAILED, NULL); |
79 return; | 91 return; |
80 } | 92 } |
81 DoCallback(OK, client_->responses[Key(qname(), qtype())]); | 93 callback_.Run(this, |
| 94 OK, |
| 95 factory_->responses_[Key(GetHostname(), GetType())]); |
82 } | 96 } |
83 | 97 |
| 98 const std::string hostname_; |
| 99 const uint16 qtype_; |
| 100 DnsTransactionFactory::CallbackType callback_; |
84 bool started_; | 101 bool started_; |
85 base::WeakPtr<MockDnsClient> client_; | 102 const base::WeakPtr<MockTransactionFactory> factory_; |
86 }; | 103 }; |
87 | 104 |
88 typedef std::pair<std::string, uint16> Key; | 105 typedef std::pair<std::string, uint16> Key; |
89 | 106 |
90 MockDnsClient() : num_requests(0) {} | 107 MockTransactionFactory() : num_requests_(0) {} |
91 ~MockDnsClient() { | 108 ~MockTransactionFactory() { |
92 STLDeleteValues(&responses); | 109 STLDeleteValues(&responses_); |
93 } | 110 } |
94 | 111 |
95 Request* CreateRequest(const base::StringPiece& qname, | 112 scoped_ptr<DnsTransaction> CreateTransaction( |
96 uint16 qtype, | 113 const std::string& qname, |
97 const RequestCallback& callback, | 114 uint16 qtype, |
98 const BoundNetLog&) { | 115 const DnsTransactionFactory::CallbackType& callback, |
99 ++num_requests; | 116 const BoundNetLog&) { |
100 return new MockRequest(qname, qtype, callback, AsWeakPtr()); | 117 ++num_requests_; |
| 118 return scoped_ptr<DnsTransaction>( |
| 119 new MockTransaction(qname, qtype, callback, AsWeakPtr())); |
101 } | 120 } |
102 | 121 |
103 int num_requests; | 122 void AddResponse(const std::string& name, uint8 type, DnsResponse* response) { |
104 std::map<Key, DnsResponse*> responses; | 123 responses_[MockTransactionFactory::Key(name, type)] = response; |
| 124 } |
| 125 |
| 126 int num_requests() const { return num_requests_; } |
| 127 |
| 128 private: |
| 129 int num_requests_; |
| 130 std::map<Key, DnsResponse*> responses_; |
105 }; | 131 }; |
106 | 132 |
107 } // namespace | 133 } // namespace |
108 | 134 |
109 | 135 |
110 // The following fixture sets up an environment for four different lookups | 136 // The following fixture sets up an environment for four different lookups |
111 // with their data defined in dns_test_util.h. All tests make use of these | 137 // with their data defined in dns_test_util.h. All tests make use of these |
112 // predefined variables instead of each defining their own, to avoid | 138 // predefined variables instead of each defining their own, to avoid |
113 // boilerplate code in every test. Assuming every coming query is for a | 139 // boilerplate code in every test. Assuming every coming query is for a |
114 // distinct hostname, as |kMaxTransactions| is set to 2 and | 140 // distinct hostname, as |kMaxTransactions| is set to 2 and |
(...skipping 15 matching lines...) Expand all Loading... |
130 ip_addresses2_(kT2IpAddresses, | 156 ip_addresses2_(kT2IpAddresses, |
131 kT2IpAddresses + arraysize(kT2IpAddresses)), | 157 kT2IpAddresses + arraysize(kT2IpAddresses)), |
132 ip_addresses3_(kT3IpAddresses, | 158 ip_addresses3_(kT3IpAddresses, |
133 kT3IpAddresses + arraysize(kT3IpAddresses)) { | 159 kT3IpAddresses + arraysize(kT3IpAddresses)) { |
134 // AF_INET only for now. | 160 // AF_INET only for now. |
135 info0_.set_address_family(ADDRESS_FAMILY_IPV4); | 161 info0_.set_address_family(ADDRESS_FAMILY_IPV4); |
136 info1_.set_address_family(ADDRESS_FAMILY_IPV4); | 162 info1_.set_address_family(ADDRESS_FAMILY_IPV4); |
137 info2_.set_address_family(ADDRESS_FAMILY_IPV4); | 163 info2_.set_address_family(ADDRESS_FAMILY_IPV4); |
138 info3_.set_address_family(ADDRESS_FAMILY_IPV4); | 164 info3_.set_address_family(ADDRESS_FAMILY_IPV4); |
139 | 165 |
140 client_.reset(new MockDnsClient()); | 166 client_ = new MockTransactionFactory(); |
141 | 167 |
142 AddResponse(std::string(kT0DnsName, arraysize(kT0DnsName)), kT0Qtype, | 168 client_->AddResponse(kT0HostName, kT0Qtype, |
143 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram), | 169 new DnsResponse(reinterpret_cast<const char*>(kT0ResponseDatagram), |
144 arraysize(kT0ResponseDatagram), | 170 arraysize(kT0ResponseDatagram), |
145 arraysize(kT0QueryDatagram))); | 171 arraysize(kT0QueryDatagram))); |
146 | 172 |
147 AddResponse(std::string(kT1DnsName, arraysize(kT1DnsName)), kT1Qtype, | 173 client_->AddResponse(kT1HostName, kT1Qtype, |
148 new DnsResponse(reinterpret_cast<const char*>(kT1ResponseDatagram), | 174 new DnsResponse(reinterpret_cast<const char*>(kT1ResponseDatagram), |
149 arraysize(kT1ResponseDatagram), | 175 arraysize(kT1ResponseDatagram), |
150 arraysize(kT1QueryDatagram))); | 176 arraysize(kT1QueryDatagram))); |
151 | 177 |
152 AddResponse(std::string(kT2DnsName, arraysize(kT2DnsName)), kT2Qtype, | 178 client_->AddResponse(kT2HostName, kT2Qtype, |
153 new DnsResponse(reinterpret_cast<const char*>(kT2ResponseDatagram), | 179 new DnsResponse(reinterpret_cast<const char*>(kT2ResponseDatagram), |
154 arraysize(kT2ResponseDatagram), | 180 arraysize(kT2ResponseDatagram), |
155 arraysize(kT2QueryDatagram))); | 181 arraysize(kT2QueryDatagram))); |
156 | 182 |
157 AddResponse(std::string(kT3DnsName, arraysize(kT3DnsName)), kT3Qtype, | 183 client_->AddResponse(kT3HostName, kT3Qtype, |
158 new DnsResponse(reinterpret_cast<const char*>(kT3ResponseDatagram), | 184 new DnsResponse(reinterpret_cast<const char*>(kT3ResponseDatagram), |
159 arraysize(kT3ResponseDatagram), | 185 arraysize(kT3ResponseDatagram), |
160 arraysize(kT3QueryDatagram))); | 186 arraysize(kT3QueryDatagram))); |
161 | 187 |
162 resolver_.reset( | 188 resolver_.reset( |
163 new AsyncHostResolver(kMaxTransactions, kMaxPendingRequests, | 189 new AsyncHostResolver(kMaxTransactions, kMaxPendingRequests, |
164 HostCache::CreateDefaultCache(), | 190 HostCache::CreateDefaultCache(), |
165 client_.get(), NULL)); | 191 scoped_ptr<DnsTransactionFactory>(client_), NULL)); |
166 } | |
167 | |
168 void AddResponse(const std::string& name, uint8 type, DnsResponse* response) { | |
169 client_->responses[MockDnsClient::Key(name, type)] = response; | |
170 } | 192 } |
171 | 193 |
172 protected: | 194 protected: |
173 AddressList addrlist0_, addrlist1_, addrlist2_, addrlist3_; | 195 AddressList addrlist0_, addrlist1_, addrlist2_, addrlist3_; |
174 HostResolver::RequestInfo info0_, info1_, info2_, info3_; | 196 HostResolver::RequestInfo info0_, info1_, info2_, info3_; |
175 std::vector<const char*> ip_addresses0_, ip_addresses1_, | 197 std::vector<const char*> ip_addresses0_, ip_addresses1_, |
176 ip_addresses2_, ip_addresses3_; | 198 ip_addresses2_, ip_addresses3_; |
177 scoped_ptr<HostResolver> resolver_; | 199 scoped_ptr<HostResolver> resolver_; |
178 scoped_ptr<MockDnsClient> client_; | 200 MockTransactionFactory* client_; // Owned by the AsyncHostResolver. |
179 TestCompletionCallback callback0_, callback1_, callback2_, callback3_; | 201 TestCompletionCallback callback0_, callback1_, callback2_, callback3_; |
180 }; | 202 }; |
181 | 203 |
182 TEST_F(AsyncHostResolverTest, EmptyHostLookup) { | 204 TEST_F(AsyncHostResolverTest, EmptyHostLookup) { |
183 info0_.set_host_port_pair(HostPortPair("", kPortNum)); | 205 info0_.set_host_port_pair(HostPortPair("", kPortNum)); |
184 int rv = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, | 206 int rv = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, |
185 BoundNetLog()); | 207 BoundNetLog()); |
186 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); | 208 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
187 } | 209 } |
188 | 210 |
(...skipping 29 matching lines...) Expand all Loading... |
218 EXPECT_EQ(OK, rv); | 240 EXPECT_EQ(OK, rv); |
219 VerifyAddressList(ip_addresses0_, kPortNum, addrlist0_); | 241 VerifyAddressList(ip_addresses0_, kPortNum, addrlist0_); |
220 | 242 |
221 // Now lookup |info0_| from cache only, store results in |addrlist1_|, | 243 // Now lookup |info0_| from cache only, store results in |addrlist1_|, |
222 // should succeed synchronously. | 244 // should succeed synchronously. |
223 rv = resolver_->ResolveFromCache(info0_, &addrlist1_, BoundNetLog()); | 245 rv = resolver_->ResolveFromCache(info0_, &addrlist1_, BoundNetLog()); |
224 EXPECT_EQ(OK, rv); | 246 EXPECT_EQ(OK, rv); |
225 VerifyAddressList(ip_addresses0_, kPortNum, addrlist1_); | 247 VerifyAddressList(ip_addresses0_, kPortNum, addrlist1_); |
226 } | 248 } |
227 | 249 |
228 TEST_F(AsyncHostResolverTest, InvalidHostNameLookup) { | 250 // TODO(szym): This tests DnsTransaction not AsyncHostResolver. Remove or move |
| 251 // to dns_transaction_unittest.cc |
| 252 TEST_F(AsyncHostResolverTest, DISABLED_InvalidHostNameLookup) { |
229 const std::string kHostName1(64, 'a'); | 253 const std::string kHostName1(64, 'a'); |
230 info0_.set_host_port_pair(HostPortPair(kHostName1, kPortNum)); | 254 info0_.set_host_port_pair(HostPortPair(kHostName1, kPortNum)); |
231 int rv = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, | 255 int rv = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, |
232 BoundNetLog()); | 256 BoundNetLog()); |
233 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); | 257 EXPECT_EQ(ERR_INVALID_ARGUMENT, rv); |
234 | 258 |
235 const std::string kHostName2(4097, 'b'); | 259 const std::string kHostName2(4097, 'b'); |
236 info0_.set_host_port_pair(HostPortPair(kHostName2, kPortNum)); | 260 info0_.set_host_port_pair(HostPortPair(kHostName2, kPortNum)); |
237 rv = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, | 261 rv = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, |
238 BoundNetLog()); | 262 BoundNetLog()); |
239 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); | 263 EXPECT_EQ(ERR_INVALID_ARGUMENT, rv); |
240 } | 264 } |
241 | 265 |
242 TEST_F(AsyncHostResolverTest, Lookup) { | 266 TEST_F(AsyncHostResolverTest, Lookup) { |
243 int rv = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, | 267 int rv = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, |
244 BoundNetLog()); | 268 BoundNetLog()); |
245 EXPECT_EQ(ERR_IO_PENDING, rv); | 269 EXPECT_EQ(ERR_IO_PENDING, rv); |
246 rv = callback0_.WaitForResult(); | 270 rv = callback0_.WaitForResult(); |
247 EXPECT_EQ(OK, rv); | 271 EXPECT_EQ(OK, rv); |
248 VerifyAddressList(ip_addresses0_, kPortNum, addrlist0_); | 272 VerifyAddressList(ip_addresses0_, kPortNum, addrlist0_); |
249 } | 273 } |
(...skipping 14 matching lines...) Expand all Loading... |
264 VerifyAddressList(ip_addresses0_, kPortNum, addrlist0_); | 288 VerifyAddressList(ip_addresses0_, kPortNum, addrlist0_); |
265 | 289 |
266 rv1 = callback1_.WaitForResult(); | 290 rv1 = callback1_.WaitForResult(); |
267 EXPECT_EQ(OK, rv1); | 291 EXPECT_EQ(OK, rv1); |
268 VerifyAddressList(ip_addresses1_, kPortNum, addrlist1_); | 292 VerifyAddressList(ip_addresses1_, kPortNum, addrlist1_); |
269 | 293 |
270 rv2 = callback2_.WaitForResult(); | 294 rv2 = callback2_.WaitForResult(); |
271 EXPECT_EQ(OK, rv2); | 295 EXPECT_EQ(OK, rv2); |
272 VerifyAddressList(ip_addresses2_, kPortNum, addrlist2_); | 296 VerifyAddressList(ip_addresses2_, kPortNum, addrlist2_); |
273 | 297 |
274 EXPECT_EQ(3, client_->num_requests); | 298 EXPECT_EQ(3, client_->num_requests()); |
275 } | 299 } |
276 | 300 |
277 TEST_F(AsyncHostResolverTest, SameHostLookupsConsumeSingleTransaction) { | 301 TEST_F(AsyncHostResolverTest, SameHostLookupsConsumeSingleTransaction) { |
278 // We pass the info0_ to all requests. | 302 // We pass the info0_ to all requests. |
279 int rv0 = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, | 303 int rv0 = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, |
280 BoundNetLog()); | 304 BoundNetLog()); |
281 int rv1 = resolver_->Resolve(info0_, &addrlist1_, callback1_.callback(), NULL, | 305 int rv1 = resolver_->Resolve(info0_, &addrlist1_, callback1_.callback(), NULL, |
282 BoundNetLog()); | 306 BoundNetLog()); |
283 int rv2 = resolver_->Resolve(info0_, &addrlist2_, callback2_.callback(), NULL, | 307 int rv2 = resolver_->Resolve(info0_, &addrlist2_, callback2_.callback(), NULL, |
284 BoundNetLog()); | 308 BoundNetLog()); |
285 EXPECT_EQ(ERR_IO_PENDING, rv0); | 309 EXPECT_EQ(ERR_IO_PENDING, rv0); |
286 EXPECT_EQ(ERR_IO_PENDING, rv1); | 310 EXPECT_EQ(ERR_IO_PENDING, rv1); |
287 EXPECT_EQ(ERR_IO_PENDING, rv2); | 311 EXPECT_EQ(ERR_IO_PENDING, rv2); |
288 | 312 |
289 rv0 = callback0_.WaitForResult(); | 313 rv0 = callback0_.WaitForResult(); |
290 EXPECT_EQ(OK, rv0); | 314 EXPECT_EQ(OK, rv0); |
291 VerifyAddressList(ip_addresses0_, kPortNum, addrlist0_); | 315 VerifyAddressList(ip_addresses0_, kPortNum, addrlist0_); |
292 | 316 |
293 rv1 = callback1_.WaitForResult(); | 317 rv1 = callback1_.WaitForResult(); |
294 EXPECT_EQ(OK, rv1); | 318 EXPECT_EQ(OK, rv1); |
295 VerifyAddressList(ip_addresses0_, kPortNum, addrlist1_); | 319 VerifyAddressList(ip_addresses0_, kPortNum, addrlist1_); |
296 | 320 |
297 rv2 = callback2_.WaitForResult(); | 321 rv2 = callback2_.WaitForResult(); |
298 EXPECT_EQ(OK, rv2); | 322 EXPECT_EQ(OK, rv2); |
299 VerifyAddressList(ip_addresses0_, kPortNum, addrlist2_); | 323 VerifyAddressList(ip_addresses0_, kPortNum, addrlist2_); |
300 | 324 |
301 // Although we have three lookups, a single UDP socket was used. | 325 // Although we have three lookups, a single UDP socket was used. |
302 EXPECT_EQ(1, client_->num_requests); | 326 EXPECT_EQ(1, client_->num_requests()); |
303 } | 327 } |
304 | 328 |
305 TEST_F(AsyncHostResolverTest, CancelLookup) { | 329 TEST_F(AsyncHostResolverTest, CancelLookup) { |
306 HostResolver::RequestHandle req0 = NULL, req2 = NULL; | 330 HostResolver::RequestHandle req0 = NULL, req2 = NULL; |
307 int rv0 = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), | 331 int rv0 = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), |
308 &req0, BoundNetLog()); | 332 &req0, BoundNetLog()); |
309 int rv1 = resolver_->Resolve(info1_, &addrlist1_, callback1_.callback(), NULL, | 333 int rv1 = resolver_->Resolve(info1_, &addrlist1_, callback1_.callback(), NULL, |
310 BoundNetLog()); | 334 BoundNetLog()); |
311 int rv2 = resolver_->Resolve(info2_, &addrlist2_, callback2_.callback(), | 335 int rv2 = resolver_->Resolve(info2_, &addrlist2_, callback2_.callback(), |
312 &req2, BoundNetLog()); | 336 &req2, BoundNetLog()); |
(...skipping 28 matching lines...) Expand all Loading... |
341 EXPECT_EQ(ERR_IO_PENDING, rv1); | 365 EXPECT_EQ(ERR_IO_PENDING, rv1); |
342 | 366 |
343 resolver_->CancelRequest(req0); | 367 resolver_->CancelRequest(req0); |
344 MessageLoop::current()->RunAllPending(); | 368 MessageLoop::current()->RunAllPending(); |
345 EXPECT_FALSE(callback0_.have_result()); | 369 EXPECT_FALSE(callback0_.have_result()); |
346 | 370 |
347 rv1 = callback1_.WaitForResult(); | 371 rv1 = callback1_.WaitForResult(); |
348 EXPECT_EQ(OK, rv1); | 372 EXPECT_EQ(OK, rv1); |
349 VerifyAddressList(ip_addresses0_, kPortNum, addrlist1_); | 373 VerifyAddressList(ip_addresses0_, kPortNum, addrlist1_); |
350 | 374 |
351 EXPECT_EQ(1, client_->num_requests); | 375 EXPECT_EQ(1, client_->num_requests()); |
352 } | 376 } |
353 | 377 |
354 // Test that a queued lookup completes. | 378 // Test that a queued lookup completes. |
355 TEST_F(AsyncHostResolverTest, QueuedLookup) { | 379 TEST_F(AsyncHostResolverTest, QueuedLookup) { |
356 // kMaxTransactions is 2, thus the following requests consume all | 380 // kMaxTransactions is 2, thus the following requests consume all |
357 // available transactions. | 381 // available transactions. |
358 int rv0 = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, | 382 int rv0 = resolver_->Resolve(info0_, &addrlist0_, callback0_.callback(), NULL, |
359 BoundNetLog()); | 383 BoundNetLog()); |
360 int rv1 = resolver_->Resolve(info1_, &addrlist1_, callback1_.callback(), NULL, | 384 int rv1 = resolver_->Resolve(info1_, &addrlist1_, callback1_.callback(), NULL, |
361 BoundNetLog()); | 385 BoundNetLog()); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 rv_fail = callback_fail.WaitForResult(); | 534 rv_fail = callback_fail.WaitForResult(); |
511 EXPECT_EQ(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE, rv_fail); | 535 EXPECT_EQ(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE, rv_fail); |
512 EXPECT_EQ(static_cast<addrinfo*>(NULL), addrlist_fail.head()); | 536 EXPECT_EQ(static_cast<addrinfo*>(NULL), addrlist_fail.head()); |
513 | 537 |
514 rv2 = callback2_.WaitForResult(); | 538 rv2 = callback2_.WaitForResult(); |
515 EXPECT_EQ(OK, rv2); | 539 EXPECT_EQ(OK, rv2); |
516 VerifyAddressList(ip_addresses2_, kPortNum, addrlist2_); | 540 VerifyAddressList(ip_addresses2_, kPortNum, addrlist2_); |
517 } | 541 } |
518 | 542 |
519 } // namespace net | 543 } // namespace net |
OLD | NEW |