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

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

Issue 1163903002: Remove "Default Address Family" behavior from the HostResolver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Override IPv6 reachability tests for unit tests Created 5 years, 6 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
« net/dns/host_resolver_impl.h ('K') | « 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 <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 int current_attempt_number_; // Incremented whenever Resolve is called. 409 int current_attempt_number_; // Incremented whenever Resolve is called.
410 int total_attempts_; 410 int total_attempts_;
411 int total_attempts_resolved_; 411 int total_attempts_resolved_;
412 int resolved_attempt_number_; 412 int resolved_attempt_number_;
413 413
414 // All attempts wait for right attempt to be resolve. 414 // All attempts wait for right attempt to be resolve.
415 base::Lock lock_; 415 base::Lock lock_;
416 base::ConditionVariable all_done_; 416 base::ConditionVariable all_done_;
417 }; 417 };
418 418
419 class TestHostResolverImpl : public HostResolverImpl {
420 public:
421 TestHostResolverImpl(const Options& options, NetLog* net_log)
422 : HostResolverImpl(options, net_log) {}
mmenke 2015/06/03 13:31:03 nit: Add virtual destructor.
cbentzel 2015/06/03 15:43:19 Done.
423
424 bool IsIPv6Reachable(const BoundNetLog& net_log) override { return true; }
425 };
426
419 } // namespace 427 } // namespace
420 428
421 class HostResolverImplTest : public testing::Test { 429 class HostResolverImplTest : public testing::Test {
422 public: 430 public:
423 static const int kDefaultPort = 80; 431 static const int kDefaultPort = 80;
424 432
425 HostResolverImplTest() : proc_(new MockHostResolverProc()) {} 433 HostResolverImplTest() : proc_(new MockHostResolverProc()) {}
426 434
427 void CreateResolver() { 435 void CreateResolver() {
428 CreateResolverWithLimitsAndParams(kMaxJobs, 436 CreateResolverWithLimitsAndParams(kMaxJobs,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 if (resolver_.get()) 475 if (resolver_.get())
468 EXPECT_EQ(0u, resolver_->num_running_dispatcher_jobs_for_tests()); 476 EXPECT_EQ(0u, resolver_->num_running_dispatcher_jobs_for_tests());
469 EXPECT_FALSE(proc_->HasBlockedRequests()); 477 EXPECT_FALSE(proc_->HasBlockedRequests());
470 } 478 }
471 479
472 virtual void CreateResolverWithLimitsAndParams( 480 virtual void CreateResolverWithLimitsAndParams(
473 size_t max_concurrent_resolves, 481 size_t max_concurrent_resolves,
474 const HostResolverImpl::ProcTaskParams& params) { 482 const HostResolverImpl::ProcTaskParams& params) {
475 HostResolverImpl::Options options = DefaultOptions(); 483 HostResolverImpl::Options options = DefaultOptions();
476 options.max_concurrent_resolves = max_concurrent_resolves; 484 options.max_concurrent_resolves = max_concurrent_resolves;
477 resolver_.reset(new HostResolverImpl(options, NULL)); 485 resolver_.reset(new TestHostResolverImpl(options, NULL));
478 resolver_->set_proc_params_for_test(params); 486 resolver_->set_proc_params_for_test(params);
479 } 487 }
480 488
481 // The Request will not be made until a call to |Resolve()|, and the Job will 489 // The Request will not be made until a call to |Resolve()|, and the Job will
482 // not start until released by |proc_->SignalXXX|. 490 // not start until released by |proc_->SignalXXX|.
483 Request* CreateRequest(const HostResolver::RequestInfo& info, 491 Request* CreateRequest(const HostResolver::RequestInfo& info,
484 RequestPriority priority) { 492 RequestPriority priority) {
485 Request* req = new Request( 493 Request* req = new Request(
486 info, priority, requests_.size(), resolver_.get(), handler_.get()); 494 info, priority, requests_.size(), resolver_.get(), handler_.get());
487 requests_.push_back(req); 495 requests_.push_back(req);
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 // Since caching is disabled, this will result in another async request. 855 // Since caching is disabled, this will result in another async request.
848 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 70)->Resolve()); 856 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 70)->Resolve());
849 } 857 }
850 } 858 }
851 }; 859 };
852 set_handler(new MyHandler()); 860 set_handler(new MyHandler());
853 861
854 // Turn off caching for this host resolver. 862 // Turn off caching for this host resolver.
855 HostResolver::Options options = DefaultOptions(); 863 HostResolver::Options options = DefaultOptions();
856 options.enable_caching = false; 864 options.enable_caching = false;
857 resolver_.reset(new HostResolverImpl(options, NULL)); 865 resolver_.reset(new TestHostResolverImpl(options, NULL));
858 resolver_->set_proc_params_for_test(DefaultParams(proc_.get())); 866 resolver_->set_proc_params_for_test(DefaultParams(proc_.get()));
859 867
860 for (size_t i = 0; i < 4; ++i) { 868 for (size_t i = 0; i < 4; ++i) {
861 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; 869 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i;
862 } 870 }
863 871
864 proc_->SignalMultiple(2u); // One for "a". One for the second "a". 872 proc_->SignalMultiple(2u); // One for "a". One for the second "a".
865 873
866 EXPECT_EQ(OK, requests_[0]->WaitForResult()); 874 EXPECT_EQ(OK, requests_[0]->WaitForResult());
867 ASSERT_EQ(5u, requests_.size()); 875 ASSERT_EQ(5u, requests_.size());
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 EXPECT_EQ("req7", capture_list[3].hostname); 1177 EXPECT_EQ("req7", capture_list[3].hostname);
1170 1178
1171 // Verify that the evicted (incomplete) requests were not cached. 1179 // Verify that the evicted (incomplete) requests were not cached.
1172 EXPECT_EQ(4u, resolver_->GetHostCache()->size()); 1180 EXPECT_EQ(4u, resolver_->GetHostCache()->size());
1173 1181
1174 for (size_t i = 0; i < requests_.size(); ++i) { 1182 for (size_t i = 0; i < requests_.size(); ++i) {
1175 EXPECT_TRUE(requests_[i]->completed()) << i; 1183 EXPECT_TRUE(requests_[i]->completed()) << i;
1176 } 1184 }
1177 } 1185 }
1178 1186
1179 // Tests that after changing the default AddressFamily to IPV4, requests
1180 // with UNSPECIFIED address family map to IPV4.
1181 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) {
1182 CreateSerialResolver(); // To guarantee order of resolutions.
1183
1184 proc_->AddRule("h1", ADDRESS_FAMILY_IPV4, "1.0.0.1");
1185 proc_->AddRule("h1", ADDRESS_FAMILY_IPV6, "::2");
1186
1187 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
1188
1189 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED);
1190 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
1191 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
1192
1193 // Start all of the requests.
1194 for (size_t i = 0; i < requests_.size(); ++i) {
1195 EXPECT_EQ(ERR_IO_PENDING, requests_[i]->Resolve()) << i;
1196 }
1197
1198 proc_->SignalMultiple(requests_.size());
1199
1200 // Wait for all the requests to complete.
1201 for (size_t i = 0u; i < requests_.size(); ++i) {
1202 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i;
1203 }
1204
1205 // Since the requests all had the same priority and we limited the thread
1206 // count to 1, they should have completed in the same order as they were
1207 // requested. Moreover, request0 and request1 will have been serviced by
1208 // the same job.
1209
1210 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList();
1211 ASSERT_EQ(2u, capture_list.size());
1212
1213 EXPECT_EQ("h1", capture_list[0].hostname);
1214 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[0].address_family);
1215
1216 EXPECT_EQ("h1", capture_list[1].hostname);
1217 EXPECT_EQ(ADDRESS_FAMILY_IPV6, capture_list[1].address_family);
1218
1219 // Now check that the correct resolved IP addresses were returned.
1220 EXPECT_TRUE(requests_[0]->HasOneAddress("1.0.0.1", 80));
1221 EXPECT_TRUE(requests_[1]->HasOneAddress("1.0.0.1", 80));
1222 EXPECT_TRUE(requests_[2]->HasOneAddress("::2", 80));
1223 }
1224
1225 // This is the exact same test as SetDefaultAddressFamily_IPv4, except the
1226 // default family is set to IPv6 and the family of requests is flipped where
1227 // specified.
1228 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) {
1229 CreateSerialResolver(); // To guarantee order of resolutions.
1230
1231 // Don't use IPv6 replacements here since some systems don't support it.
1232 proc_->AddRule("h1", ADDRESS_FAMILY_IPV4, "1.0.0.1");
1233 proc_->AddRule("h1", ADDRESS_FAMILY_IPV6, "::2");
1234
1235 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6);
1236
1237 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED);
1238 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
1239 CreateRequest("h1", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
1240
1241 // Start all of the requests.
1242 for (size_t i = 0; i < requests_.size(); ++i) {
1243 EXPECT_EQ(ERR_IO_PENDING, requests_[i]->Resolve()) << i;
1244 }
1245
1246 proc_->SignalMultiple(requests_.size());
1247
1248 // Wait for all the requests to complete.
1249 for (size_t i = 0u; i < requests_.size(); ++i) {
1250 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i;
1251 }
1252
1253 // Since the requests all had the same priority and we limited the thread
1254 // count to 1, they should have completed in the same order as they were
1255 // requested. Moreover, request0 and request1 will have been serviced by
1256 // the same job.
1257
1258 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList();
1259 ASSERT_EQ(2u, capture_list.size());
1260
1261 EXPECT_EQ("h1", capture_list[0].hostname);
1262 EXPECT_EQ(ADDRESS_FAMILY_IPV6, capture_list[0].address_family);
1263
1264 EXPECT_EQ("h1", capture_list[1].hostname);
1265 EXPECT_EQ(ADDRESS_FAMILY_IPV4, capture_list[1].address_family);
1266
1267 // Now check that the correct resolved IP addresses were returned.
1268 EXPECT_TRUE(requests_[0]->HasOneAddress("::2", 80));
1269 EXPECT_TRUE(requests_[1]->HasOneAddress("::2", 80));
1270 EXPECT_TRUE(requests_[2]->HasOneAddress("1.0.0.1", 80));
1271 }
1272
1273 // Make sure that the address family parameter is respected when raw IPs are 1187 // Make sure that the address family parameter is respected when raw IPs are
1274 // passed in. 1188 // passed in.
1275 TEST_F(HostResolverImplTest, AddressFamilyWithRawIPs) { 1189 TEST_F(HostResolverImplTest, AddressFamilyWithRawIPs) {
1276 Request* request = 1190 Request* request =
1277 CreateRequest("127.0.0.1", 80, MEDIUM, ADDRESS_FAMILY_IPV4); 1191 CreateRequest("127.0.0.1", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
1278 EXPECT_EQ(OK, request->Resolve()); 1192 EXPECT_EQ(OK, request->Resolve());
1279 EXPECT_TRUE(request->HasOneAddress("127.0.0.1", 80)); 1193 EXPECT_TRUE(request->HasOneAddress("127.0.0.1", 80));
1280 1194
1281 request = CreateRequest("127.0.0.1", 80, MEDIUM, ADDRESS_FAMILY_IPV6); 1195 request = CreateRequest("127.0.0.1", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
1282 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, request->Resolve()); 1196 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, request->Resolve());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 new LookupAttemptHostResolverProc( 1243 new LookupAttemptHostResolverProc(
1330 NULL, kAttemptNumberToResolve, kTotalAttempts)); 1244 NULL, kAttemptNumberToResolve, kTotalAttempts));
1331 1245
1332 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc.get()); 1246 HostResolverImpl::ProcTaskParams params = DefaultParams(resolver_proc.get());
1333 1247
1334 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so 1248 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so
1335 // that unit test runs faster. For example, this test finishes in 1.5 secs 1249 // that unit test runs faster. For example, this test finishes in 1.5 secs
1336 // (500ms * 3). 1250 // (500ms * 3).
1337 params.unresponsive_delay = base::TimeDelta::FromMilliseconds(500); 1251 params.unresponsive_delay = base::TimeDelta::FromMilliseconds(500);
1338 1252
1339 resolver_.reset(new HostResolverImpl(DefaultOptions(), NULL)); 1253 resolver_.reset(new TestHostResolverImpl(DefaultOptions(), NULL));
1340 resolver_->set_proc_params_for_test(params); 1254 resolver_->set_proc_params_for_test(params);
1341 1255
1342 // Resolve "host1". 1256 // Resolve "host1".
1343 HostResolver::RequestInfo info(HostPortPair("host1", 70)); 1257 HostResolver::RequestInfo info(HostPortPair("host1", 70));
1344 Request* req = CreateRequest(info, DEFAULT_PRIORITY); 1258 Request* req = CreateRequest(info, DEFAULT_PRIORITY);
1345 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); 1259 EXPECT_EQ(ERR_IO_PENDING, req->Resolve());
1346 1260
1347 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. 1261 // Resolve returns -4 to indicate that 3rd attempt has resolved the host.
1348 EXPECT_EQ(-4, req->WaitForResult()); 1262 EXPECT_EQ(-4, req->WaitForResult());
1349 1263
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 request = CreateRequest("not_reserved2"); 1310 request = CreateRequest("not_reserved2");
1397 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); 1311 EXPECT_EQ(ERR_IO_PENDING, request->Resolve());
1398 EXPECT_EQ(OK, request->WaitForResult()); 1312 EXPECT_EQ(OK, request->WaitForResult());
1399 1313
1400 request = CreateRequest("not_reserved3"); 1314 request = CreateRequest("not_reserved3");
1401 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); 1315 EXPECT_EQ(ERR_IO_PENDING, request->Resolve());
1402 EXPECT_EQ(OK, request->WaitForResult()); 1316 EXPECT_EQ(OK, request->WaitForResult());
1403 } 1317 }
1404 1318
1405 TEST_F(HostResolverImplTest, IsIPv6Reachable) { 1319 TEST_F(HostResolverImplTest, IsIPv6Reachable) {
1320 // We need to use the real resolver here.
1321 resolver_.reset(new HostResolverImpl(DefaultOptions(), nullptr));
1406 // Verify that two consecutive calls return the same value. 1322 // Verify that two consecutive calls return the same value.
1407 TestNetLog net_log; 1323 TestNetLog net_log;
1408 BoundNetLog bound_net_log = BoundNetLog::Make(&net_log, NetLog::SOURCE_NONE); 1324 BoundNetLog bound_net_log = BoundNetLog::Make(&net_log, NetLog::SOURCE_NONE);
1409 bool result1 = IsIPv6Reachable(bound_net_log); 1325 bool result1 = IsIPv6Reachable(bound_net_log);
1410 bool result2 = IsIPv6Reachable(bound_net_log); 1326 bool result2 = IsIPv6Reachable(bound_net_log);
1411 EXPECT_EQ(result1, result2); 1327 EXPECT_EQ(result1, result2);
1412 1328
1413 // Filter reachability check events and verify that there are two of them. 1329 // Filter reachability check events and verify that there are two of them.
1414 TestNetLogEntry::List event_list; 1330 TestNetLogEntry::List event_list;
1415 net_log.GetEntries(&event_list); 1331 net_log.GetEntries(&event_list);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 MockDnsClientRule::TIMEOUT, false); 1401 MockDnsClientRule::TIMEOUT, false);
1486 CreateResolver(); 1402 CreateResolver();
1487 } 1403 }
1488 1404
1489 // HostResolverImplTest implementation: 1405 // HostResolverImplTest implementation:
1490 void CreateResolverWithLimitsAndParams( 1406 void CreateResolverWithLimitsAndParams(
1491 size_t max_concurrent_resolves, 1407 size_t max_concurrent_resolves,
1492 const HostResolverImpl::ProcTaskParams& params) override { 1408 const HostResolverImpl::ProcTaskParams& params) override {
1493 HostResolverImpl::Options options = DefaultOptions(); 1409 HostResolverImpl::Options options = DefaultOptions();
1494 options.max_concurrent_resolves = max_concurrent_resolves; 1410 options.max_concurrent_resolves = max_concurrent_resolves;
1495 resolver_.reset(new HostResolverImpl(options, NULL)); 1411 resolver_.reset(new TestHostResolverImpl(options, NULL));
1496 resolver_->set_proc_params_for_test(params); 1412 resolver_->set_proc_params_for_test(params);
1497 // Disable IPv6 support probing.
1498 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1499 dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_); 1413 dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_);
1500 resolver_->SetDnsClient(scoped_ptr<DnsClient>(dns_client_)); 1414 resolver_->SetDnsClient(scoped_ptr<DnsClient>(dns_client_));
1501 } 1415 }
1502 1416
1503 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply. 1417 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply.
1504 void AddDnsRule(const std::string& prefix, 1418 void AddDnsRule(const std::string& prefix,
1505 uint16 qtype, 1419 uint16 qtype,
1506 MockDnsClientRule::Result result, 1420 MockDnsClientRule::Result result,
1507 bool delay) { 1421 bool delay) {
1508 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result, delay)); 1422 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result, delay));
1509 } 1423 }
1510 1424
1511 void ChangeDnsConfig(const DnsConfig& config) { 1425 void ChangeDnsConfig(const DnsConfig& config) {
1512 NetworkChangeNotifier::SetDnsConfig(config); 1426 NetworkChangeNotifier::SetDnsConfig(config);
1513 // Notification is delivered asynchronously. 1427 // Notification is delivered asynchronously.
1514 base::MessageLoop::current()->RunUntilIdle(); 1428 base::MessageLoop::current()->RunUntilIdle();
1515 } 1429 }
1516 1430
1517 MockDnsClientRuleList dns_rules_; 1431 MockDnsClientRuleList dns_rules_;
1518 // Owned by |resolver_|. 1432 // Owned by |resolver_|.
1519 MockDnsClient* dns_client_; 1433 MockDnsClient* dns_client_;
1520 }; 1434 };
1521 1435
1522 // TODO(szym): Test AbortAllInProgressJobs due to DnsConfig change. 1436 // TODO(szym): Test AbortAllInProgressJobs due to DnsConfig change.
1523 1437
1524 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. 1438 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags.
1525 1439
1526 // Test successful and fallback resolutions in HostResolverImpl::DnsTask. 1440 // Test successful and fallback resolutions in HostResolverImpl::DnsTask.
1527 TEST_F(HostResolverImplDnsTest, DnsTask) { 1441 TEST_F(HostResolverImplDnsTest, DnsTask) {
1528 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
1529
1530 proc_->AddRuleForAllFamilies("nx_succeed", "192.168.1.102"); 1442 proc_->AddRuleForAllFamilies("nx_succeed", "192.168.1.102");
1531 // All other hostnames will fail in proc_. 1443 // All other hostnames will fail in proc_.
1532 1444
1533 // Initially there is no config, so client should not be invoked. 1445 // Initially there is no config, so client should not be invoked.
1534 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve()); 1446 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve());
1535 proc_->SignalMultiple(requests_.size()); 1447 proc_->SignalMultiple(requests_.size());
1536 1448
1537 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[0]->WaitForResult()); 1449 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[0]->WaitForResult());
1538 1450
1539 ChangeDnsConfig(CreateValidDnsConfig()); 1451 ChangeDnsConfig(CreateValidDnsConfig());
1540 1452
1541 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve()); 1453 EXPECT_EQ(ERR_IO_PENDING,
1542 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_fail", 80)->Resolve()); 1454 CreateRequest("ok_fail", 80, IDLE, ADDRESS_FAMILY_IPV4)->Resolve());
1543 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_succeed", 80)->Resolve()); 1455 EXPECT_EQ(ERR_IO_PENDING,
1456 CreateRequest("nx_fail", 80, IDLE, ADDRESS_FAMILY_IPV4)->Resolve());
1457 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_succeed", 80, IDLE,
1458 ADDRESS_FAMILY_IPV4)->Resolve());
1544 1459
1545 proc_->SignalMultiple(requests_.size()); 1460 proc_->SignalMultiple(requests_.size());
1546 1461
1547 for (size_t i = 1; i < requests_.size(); ++i) 1462 for (size_t i = 1; i < requests_.size(); ++i)
1548 EXPECT_NE(ERR_UNEXPECTED, requests_[i]->WaitForResult()) << i; 1463 EXPECT_NE(ERR_UNEXPECTED, requests_[i]->WaitForResult()) << i;
1549 1464
1550 EXPECT_EQ(OK, requests_[1]->result()); 1465 EXPECT_EQ(OK, requests_[1]->result());
1551 // Resolved by MockDnsClient. 1466 // Resolved by MockDnsClient.
1552 EXPECT_TRUE(requests_[1]->HasOneAddress("127.0.0.1", 80)); 1467 EXPECT_TRUE(requests_[1]->HasOneAddress("127.0.0.1", 80));
1553 // Fallback to ProcTask. 1468 // Fallback to ProcTask.
1554 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[2]->result()); 1469 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[2]->result());
1555 EXPECT_EQ(OK, requests_[3]->result()); 1470 EXPECT_EQ(OK, requests_[3]->result());
1556 EXPECT_TRUE(requests_[3]->HasOneAddress("192.168.1.102", 80)); 1471 EXPECT_TRUE(requests_[3]->HasOneAddress("192.168.1.102", 80));
1557 } 1472 }
1558 1473
1559 // Test successful and failing resolutions in HostResolverImpl::DnsTask when 1474 // Test successful and failing resolutions in HostResolverImpl::DnsTask when
1560 // fallback to ProcTask is disabled. 1475 // fallback to ProcTask is disabled.
1561 TEST_F(HostResolverImplDnsTest, NoFallbackToProcTask) { 1476 TEST_F(HostResolverImplDnsTest, NoFallbackToProcTask) {
1562 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
1563 set_fallback_to_proctask(false); 1477 set_fallback_to_proctask(false);
1564 1478
1565 proc_->AddRuleForAllFamilies("nx_succeed", "192.168.1.102"); 1479 proc_->AddRuleForAllFamilies("nx_succeed", "192.168.1.102");
1566 // All other hostnames will fail in proc_. 1480 // All other hostnames will fail in proc_.
1567 1481
1568 // Set empty DnsConfig. 1482 // Set empty DnsConfig.
1569 ChangeDnsConfig(DnsConfig()); 1483 ChangeDnsConfig(DnsConfig());
1570 // Initially there is no config, so client should not be invoked. 1484 // Initially there is no config, so client should not be invoked.
1571 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve()); 1485 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve());
1572 // There is no config, so fallback to ProcTask must work. 1486 // There is no config, so fallback to ProcTask must work.
1573 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_succeed", 80)->Resolve()); 1487 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_succeed", 80)->Resolve());
1574 proc_->SignalMultiple(requests_.size()); 1488 proc_->SignalMultiple(requests_.size());
1575 1489
1576 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[0]->WaitForResult()); 1490 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[0]->WaitForResult());
1577 EXPECT_EQ(OK, requests_[1]->WaitForResult()); 1491 EXPECT_EQ(OK, requests_[1]->WaitForResult());
1578 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.1.102", 80)); 1492 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.1.102", 80));
1579 1493
1580 ChangeDnsConfig(CreateValidDnsConfig()); 1494 ChangeDnsConfig(CreateValidDnsConfig());
1581 1495
1582 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_abort", 80)->Resolve()); 1496 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_abort", 80, IDLE,
1583 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); 1497 ADDRESS_FAMILY_IPV4)->Resolve());
1498 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80, IDLE,
1499 ADDRESS_FAMILY_IPV4)->Resolve());
1584 1500
1585 // Simulate the case when the preference or policy has disabled the DNS client 1501 // Simulate the case when the preference or policy has disabled the DNS client
1586 // causing AbortDnsTasks. 1502 // causing AbortDnsTasks.
1587 resolver_->SetDnsClient( 1503 resolver_->SetDnsClient(
1588 scoped_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_))); 1504 scoped_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_)));
1589 ChangeDnsConfig(CreateValidDnsConfig()); 1505 ChangeDnsConfig(CreateValidDnsConfig());
1590 1506
1591 // First request is resolved by MockDnsClient, others should fail due to 1507 // First request is resolved by MockDnsClient, others should fail due to
1592 // disabled fallback to ProcTask. 1508 // disabled fallback to ProcTask.
1593 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok_fail", 80)->Resolve()); 1509 EXPECT_EQ(ERR_IO_PENDING,
1594 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_fail", 80)->Resolve()); 1510 CreateRequest("ok_fail", 80, IDLE, ADDRESS_FAMILY_IPV4)->Resolve());
1511 EXPECT_EQ(ERR_IO_PENDING,
1512 CreateRequest("nx_fail", 80, IDLE, ADDRESS_FAMILY_IPV4)->Resolve());
1595 proc_->SignalMultiple(requests_.size()); 1513 proc_->SignalMultiple(requests_.size());
1596 1514
1597 // Aborted due to Network Change. 1515 // Aborted due to Network Change.
1598 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[2]->WaitForResult()); 1516 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[2]->WaitForResult());
1599 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[3]->WaitForResult()); 1517 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[3]->WaitForResult());
1600 // Resolved by MockDnsClient. 1518 // Resolved by MockDnsClient.
1601 EXPECT_EQ(OK, requests_[4]->WaitForResult()); 1519 EXPECT_EQ(OK, requests_[4]->WaitForResult());
1602 EXPECT_TRUE(requests_[4]->HasOneAddress("127.0.0.1", 80)); 1520 EXPECT_TRUE(requests_[4]->HasOneAddress("127.0.0.1", 80));
1603 // Fallback to ProcTask is disabled. 1521 // Fallback to ProcTask is disabled.
1604 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[5]->WaitForResult()); 1522 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[5]->WaitForResult());
1605 } 1523 }
1606 1524
1607 // Test behavior of OnDnsTaskFailure when Job is aborted. 1525 // Test behavior of OnDnsTaskFailure when Job is aborted.
1608 TEST_F(HostResolverImplDnsTest, OnDnsTaskFailureAbortedJob) { 1526 TEST_F(HostResolverImplDnsTest, OnDnsTaskFailureAbortedJob) {
1609 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
1610 ChangeDnsConfig(CreateValidDnsConfig()); 1527 ChangeDnsConfig(CreateValidDnsConfig());
1611 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); 1528 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve());
1612 // Abort all jobs here. 1529 // Abort all jobs here.
1613 CreateResolver(); 1530 CreateResolver();
1614 proc_->SignalMultiple(requests_.size()); 1531 proc_->SignalMultiple(requests_.size());
1615 // Run to completion. 1532 // Run to completion.
1616 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. 1533 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async.
1617 // It shouldn't crash during OnDnsTaskFailure callbacks. 1534 // It shouldn't crash during OnDnsTaskFailure callbacks.
1618 EXPECT_EQ(ERR_IO_PENDING, requests_[0]->result()); 1535 EXPECT_EQ(ERR_IO_PENDING, requests_[0]->result());
1619 1536
1620 // Repeat test with Fallback to ProcTask disabled 1537 // Repeat test with Fallback to ProcTask disabled
1621 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
1622 set_fallback_to_proctask(false); 1538 set_fallback_to_proctask(false);
1623 ChangeDnsConfig(CreateValidDnsConfig()); 1539 ChangeDnsConfig(CreateValidDnsConfig());
1624 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); 1540 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve());
1625 // Abort all jobs here. 1541 // Abort all jobs here.
1626 CreateResolver(); 1542 CreateResolver();
1627 // Run to completion. 1543 // Run to completion.
1628 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. 1544 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async.
1629 // It shouldn't crash during OnDnsTaskFailure callbacks. 1545 // It shouldn't crash during OnDnsTaskFailure callbacks.
1630 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->result()); 1546 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->result());
1631 } 1547 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); 1732 EXPECT_EQ(ERR_IO_PENDING, req->Resolve());
1817 EXPECT_EQ(OK, req->WaitForResult()); 1733 EXPECT_EQ(OK, req->WaitForResult());
1818 } 1734 }
1819 1735
1820 // Confirm that resolving "localhost" is unrestricted even if there are no 1736 // Confirm that resolving "localhost" is unrestricted even if there are no
1821 // global IPv6 address. See SystemHostResolverCall for rationale. 1737 // global IPv6 address. See SystemHostResolverCall for rationale.
1822 // Test both the DnsClient and system host resolver paths. 1738 // Test both the DnsClient and system host resolver paths.
1823 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) { 1739 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) {
1824 // Use regular SystemHostResolverCall! 1740 // Use regular SystemHostResolverCall!
1825 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc()); 1741 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc());
1826 resolver_.reset(new HostResolverImpl(DefaultOptions(), NULL)); 1742 resolver_.reset(new TestHostResolverImpl(DefaultOptions(), NULL));
1827 resolver_->set_proc_params_for_test(DefaultParams(proc.get())); 1743 resolver_->set_proc_params_for_test(DefaultParams(proc.get()));
1828 1744
1829 resolver_->SetDnsClient( 1745 resolver_->SetDnsClient(
1830 scoped_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_))); 1746 scoped_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_)));
1831 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
1832 1747
1833 // Get the expected output. 1748 // Get the expected output.
1834 AddressList addrlist; 1749 AddressList addrlist;
1835 int rv = proc->Resolve("localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist, 1750 int rv = proc->Resolve("localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist,
1836 NULL); 1751 NULL);
1837 if (rv != OK) 1752 if (rv != OK)
1838 return; 1753 return;
1839 1754
1840 for (unsigned i = 0; i < addrlist.size(); ++i) 1755 for (unsigned i = 0; i < addrlist.size(); ++i)
1841 LOG(WARNING) << addrlist[i].ToString(); 1756 LOG(WARNING) << addrlist[i].ToString();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 req = CreateRequest(info, DEFAULT_PRIORITY); 1790 req = CreateRequest(info, DEFAULT_PRIORITY);
1876 // Expect synchronous resolution from DnsHosts. 1791 // Expect synchronous resolution from DnsHosts.
1877 EXPECT_EQ(OK, req->Resolve()); 1792 EXPECT_EQ(OK, req->Resolve());
1878 1793
1879 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80)); 1794 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80));
1880 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80)); 1795 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80));
1881 } 1796 }
1882 1797
1883 // Cancel a request with a single DNS transaction active. 1798 // Cancel a request with a single DNS transaction active.
1884 TEST_F(HostResolverImplDnsTest, CancelWithOneTransactionActive) { 1799 TEST_F(HostResolverImplDnsTest, CancelWithOneTransactionActive) {
1885 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
1886 ChangeDnsConfig(CreateValidDnsConfig()); 1800 ChangeDnsConfig(CreateValidDnsConfig());
1887 1801
1888 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); 1802 EXPECT_EQ(ERR_IO_PENDING,
1803 CreateRequest("ok", 80, IDLE, ADDRESS_FAMILY_IPV4)->Resolve());
1889 EXPECT_EQ(1u, num_running_dispatcher_jobs()); 1804 EXPECT_EQ(1u, num_running_dispatcher_jobs());
1890 requests_[0]->Cancel(); 1805 requests_[0]->Cancel();
1891 1806
1892 // Dispatcher state checked in TearDown. 1807 // Dispatcher state checked in TearDown.
1893 } 1808 }
1894 1809
1895 // Cancel a request with a single DNS transaction active and another pending. 1810 // Cancel a request with a single DNS transaction active and another pending.
1896 TEST_F(HostResolverImplDnsTest, CancelWithOneTransactionActiveOnePending) { 1811 TEST_F(HostResolverImplDnsTest, CancelWithOneTransactionActiveOnePending) {
1897 CreateSerialResolver(); 1812 CreateSerialResolver();
1898 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1899 ChangeDnsConfig(CreateValidDnsConfig()); 1813 ChangeDnsConfig(CreateValidDnsConfig());
1900 1814
1901 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); 1815 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve());
1902 EXPECT_EQ(1u, num_running_dispatcher_jobs()); 1816 EXPECT_EQ(1u, num_running_dispatcher_jobs());
1903 requests_[0]->Cancel(); 1817 requests_[0]->Cancel();
1904 1818
1905 // Dispatcher state checked in TearDown. 1819 // Dispatcher state checked in TearDown.
1906 } 1820 }
1907 1821
1908 // Cancel a request with two DNS transactions active. 1822 // Cancel a request with two DNS transactions active.
1909 TEST_F(HostResolverImplDnsTest, CancelWithTwoTransactionsActive) { 1823 TEST_F(HostResolverImplDnsTest, CancelWithTwoTransactionsActive) {
1910 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1911 ChangeDnsConfig(CreateValidDnsConfig()); 1824 ChangeDnsConfig(CreateValidDnsConfig());
1912 1825
1913 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); 1826 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve());
1914 EXPECT_EQ(2u, num_running_dispatcher_jobs()); 1827 EXPECT_EQ(2u, num_running_dispatcher_jobs());
1915 requests_[0]->Cancel(); 1828 requests_[0]->Cancel();
1916 1829
1917 // Dispatcher state checked in TearDown. 1830 // Dispatcher state checked in TearDown.
1918 } 1831 }
1919 1832
1920 // Delete a resolver with some active requests and some queued requests. 1833 // Delete a resolver with some active requests and some queued requests.
1921 TEST_F(HostResolverImplDnsTest, DeleteWithActiveTransactions) { 1834 TEST_F(HostResolverImplDnsTest, DeleteWithActiveTransactions) {
1922 // At most 10 Jobs active at once. 1835 // At most 10 Jobs active at once.
1923 CreateResolverWithLimitsAndParams(10u, DefaultParams(proc_.get())); 1836 CreateResolverWithLimitsAndParams(10u, DefaultParams(proc_.get()));
1924 1837
1925 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1926 ChangeDnsConfig(CreateValidDnsConfig()); 1838 ChangeDnsConfig(CreateValidDnsConfig());
1927 1839
1928 // First active job is an IPv4 request. 1840 // First active job is an IPv4 request.
1929 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM, 1841 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM,
1930 ADDRESS_FAMILY_IPV4)->Resolve()); 1842 ADDRESS_FAMILY_IPV4)->Resolve());
1931 1843
1932 // Add 10 more DNS lookups for different hostnames. First 4 should have two 1844 // Add 10 more DNS lookups for different hostnames. First 4 should have two
1933 // active jobs, next one has a single active job, and one pending. Others 1845 // active jobs, next one has a single active job, and one pending. Others
1934 // should all be queued. 1846 // should all be queued.
1935 for (int i = 0; i < 10; ++i) { 1847 for (int i = 0; i < 10; ++i) {
1936 EXPECT_EQ(ERR_IO_PENDING, CreateRequest( 1848 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(
1937 base::StringPrintf("ok%i", i))->Resolve()); 1849 base::StringPrintf("ok%i", i))->Resolve());
1938 } 1850 }
1939 EXPECT_EQ(10u, num_running_dispatcher_jobs()); 1851 EXPECT_EQ(10u, num_running_dispatcher_jobs());
1940 1852
1941 resolver_.reset(); 1853 resolver_.reset();
1942 } 1854 }
1943 1855
1944 // Cancel a request with only the IPv6 transaction active. 1856 // Cancel a request with only the IPv6 transaction active.
1945 TEST_F(HostResolverImplDnsTest, CancelWithIPv6TransactionActive) { 1857 TEST_F(HostResolverImplDnsTest, CancelWithIPv6TransactionActive) {
1946 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1947 ChangeDnsConfig(CreateValidDnsConfig()); 1858 ChangeDnsConfig(CreateValidDnsConfig());
1948 1859
1949 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("6slow_ok", 80)->Resolve()); 1860 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("6slow_ok", 80)->Resolve());
1950 EXPECT_EQ(2u, num_running_dispatcher_jobs()); 1861 EXPECT_EQ(2u, num_running_dispatcher_jobs());
1951 1862
1952 // The IPv4 request should complete, the IPv6 request is still pending. 1863 // The IPv4 request should complete, the IPv6 request is still pending.
1953 base::RunLoop().RunUntilIdle(); 1864 base::RunLoop().RunUntilIdle();
1954 EXPECT_EQ(1u, num_running_dispatcher_jobs()); 1865 EXPECT_EQ(1u, num_running_dispatcher_jobs());
1955 requests_[0]->Cancel(); 1866 requests_[0]->Cancel();
1956 1867
1957 // Dispatcher state checked in TearDown. 1868 // Dispatcher state checked in TearDown.
1958 } 1869 }
1959 1870
1960 // Cancel a request with only the IPv4 transaction pending. 1871 // Cancel a request with only the IPv4 transaction pending.
1961 TEST_F(HostResolverImplDnsTest, CancelWithIPv4TransactionPending) { 1872 TEST_F(HostResolverImplDnsTest, CancelWithIPv4TransactionPending) {
1962 set_fallback_to_proctask(false); 1873 set_fallback_to_proctask(false);
1963 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1964 ChangeDnsConfig(CreateValidDnsConfig()); 1874 ChangeDnsConfig(CreateValidDnsConfig());
1965 1875
1966 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80)->Resolve()); 1876 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80)->Resolve());
1967 EXPECT_EQ(2u, num_running_dispatcher_jobs()); 1877 EXPECT_EQ(2u, num_running_dispatcher_jobs());
1968 1878
1969 // The IPv6 request should complete, the IPv4 request is still pending. 1879 // The IPv6 request should complete, the IPv4 request is still pending.
1970 base::RunLoop().RunUntilIdle(); 1880 base::RunLoop().RunUntilIdle();
1971 EXPECT_EQ(1u, num_running_dispatcher_jobs()); 1881 EXPECT_EQ(1u, num_running_dispatcher_jobs());
1972 1882
1973 requests_[0]->Cancel(); 1883 requests_[0]->Cancel();
1974 } 1884 }
1975 1885
1976 // Test cases where AAAA completes first. 1886 // Test cases where AAAA completes first.
1977 TEST_F(HostResolverImplDnsTest, AAAACompletesFirst) { 1887 TEST_F(HostResolverImplDnsTest, AAAACompletesFirst) {
1978 set_fallback_to_proctask(false); 1888 set_fallback_to_proctask(false);
1979 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
1980 ChangeDnsConfig(CreateValidDnsConfig()); 1889 ChangeDnsConfig(CreateValidDnsConfig());
1981 1890
1982 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80)->Resolve()); 1891 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_ok", 80)->Resolve());
1983 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_4ok", 80)->Resolve()); 1892 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_4ok", 80)->Resolve());
1984 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_4timeout", 80)->Resolve()); 1893 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_4timeout", 80)->Resolve());
1985 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_6timeout", 80)->Resolve()); 1894 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("4slow_6timeout", 80)->Resolve());
1986 1895
1987 base::RunLoop().RunUntilIdle(); 1896 base::RunLoop().RunUntilIdle();
1988 EXPECT_FALSE(requests_[0]->completed()); 1897 EXPECT_FALSE(requests_[0]->completed());
1989 EXPECT_FALSE(requests_[1]->completed()); 1898 EXPECT_FALSE(requests_[1]->completed());
(...skipping 17 matching lines...) Expand all
2007 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80)); 1916 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80));
2008 1917
2009 EXPECT_TRUE(requests_[2]->completed()); 1918 EXPECT_TRUE(requests_[2]->completed());
2010 EXPECT_EQ(ERR_DNS_TIMED_OUT, requests_[2]->result()); 1919 EXPECT_EQ(ERR_DNS_TIMED_OUT, requests_[2]->result());
2011 } 1920 }
2012 1921
2013 // Test the case where only a single transaction slot is available. 1922 // Test the case where only a single transaction slot is available.
2014 TEST_F(HostResolverImplDnsTest, SerialResolver) { 1923 TEST_F(HostResolverImplDnsTest, SerialResolver) {
2015 CreateSerialResolver(); 1924 CreateSerialResolver();
2016 set_fallback_to_proctask(false); 1925 set_fallback_to_proctask(false);
2017 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
2018 ChangeDnsConfig(CreateValidDnsConfig()); 1926 ChangeDnsConfig(CreateValidDnsConfig());
2019 1927
2020 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve()); 1928 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80)->Resolve());
2021 EXPECT_EQ(1u, num_running_dispatcher_jobs()); 1929 EXPECT_EQ(1u, num_running_dispatcher_jobs());
2022 1930
2023 base::RunLoop().RunUntilIdle(); 1931 base::RunLoop().RunUntilIdle();
2024 EXPECT_TRUE(requests_[0]->completed()); 1932 EXPECT_TRUE(requests_[0]->completed());
2025 EXPECT_EQ(OK, requests_[0]->result()); 1933 EXPECT_EQ(OK, requests_[0]->result());
2026 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses()); 1934 EXPECT_EQ(2u, requests_[0]->NumberOfAddresses());
2027 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); 1935 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80));
2028 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); 1936 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80));
2029 } 1937 }
2030 1938
2031 // Test the case where the AAAA query is started when another transaction 1939 // Test the case where the AAAA query is started when another transaction
2032 // completes. 1940 // completes.
2033 TEST_F(HostResolverImplDnsTest, AAAAStartsAfterOtherJobFinishes) { 1941 TEST_F(HostResolverImplDnsTest, AAAAStartsAfterOtherJobFinishes) {
2034 CreateResolverWithLimitsAndParams(2u, DefaultParams(proc_.get())); 1942 CreateResolverWithLimitsAndParams(2u, DefaultParams(proc_.get()));
2035 set_fallback_to_proctask(false); 1943 set_fallback_to_proctask(false);
2036 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
2037 ChangeDnsConfig(CreateValidDnsConfig()); 1944 ChangeDnsConfig(CreateValidDnsConfig());
2038 1945
2039 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM, 1946 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ok", 80, MEDIUM,
2040 ADDRESS_FAMILY_IPV4)->Resolve()); 1947 ADDRESS_FAMILY_IPV4)->Resolve());
2041 EXPECT_EQ(ERR_IO_PENDING, 1948 EXPECT_EQ(ERR_IO_PENDING,
2042 CreateRequest("4slow_ok", 80, MEDIUM)->Resolve()); 1949 CreateRequest("4slow_ok", 80, MEDIUM)->Resolve());
2043 // An IPv4 request should have been started pending for each job. 1950 // An IPv4 request should have been started pending for each job.
2044 EXPECT_EQ(2u, num_running_dispatcher_jobs()); 1951 EXPECT_EQ(2u, num_running_dispatcher_jobs());
2045 1952
2046 // Request 0's IPv4 request should complete, starting Request 1's IPv6 1953 // Request 0's IPv4 request should complete, starting Request 1's IPv6
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 } 1992 }
2086 1993
2087 // Tests getting a new invalid DnsConfig while there are active DnsTasks. 1994 // Tests getting a new invalid DnsConfig while there are active DnsTasks.
2088 TEST_F(HostResolverImplDnsTest, InvalidDnsConfigWithPendingRequests) { 1995 TEST_F(HostResolverImplDnsTest, InvalidDnsConfigWithPendingRequests) {
2089 // At most 3 jobs active at once. This number is important, since we want to 1996 // At most 3 jobs active at once. This number is important, since we want to
2090 // make sure that aborting the first HostResolverImpl::Job does not trigger 1997 // make sure that aborting the first HostResolverImpl::Job does not trigger
2091 // another DnsTransaction on the second Job when it releases its second 1998 // another DnsTransaction on the second Job when it releases its second
2092 // prioritized dispatcher slot. 1999 // prioritized dispatcher slot.
2093 CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get())); 2000 CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get()));
2094 2001
2095 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
2096 ChangeDnsConfig(CreateValidDnsConfig()); 2002 ChangeDnsConfig(CreateValidDnsConfig());
2097 2003
2098 proc_->AddRuleForAllFamilies("slow_nx1", "192.168.0.1"); 2004 proc_->AddRuleForAllFamilies("slow_nx1", "192.168.0.1");
2099 proc_->AddRuleForAllFamilies("slow_nx2", "192.168.0.2"); 2005 proc_->AddRuleForAllFamilies("slow_nx2", "192.168.0.2");
2100 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); 2006 proc_->AddRuleForAllFamilies("ok", "192.168.0.3");
2101 2007
2102 // First active job gets two slots. 2008 // First active job gets two slots.
2103 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_nx1")->Resolve()); 2009 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_nx1")->Resolve());
2104 // Next job gets one slot, and waits on another. 2010 // Next job gets one slot, and waits on another.
2105 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_nx2")->Resolve()); 2011 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_nx2")->Resolve());
(...skipping 20 matching lines...) Expand all
2126 TEST_F(HostResolverImplDnsTest, 2032 TEST_F(HostResolverImplDnsTest,
2127 AutomaticallyDisableDnsClientWithPendingRequests) { 2033 AutomaticallyDisableDnsClientWithPendingRequests) {
2128 // Trying different limits is important for this test: Different limits 2034 // Trying different limits is important for this test: Different limits
2129 // result in different behavior when aborting in-progress DnsTasks. Having 2035 // result in different behavior when aborting in-progress DnsTasks. Having
2130 // a DnsTask that has one job active and one in the queue when another job 2036 // a DnsTask that has one job active and one in the queue when another job
2131 // occupying two slots has its DnsTask aborted is the case most likely to run 2037 // occupying two slots has its DnsTask aborted is the case most likely to run
2132 // into problems. 2038 // into problems.
2133 for (size_t limit = 1u; limit < 6u; ++limit) { 2039 for (size_t limit = 1u; limit < 6u; ++limit) {
2134 CreateResolverWithLimitsAndParams(limit, DefaultParams(proc_.get())); 2040 CreateResolverWithLimitsAndParams(limit, DefaultParams(proc_.get()));
2135 2041
2136 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
2137 ChangeDnsConfig(CreateValidDnsConfig()); 2042 ChangeDnsConfig(CreateValidDnsConfig());
2138 2043
2139 // Queue up enough failures to disable DnsTasks. These will all fall back 2044 // Queue up enough failures to disable DnsTasks. These will all fall back
2140 // to ProcTasks, and succeed there. 2045 // to ProcTasks, and succeed there.
2141 for (unsigned i = 0u; i < maximum_dns_failures(); ++i) { 2046 for (unsigned i = 0u; i < maximum_dns_failures(); ++i) {
2142 std::string host = base::StringPrintf("nx%u", i); 2047 std::string host = base::StringPrintf("nx%u", i);
2143 proc_->AddRuleForAllFamilies(host, "192.168.0.1"); 2048 proc_->AddRuleForAllFamilies(host, "192.168.0.1");
2144 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(host)->Resolve()); 2049 EXPECT_EQ(ERR_IO_PENDING, CreateRequest(host)->Resolve());
2145 } 2050 }
2146 2051
(...skipping 26 matching lines...) Expand all
2173 } 2078 }
2174 2079
2175 // Tests a call to SetDnsClient while there are active DnsTasks. 2080 // Tests a call to SetDnsClient while there are active DnsTasks.
2176 TEST_F(HostResolverImplDnsTest, ManuallyDisableDnsClientWithPendingRequests) { 2081 TEST_F(HostResolverImplDnsTest, ManuallyDisableDnsClientWithPendingRequests) {
2177 // At most 3 jobs active at once. This number is important, since we want to 2082 // At most 3 jobs active at once. This number is important, since we want to
2178 // make sure that aborting the first HostResolverImpl::Job does not trigger 2083 // make sure that aborting the first HostResolverImpl::Job does not trigger
2179 // another DnsTransaction on the second Job when it releases its second 2084 // another DnsTransaction on the second Job when it releases its second
2180 // prioritized dispatcher slot. 2085 // prioritized dispatcher slot.
2181 CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get())); 2086 CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get()));
2182 2087
2183 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED);
2184 ChangeDnsConfig(CreateValidDnsConfig()); 2088 ChangeDnsConfig(CreateValidDnsConfig());
2185 2089
2186 proc_->AddRuleForAllFamilies("slow_ok1", "192.168.0.1"); 2090 proc_->AddRuleForAllFamilies("slow_ok1", "192.168.0.1");
2187 proc_->AddRuleForAllFamilies("slow_ok2", "192.168.0.2"); 2091 proc_->AddRuleForAllFamilies("slow_ok2", "192.168.0.2");
2188 proc_->AddRuleForAllFamilies("ok", "192.168.0.3"); 2092 proc_->AddRuleForAllFamilies("ok", "192.168.0.3");
2189 2093
2190 // First active job gets two slots. 2094 // First active job gets two slots.
2191 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok1")->Resolve()); 2095 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok1")->Resolve());
2192 // Next job gets one slot, and waits on another. 2096 // Next job gets one slot, and waits on another.
2193 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok2")->Resolve()); 2097 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("slow_ok2")->Resolve());
(...skipping 12 matching lines...) Expand all
2206 2110
2207 EXPECT_EQ(OK, requests_[0]->WaitForResult()); 2111 EXPECT_EQ(OK, requests_[0]->WaitForResult());
2208 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); 2112 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80));
2209 EXPECT_EQ(OK, requests_[1]->WaitForResult()); 2113 EXPECT_EQ(OK, requests_[1]->WaitForResult());
2210 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); 2114 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80));
2211 EXPECT_EQ(OK, requests_[2]->WaitForResult()); 2115 EXPECT_EQ(OK, requests_[2]->WaitForResult());
2212 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); 2116 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80));
2213 } 2117 }
2214 2118
2215 } // namespace net 2119 } // namespace net
OLDNEW
« net/dns/host_resolver_impl.h ('K') | « net/dns/host_resolver_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698