OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/host_resolver_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | |
10 #include "base/bind_helpers.h" | |
9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
11 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
12 #include "base/string_util.h" | 14 #include "base/string_util.h" |
13 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
14 #include "base/synchronization/condition_variable.h" | 16 #include "base/synchronization/condition_variable.h" |
15 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
16 #include "base/time.h" | 18 #include "base/time.h" |
17 #include "net/base/address_list.h" | 19 #include "net/base/address_list.h" |
18 #include "net/base/completion_callback.h" | 20 #include "net/base/completion_callback.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 virtual ~Delegate() {} | 263 virtual ~Delegate() {} |
262 virtual void OnCompleted(ResolveRequest* resolve) = 0; | 264 virtual void OnCompleted(ResolveRequest* resolve) = 0; |
263 }; | 265 }; |
264 | 266 |
265 ResolveRequest(HostResolver* resolver, | 267 ResolveRequest(HostResolver* resolver, |
266 const std::string& hostname, | 268 const std::string& hostname, |
267 int port, | 269 int port, |
268 Delegate* delegate) | 270 Delegate* delegate) |
269 : info_(HostPortPair(hostname, port)), | 271 : info_(HostPortPair(hostname, port)), |
270 resolver_(resolver), | 272 resolver_(resolver), |
271 delegate_(delegate), | 273 delegate_(delegate) { |
272 ALLOW_THIS_IN_INITIALIZER_LIST( | |
273 callback_(this, &ResolveRequest::OnLookupFinished)) { | |
274 // Start the request. | 274 // Start the request. |
275 int err = resolver->Resolve(info_, &addrlist_, &callback_, &req_, | 275 int err = resolver->Resolve( |
276 BoundNetLog()); | 276 info_, &addrlist_, |
277 base::Bind(&ResolveRequest::OnLookupFinished, base::Unretained(this)), | |
278 &req_, BoundNetLog()); | |
277 EXPECT_EQ(ERR_IO_PENDING, err); | 279 EXPECT_EQ(ERR_IO_PENDING, err); |
278 } | 280 } |
279 | 281 |
280 ResolveRequest(HostResolver* resolver, | 282 ResolveRequest(HostResolver* resolver, |
281 const HostResolver::RequestInfo& info, | 283 const HostResolver::RequestInfo& info, |
282 Delegate* delegate) | 284 Delegate* delegate) |
283 : info_(info), resolver_(resolver), delegate_(delegate), | 285 : info_(info), resolver_(resolver), delegate_(delegate) { |
284 ALLOW_THIS_IN_INITIALIZER_LIST( | |
285 callback_(this, &ResolveRequest::OnLookupFinished)) { | |
286 // Start the request. | 286 // Start the request. |
287 int err = resolver->Resolve(info, &addrlist_, &callback_, &req_, | 287 int err = resolver->Resolve( |
288 BoundNetLog()); | 288 info, &addrlist_, |
289 base::Bind(&ResolveRequest::OnLookupFinished, | |
290 base::Unretained(this)), | |
291 &req_, BoundNetLog()); | |
289 EXPECT_EQ(ERR_IO_PENDING, err); | 292 EXPECT_EQ(ERR_IO_PENDING, err); |
290 } | 293 } |
291 | 294 |
292 void Cancel() { | 295 void Cancel() { |
293 resolver_->CancelRequest(req_); | 296 resolver_->CancelRequest(req_); |
294 } | 297 } |
295 | 298 |
296 const std::string& hostname() const { | 299 const std::string& hostname() const { |
297 return info_.hostname(); | 300 return info_.hostname(); |
298 } | 301 } |
(...skipping 24 matching lines...) Expand all Loading... | |
323 HostResolver::RequestInfo info_; | 326 HostResolver::RequestInfo info_; |
324 HostResolver::RequestHandle req_; | 327 HostResolver::RequestHandle req_; |
325 | 328 |
326 // The result of the resolve. | 329 // The result of the resolve. |
327 int result_; | 330 int result_; |
328 AddressList addrlist_; | 331 AddressList addrlist_; |
329 | 332 |
330 HostResolver* resolver_; | 333 HostResolver* resolver_; |
331 | 334 |
332 Delegate* delegate_; | 335 Delegate* delegate_; |
333 OldCompletionCallbackImpl<ResolveRequest> callback_; | |
334 | 336 |
335 DISALLOW_COPY_AND_ASSIGN(ResolveRequest); | 337 DISALLOW_COPY_AND_ASSIGN(ResolveRequest); |
336 }; | 338 }; |
337 | 339 |
338 class HostResolverImplTest : public testing::Test { | 340 class HostResolverImplTest : public testing::Test { |
339 public: | 341 public: |
340 HostResolverImplTest() | 342 HostResolverImplTest() |
341 : callback_called_(false), | 343 : callback_called_(false), |
342 ALLOW_THIS_IN_INITIALIZER_LIST( | 344 ALLOW_THIS_IN_INITIALIZER_LIST(callback_( |
343 callback_(this, &HostResolverImplTest::OnLookupFinished)) { | 345 base::Bind(&HostResolverImplTest::OnLookupFinished, |
346 base::Unretained(this)))) { | |
344 } | 347 } |
345 | 348 |
346 protected: | 349 protected: |
347 bool callback_called_; | |
348 int callback_result_; | |
349 OldCompletionCallbackImpl<HostResolverImplTest> callback_; | |
350 | |
351 private: | |
352 void OnLookupFinished(int result) { | 350 void OnLookupFinished(int result) { |
353 callback_called_ = true; | 351 callback_called_ = true; |
354 callback_result_ = result; | 352 callback_result_ = result; |
355 MessageLoop::current()->Quit(); | 353 MessageLoop::current()->Quit(); |
356 } | 354 } |
355 | |
356 bool callback_called_; | |
357 int callback_result_; | |
358 CompletionCallback callback_; | |
357 }; | 359 }; |
358 | 360 |
359 TEST_F(HostResolverImplTest, AsynchronousLookup) { | 361 TEST_F(HostResolverImplTest, AsynchronousLookup) { |
360 AddressList addrlist; | 362 AddressList addrlist; |
361 const int kPortnum = 80; | 363 const int kPortnum = 80; |
362 | 364 |
363 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( | 365 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
364 new RuleBasedHostResolverProc(NULL)); | 366 new RuleBasedHostResolverProc(NULL)); |
365 resolver_proc->AddRule("just.testing", "192.168.1.42"); | 367 resolver_proc->AddRule("just.testing", "192.168.1.42"); |
366 | 368 |
367 scoped_ptr<HostResolver> host_resolver( | 369 scoped_ptr<HostResolver> host_resolver( |
368 CreateHostResolverImpl(resolver_proc)); | 370 CreateHostResolverImpl(resolver_proc)); |
369 | 371 |
370 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); | 372 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); |
371 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 373 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
372 int err = host_resolver->Resolve(info, &addrlist, &callback_, NULL, | 374 int err = host_resolver->Resolve(info, &addrlist, callback_, NULL, |
373 log.bound()); | 375 log.bound()); |
374 EXPECT_EQ(ERR_IO_PENDING, err); | 376 EXPECT_EQ(ERR_IO_PENDING, err); |
375 | 377 |
376 CapturingNetLog::EntryList entries; | 378 CapturingNetLog::EntryList entries; |
377 log.GetEntries(&entries); | 379 log.GetEntries(&entries); |
378 | 380 |
379 EXPECT_EQ(1u, entries.size()); | 381 EXPECT_EQ(1u, entries.size()); |
380 EXPECT_TRUE(LogContainsBeginEvent( | 382 EXPECT_TRUE(LogContainsBeginEvent( |
381 entries, 0, NetLog::TYPE_HOST_RESOLVER_IMPL)); | 383 entries, 0, NetLog::TYPE_HOST_RESOLVER_IMPL)); |
382 | 384 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 scoped_ptr<HostResolver> host_resolver( | 454 scoped_ptr<HostResolver> host_resolver( |
453 new HostResolverImpl(resolver_proc, | 455 new HostResolverImpl(resolver_proc, |
454 HostCache::CreateDefaultCache(), | 456 HostCache::CreateDefaultCache(), |
455 kMaxJobs, | 457 kMaxJobs, |
456 kMaxRetryAttempts, | 458 kMaxRetryAttempts, |
457 &net_log)); | 459 &net_log)); |
458 AddressList addrlist; | 460 AddressList addrlist; |
459 const int kPortnum = 80; | 461 const int kPortnum = 80; |
460 | 462 |
461 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); | 463 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); |
462 int err = host_resolver->Resolve(info, &addrlist, &callback_, NULL, | 464 int err = host_resolver->Resolve(info, &addrlist, callback_, NULL, |
463 log.bound()); | 465 log.bound()); |
464 EXPECT_EQ(ERR_IO_PENDING, err); | 466 EXPECT_EQ(ERR_IO_PENDING, err); |
465 | 467 |
466 resolver_proc->Wait(); | 468 resolver_proc->Wait(); |
467 } | 469 } |
468 | 470 |
469 resolver_proc->Signal(); | 471 resolver_proc->Signal(); |
470 | 472 |
471 CapturingNetLog::EntryList entries; | 473 CapturingNetLog::EntryList entries; |
472 log.GetEntries(&entries); | 474 log.GetEntries(&entries); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. | 511 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. |
510 | 512 |
511 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( | 513 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
512 new RuleBasedHostResolverProc(NULL)); | 514 new RuleBasedHostResolverProc(NULL)); |
513 resolver_proc->AllowDirectLookup("*"); | 515 resolver_proc->AllowDirectLookup("*"); |
514 | 516 |
515 scoped_ptr<HostResolver> host_resolver( | 517 scoped_ptr<HostResolver> host_resolver( |
516 CreateHostResolverImpl(resolver_proc)); | 518 CreateHostResolverImpl(resolver_proc)); |
517 AddressList addrlist; | 519 AddressList addrlist; |
518 const int kPortnum = 5555; | 520 const int kPortnum = 5555; |
519 TestOldCompletionCallback callback; | 521 TestCompletionCallback callback; |
520 HostResolver::RequestInfo info(HostPortPair("127.1.2.3", kPortnum)); | 522 HostResolver::RequestInfo info(HostPortPair("127.1.2.3", kPortnum)); |
521 int err = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 523 int err = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, |
522 BoundNetLog()); | 524 BoundNetLog()); |
523 EXPECT_EQ(OK, err); | 525 EXPECT_EQ(OK, err); |
524 | 526 |
525 const struct addrinfo* ainfo = addrlist.head(); | 527 const struct addrinfo* ainfo = addrlist.head(); |
526 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); | 528 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); |
527 EXPECT_EQ(sizeof(struct sockaddr_in), ainfo->ai_addrlen); | 529 EXPECT_EQ(sizeof(struct sockaddr_in), ainfo->ai_addrlen); |
528 | 530 |
529 const struct sockaddr* sa = ainfo->ai_addr; | 531 const struct sockaddr* sa = ainfo->ai_addr; |
530 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; | 532 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; |
531 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); | 533 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); |
532 EXPECT_TRUE(htonl(0x7f010203) == sa_in->sin_addr.s_addr); | 534 EXPECT_TRUE(htonl(0x7f010203) == sa_in->sin_addr.s_addr); |
533 } | 535 } |
534 | 536 |
535 TEST_F(HostResolverImplTest, NumericIPv6Address) { | 537 TEST_F(HostResolverImplTest, NumericIPv6Address) { |
536 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( | 538 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
537 new RuleBasedHostResolverProc(NULL)); | 539 new RuleBasedHostResolverProc(NULL)); |
538 resolver_proc->AllowDirectLookup("*"); | 540 resolver_proc->AllowDirectLookup("*"); |
539 | 541 |
540 // Resolve a plain IPv6 address. Don't worry about [brackets], because | 542 // Resolve a plain IPv6 address. Don't worry about [brackets], because |
541 // the caller should have removed them. | 543 // the caller should have removed them. |
542 scoped_ptr<HostResolver> host_resolver( | 544 scoped_ptr<HostResolver> host_resolver( |
543 CreateHostResolverImpl(resolver_proc)); | 545 CreateHostResolverImpl(resolver_proc)); |
544 AddressList addrlist; | 546 AddressList addrlist; |
545 const int kPortnum = 5555; | 547 const int kPortnum = 5555; |
546 TestOldCompletionCallback callback; | 548 TestCompletionCallback callback; |
547 HostResolver::RequestInfo info(HostPortPair("2001:db8::1", kPortnum)); | 549 HostResolver::RequestInfo info(HostPortPair("2001:db8::1", kPortnum)); |
548 int err = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 550 int err = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, |
549 BoundNetLog()); | 551 BoundNetLog()); |
550 EXPECT_EQ(OK, err); | 552 EXPECT_EQ(OK, err); |
551 | 553 |
552 const struct addrinfo* ainfo = addrlist.head(); | 554 const struct addrinfo* ainfo = addrlist.head(); |
553 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); | 555 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); |
554 EXPECT_EQ(sizeof(struct sockaddr_in6), ainfo->ai_addrlen); | 556 EXPECT_EQ(sizeof(struct sockaddr_in6), ainfo->ai_addrlen); |
555 | 557 |
556 const struct sockaddr* sa = ainfo->ai_addr; | 558 const struct sockaddr* sa = ainfo->ai_addr; |
557 const struct sockaddr_in6* sa_in6 = (const struct sockaddr_in6*) sa; | 559 const struct sockaddr_in6* sa_in6 = (const struct sockaddr_in6*) sa; |
558 EXPECT_TRUE(htons(kPortnum) == sa_in6->sin6_port); | 560 EXPECT_TRUE(htons(kPortnum) == sa_in6->sin6_port); |
559 | 561 |
560 const uint8 expect_addr[] = { | 562 const uint8 expect_addr[] = { |
561 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, | 563 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, |
562 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 | 564 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 |
563 }; | 565 }; |
564 for (int i = 0; i < 16; i++) { | 566 for (int i = 0; i < 16; i++) { |
565 EXPECT_EQ(expect_addr[i], sa_in6->sin6_addr.s6_addr[i]); | 567 EXPECT_EQ(expect_addr[i], sa_in6->sin6_addr.s6_addr[i]); |
566 } | 568 } |
567 } | 569 } |
568 | 570 |
569 TEST_F(HostResolverImplTest, EmptyHost) { | 571 TEST_F(HostResolverImplTest, EmptyHost) { |
570 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( | 572 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
571 new RuleBasedHostResolverProc(NULL)); | 573 new RuleBasedHostResolverProc(NULL)); |
572 resolver_proc->AllowDirectLookup("*"); | 574 resolver_proc->AllowDirectLookup("*"); |
573 | 575 |
574 scoped_ptr<HostResolver> host_resolver( | 576 scoped_ptr<HostResolver> host_resolver( |
575 CreateHostResolverImpl(resolver_proc)); | 577 CreateHostResolverImpl(resolver_proc)); |
576 AddressList addrlist; | 578 AddressList addrlist; |
577 const int kPortnum = 5555; | 579 const int kPortnum = 5555; |
578 TestOldCompletionCallback callback; | 580 TestCompletionCallback callback; |
579 HostResolver::RequestInfo info(HostPortPair("", kPortnum)); | 581 HostResolver::RequestInfo info(HostPortPair("", kPortnum)); |
580 int err = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 582 int err = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, |
581 BoundNetLog()); | 583 BoundNetLog()); |
582 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, err); | 584 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, err); |
583 } | 585 } |
584 | 586 |
585 TEST_F(HostResolverImplTest, LongHost) { | 587 TEST_F(HostResolverImplTest, LongHost) { |
586 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( | 588 scoped_refptr<RuleBasedHostResolverProc> resolver_proc( |
587 new RuleBasedHostResolverProc(NULL)); | 589 new RuleBasedHostResolverProc(NULL)); |
588 resolver_proc->AllowDirectLookup("*"); | 590 resolver_proc->AllowDirectLookup("*"); |
589 | 591 |
590 scoped_ptr<HostResolver> host_resolver( | 592 scoped_ptr<HostResolver> host_resolver( |
591 CreateHostResolverImpl(resolver_proc)); | 593 CreateHostResolverImpl(resolver_proc)); |
592 AddressList addrlist; | 594 AddressList addrlist; |
593 const int kPortnum = 5555; | 595 const int kPortnum = 5555; |
594 std::string hostname(4097, 'a'); | 596 std::string hostname(4097, 'a'); |
595 TestOldCompletionCallback callback; | 597 TestCompletionCallback callback; |
596 HostResolver::RequestInfo info(HostPortPair(hostname, kPortnum)); | 598 HostResolver::RequestInfo info(HostPortPair(hostname, kPortnum)); |
597 int err = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 599 int err = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, |
598 BoundNetLog()); | 600 BoundNetLog()); |
599 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, err); | 601 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, err); |
600 } | 602 } |
601 | 603 |
602 // Helper class used by HostResolverImplTest.DeDupeRequests. It receives request | 604 // Helper class used by HostResolverImplTest.DeDupeRequests. It receives request |
603 // completion notifications for all the resolves, so it can tally up and | 605 // completion notifications for all the resolves, so it can tally up and |
604 // determine when we are done. | 606 // determine when we are done. |
605 class DeDupeRequestsVerifier : public ResolveRequest::Delegate { | 607 class DeDupeRequestsVerifier : public ResolveRequest::Delegate { |
606 public: | 608 public: |
607 explicit DeDupeRequestsVerifier(CapturingHostResolverProc* resolver_proc) | 609 explicit DeDupeRequestsVerifier(CapturingHostResolverProc* resolver_proc) |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
931 | 933 |
932 virtual void OnCompleted(ResolveRequest* resolve) { | 934 virtual void OnCompleted(ResolveRequest* resolve) { |
933 EXPECT_EQ("a", resolve->hostname()); | 935 EXPECT_EQ("a", resolve->hostname()); |
934 HostResolver* resolver = resolve->resolver(); | 936 HostResolver* resolver = resolve->resolver(); |
935 | 937 |
936 if (80 == resolve->port()) { | 938 if (80 == resolve->port()) { |
937 // On completing the first request, start another request for "a". | 939 // On completing the first request, start another request for "a". |
938 // Since caching is enabled, this should complete synchronously. | 940 // Since caching is enabled, this should complete synchronously. |
939 | 941 |
940 // Note that |junk_callback| shouldn't be used since we are going to | 942 // Note that |junk_callback| shouldn't be used since we are going to |
941 // complete synchronously. We can't specify NULL though since that would | 943 // complete synchronously. |
942 // mean synchronous mode so we give it a value of 1. | 944 TestCompletionCallback junk_callback; |
943 OldCompletionCallback* junk_callback = | |
944 reinterpret_cast<OldCompletionCallback*> (1); | |
945 AddressList addrlist; | 945 AddressList addrlist; |
946 | 946 |
947 HostResolver::RequestInfo info(HostPortPair("a", 70)); | 947 HostResolver::RequestInfo info(HostPortPair("a", 70)); |
948 int error = resolver->Resolve(info, &addrlist, junk_callback, NULL, | 948 int error = resolver->Resolve(info, &addrlist, junk_callback.callback(), |
949 BoundNetLog()); | 949 NULL, BoundNetLog()); |
950 EXPECT_EQ(OK, error); | 950 EXPECT_EQ(OK, error); |
951 | 951 |
952 // Ok good. Now make sure that if we ask to bypass the cache, it can no | 952 // Ok good. Now make sure that if we ask to bypass the cache, it can no |
953 // longer service the request synchronously. | 953 // longer service the request synchronously. |
954 info = HostResolver::RequestInfo(HostPortPair("a", 71)); | 954 info = HostResolver::RequestInfo(HostPortPair("a", 71)); |
955 info.set_allow_cached_response(false); | 955 info.set_allow_cached_response(false); |
956 final_request_.reset(new ResolveRequest(resolver, info, this)); | 956 final_request_.reset(new ResolveRequest(resolver, info, this)); |
957 } else if (71 == resolve->port()) { | 957 } else if (71 == resolve->port()) { |
958 // Test is done. | 958 // Test is done. |
959 MessageLoop::current()->Quit(); | 959 MessageLoop::current()->Quit(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
991 | 991 |
992 TestHostResolverObserver observer; | 992 TestHostResolverObserver observer; |
993 | 993 |
994 host_resolver->AddObserver(&observer); | 994 host_resolver->AddObserver(&observer); |
995 | 995 |
996 AddressList addrlist; | 996 AddressList addrlist; |
997 | 997 |
998 // Resolve "host1". | 998 // Resolve "host1". |
999 HostResolver::RequestInfo info1(HostPortPair("host1", 70)); | 999 HostResolver::RequestInfo info1(HostPortPair("host1", 70)); |
1000 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 1000 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
1001 TestOldCompletionCallback callback; | 1001 TestCompletionCallback callback; |
1002 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, | 1002 int rv = host_resolver->Resolve(info1, &addrlist, callback.callback(), NULL, |
1003 log.bound()); | 1003 log.bound()); |
1004 EXPECT_EQ(ERR_IO_PENDING, rv); | 1004 EXPECT_EQ(ERR_IO_PENDING, rv); |
1005 rv = callback.WaitForResult(); | 1005 rv = callback.WaitForResult(); |
1006 EXPECT_EQ(OK, rv); | 1006 EXPECT_EQ(OK, rv); |
1007 | 1007 |
1008 CapturingNetLog::EntryList entries; | 1008 CapturingNetLog::EntryList entries; |
1009 log.GetEntries(&entries); | 1009 log.GetEntries(&entries); |
1010 | 1010 |
1011 EXPECT_EQ(2u, entries.size()); | 1011 EXPECT_EQ(2u, entries.size()); |
1012 EXPECT_TRUE(LogContainsBeginEvent( | 1012 EXPECT_TRUE(LogContainsBeginEvent( |
1013 entries, 0, NetLog::TYPE_HOST_RESOLVER_IMPL)); | 1013 entries, 0, NetLog::TYPE_HOST_RESOLVER_IMPL)); |
1014 EXPECT_TRUE(LogContainsEndEvent( | 1014 EXPECT_TRUE(LogContainsEndEvent( |
1015 entries, 1, NetLog::TYPE_HOST_RESOLVER_IMPL)); | 1015 entries, 1, NetLog::TYPE_HOST_RESOLVER_IMPL)); |
1016 | 1016 |
1017 EXPECT_EQ(1U, observer.start_log.size()); | 1017 EXPECT_EQ(1U, observer.start_log.size()); |
1018 EXPECT_EQ(1U, observer.finish_log.size()); | 1018 EXPECT_EQ(1U, observer.finish_log.size()); |
1019 EXPECT_EQ(0U, observer.cancel_log.size()); | 1019 EXPECT_EQ(0U, observer.cancel_log.size()); |
1020 EXPECT_TRUE(observer.start_log[0] == | 1020 EXPECT_TRUE(observer.start_log[0] == |
1021 TestHostResolverObserver::StartOrCancelEntry(0, info1)); | 1021 TestHostResolverObserver::StartOrCancelEntry(0, info1)); |
1022 EXPECT_TRUE(observer.finish_log[0] == | 1022 EXPECT_TRUE(observer.finish_log[0] == |
1023 TestHostResolverObserver::FinishEntry(0, true, info1)); | 1023 TestHostResolverObserver::FinishEntry(0, true, info1)); |
1024 | 1024 |
1025 // Resolve "host1" again -- this time it will be served from cache, but it | 1025 // Resolve "host1" again -- this time it will be served from cache, but it |
1026 // should still notify of completion. | 1026 // should still notify of completion. |
1027 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog()); | 1027 rv = host_resolver->Resolve(info1, &addrlist, callback.callback(), NULL, |
1028 BoundNetLog()); | |
1028 ASSERT_EQ(OK, rv); // Should complete synchronously. | 1029 ASSERT_EQ(OK, rv); // Should complete synchronously. |
1029 | 1030 |
1030 EXPECT_EQ(2U, observer.start_log.size()); | 1031 EXPECT_EQ(2U, observer.start_log.size()); |
1031 EXPECT_EQ(2U, observer.finish_log.size()); | 1032 EXPECT_EQ(2U, observer.finish_log.size()); |
1032 EXPECT_EQ(0U, observer.cancel_log.size()); | 1033 EXPECT_EQ(0U, observer.cancel_log.size()); |
1033 EXPECT_TRUE(observer.start_log[1] == | 1034 EXPECT_TRUE(observer.start_log[1] == |
1034 TestHostResolverObserver::StartOrCancelEntry(1, info1)); | 1035 TestHostResolverObserver::StartOrCancelEntry(1, info1)); |
1035 EXPECT_TRUE(observer.finish_log[1] == | 1036 EXPECT_TRUE(observer.finish_log[1] == |
1036 TestHostResolverObserver::FinishEntry(1, true, info1)); | 1037 TestHostResolverObserver::FinishEntry(1, true, info1)); |
1037 | 1038 |
1038 // Resolve "host2", setting referrer to "http://foobar.com" | 1039 // Resolve "host2", setting referrer to "http://foobar.com" |
1039 HostResolver::RequestInfo info2(HostPortPair("host2", 70)); | 1040 HostResolver::RequestInfo info2(HostPortPair("host2", 70)); |
1040 info2.set_referrer(GURL("http://foobar.com")); | 1041 info2.set_referrer(GURL("http://foobar.com")); |
1041 rv = host_resolver->Resolve(info2, &addrlist, &callback, NULL, BoundNetLog()); | 1042 rv = host_resolver->Resolve(info2, &addrlist, callback.callback(), NULL, |
1043 BoundNetLog()); | |
1042 EXPECT_EQ(ERR_IO_PENDING, rv); | 1044 EXPECT_EQ(ERR_IO_PENDING, rv); |
1043 rv = callback.WaitForResult(); | 1045 rv = callback.WaitForResult(); |
1044 EXPECT_EQ(OK, rv); | 1046 EXPECT_EQ(OK, rv); |
1045 | 1047 |
1046 EXPECT_EQ(3U, observer.start_log.size()); | 1048 EXPECT_EQ(3U, observer.start_log.size()); |
1047 EXPECT_EQ(3U, observer.finish_log.size()); | 1049 EXPECT_EQ(3U, observer.finish_log.size()); |
1048 EXPECT_EQ(0U, observer.cancel_log.size()); | 1050 EXPECT_EQ(0U, observer.cancel_log.size()); |
1049 EXPECT_TRUE(observer.start_log[2] == | 1051 EXPECT_TRUE(observer.start_log[2] == |
1050 TestHostResolverObserver::StartOrCancelEntry(2, info2)); | 1052 TestHostResolverObserver::StartOrCancelEntry(2, info2)); |
1051 EXPECT_TRUE(observer.finish_log[2] == | 1053 EXPECT_TRUE(observer.finish_log[2] == |
1052 TestHostResolverObserver::FinishEntry(2, true, info2)); | 1054 TestHostResolverObserver::FinishEntry(2, true, info2)); |
1053 | 1055 |
1054 // Unregister the observer. | 1056 // Unregister the observer. |
1055 host_resolver->RemoveObserver(&observer); | 1057 host_resolver->RemoveObserver(&observer); |
1056 | 1058 |
1057 // Resolve "host3" | 1059 // Resolve "host3" |
1058 HostResolver::RequestInfo info3(HostPortPair("host3", 70)); | 1060 HostResolver::RequestInfo info3(HostPortPair("host3", 70)); |
1059 host_resolver->Resolve(info3, &addrlist, &callback, NULL, BoundNetLog()); | 1061 host_resolver->Resolve(info3, &addrlist, callback.callback(), NULL, |
1062 BoundNetLog()); | |
1060 | 1063 |
1061 // No effect this time, since observer was removed. | 1064 // No effect this time, since observer was removed. |
1062 EXPECT_EQ(3U, observer.start_log.size()); | 1065 EXPECT_EQ(3U, observer.start_log.size()); |
1063 EXPECT_EQ(3U, observer.finish_log.size()); | 1066 EXPECT_EQ(3U, observer.finish_log.size()); |
1064 EXPECT_EQ(0U, observer.cancel_log.size()); | 1067 EXPECT_EQ(0U, observer.cancel_log.size()); |
1065 } | 1068 } |
1066 | 1069 |
1067 // Tests that observers are sent OnCancelResolution() whenever a request is | 1070 // Tests that observers are sent OnCancelResolution() whenever a request is |
1068 // cancelled. There are two ways to cancel a request: | 1071 // cancelled. There are two ways to cancel a request: |
1069 // (1) Delete the HostResolver while job is outstanding. | 1072 // (1) Delete the HostResolver while job is outstanding. |
1070 // (2) Call HostResolver::CancelRequest() while a request is outstanding. | 1073 // (2) Call HostResolver::CancelRequest() while a request is outstanding. |
1071 TEST_F(HostResolverImplTest, CancellationObserver) { | 1074 TEST_F(HostResolverImplTest, CancellationObserver) { |
1072 TestHostResolverObserver observer; | 1075 TestHostResolverObserver observer; |
1073 { | 1076 { |
1074 // Create a host resolver and attach an observer. | 1077 // Create a host resolver and attach an observer. |
1075 scoped_ptr<HostResolver> host_resolver( | 1078 scoped_ptr<HostResolver> host_resolver( |
1076 CreateHostResolverImpl(NULL)); | 1079 CreateHostResolverImpl(NULL)); |
1077 host_resolver->AddObserver(&observer); | 1080 host_resolver->AddObserver(&observer); |
1078 | 1081 |
1079 TestOldCompletionCallback callback; | 1082 TestCompletionCallback callback; |
1080 | 1083 |
1081 EXPECT_EQ(0U, observer.start_log.size()); | 1084 EXPECT_EQ(0U, observer.start_log.size()); |
1082 EXPECT_EQ(0U, observer.finish_log.size()); | 1085 EXPECT_EQ(0U, observer.finish_log.size()); |
1083 EXPECT_EQ(0U, observer.cancel_log.size()); | 1086 EXPECT_EQ(0U, observer.cancel_log.size()); |
1084 | 1087 |
1085 // Start an async resolve for (host1:70). | 1088 // Start an async resolve for (host1:70). |
1086 HostResolver::RequestInfo info1(HostPortPair("host1", 70)); | 1089 HostResolver::RequestInfo info1(HostPortPair("host1", 70)); |
1087 HostResolver::RequestHandle req = NULL; | 1090 HostResolver::RequestHandle req = NULL; |
1088 AddressList addrlist; | 1091 AddressList addrlist; |
1089 int rv = host_resolver->Resolve(info1, &addrlist, &callback, &req, | 1092 int rv = host_resolver->Resolve(info1, &addrlist, callback.callback(), &req, |
1090 BoundNetLog()); | 1093 BoundNetLog()); |
1091 EXPECT_EQ(ERR_IO_PENDING, rv); | 1094 EXPECT_EQ(ERR_IO_PENDING, rv); |
1092 EXPECT_TRUE(NULL != req); | 1095 EXPECT_TRUE(NULL != req); |
1093 | 1096 |
1094 EXPECT_EQ(1U, observer.start_log.size()); | 1097 EXPECT_EQ(1U, observer.start_log.size()); |
1095 EXPECT_EQ(0U, observer.finish_log.size()); | 1098 EXPECT_EQ(0U, observer.finish_log.size()); |
1096 EXPECT_EQ(0U, observer.cancel_log.size()); | 1099 EXPECT_EQ(0U, observer.cancel_log.size()); |
1097 | 1100 |
1098 EXPECT_TRUE(observer.start_log[0] == | 1101 EXPECT_TRUE(observer.start_log[0] == |
1099 TestHostResolverObserver::StartOrCancelEntry(0, info1)); | 1102 TestHostResolverObserver::StartOrCancelEntry(0, info1)); |
1100 | 1103 |
1101 // Cancel the request. | 1104 // Cancel the request. |
1102 host_resolver->CancelRequest(req); | 1105 host_resolver->CancelRequest(req); |
1103 | 1106 |
1104 EXPECT_EQ(1U, observer.start_log.size()); | 1107 EXPECT_EQ(1U, observer.start_log.size()); |
1105 EXPECT_EQ(0U, observer.finish_log.size()); | 1108 EXPECT_EQ(0U, observer.finish_log.size()); |
1106 EXPECT_EQ(1U, observer.cancel_log.size()); | 1109 EXPECT_EQ(1U, observer.cancel_log.size()); |
1107 | 1110 |
1108 EXPECT_TRUE(observer.cancel_log[0] == | 1111 EXPECT_TRUE(observer.cancel_log[0] == |
1109 TestHostResolverObserver::StartOrCancelEntry(0, info1)); | 1112 TestHostResolverObserver::StartOrCancelEntry(0, info1)); |
1110 | 1113 |
1111 // Start an async request for (host2:60) | 1114 // Start an async request for (host2:60) |
1112 HostResolver::RequestInfo info2(HostPortPair("host2", 60)); | 1115 HostResolver::RequestInfo info2(HostPortPair("host2", 60)); |
1113 rv = host_resolver->Resolve(info2, &addrlist, &callback, NULL, | 1116 rv = host_resolver->Resolve(info2, &addrlist, callback.callback(), NULL, |
1114 BoundNetLog()); | 1117 BoundNetLog()); |
1115 EXPECT_EQ(ERR_IO_PENDING, rv); | 1118 EXPECT_EQ(ERR_IO_PENDING, rv); |
1116 EXPECT_TRUE(NULL != req); | 1119 EXPECT_TRUE(NULL != req); |
1117 | 1120 |
1118 EXPECT_EQ(2U, observer.start_log.size()); | 1121 EXPECT_EQ(2U, observer.start_log.size()); |
1119 EXPECT_EQ(0U, observer.finish_log.size()); | 1122 EXPECT_EQ(0U, observer.finish_log.size()); |
1120 EXPECT_EQ(1U, observer.cancel_log.size()); | 1123 EXPECT_EQ(1U, observer.cancel_log.size()); |
1121 | 1124 |
1122 EXPECT_TRUE(observer.start_log[1] == | 1125 EXPECT_TRUE(observer.start_log[1] == |
1123 TestHostResolverObserver::StartOrCancelEntry(1, info2)); | 1126 TestHostResolverObserver::StartOrCancelEntry(1, info2)); |
(...skipping 17 matching lines...) Expand all Loading... | |
1141 // Test that IP address changes flush the cache. | 1144 // Test that IP address changes flush the cache. |
1142 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { | 1145 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { |
1143 scoped_ptr<HostResolver> host_resolver( | 1146 scoped_ptr<HostResolver> host_resolver( |
1144 new HostResolverImpl(NULL, HostCache::CreateDefaultCache(), kMaxJobs, | 1147 new HostResolverImpl(NULL, HostCache::CreateDefaultCache(), kMaxJobs, |
1145 kMaxRetryAttempts, NULL)); | 1148 kMaxRetryAttempts, NULL)); |
1146 | 1149 |
1147 AddressList addrlist; | 1150 AddressList addrlist; |
1148 | 1151 |
1149 // Resolve "host1". | 1152 // Resolve "host1". |
1150 HostResolver::RequestInfo info1(HostPortPair("host1", 70)); | 1153 HostResolver::RequestInfo info1(HostPortPair("host1", 70)); |
1151 TestOldCompletionCallback callback; | 1154 TestCompletionCallback callback; |
1152 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, | 1155 int rv = host_resolver->Resolve(info1, &addrlist, callback.callback(), NULL, |
1153 BoundNetLog()); | 1156 BoundNetLog()); |
1154 EXPECT_EQ(ERR_IO_PENDING, rv); | 1157 EXPECT_EQ(ERR_IO_PENDING, rv); |
1155 EXPECT_EQ(OK, callback.WaitForResult()); | 1158 EXPECT_EQ(OK, callback.WaitForResult()); |
1156 | 1159 |
1157 // Resolve "host1" again -- this time it will be served from cache, but it | 1160 // Resolve "host1" again -- this time it will be served from cache, but it |
1158 // should still notify of completion. | 1161 // should still notify of completion. |
1159 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog()); | 1162 rv = host_resolver->Resolve(info1, &addrlist, callback.callback(), NULL, |
1163 BoundNetLog()); | |
1160 ASSERT_EQ(OK, rv); // Should complete synchronously. | 1164 ASSERT_EQ(OK, rv); // Should complete synchronously. |
1161 | 1165 |
1162 // Flush cache by triggering an IP address change. | 1166 // Flush cache by triggering an IP address change. |
1163 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1167 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
1164 MessageLoop::current()->RunAllPending(); // Notification happens async. | 1168 MessageLoop::current()->RunAllPending(); // Notification happens async. |
1165 | 1169 |
1166 // Resolve "host1" again -- this time it won't be served from cache, so it | 1170 // Resolve "host1" again -- this time it won't be served from cache, so it |
1167 // will complete asynchronously. | 1171 // will complete asynchronously. |
1168 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog()); | 1172 rv = host_resolver->Resolve(info1, &addrlist, callback.callback(), NULL, |
1173 BoundNetLog()); | |
1169 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. | 1174 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. |
1170 EXPECT_EQ(OK, callback.WaitForResult()); | 1175 EXPECT_EQ(OK, callback.WaitForResult()); |
1171 } | 1176 } |
1172 | 1177 |
1173 // Test that IP address changes send ERR_ABORTED to pending requests. | 1178 // Test that IP address changes send ERR_ABORTED to pending requests. |
1174 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { | 1179 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { |
1175 scoped_refptr<WaitingHostResolverProc> resolver_proc( | 1180 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
1176 new WaitingHostResolverProc(NULL)); | 1181 new WaitingHostResolverProc(NULL)); |
1177 scoped_ptr<HostResolver> host_resolver(CreateHostResolverImpl(resolver_proc)); | 1182 scoped_ptr<HostResolver> host_resolver(CreateHostResolverImpl(resolver_proc)); |
1178 | 1183 |
1179 // Resolve "host1". | 1184 // Resolve "host1". |
1180 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1185 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
1181 TestOldCompletionCallback callback; | 1186 TestCompletionCallback callback; |
1182 AddressList addrlist; | 1187 AddressList addrlist; |
1183 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 1188 int rv = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, |
1184 BoundNetLog()); | 1189 BoundNetLog()); |
1185 EXPECT_EQ(ERR_IO_PENDING, rv); | 1190 EXPECT_EQ(ERR_IO_PENDING, rv); |
1186 | 1191 |
1187 resolver_proc->Wait(); | 1192 resolver_proc->Wait(); |
1188 // Triggering an IP address change. | 1193 // Triggering an IP address change. |
1189 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1194 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
1190 MessageLoop::current()->RunAllPending(); // Notification happens async. | 1195 MessageLoop::current()->RunAllPending(); // Notification happens async. |
1191 resolver_proc->Signal(); | 1196 resolver_proc->Signal(); |
1192 | 1197 |
1193 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); | 1198 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); |
1194 EXPECT_EQ(0u, host_resolver->GetHostCache()->size()); | 1199 EXPECT_EQ(0u, host_resolver->GetHostCache()->size()); |
1195 } | 1200 } |
1196 | 1201 |
1197 // Obey pool constraints after IP address has changed. | 1202 // Obey pool constraints after IP address has changed. |
1198 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { | 1203 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { |
1199 scoped_refptr<WaitingHostResolverProc> resolver_proc( | 1204 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
1200 new WaitingHostResolverProc(CreateCatchAllHostResolverProc())); | 1205 new WaitingHostResolverProc(CreateCatchAllHostResolverProc())); |
1201 scoped_ptr<HostResolverImpl> host_resolver( | 1206 scoped_ptr<HostResolverImpl> host_resolver( |
1202 new HostResolverImpl(resolver_proc, HostCache::CreateDefaultCache(), | 1207 new HostResolverImpl(resolver_proc, HostCache::CreateDefaultCache(), |
1203 kMaxJobs, kMaxRetryAttempts, NULL)); | 1208 kMaxJobs, kMaxRetryAttempts, NULL)); |
1204 | 1209 |
1205 const size_t kMaxOutstandingJobs = 1u; | 1210 const size_t kMaxOutstandingJobs = 1u; |
1206 const size_t kMaxPendingRequests = 1000000u; // not relevant. | 1211 const size_t kMaxPendingRequests = 1000000u; // not relevant. |
1207 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, | 1212 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, |
1208 kMaxOutstandingJobs, | 1213 kMaxOutstandingJobs, |
1209 kMaxPendingRequests); | 1214 kMaxPendingRequests); |
1210 | 1215 |
1211 // Resolve "host1". | 1216 // Resolve "host1". |
1212 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1217 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
1213 TestOldCompletionCallback callback; | 1218 TestCompletionCallback callback; |
1214 AddressList addrlist; | 1219 AddressList addrlist; |
1215 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 1220 int rv = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, |
1216 BoundNetLog()); | 1221 BoundNetLog()); |
1217 EXPECT_EQ(ERR_IO_PENDING, rv); | 1222 EXPECT_EQ(ERR_IO_PENDING, rv); |
1218 | 1223 |
1219 // Must wait before signal to ensure that the two signals don't get merged | 1224 // Must wait before signal to ensure that the two signals don't get merged |
1220 // together. (Worker threads might not start until the last WaitForResult.) | 1225 // together. (Worker threads might not start until the last WaitForResult.) |
1221 resolver_proc->Wait(); | 1226 resolver_proc->Wait(); |
1222 // Triggering an IP address change. | 1227 // Triggering an IP address change. |
1223 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1228 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
1224 MessageLoop::current()->RunAllPending(); // Notification happens async. | 1229 MessageLoop::current()->RunAllPending(); // Notification happens async. |
1225 resolver_proc->Signal(); | 1230 resolver_proc->Signal(); |
1226 | 1231 |
1227 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); | 1232 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); |
1228 | 1233 |
1229 rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 1234 rv = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, |
1230 BoundNetLog()); | 1235 BoundNetLog()); |
1231 EXPECT_EQ(ERR_IO_PENDING, rv); | 1236 EXPECT_EQ(ERR_IO_PENDING, rv); |
1232 resolver_proc->Wait(); | 1237 resolver_proc->Wait(); |
1233 resolver_proc->Signal(); | 1238 resolver_proc->Signal(); |
1234 EXPECT_EQ(OK, callback.WaitForResult()); | 1239 EXPECT_EQ(OK, callback.WaitForResult()); |
1235 } | 1240 } |
1236 | 1241 |
1237 class ResolveWithinCallback : public CallbackRunner< Tuple1<int> > { | 1242 class ResolveWithinCallback : public CallbackRunner< Tuple1<int> > { |
1238 public: | 1243 public: |
1239 explicit ResolveWithinCallback(const HostResolver::RequestInfo& info) | 1244 explicit ResolveWithinCallback(const HostResolver::RequestInfo& info) |
1240 : info_(info) {} | 1245 : info_(info) {} |
1241 | 1246 |
1242 virtual void RunWithParams(const Tuple1<int>& params) { | 1247 virtual void RunWithParams(const Tuple1<int>& params) { |
1243 // Ditch the WaitingHostResolverProc so that the subsequent request | 1248 // Ditch the WaitingHostResolverProc so that the subsequent request |
1244 // succeeds. | 1249 // succeeds. |
1245 callback_.RunWithParams(params); | 1250 //callback_.RunWithParams(params); |
willchan no longer on Chromium
2011/11/14 16:45:12
Change this to callback_.callback()->Run(params.a)
James Hawkins
2011/11/15 23:34:33
Unfortunately the issue is that Resolve takes a Co
willchan no longer on Chromium
2011/11/16 00:08:01
Oh, you probably want to do the same transformatio
James Hawkins
2011/11/16 00:49:54
Cool, done.
| |
1246 host_resolver_.reset( | 1251 host_resolver_.reset( |
1247 CreateHostResolverImpl(CreateCatchAllHostResolverProc())); | 1252 CreateHostResolverImpl(CreateCatchAllHostResolverProc())); |
1248 EXPECT_EQ(ERR_IO_PENDING, | 1253 EXPECT_EQ(ERR_IO_PENDING, |
1249 host_resolver_->Resolve(info_, &addrlist_, &nested_callback_, | 1254 host_resolver_->Resolve(info_, &addrlist_, |
1250 NULL, BoundNetLog())); | 1255 nested_callback_.callback(), NULL, |
1256 BoundNetLog())); | |
1251 } | 1257 } |
1252 | 1258 |
1253 int WaitForResult() { | 1259 int WaitForResult() { |
1254 return callback_.WaitForResult(); | 1260 return callback_.WaitForResult(); |
1255 } | 1261 } |
1256 | 1262 |
1257 int WaitForNestedResult() { | 1263 int WaitForNestedResult() { |
1258 return nested_callback_.WaitForResult(); | 1264 return nested_callback_.WaitForResult(); |
1259 } | 1265 } |
1260 | 1266 |
1261 private: | 1267 private: |
1262 const HostResolver::RequestInfo info_; | 1268 const HostResolver::RequestInfo info_; |
1263 AddressList addrlist_; | 1269 AddressList addrlist_; |
1264 TestOldCompletionCallback callback_; | 1270 TestCompletionCallback callback_; |
1265 TestOldCompletionCallback nested_callback_; | 1271 TestCompletionCallback nested_callback_; |
1266 scoped_ptr<HostResolver> host_resolver_; | 1272 scoped_ptr<HostResolver> host_resolver_; |
1267 }; | 1273 }; |
1268 | 1274 |
1269 TEST_F(HostResolverImplTest, OnlyAbortExistingRequestsOnIPAddressChange) { | 1275 TEST_F(HostResolverImplTest, OnlyAbortExistingRequestsOnIPAddressChange) { |
1270 scoped_refptr<WaitingHostResolverProc> resolver_proc( | 1276 scoped_refptr<WaitingHostResolverProc> resolver_proc( |
1271 new WaitingHostResolverProc(CreateCatchAllHostResolverProc())); | 1277 new WaitingHostResolverProc(CreateCatchAllHostResolverProc())); |
1272 scoped_ptr<HostResolver> host_resolver(CreateHostResolverImpl(resolver_proc)); | 1278 scoped_ptr<HostResolver> host_resolver(CreateHostResolverImpl(resolver_proc)); |
1273 | 1279 |
1274 // Resolve "host1". | 1280 // Resolve "host1". |
1275 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1281 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
1276 ResolveWithinCallback callback(info); | 1282 ResolveWithinCallback callback(info); |
1277 AddressList addrlist; | 1283 AddressList addrlist; |
1278 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 1284 int rv = host_resolver->Resolve(info, &addrlist, /*callback.callback()*/Comple tionCallback(), NULL, |
1279 BoundNetLog()); | 1285 BoundNetLog()); |
1280 EXPECT_EQ(ERR_IO_PENDING, rv); | 1286 EXPECT_EQ(ERR_IO_PENDING, rv); |
1281 | 1287 |
1282 resolver_proc->Wait(); | 1288 resolver_proc->Wait(); |
1283 // Triggering an IP address change. | 1289 // Triggering an IP address change. |
1284 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1290 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
1285 MessageLoop::current()->RunAllPending(); // Notification happens async. | 1291 MessageLoop::current()->RunAllPending(); // Notification happens async. |
1286 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); | 1292 EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); |
1287 resolver_proc->Signal(); // release the thread from WorkerPool for cleanup | 1293 resolver_proc->Signal(); // release the thread from WorkerPool for cleanup |
1288 EXPECT_EQ(OK, callback.WaitForNestedResult()); | 1294 EXPECT_EQ(OK, callback.WaitForNestedResult()); |
(...skipping 22 matching lines...) Expand all Loading... | |
1311 CreateResolverRequest("req0", LOW), | 1317 CreateResolverRequest("req0", LOW), |
1312 CreateResolverRequest("req1", MEDIUM), | 1318 CreateResolverRequest("req1", MEDIUM), |
1313 CreateResolverRequest("req2", MEDIUM), | 1319 CreateResolverRequest("req2", MEDIUM), |
1314 CreateResolverRequest("req3", LOW), | 1320 CreateResolverRequest("req3", LOW), |
1315 CreateResolverRequest("req4", HIGHEST), | 1321 CreateResolverRequest("req4", HIGHEST), |
1316 CreateResolverRequest("req5", LOW), | 1322 CreateResolverRequest("req5", LOW), |
1317 CreateResolverRequest("req6", LOW), | 1323 CreateResolverRequest("req6", LOW), |
1318 CreateResolverRequest("req5", HIGHEST), | 1324 CreateResolverRequest("req5", HIGHEST), |
1319 }; | 1325 }; |
1320 | 1326 |
1321 TestOldCompletionCallback callback[arraysize(req)]; | 1327 TestCompletionCallback callback[arraysize(req)]; |
1322 AddressList addrlist[arraysize(req)]; | 1328 AddressList addrlist[arraysize(req)]; |
1323 | 1329 |
1324 // Start all of the requests. | 1330 // Start all of the requests. |
1325 for (size_t i = 0; i < arraysize(req); ++i) { | 1331 for (size_t i = 0; i < arraysize(req); ++i) { |
1326 int rv = host_resolver->Resolve(req[i], &addrlist[i], | 1332 int rv = host_resolver->Resolve(req[i], &addrlist[i], |
1327 &callback[i], NULL, BoundNetLog()); | 1333 callback[i].callback(), NULL, |
1334 BoundNetLog()); | |
1328 EXPECT_EQ(ERR_IO_PENDING, rv); | 1335 EXPECT_EQ(ERR_IO_PENDING, rv); |
1329 } | 1336 } |
1330 | 1337 |
1331 // Unblock the resolver thread so the requests can run. | 1338 // Unblock the resolver thread so the requests can run. |
1332 resolver_proc->Signal(); | 1339 resolver_proc->Signal(); |
1333 | 1340 |
1334 // Wait for all the requests to complete succesfully. | 1341 // Wait for all the requests to complete succesfully. |
1335 for (size_t i = 0; i < arraysize(req); ++i) { | 1342 for (size_t i = 0; i < arraysize(req); ++i) { |
1336 EXPECT_EQ(OK, callback[i].WaitForResult()) << "i=" << i; | 1343 EXPECT_EQ(OK, callback[i].WaitForResult()) << "i=" << i; |
1337 } | 1344 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1393 HostResolver::RequestInfo req[] = { | 1400 HostResolver::RequestInfo req[] = { |
1394 CreateResolverRequest("req0", LOWEST), | 1401 CreateResolverRequest("req0", LOWEST), |
1395 CreateResolverRequest("req1", HIGHEST), // Will cancel. | 1402 CreateResolverRequest("req1", HIGHEST), // Will cancel. |
1396 CreateResolverRequest("req2", MEDIUM), | 1403 CreateResolverRequest("req2", MEDIUM), |
1397 CreateResolverRequest("req3", LOW), | 1404 CreateResolverRequest("req3", LOW), |
1398 CreateResolverRequest("req4", HIGHEST), // Will cancel. | 1405 CreateResolverRequest("req4", HIGHEST), // Will cancel. |
1399 CreateResolverRequest("req5", LOWEST), // Will cancel. | 1406 CreateResolverRequest("req5", LOWEST), // Will cancel. |
1400 CreateResolverRequest("req6", MEDIUM), | 1407 CreateResolverRequest("req6", MEDIUM), |
1401 }; | 1408 }; |
1402 | 1409 |
1403 TestOldCompletionCallback callback[arraysize(req)]; | 1410 TestCompletionCallback callback[arraysize(req)]; |
1404 AddressList addrlist[arraysize(req)]; | 1411 AddressList addrlist[arraysize(req)]; |
1405 HostResolver::RequestHandle handle[arraysize(req)]; | 1412 HostResolver::RequestHandle handle[arraysize(req)]; |
1406 | 1413 |
1407 // Start all of the requests. | 1414 // Start all of the requests. |
1408 for (size_t i = 0; i < arraysize(req); ++i) { | 1415 for (size_t i = 0; i < arraysize(req); ++i) { |
1409 int rv = host_resolver->Resolve(req[i], &addrlist[i], | 1416 int rv = host_resolver->Resolve(req[i], &addrlist[i], |
1410 &callback[i], &handle[i], BoundNetLog()); | 1417 callback[i].callback(), &handle[i], |
1418 BoundNetLog()); | |
1411 EXPECT_EQ(ERR_IO_PENDING, rv); | 1419 EXPECT_EQ(ERR_IO_PENDING, rv); |
1412 } | 1420 } |
1413 | 1421 |
1414 // Cancel some requests | 1422 // Cancel some requests |
1415 host_resolver->CancelRequest(handle[1]); | 1423 host_resolver->CancelRequest(handle[1]); |
1416 host_resolver->CancelRequest(handle[4]); | 1424 host_resolver->CancelRequest(handle[4]); |
1417 host_resolver->CancelRequest(handle[5]); | 1425 host_resolver->CancelRequest(handle[5]); |
1418 handle[1] = handle[4] = handle[5] = NULL; | 1426 handle[1] = handle[4] = handle[5] = NULL; |
1419 | 1427 |
1420 // Unblock the resolver thread so the requests can run. | 1428 // Unblock the resolver thread so the requests can run. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1469 // At this point, there are 3 enqueued requests. | 1477 // At this point, there are 3 enqueued requests. |
1470 // Insertion of subsequent requests will cause evictions | 1478 // Insertion of subsequent requests will cause evictions |
1471 // based on priority. | 1479 // based on priority. |
1472 | 1480 |
1473 CreateResolverRequest("req4", LOW), // Evicts itself! | 1481 CreateResolverRequest("req4", LOW), // Evicts itself! |
1474 CreateResolverRequest("req5", MEDIUM), // Evicts req3 | 1482 CreateResolverRequest("req5", MEDIUM), // Evicts req3 |
1475 CreateResolverRequest("req6", HIGHEST), // Evicts req5. | 1483 CreateResolverRequest("req6", HIGHEST), // Evicts req5. |
1476 CreateResolverRequest("req7", MEDIUM), // Evicts req2. | 1484 CreateResolverRequest("req7", MEDIUM), // Evicts req2. |
1477 }; | 1485 }; |
1478 | 1486 |
1479 TestOldCompletionCallback callback[arraysize(req)]; | 1487 TestCompletionCallback callback[arraysize(req)]; |
1480 AddressList addrlist[arraysize(req)]; | 1488 AddressList addrlist[arraysize(req)]; |
1481 HostResolver::RequestHandle handle[arraysize(req)]; | 1489 HostResolver::RequestHandle handle[arraysize(req)]; |
1482 | 1490 |
1483 // Start all of the requests. | 1491 // Start all of the requests. |
1484 for (size_t i = 0; i < arraysize(req); ++i) { | 1492 for (size_t i = 0; i < arraysize(req); ++i) { |
1485 int rv = host_resolver->Resolve(req[i], &addrlist[i], | 1493 int rv = host_resolver->Resolve(req[i], &addrlist[i], |
1486 &callback[i], &handle[i], BoundNetLog()); | 1494 callback[i].callback(), &handle[i], |
1495 BoundNetLog()); | |
1487 if (i == 4u) | 1496 if (i == 4u) |
1488 EXPECT_EQ(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE, rv); | 1497 EXPECT_EQ(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE, rv); |
1489 else | 1498 else |
1490 EXPECT_EQ(ERR_IO_PENDING, rv) << i; | 1499 EXPECT_EQ(ERR_IO_PENDING, rv) << i; |
1491 } | 1500 } |
1492 | 1501 |
1493 // Unblock the resolver thread so the requests can run. | 1502 // Unblock the resolver thread so the requests can run. |
1494 resolver_proc->Signal(); | 1503 resolver_proc->Signal(); |
1495 | 1504 |
1496 // Requests 3, 5, 2 will have been evicted due to queue overflow. | 1505 // Requests 3, 5, 2 will have been evicted due to queue overflow. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1536 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1545 // Note that at this point the CapturingHostResolverProc is blocked, so any |
1537 // requests we make will not complete. | 1546 // requests we make will not complete. |
1538 | 1547 |
1539 HostResolver::RequestInfo req[] = { | 1548 HostResolver::RequestInfo req[] = { |
1540 CreateResolverRequestForAddressFamily("h1", MEDIUM, | 1549 CreateResolverRequestForAddressFamily("h1", MEDIUM, |
1541 ADDRESS_FAMILY_UNSPECIFIED), | 1550 ADDRESS_FAMILY_UNSPECIFIED), |
1542 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), | 1551 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), |
1543 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), | 1552 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), |
1544 }; | 1553 }; |
1545 | 1554 |
1546 TestOldCompletionCallback callback[arraysize(req)]; | 1555 TestCompletionCallback callback[arraysize(req)]; |
1547 AddressList addrlist[arraysize(req)]; | 1556 AddressList addrlist[arraysize(req)]; |
1548 HostResolver::RequestHandle handle[arraysize(req)]; | 1557 HostResolver::RequestHandle handle[arraysize(req)]; |
1549 | 1558 |
1550 // Start all of the requests. | 1559 // Start all of the requests. |
1551 for (size_t i = 0; i < arraysize(req); ++i) { | 1560 for (size_t i = 0; i < arraysize(req); ++i) { |
1552 int rv = host_resolver->Resolve(req[i], &addrlist[i], | 1561 int rv = host_resolver->Resolve(req[i], &addrlist[i], |
1553 &callback[i], &handle[i], BoundNetLog()); | 1562 callback[i].callback(), &handle[i], |
1563 BoundNetLog()); | |
1554 EXPECT_EQ(ERR_IO_PENDING, rv) << i; | 1564 EXPECT_EQ(ERR_IO_PENDING, rv) << i; |
1555 } | 1565 } |
1556 | 1566 |
1557 // Unblock the resolver thread so the requests can run. | 1567 // Unblock the resolver thread so the requests can run. |
1558 resolver_proc->Signal(); | 1568 resolver_proc->Signal(); |
1559 | 1569 |
1560 // Wait for all the requests to complete. | 1570 // Wait for all the requests to complete. |
1561 for (size_t i = 0u; i < arraysize(req); ++i) { | 1571 for (size_t i = 0u; i < arraysize(req); ++i) { |
1562 EXPECT_EQ(OK, callback[i].WaitForResult()); | 1572 EXPECT_EQ(OK, callback[i].WaitForResult()); |
1563 } | 1573 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1606 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1616 // Note that at this point the CapturingHostResolverProc is blocked, so any |
1607 // requests we make will not complete. | 1617 // requests we make will not complete. |
1608 | 1618 |
1609 HostResolver::RequestInfo req[] = { | 1619 HostResolver::RequestInfo req[] = { |
1610 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), | 1620 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), |
1611 CreateResolverRequestForAddressFamily("h1", MEDIUM, | 1621 CreateResolverRequestForAddressFamily("h1", MEDIUM, |
1612 ADDRESS_FAMILY_UNSPECIFIED), | 1622 ADDRESS_FAMILY_UNSPECIFIED), |
1613 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), | 1623 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), |
1614 }; | 1624 }; |
1615 | 1625 |
1616 TestOldCompletionCallback callback[arraysize(req)]; | 1626 TestCompletionCallback callback[arraysize(req)]; |
1617 AddressList addrlist[arraysize(req)]; | 1627 AddressList addrlist[arraysize(req)]; |
1618 HostResolver::RequestHandle handle[arraysize(req)]; | 1628 HostResolver::RequestHandle handle[arraysize(req)]; |
1619 | 1629 |
1620 // Start all of the requests. | 1630 // Start all of the requests. |
1621 for (size_t i = 0; i < arraysize(req); ++i) { | 1631 for (size_t i = 0; i < arraysize(req); ++i) { |
1622 int rv = host_resolver->Resolve(req[i], &addrlist[i], | 1632 int rv = host_resolver->Resolve(req[i], &addrlist[i], |
1623 &callback[i], &handle[i], BoundNetLog()); | 1633 callback[i].callback(), &handle[i], |
1634 BoundNetLog()); | |
1624 EXPECT_EQ(ERR_IO_PENDING, rv) << i; | 1635 EXPECT_EQ(ERR_IO_PENDING, rv) << i; |
1625 } | 1636 } |
1626 | 1637 |
1627 // Unblock the resolver thread so the requests can run. | 1638 // Unblock the resolver thread so the requests can run. |
1628 resolver_proc->Signal(); | 1639 resolver_proc->Signal(); |
1629 | 1640 |
1630 // Wait for all the requests to complete. | 1641 // Wait for all the requests to complete. |
1631 for (size_t i = 0u; i < arraysize(req); ++i) { | 1642 for (size_t i = 0u; i < arraysize(req); ++i) { |
1632 EXPECT_EQ(OK, callback[i].WaitForResult()); | 1643 EXPECT_EQ(OK, callback[i].WaitForResult()); |
1633 } | 1644 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1668 scoped_ptr<HostResolver> host_resolver( | 1679 scoped_ptr<HostResolver> host_resolver( |
1669 CreateHostResolverImpl(resolver_proc)); | 1680 CreateHostResolverImpl(resolver_proc)); |
1670 | 1681 |
1671 // First hit will miss the cache. | 1682 // First hit will miss the cache. |
1672 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); | 1683 HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); |
1673 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 1684 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
1674 int err = host_resolver->ResolveFromCache(info, &addrlist, log.bound()); | 1685 int err = host_resolver->ResolveFromCache(info, &addrlist, log.bound()); |
1675 EXPECT_EQ(ERR_DNS_CACHE_MISS, err); | 1686 EXPECT_EQ(ERR_DNS_CACHE_MISS, err); |
1676 | 1687 |
1677 // This time, we fetch normally. | 1688 // This time, we fetch normally. |
1678 TestOldCompletionCallback callback; | 1689 TestCompletionCallback callback; |
1679 err = host_resolver->Resolve(info, &addrlist, &callback, NULL, log.bound()); | 1690 err = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, |
1691 log.bound()); | |
1680 EXPECT_EQ(ERR_IO_PENDING, err); | 1692 EXPECT_EQ(ERR_IO_PENDING, err); |
1681 err = callback.WaitForResult(); | 1693 err = callback.WaitForResult(); |
1682 EXPECT_EQ(OK, err); | 1694 EXPECT_EQ(OK, err); |
1683 | 1695 |
1684 // Now we should be able to fetch from the cache. | 1696 // Now we should be able to fetch from the cache. |
1685 err = host_resolver->ResolveFromCache(info, &addrlist, log.bound()); | 1697 err = host_resolver->ResolveFromCache(info, &addrlist, log.bound()); |
1686 EXPECT_EQ(OK, err); | 1698 EXPECT_EQ(OK, err); |
1687 | 1699 |
1688 const struct addrinfo* ainfo = addrlist.head(); | 1700 const struct addrinfo* ainfo = addrlist.head(); |
1689 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); | 1701 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); |
(...skipping 23 matching lines...) Expand all Loading... | |
1713 NULL)); | 1725 NULL)); |
1714 | 1726 |
1715 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so | 1727 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so |
1716 // that unit test runs faster. For example, this test finishes in 1.5 secs | 1728 // that unit test runs faster. For example, this test finishes in 1.5 secs |
1717 // (500ms * 3). | 1729 // (500ms * 3). |
1718 TimeDelta kUnresponsiveTime = TimeDelta::FromMilliseconds(500); | 1730 TimeDelta kUnresponsiveTime = TimeDelta::FromMilliseconds(500); |
1719 host_resolver->set_unresponsive_delay(kUnresponsiveTime); | 1731 host_resolver->set_unresponsive_delay(kUnresponsiveTime); |
1720 | 1732 |
1721 // Resolve "host1". | 1733 // Resolve "host1". |
1722 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1734 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
1723 TestOldCompletionCallback callback; | 1735 TestCompletionCallback callback; |
1724 AddressList addrlist; | 1736 AddressList addrlist; |
1725 int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, | 1737 int rv = host_resolver->Resolve(info, &addrlist, callback.callback(), NULL, |
1726 BoundNetLog()); | 1738 BoundNetLog()); |
1727 EXPECT_EQ(ERR_IO_PENDING, rv); | 1739 EXPECT_EQ(ERR_IO_PENDING, rv); |
1728 | 1740 |
1729 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. | 1741 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. |
1730 EXPECT_EQ(-4, callback.WaitForResult()); | 1742 EXPECT_EQ(-4, callback.WaitForResult()); |
1731 | 1743 |
1732 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); | 1744 resolver_proc->WaitForAllAttemptsToFinish(TimeDelta::FromMilliseconds(60000)); |
1733 MessageLoop::current()->RunAllPending(); | 1745 MessageLoop::current()->RunAllPending(); |
1734 | 1746 |
1735 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); | 1747 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); |
1736 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); | 1748 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); |
1737 } | 1749 } |
1738 | 1750 |
1739 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1751 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
1740 | 1752 |
1741 } // namespace net | 1753 } // namespace net |
OLD | NEW |