| 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 #include "net/dns/host_resolver_impl.h" | 5 #include "net/dns/host_resolver_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 2588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2599 EXPECT_EQ(2, count1); | 2599 EXPECT_EQ(2, count1); |
| 2600 EXPECT_EQ(1, count2); | 2600 EXPECT_EQ(1, count2); |
| 2601 | 2601 |
| 2602 // Make another request to make sure both callbacks were cleared. | 2602 // Make another request to make sure both callbacks were cleared. |
| 2603 req = CreateRequest("just.testing", 80); | 2603 req = CreateRequest("just.testing", 80); |
| 2604 EXPECT_THAT(req->Resolve(), IsOk()); | 2604 EXPECT_THAT(req->Resolve(), IsOk()); |
| 2605 EXPECT_EQ(2, count1); | 2605 EXPECT_EQ(2, count1); |
| 2606 EXPECT_EQ(1, count2); | 2606 EXPECT_EQ(1, count2); |
| 2607 } | 2607 } |
| 2608 | 2608 |
| 2609 // Tests that after changing the default AddressFamily to IPV4, requests | |
| 2610 // with UNSPECIFIED address family map to IPV4. | |
| 2611 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { | |
| 2612 CreateSerialResolver(); // To guarantee order of resolutions. | |
| 2613 | |
| 2614 proc_->AddRule("h1", ADDRESS_FAMILY_IPV4, "1.0.0.1"); | |
| 2615 proc_->AddRule("h1", ADDRESS_FAMILY_IPV6, "::2"); | |
| 2616 | |
| 2617 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | |
| 2618 | |
| 2619 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED); | |
| 2620 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4); | |
| 2621 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6); | |
| 2622 | |
| 2623 // Start all of the requests. | |
| 2624 for (size_t i = 0; i < requests_.size(); ++i) { | |
| 2625 EXPECT_EQ(ERR_IO_PENDING, requests_[i]->Resolve()) << i; | |
| 2626 } | |
| 2627 | |
| 2628 proc_->SignalMultiple(requests_.size()); | |
| 2629 | |
| 2630 // Wait for all the requests to complete. | |
| 2631 for (size_t i = 0u; i < requests_.size(); ++i) { | |
| 2632 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; | |
| 2633 } | |
| 2634 | |
| 2635 // Since the requests all had the same priority and we limited the thread | |
| 2636 // count to 1, they should have completed in the same order as they were | |
| 2637 // requested. Moreover, request0 and request1 will have been serviced by | |
| 2638 // the same job. | |
| 2639 | |
| 2640 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList(); | |
| 2641 ASSERT_EQ(2u, capture_list.size()); | |
| 2642 | |
| 2643 EXPECT_EQ("h1", capture_list[0].hostname); | |
| 2644 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[0].address_family); | |
| 2645 | |
| 2646 EXPECT_EQ("h1", capture_list[1].hostname); | |
| 2647 EXPECT_EQ(ADDRESS_FAMILY_IPV6, capture_list[1].address_family); | |
| 2648 | |
| 2649 // Now check that the correct resolved IP addresses were returned. | |
| 2650 EXPECT_TRUE(requests_[0]->HasOneAddress("1.0.0.1", 80)); | |
| 2651 EXPECT_TRUE(requests_[1]->HasOneAddress("1.0.0.1", 80)); | |
| 2652 EXPECT_TRUE(requests_[2]->HasOneAddress("::2", 80)); | |
| 2653 } | |
| 2654 | |
| 2655 // This is the exact same test as SetDefaultAddressFamily_IPv4, except the | |
| 2656 // default family is set to IPv6 and the family of requests is flipped where | |
| 2657 // specified. | |
| 2658 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { | |
| 2659 CreateSerialResolver(); // To guarantee order of resolutions. | |
| 2660 | |
| 2661 // Don't use IPv6 replacements here since some systems don't support it. | |
| 2662 proc_->AddRule("h1", ADDRESS_FAMILY_IPV4, "1.0.0.1"); | |
| 2663 proc_->AddRule("h1", ADDRESS_FAMILY_IPV6, "::2"); | |
| 2664 | |
| 2665 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); | |
| 2666 | |
| 2667 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED); | |
| 2668 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6); | |
| 2669 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4); | |
| 2670 | |
| 2671 // Start all of the requests. | |
| 2672 for (size_t i = 0; i < requests_.size(); ++i) { | |
| 2673 EXPECT_EQ(ERR_IO_PENDING, requests_[i]->Resolve()) << i; | |
| 2674 } | |
| 2675 | |
| 2676 proc_->SignalMultiple(requests_.size()); | |
| 2677 | |
| 2678 // Wait for all the requests to complete. | |
| 2679 for (size_t i = 0u; i < requests_.size(); ++i) { | |
| 2680 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; | |
| 2681 } | |
| 2682 | |
| 2683 // Since the requests all had the same priority and we limited the thread | |
| 2684 // count to 1, they should have completed in the same order as they were | |
| 2685 // requested. Moreover, request0 and request1 will have been serviced by | |
| 2686 // the same job. | |
| 2687 | |
| 2688 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList(); | |
| 2689 ASSERT_EQ(2u, capture_list.size()); | |
| 2690 | |
| 2691 EXPECT_EQ("h1", capture_list[0].hostname); | |
| 2692 EXPECT_EQ(ADDRESS_FAMILY_IPV6, capture_list[0].address_family); | |
| 2693 | |
| 2694 EXPECT_EQ("h1", capture_list[1].hostname); | |
| 2695 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[1].address_family); | |
| 2696 | |
| 2697 // Now check that the correct resolved IP addresses were returned. | |
| 2698 EXPECT_TRUE(requests_[0]->HasOneAddress("::2", 80)); | |
| 2699 EXPECT_TRUE(requests_[1]->HasOneAddress("::2", 80)); | |
| 2700 EXPECT_TRUE(requests_[2]->HasOneAddress("1.0.0.1", 80)); | |
| 2701 } | |
| 2702 | |
| 2703 } // namespace net | 2609 } // namespace net |
| OLD | NEW |