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

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

Issue 2811183003: Change Cronet's "disable_ipv6" to "disable_ipv6_on_wifi" (Closed)
Patch Set: more comments Created 3 years, 8 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') | net/dns/mapped_host_resolver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #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 10 matching lines...) Expand all
21 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/synchronization/condition_variable.h" 24 #include "base/synchronization/condition_variable.h"
25 #include "base/synchronization/lock.h" 25 #include "base/synchronization/lock.h"
26 #include "base/test/test_timeouts.h" 26 #include "base/test/test_timeouts.h"
27 #include "base/threading/thread_task_runner_handle.h" 27 #include "base/threading/thread_task_runner_handle.h"
28 #include "base/time/time.h" 28 #include "base/time/time.h"
29 #include "net/base/address_list.h" 29 #include "net/base/address_list.h"
30 #include "net/base/ip_address.h" 30 #include "net/base/ip_address.h"
31 #include "net/base/mock_network_change_notifier.h"
31 #include "net/base/net_errors.h" 32 #include "net/base/net_errors.h"
32 #include "net/dns/dns_client.h" 33 #include "net/dns/dns_client.h"
33 #include "net/dns/dns_test_util.h" 34 #include "net/dns/dns_test_util.h"
34 #include "net/dns/mock_host_resolver.h" 35 #include "net/dns/mock_host_resolver.h"
35 #include "net/log/net_log_event_type.h" 36 #include "net/log/net_log_event_type.h"
36 #include "net/log/net_log_source_type.h" 37 #include "net/log/net_log_source_type.h"
37 #include "net/log/net_log_with_source.h" 38 #include "net/log/net_log_with_source.h"
38 #include "net/log/test_net_log.h" 39 #include "net/log/test_net_log.h"
39 #include "net/test/gtest_util.h" 40 #include "net/test/gtest_util.h"
40 #include "testing/gmock/include/gmock/gmock.h" 41 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 TestHostResolverImpl(const Options& options, 456 TestHostResolverImpl(const Options& options,
456 NetLog* net_log, 457 NetLog* net_log,
457 bool ipv6_reachable) 458 bool ipv6_reachable)
458 : HostResolverImpl(options, net_log), ipv6_reachable_(ipv6_reachable) {} 459 : HostResolverImpl(options, net_log), ipv6_reachable_(ipv6_reachable) {}
459 460
460 ~TestHostResolverImpl() override {} 461 ~TestHostResolverImpl() override {}
461 462
462 private: 463 private:
463 const bool ipv6_reachable_; 464 const bool ipv6_reachable_;
464 465
465 bool IsIPv6Reachable(const NetLogWithSource& net_log) override { 466 bool IsGloballyReachable(const IPAddress& dest,
467 const NetLogWithSource& net_log) override {
466 return ipv6_reachable_; 468 return ipv6_reachable_;
467 } 469 }
468 }; 470 };
469 471
470 const uint16_t kLocalhostLookupPort = 80; 472 const uint16_t kLocalhostLookupPort = 80;
471 473
472 bool HasEndpoint(const IPEndPoint& endpoint, const AddressList& addresses) { 474 bool HasEndpoint(const IPEndPoint& endpoint, const AddressList& addresses) {
473 for (const auto& address : addresses) { 475 for (const auto& address : addresses) {
474 if (endpoint == address) 476 if (endpoint == address)
475 return true; 477 return true;
(...skipping 1922 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 proc_->SignalMultiple(3u); 2400 proc_->SignalMultiple(3u);
2399 2401
2400 EXPECT_THAT(requests_[0]->WaitForResult(), IsOk()); 2402 EXPECT_THAT(requests_[0]->WaitForResult(), IsOk());
2401 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); 2403 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80));
2402 EXPECT_THAT(requests_[1]->WaitForResult(), IsOk()); 2404 EXPECT_THAT(requests_[1]->WaitForResult(), IsOk());
2403 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); 2405 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80));
2404 EXPECT_THAT(requests_[2]->WaitForResult(), IsOk()); 2406 EXPECT_THAT(requests_[2]->WaitForResult(), IsOk());
2405 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); 2407 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80));
2406 } 2408 }
2407 2409
2410 TEST_F(HostResolverImplDnsTest, NoIPv6OnWifi) {
2411 test::ScopedMockNetworkChangeNotifier notifier;
2412 CreateSerialResolver(); // To guarantee order of resolutions.
2413 resolver_->SetNoIPv6OnWifi(true);
2414
2415 notifier.mock_network_change_notifier()->SetConnectionType(
2416 NetworkChangeNotifier::CONNECTION_WIFI);
2417 // Needed so IPv6 availability check isn't skipped.
2418 ChangeDnsConfig(CreateValidDnsConfig());
2419
2420 proc_->AddRule("h1", ADDRESS_FAMILY_UNSPECIFIED, "::3");
2421 proc_->AddRule("h1", ADDRESS_FAMILY_IPV4, "1.0.0.1");
2422 proc_->AddRule("h1", ADDRESS_FAMILY_IPV6, "::2");
2423
2424 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED);
2425 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
2426 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
2427
2428 // Start all of the requests.
2429 for (size_t i = 0u; i < requests_.size(); ++i) {
2430 EXPECT_THAT(requests_[i]->Resolve(), IsError(ERR_IO_PENDING)) << i;
2431 }
2432
2433 proc_->SignalMultiple(requests_.size());
2434
2435 // Wait for all the requests to complete.
2436 for (size_t i = 0u; i < requests_.size(); ++i) {
2437 EXPECT_THAT(requests_[i]->WaitForResult(), IsOk()) << i;
2438 }
2439
2440 // Since the requests all had the same priority and we limited the thread
2441 // count to 1, they should have completed in the same order as they were
2442 // requested.
2443 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList();
2444 ASSERT_EQ(3u, capture_list.size());
2445
2446 EXPECT_EQ("h1", capture_list[0].hostname);
2447 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[0].address_family);
2448
2449 EXPECT_EQ("h1", capture_list[1].hostname);
2450 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[1].address_family);
2451
2452 EXPECT_EQ("h1", capture_list[2].hostname);
2453 EXPECT_EQ(ADDRESS_FAMILY_IPV6, capture_list[2].address_family);
2454
2455 // Now check that the correct resolved IP addresses were returned.
2456 EXPECT_TRUE(requests_[0]->HasOneAddress("1.0.0.1", 80));
2457 EXPECT_TRUE(requests_[1]->HasOneAddress("1.0.0.1", 80));
2458 EXPECT_TRUE(requests_[2]->HasOneAddress("::2", 80));
2459
2460 // Now repeat the test on non-wifi to check that IPv6 is used as normal
2461 // after the network changes.
2462 notifier.mock_network_change_notifier()->SetConnectionType(
2463 NetworkChangeNotifier::CONNECTION_4G);
2464 base::RunLoop().RunUntilIdle(); // Wait for NetworkChangeNotifier.
2465
2466 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED);
2467 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
2468 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
2469
2470 // The IPv4 and IPv6 requests are in cache, but the UNSPECIFIED one isn't.
2471 EXPECT_THAT(requests_[3]->Resolve(), IsError(ERR_IO_PENDING));
2472 EXPECT_THAT(requests_[4]->Resolve(), IsOk());
2473 EXPECT_THAT(requests_[5]->Resolve(), IsOk());
2474
2475 proc_->SignalMultiple(1);
2476
2477 EXPECT_THAT(requests_[3]->WaitForResult(), IsOk());
2478
2479 // The MockHostResolverProc has only seen one new request.
2480 capture_list = proc_->GetCaptureList();
2481 ASSERT_EQ(4u, capture_list.size());
2482
2483 EXPECT_EQ("h1", capture_list[3].hostname);
2484 EXPECT_EQ(ADDRESS_FAMILY_UNSPECIFIED, capture_list[3].address_family);
2485
2486 // Now check that the correct resolved IP addresses were returned.
2487 EXPECT_TRUE(requests_[3]->HasOneAddress("::3", 80));
2488 EXPECT_TRUE(requests_[4]->HasOneAddress("1.0.0.1", 80));
2489 EXPECT_TRUE(requests_[5]->HasOneAddress("::2", 80));
2490 }
2491
2408 TEST_F(HostResolverImplTest, ResolveLocalHostname) { 2492 TEST_F(HostResolverImplTest, ResolveLocalHostname) {
2409 AddressList addresses; 2493 AddressList addresses;
2410 2494
2411 TestBothLoopbackIPs("localhost"); 2495 TestBothLoopbackIPs("localhost");
2412 TestBothLoopbackIPs("localhoST"); 2496 TestBothLoopbackIPs("localhoST");
2413 TestBothLoopbackIPs("localhost."); 2497 TestBothLoopbackIPs("localhost.");
2414 TestBothLoopbackIPs("localhoST."); 2498 TestBothLoopbackIPs("localhoST.");
2415 TestBothLoopbackIPs("localhost.localdomain"); 2499 TestBothLoopbackIPs("localhost.localdomain");
2416 TestBothLoopbackIPs("localhost.localdomAIn"); 2500 TestBothLoopbackIPs("localhost.localdomAIn");
2417 TestBothLoopbackIPs("localhost.localdomain."); 2501 TestBothLoopbackIPs("localhost.localdomain.");
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 EXPECT_EQ("h1", capture_list[1].hostname); 2694 EXPECT_EQ("h1", capture_list[1].hostname);
2611 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[1].address_family); 2695 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[1].address_family);
2612 2696
2613 // Now check that the correct resolved IP addresses were returned. 2697 // Now check that the correct resolved IP addresses were returned.
2614 EXPECT_TRUE(requests_[0]->HasOneAddress("::2", 80)); 2698 EXPECT_TRUE(requests_[0]->HasOneAddress("::2", 80));
2615 EXPECT_TRUE(requests_[1]->HasOneAddress("::2", 80)); 2699 EXPECT_TRUE(requests_[1]->HasOneAddress("::2", 80));
2616 EXPECT_TRUE(requests_[2]->HasOneAddress("1.0.0.1", 80)); 2700 EXPECT_TRUE(requests_[2]->HasOneAddress("1.0.0.1", 80));
2617 } 2701 }
2618 2702
2619 } // namespace net 2703 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | net/dns/mapped_host_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698