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

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: 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
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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 TestHostResolverImpl(const Options& options, 455 TestHostResolverImpl(const Options& options,
456 NetLog* net_log, 456 NetLog* net_log,
457 bool ipv6_reachable) 457 bool ipv6_reachable)
458 : HostResolverImpl(options, net_log), ipv6_reachable_(ipv6_reachable) {} 458 : HostResolverImpl(options, net_log), ipv6_reachable_(ipv6_reachable) {}
459 459
460 ~TestHostResolverImpl() override {} 460 ~TestHostResolverImpl() override {}
461 461
462 private: 462 private:
463 const bool ipv6_reachable_; 463 const bool ipv6_reachable_;
464 464
465 bool IsIPv6Reachable(const NetLogWithSource& net_log) override { 465 bool IsGloballyReachable(const IPAddress& dest,
466 const NetLogWithSource& net_log) override {
466 return ipv6_reachable_; 467 return ipv6_reachable_;
467 } 468 }
468 }; 469 };
469 470
470 const uint16_t kLocalhostLookupPort = 80; 471 const uint16_t kLocalhostLookupPort = 80;
471 472
472 bool HasEndpoint(const IPEndPoint& endpoint, const AddressList& addresses) { 473 bool HasEndpoint(const IPEndPoint& endpoint, const AddressList& addresses) {
473 for (const auto& address : addresses) { 474 for (const auto& address : addresses) {
474 if (endpoint == address) 475 if (endpoint == address)
475 return true; 476 return true;
(...skipping 1922 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 proc_->SignalMultiple(3u); 2399 proc_->SignalMultiple(3u);
2399 2400
2400 EXPECT_THAT(requests_[0]->WaitForResult(), IsOk()); 2401 EXPECT_THAT(requests_[0]->WaitForResult(), IsOk());
2401 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); 2402 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80));
2402 EXPECT_THAT(requests_[1]->WaitForResult(), IsOk()); 2403 EXPECT_THAT(requests_[1]->WaitForResult(), IsOk());
2403 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); 2404 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80));
2404 EXPECT_THAT(requests_[2]->WaitForResult(), IsOk()); 2405 EXPECT_THAT(requests_[2]->WaitForResult(), IsOk());
2405 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); 2406 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80));
2406 } 2407 }
2407 2408
2409 TEST_F(HostResolverImplDnsTest, NoIPv6OnWifi) {
2410 CreateSerialResolver(); // To guarantee order of resolutions.
2411 resolver_->SetNoIPv6OnWifi();
2412
2413 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
2414 NetworkChangeNotifier::CONNECTION_WIFI);
2415 // Needed so IPv6 availability check isn't skipped.
2416 ChangeDnsConfig(CreateValidDnsConfig());
2417
2418 proc_->AddRule("h1", ADDRESS_FAMILY_UNSPECIFIED, "::3");
2419 proc_->AddRule("h1", ADDRESS_FAMILY_IPV4, "1.0.0.1");
2420 proc_->AddRule("h1", ADDRESS_FAMILY_IPV6, "::2");
2421
2422 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED);
2423 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
2424 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
2425
2426 // Start all of the requests.
2427 for (size_t i = 0u; i < requests_.size(); ++i) {
2428 EXPECT_THAT(requests_[i]->Resolve(), IsError(ERR_IO_PENDING)) << i;
2429 }
2430
2431 proc_->SignalMultiple(requests_.size());
2432
2433 // Wait for all the requests to complete.
2434 for (size_t i = 0u; i < requests_.size(); ++i) {
2435 EXPECT_THAT(requests_[i]->WaitForResult(), IsOk()) << i;
2436 }
2437
2438 // Since the requests all had the same priority and we limited the thread
2439 // count to 1, they should have completed in the same order as they were
2440 // requested.
2441 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList();
2442 ASSERT_EQ(3u, capture_list.size());
2443
2444 EXPECT_EQ("h1", capture_list[0].hostname);
2445 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[0].address_family);
2446
2447 EXPECT_EQ("h1", capture_list[1].hostname);
2448 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[1].address_family);
2449
2450 EXPECT_EQ("h1", capture_list[2].hostname);
2451 EXPECT_EQ(ADDRESS_FAMILY_IPV6, capture_list[2].address_family);
2452
2453 // Now check that the correct resolved IP addresses were returned.
2454 EXPECT_TRUE(requests_[0]->HasOneAddress("1.0.0.1", 80));
2455 EXPECT_TRUE(requests_[1]->HasOneAddress("1.0.0.1", 80));
2456 EXPECT_TRUE(requests_[2]->HasOneAddress("::2", 80));
2457
2458 // Now repeat the test on non-wifi to check that IPv6 is used as normal
2459 // after the network changes.
2460 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
2461 NetworkChangeNotifier::CONNECTION_4G);
2462 base::RunLoop().RunUntilIdle(); // Wait for NetworkChangeNotifier.
2463
2464 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED);
2465 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
2466 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
2467
2468 // The IPv4 and IPv6 requests are in cache, but the UNSPECIFIED one isn't.
2469 EXPECT_THAT(requests_[3]->Resolve(), IsError(ERR_IO_PENDING));
2470 EXPECT_THAT(requests_[4]->Resolve(), IsOk());
2471 EXPECT_THAT(requests_[5]->Resolve(), IsOk());
2472
2473 proc_->SignalMultiple(1);
2474
2475 EXPECT_THAT(requests_[3]->WaitForResult(), IsOk());
2476
2477 // The MockHostResolverProc has only seen one new request.
2478 capture_list = proc_->GetCaptureList();
2479 ASSERT_EQ(4u, capture_list.size());
2480
2481 EXPECT_EQ("h1", capture_list[3].hostname);
2482 EXPECT_EQ(ADDRESS_FAMILY_UNSPECIFIED, capture_list[3].address_family);
2483
2484 // Now check that the correct resolved IP addresses were returned.
2485 EXPECT_TRUE(requests_[3]->HasOneAddress("::3", 80));
2486 EXPECT_TRUE(requests_[4]->HasOneAddress("1.0.0.1", 80));
2487 EXPECT_TRUE(requests_[5]->HasOneAddress("::2", 80));
2488 }
2489
2408 TEST_F(HostResolverImplTest, ResolveLocalHostname) { 2490 TEST_F(HostResolverImplTest, ResolveLocalHostname) {
2409 AddressList addresses; 2491 AddressList addresses;
2410 2492
2411 TestBothLoopbackIPs("localhost"); 2493 TestBothLoopbackIPs("localhost");
2412 TestBothLoopbackIPs("localhoST"); 2494 TestBothLoopbackIPs("localhoST");
2413 TestBothLoopbackIPs("localhost."); 2495 TestBothLoopbackIPs("localhost.");
2414 TestBothLoopbackIPs("localhoST."); 2496 TestBothLoopbackIPs("localhoST.");
2415 TestBothLoopbackIPs("localhost.localdomain"); 2497 TestBothLoopbackIPs("localhost.localdomain");
2416 TestBothLoopbackIPs("localhost.localdomAIn"); 2498 TestBothLoopbackIPs("localhost.localdomAIn");
2417 TestBothLoopbackIPs("localhost.localdomain."); 2499 TestBothLoopbackIPs("localhost.localdomain.");
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 EXPECT_EQ("h1", capture_list[1].hostname); 2692 EXPECT_EQ("h1", capture_list[1].hostname);
2611 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[1].address_family); 2693 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[1].address_family);
2612 2694
2613 // Now check that the correct resolved IP addresses were returned. 2695 // Now check that the correct resolved IP addresses were returned.
2614 EXPECT_TRUE(requests_[0]->HasOneAddress("::2", 80)); 2696 EXPECT_TRUE(requests_[0]->HasOneAddress("::2", 80));
2615 EXPECT_TRUE(requests_[1]->HasOneAddress("::2", 80)); 2697 EXPECT_TRUE(requests_[1]->HasOneAddress("::2", 80));
2616 EXPECT_TRUE(requests_[2]->HasOneAddress("1.0.0.1", 80)); 2698 EXPECT_TRUE(requests_[2]->HasOneAddress("1.0.0.1", 80));
2617 } 2699 }
2618 2700
2619 } // namespace net 2701 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698