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