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

Side by Side Diff: net/dns/host_resolver_impl_unittest.cc

Issue 2709393007: Add back "default address family" to HostResolver (Closed)
Patch Set: comments Created 3 years, 9 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
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | no next file » | 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 #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 2504 matching lines...) Expand 10 before | Expand all | Expand 10 after
2515 EXPECT_EQ(2, count1); 2515 EXPECT_EQ(2, count1);
2516 EXPECT_EQ(1, count2); 2516 EXPECT_EQ(1, count2);
2517 2517
2518 // Make another request to make sure both callbacks were cleared. 2518 // Make another request to make sure both callbacks were cleared.
2519 req = CreateRequest("just.testing", 80); 2519 req = CreateRequest("just.testing", 80);
2520 EXPECT_THAT(req->Resolve(), IsOk()); 2520 EXPECT_THAT(req->Resolve(), IsOk());
2521 EXPECT_EQ(2, count1); 2521 EXPECT_EQ(2, count1);
2522 EXPECT_EQ(1, count2); 2522 EXPECT_EQ(1, count2);
2523 } 2523 }
2524 2524
2525 // Tests that after changing the default AddressFamily to IPV4, requests
2526 // with UNSPECIFIED address family map to IPV4.
2527 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) {
2528 CreateSerialResolver(); // To guarantee order of resolutions.
2529
2530 proc_->AddRule("h1", ADDRESS_FAMILY_IPV4, "1.0.0.1");
2531 proc_->AddRule("h1", ADDRESS_FAMILY_IPV6, "::2");
2532
2533 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
2534
2535 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED);
2536 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
2537 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
2538
2539 // Start all of the requests.
2540 for (size_t i = 0; i < requests_.size(); ++i) {
2541 EXPECT_EQ(ERR_IO_PENDING, requests_[i]->Resolve()) << i;
2542 }
2543
2544 proc_->SignalMultiple(requests_.size());
2545
2546 // Wait for all the requests to complete.
2547 for (size_t i = 0u; i < requests_.size(); ++i) {
2548 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i;
2549 }
2550
2551 // Since the requests all had the same priority and we limited the thread
2552 // count to 1, they should have completed in the same order as they were
2553 // requested. Moreover, request0 and request1 will have been serviced by
2554 // the same job.
2555
2556 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList();
2557 ASSERT_EQ(2u, capture_list.size());
2558
2559 EXPECT_EQ("h1", capture_list[0].hostname);
2560 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[0].address_family);
2561
2562 EXPECT_EQ("h1", capture_list[1].hostname);
2563 EXPECT_EQ(ADDRESS_FAMILY_IPV6, capture_list[1].address_family);
2564
2565 // Now check that the correct resolved IP addresses were returned.
2566 EXPECT_TRUE(requests_[0]->HasOneAddress("1.0.0.1", 80));
2567 EXPECT_TRUE(requests_[1]->HasOneAddress("1.0.0.1", 80));
2568 EXPECT_TRUE(requests_[2]->HasOneAddress("::2", 80));
2569 }
2570
2571 // This is the exact same test as SetDefaultAddressFamily_IPv4, except the
2572 // default family is set to IPv6 and the family of requests is flipped where
2573 // specified.
2574 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) {
2575 CreateSerialResolver(); // To guarantee order of resolutions.
2576
2577 // Don't use IPv6 replacements here since some systems don't support it.
2578 proc_->AddRule("h1", ADDRESS_FAMILY_IPV4, "1.0.0.1");
2579 proc_->AddRule("h1", ADDRESS_FAMILY_IPV6, "::2");
2580
2581 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6);
2582
2583 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED);
2584 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
2585 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
2586
2587 // Start all of the requests.
2588 for (size_t i = 0; i < requests_.size(); ++i) {
2589 EXPECT_EQ(ERR_IO_PENDING, requests_[i]->Resolve()) << i;
2590 }
2591
2592 proc_->SignalMultiple(requests_.size());
2593
2594 // Wait for all the requests to complete.
2595 for (size_t i = 0u; i < requests_.size(); ++i) {
2596 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i;
2597 }
2598
2599 // Since the requests all had the same priority and we limited the thread
2600 // count to 1, they should have completed in the same order as they were
2601 // requested. Moreover, request0 and request1 will have been serviced by
2602 // the same job.
2603
2604 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList();
2605 ASSERT_EQ(2u, capture_list.size());
2606
2607 EXPECT_EQ("h1", capture_list[0].hostname);
2608 EXPECT_EQ(ADDRESS_FAMILY_IPV6, capture_list[0].address_family);
2609
2610 EXPECT_EQ("h1", capture_list[1].hostname);
2611 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[1].address_family);
2612
2613 // Now check that the correct resolved IP addresses were returned.
2614 EXPECT_TRUE(requests_[0]->HasOneAddress("::2", 80));
2615 EXPECT_TRUE(requests_[1]->HasOneAddress("::2", 80));
2616 EXPECT_TRUE(requests_[2]->HasOneAddress("1.0.0.1", 80));
2617 }
2618
2525 } // namespace net 2619 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698