| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } | 287 } |
| 288 | 288 |
| 289 // Returns ERR_UNEXPECTED if timed out. | 289 // Returns ERR_UNEXPECTED if timed out. |
| 290 int WaitForResult() { | 290 int WaitForResult() { |
| 291 if (completed()) | 291 if (completed()) |
| 292 return result_; | 292 return result_; |
| 293 base::CancelableClosure closure(base::MessageLoop::QuitWhenIdleClosure()); | 293 base::CancelableClosure closure(base::MessageLoop::QuitWhenIdleClosure()); |
| 294 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 294 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 295 FROM_HERE, closure.callback(), TestTimeouts::action_max_timeout()); | 295 FROM_HERE, closure.callback(), TestTimeouts::action_max_timeout()); |
| 296 quit_on_complete_ = true; | 296 quit_on_complete_ = true; |
| 297 base::MessageLoop::current()->Run(); | 297 base::RunLoop().Run(); |
| 298 bool did_quit = !quit_on_complete_; | 298 bool did_quit = !quit_on_complete_; |
| 299 quit_on_complete_ = false; | 299 quit_on_complete_ = false; |
| 300 closure.Cancel(); | 300 closure.Cancel(); |
| 301 if (did_quit) | 301 if (did_quit) |
| 302 return result_; | 302 return result_; |
| 303 else | 303 else |
| 304 return ERR_UNEXPECTED; | 304 return ERR_UNEXPECTED; |
| 305 } | 305 } |
| 306 | 306 |
| 307 private: | 307 private: |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 }; | 925 }; |
| 926 set_handler(new MyHandler()); | 926 set_handler(new MyHandler()); |
| 927 | 927 |
| 928 for (size_t i = 0; i < 4; ++i) { | 928 for (size_t i = 0; i < 4; ++i) { |
| 929 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; | 929 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; |
| 930 } | 930 } |
| 931 | 931 |
| 932 proc_->SignalMultiple(1u); // One for "a". | 932 proc_->SignalMultiple(1u); // One for "a". |
| 933 | 933 |
| 934 // |MyHandler| will send quit message once all the requests have finished. | 934 // |MyHandler| will send quit message once all the requests have finished. |
| 935 base::MessageLoop::current()->Run(); | 935 base::RunLoop().Run(); |
| 936 } | 936 } |
| 937 | 937 |
| 938 TEST_F(HostResolverImplTest, DeleteWithinAbortedCallback) { | 938 TEST_F(HostResolverImplTest, DeleteWithinAbortedCallback) { |
| 939 struct MyHandler : public Handler { | 939 struct MyHandler : public Handler { |
| 940 void Handle(Request* req) override { | 940 void Handle(Request* req) override { |
| 941 EXPECT_EQ("a", req->info().hostname()); | 941 EXPECT_EQ("a", req->info().hostname()); |
| 942 EXPECT_EQ(80, req->info().port()); | 942 EXPECT_EQ(80, req->info().port()); |
| 943 | 943 |
| 944 DeleteResolver(); | 944 DeleteResolver(); |
| 945 | 945 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 958 // Job for 'b' will be aborted before it can complete. | 958 // Job for 'b' will be aborted before it can complete. |
| 959 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 82)->Resolve()); | 959 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 82)->Resolve()); |
| 960 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 83)->Resolve()); | 960 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 83)->Resolve()); |
| 961 | 961 |
| 962 EXPECT_TRUE(proc_->WaitFor(1u)); | 962 EXPECT_TRUE(proc_->WaitFor(1u)); |
| 963 | 963 |
| 964 // Triggering an IP address change. | 964 // Triggering an IP address change. |
| 965 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 965 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 966 | 966 |
| 967 // |MyHandler| will send quit message once all the requests have finished. | 967 // |MyHandler| will send quit message once all the requests have finished. |
| 968 base::MessageLoop::current()->Run(); | 968 base::RunLoop().Run(); |
| 969 | 969 |
| 970 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->result()); | 970 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->result()); |
| 971 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->result()); | 971 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->result()); |
| 972 EXPECT_EQ(ERR_IO_PENDING, requests_[2]->result()); | 972 EXPECT_EQ(ERR_IO_PENDING, requests_[2]->result()); |
| 973 EXPECT_EQ(ERR_IO_PENDING, requests_[3]->result()); | 973 EXPECT_EQ(ERR_IO_PENDING, requests_[3]->result()); |
| 974 // Clean up. | 974 // Clean up. |
| 975 proc_->SignalMultiple(requests_.size()); | 975 proc_->SignalMultiple(requests_.size()); |
| 976 } | 976 } |
| 977 | 977 |
| 978 TEST_F(HostResolverImplTest, StartWithinCallback) { | 978 TEST_F(HostResolverImplTest, StartWithinCallback) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 FAIL() << "Unexpected request"; | 1029 FAIL() << "Unexpected request"; |
| 1030 } | 1030 } |
| 1031 } | 1031 } |
| 1032 }; | 1032 }; |
| 1033 set_handler(new MyHandler()); | 1033 set_handler(new MyHandler()); |
| 1034 | 1034 |
| 1035 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80)->Resolve()); | 1035 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80)->Resolve()); |
| 1036 proc_->SignalMultiple(3u); // Only need two, but be generous. | 1036 proc_->SignalMultiple(3u); // Only need two, but be generous. |
| 1037 | 1037 |
| 1038 // |verifier| will send quit message once all the requests have finished. | 1038 // |verifier| will send quit message once all the requests have finished. |
| 1039 base::MessageLoop::current()->Run(); | 1039 base::RunLoop().Run(); |
| 1040 EXPECT_EQ(2u, proc_->GetCaptureList().size()); | 1040 EXPECT_EQ(2u, proc_->GetCaptureList().size()); |
| 1041 } | 1041 } |
| 1042 | 1042 |
| 1043 // Test that IP address changes flush the cache but initial DNS config reads do | 1043 // Test that IP address changes flush the cache but initial DNS config reads do |
| 1044 // not. | 1044 // not. |
| 1045 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { | 1045 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { |
| 1046 proc_->SignalMultiple(2u); // One before the flush, one after. | 1046 proc_->SignalMultiple(2u); // One before the flush, one after. |
| 1047 | 1047 |
| 1048 Request* req = CreateRequest("host1", 70); | 1048 Request* req = CreateRequest("host1", 70); |
| 1049 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1049 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
| 1050 EXPECT_EQ(OK, req->WaitForResult()); | 1050 EXPECT_EQ(OK, req->WaitForResult()); |
| 1051 | 1051 |
| 1052 req = CreateRequest("host1", 75); | 1052 req = CreateRequest("host1", 75); |
| 1053 EXPECT_EQ(OK, req->Resolve()); // Should complete synchronously. | 1053 EXPECT_EQ(OK, req->Resolve()); // Should complete synchronously. |
| 1054 | 1054 |
| 1055 // Verify initial DNS config read does not flush cache. | 1055 // Verify initial DNS config read does not flush cache. |
| 1056 NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); | 1056 NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); |
| 1057 req = CreateRequest("host1", 75); | 1057 req = CreateRequest("host1", 75); |
| 1058 EXPECT_EQ(OK, req->Resolve()); // Should complete synchronously. | 1058 EXPECT_EQ(OK, req->Resolve()); // Should complete synchronously. |
| 1059 | 1059 |
| 1060 // Flush cache by triggering an IP address change. | 1060 // Flush cache by triggering an IP address change. |
| 1061 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1061 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 1062 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 1062 base::RunLoop().RunUntilIdle(); // Notification happens async. |
| 1063 | 1063 |
| 1064 // Resolve "host1" again -- this time it won't be served from cache, so it | 1064 // Resolve "host1" again -- this time it won't be served from cache, so it |
| 1065 // will complete asynchronously. | 1065 // will complete asynchronously. |
| 1066 req = CreateRequest("host1", 80); | 1066 req = CreateRequest("host1", 80); |
| 1067 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1067 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
| 1068 EXPECT_EQ(OK, req->WaitForResult()); | 1068 EXPECT_EQ(OK, req->WaitForResult()); |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 // Test that IP address changes send ERR_NETWORK_CHANGED to pending requests. | 1071 // Test that IP address changes send ERR_NETWORK_CHANGED to pending requests. |
| 1072 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { | 1072 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { |
| 1073 Request* req = CreateRequest("host1", 70); | 1073 Request* req = CreateRequest("host1", 70); |
| 1074 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1074 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
| 1075 | 1075 |
| 1076 EXPECT_TRUE(proc_->WaitFor(1u)); | 1076 EXPECT_TRUE(proc_->WaitFor(1u)); |
| 1077 // Triggering an IP address change. | 1077 // Triggering an IP address change. |
| 1078 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1078 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 1079 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 1079 base::RunLoop().RunUntilIdle(); // Notification happens async. |
| 1080 proc_->SignalAll(); | 1080 proc_->SignalAll(); |
| 1081 | 1081 |
| 1082 EXPECT_EQ(ERR_NETWORK_CHANGED, req->WaitForResult()); | 1082 EXPECT_EQ(ERR_NETWORK_CHANGED, req->WaitForResult()); |
| 1083 EXPECT_EQ(0u, resolver_->GetHostCache()->size()); | 1083 EXPECT_EQ(0u, resolver_->GetHostCache()->size()); |
| 1084 } | 1084 } |
| 1085 | 1085 |
| 1086 // Test that initial DNS config read signals do not abort pending requests. | 1086 // Test that initial DNS config read signals do not abort pending requests. |
| 1087 TEST_F(HostResolverImplTest, DontAbortOnInitialDNSConfigRead) { | 1087 TEST_F(HostResolverImplTest, DontAbortOnInitialDNSConfigRead) { |
| 1088 Request* req = CreateRequest("host1", 70); | 1088 Request* req = CreateRequest("host1", 70); |
| 1089 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1089 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
| 1090 | 1090 |
| 1091 EXPECT_TRUE(proc_->WaitFor(1u)); | 1091 EXPECT_TRUE(proc_->WaitFor(1u)); |
| 1092 // Triggering initial DNS config read signal. | 1092 // Triggering initial DNS config read signal. |
| 1093 NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); | 1093 NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); |
| 1094 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 1094 base::RunLoop().RunUntilIdle(); // Notification happens async. |
| 1095 proc_->SignalAll(); | 1095 proc_->SignalAll(); |
| 1096 | 1096 |
| 1097 EXPECT_EQ(OK, req->WaitForResult()); | 1097 EXPECT_EQ(OK, req->WaitForResult()); |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 // Obey pool constraints after IP address has changed. | 1100 // Obey pool constraints after IP address has changed. |
| 1101 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { | 1101 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { |
| 1102 // Runs at most one job at a time. | 1102 // Runs at most one job at a time. |
| 1103 CreateSerialResolver(); | 1103 CreateSerialResolver(); |
| 1104 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a")->Resolve()); | 1104 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a")->Resolve()); |
| 1105 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b")->Resolve()); | 1105 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b")->Resolve()); |
| 1106 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("c")->Resolve()); | 1106 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("c")->Resolve()); |
| 1107 | 1107 |
| 1108 EXPECT_TRUE(proc_->WaitFor(1u)); | 1108 EXPECT_TRUE(proc_->WaitFor(1u)); |
| 1109 // Triggering an IP address change. | 1109 // Triggering an IP address change. |
| 1110 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1110 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 1111 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 1111 base::RunLoop().RunUntilIdle(); // Notification happens async. |
| 1112 proc_->SignalMultiple(3u); // Let the false-start go so that we can catch it. | 1112 proc_->SignalMultiple(3u); // Let the false-start go so that we can catch it. |
| 1113 | 1113 |
| 1114 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->WaitForResult()); | 1114 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->WaitForResult()); |
| 1115 | 1115 |
| 1116 EXPECT_EQ(1u, num_running_dispatcher_jobs()); | 1116 EXPECT_EQ(1u, num_running_dispatcher_jobs()); |
| 1117 | 1117 |
| 1118 EXPECT_FALSE(requests_[1]->completed()); | 1118 EXPECT_FALSE(requests_[1]->completed()); |
| 1119 EXPECT_FALSE(requests_[2]->completed()); | 1119 EXPECT_FALSE(requests_[2]->completed()); |
| 1120 | 1120 |
| 1121 EXPECT_EQ(OK, requests_[2]->WaitForResult()); | 1121 EXPECT_EQ(OK, requests_[2]->WaitForResult()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1145 | 1145 |
| 1146 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("bbb")->Resolve()); | 1146 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("bbb")->Resolve()); |
| 1147 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("eee")->Resolve()); | 1147 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("eee")->Resolve()); |
| 1148 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ccc")->Resolve()); | 1148 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ccc")->Resolve()); |
| 1149 | 1149 |
| 1150 // Wait until all are blocked; | 1150 // Wait until all are blocked; |
| 1151 EXPECT_TRUE(proc_->WaitFor(3u)); | 1151 EXPECT_TRUE(proc_->WaitFor(3u)); |
| 1152 // Trigger an IP address change. | 1152 // Trigger an IP address change. |
| 1153 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 1153 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 1154 // This should abort all running jobs. | 1154 // This should abort all running jobs. |
| 1155 base::MessageLoop::current()->RunUntilIdle(); | 1155 base::RunLoop().RunUntilIdle(); |
| 1156 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->result()); | 1156 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->result()); |
| 1157 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[1]->result()); | 1157 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[1]->result()); |
| 1158 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[2]->result()); | 1158 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[2]->result()); |
| 1159 ASSERT_EQ(6u, requests_.size()); | 1159 ASSERT_EQ(6u, requests_.size()); |
| 1160 // Unblock all calls to proc. | 1160 // Unblock all calls to proc. |
| 1161 proc_->SignalMultiple(requests_.size()); | 1161 proc_->SignalMultiple(requests_.size()); |
| 1162 // Run until the re-started requests finish. | 1162 // Run until the re-started requests finish. |
| 1163 EXPECT_EQ(OK, requests_[3]->WaitForResult()); | 1163 EXPECT_EQ(OK, requests_[3]->WaitForResult()); |
| 1164 EXPECT_EQ(OK, requests_[4]->WaitForResult()); | 1164 EXPECT_EQ(OK, requests_[4]->WaitForResult()); |
| 1165 EXPECT_EQ(OK, requests_[5]->WaitForResult()); | 1165 EXPECT_EQ(OK, requests_[5]->WaitForResult()); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 // Resolve "host1". | 1451 // Resolve "host1". |
| 1452 HostResolver::RequestInfo info(HostPortPair("host1", 70)); | 1452 HostResolver::RequestInfo info(HostPortPair("host1", 70)); |
| 1453 Request* req = CreateRequest(info, DEFAULT_PRIORITY); | 1453 Request* req = CreateRequest(info, DEFAULT_PRIORITY); |
| 1454 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 1454 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
| 1455 | 1455 |
| 1456 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. | 1456 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. |
| 1457 EXPECT_EQ(-4, req->WaitForResult()); | 1457 EXPECT_EQ(-4, req->WaitForResult()); |
| 1458 | 1458 |
| 1459 resolver_proc->WaitForAllAttemptsToFinish( | 1459 resolver_proc->WaitForAllAttemptsToFinish( |
| 1460 base::TimeDelta::FromMilliseconds(60000)); | 1460 base::TimeDelta::FromMilliseconds(60000)); |
| 1461 base::MessageLoop::current()->RunUntilIdle(); | 1461 base::RunLoop().RunUntilIdle(); |
| 1462 | 1462 |
| 1463 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); | 1463 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); |
| 1464 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); | 1464 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); |
| 1465 } | 1465 } |
| 1466 | 1466 |
| 1467 // If a host resolves to a list that includes 127.0.53.53, this is treated as | 1467 // If a host resolves to a list that includes 127.0.53.53, this is treated as |
| 1468 // an error. 127.0.53.53 is a localhost address, however it has been given a | 1468 // an error. 127.0.53.53 is a localhost address, however it has been given a |
| 1469 // special significance by ICANN to help surfance name collision resulting from | 1469 // special significance by ICANN to help surfance name collision resulting from |
| 1470 // the new gTLDs. | 1470 // the new gTLDs. |
| 1471 TEST_F(HostResolverImplTest, NameCollision127_0_53_53) { | 1471 TEST_F(HostResolverImplTest, NameCollision127_0_53_53) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 void AddDnsRule(const std::string& prefix, | 1612 void AddDnsRule(const std::string& prefix, |
| 1613 uint16_t qtype, | 1613 uint16_t qtype, |
| 1614 MockDnsClientRule::Result result, | 1614 MockDnsClientRule::Result result, |
| 1615 bool delay) { | 1615 bool delay) { |
| 1616 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result, delay)); | 1616 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result, delay)); |
| 1617 } | 1617 } |
| 1618 | 1618 |
| 1619 void ChangeDnsConfig(const DnsConfig& config) { | 1619 void ChangeDnsConfig(const DnsConfig& config) { |
| 1620 NetworkChangeNotifier::SetDnsConfig(config); | 1620 NetworkChangeNotifier::SetDnsConfig(config); |
| 1621 // Notification is delivered asynchronously. | 1621 // Notification is delivered asynchronously. |
| 1622 base::MessageLoop::current()->RunUntilIdle(); | 1622 base::RunLoop().RunUntilIdle(); |
| 1623 } | 1623 } |
| 1624 | 1624 |
| 1625 MockDnsClientRuleList dns_rules_; | 1625 MockDnsClientRuleList dns_rules_; |
| 1626 // Owned by |resolver_|. | 1626 // Owned by |resolver_|. |
| 1627 MockDnsClient* dns_client_; | 1627 MockDnsClient* dns_client_; |
| 1628 }; | 1628 }; |
| 1629 | 1629 |
| 1630 // TODO(szym): Test AbortAllInProgressJobs due to DnsConfig change. | 1630 // TODO(szym): Test AbortAllInProgressJobs due to DnsConfig change. |
| 1631 | 1631 |
| 1632 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1632 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1717 } | 1717 } |
| 1718 | 1718 |
| 1719 // Test behavior of OnDnsTaskFailure when Job is aborted. | 1719 // Test behavior of OnDnsTaskFailure when Job is aborted. |
| 1720 TEST_F(HostResolverImplDnsTest, OnDnsTaskFailureAbortedJob) { | 1720 TEST_F(HostResolverImplDnsTest, OnDnsTaskFailureAbortedJob) { |
| 1721 ChangeDnsConfig(CreateValidDnsConfig()); | 1721 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1722 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); | 1722 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); |
| 1723 // Abort all jobs here. | 1723 // Abort all jobs here. |
| 1724 CreateResolver(); | 1724 CreateResolver(); |
| 1725 proc_->SignalMultiple(requests_.size()); | 1725 proc_->SignalMultiple(requests_.size()); |
| 1726 // Run to completion. | 1726 // Run to completion. |
| 1727 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 1727 base::RunLoop().RunUntilIdle(); // Notification happens async. |
| 1728 // It shouldn't crash during OnDnsTaskFailure callbacks. | 1728 // It shouldn't crash during OnDnsTaskFailure callbacks. |
| 1729 EXPECT_EQ(ERR_IO_PENDING, requests_[0]->result()); | 1729 EXPECT_EQ(ERR_IO_PENDING, requests_[0]->result()); |
| 1730 | 1730 |
| 1731 // Repeat test with Fallback to ProcTask disabled | 1731 // Repeat test with Fallback to ProcTask disabled |
| 1732 set_fallback_to_proctask(false); | 1732 set_fallback_to_proctask(false); |
| 1733 ChangeDnsConfig(CreateValidDnsConfig()); | 1733 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1734 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); | 1734 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("nx_abort", 80)->Resolve()); |
| 1735 // Abort all jobs here. | 1735 // Abort all jobs here. |
| 1736 CreateResolver(); | 1736 CreateResolver(); |
| 1737 // Run to completion. | 1737 // Run to completion. |
| 1738 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 1738 base::RunLoop().RunUntilIdle(); // Notification happens async. |
| 1739 // It shouldn't crash during OnDnsTaskFailure callbacks. | 1739 // It shouldn't crash during OnDnsTaskFailure callbacks. |
| 1740 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->result()); | 1740 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->result()); |
| 1741 } | 1741 } |
| 1742 | 1742 |
| 1743 TEST_F(HostResolverImplDnsTest, DnsTaskUnspec) { | 1743 TEST_F(HostResolverImplDnsTest, DnsTaskUnspec) { |
| 1744 ChangeDnsConfig(CreateValidDnsConfig()); | 1744 ChangeDnsConfig(CreateValidDnsConfig()); |
| 1745 | 1745 |
| 1746 proc_->AddRuleForAllFamilies("4nx", "192.168.1.101"); | 1746 proc_->AddRuleForAllFamilies("4nx", "192.168.1.101"); |
| 1747 // All other hostnames will fail in proc_. | 1747 // All other hostnames will fail in proc_. |
| 1748 | 1748 |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2362 EXPECT_FALSE(ResolveLocalHostname("::1:1", kLocalhostLookupPort, &addresses)); | 2362 EXPECT_FALSE(ResolveLocalHostname("::1:1", kLocalhostLookupPort, &addresses)); |
| 2363 EXPECT_FALSE(ResolveLocalHostname("0:0:0:0:0:0:0:0:1", kLocalhostLookupPort, | 2363 EXPECT_FALSE(ResolveLocalHostname("0:0:0:0:0:0:0:0:1", kLocalhostLookupPort, |
| 2364 &addresses)); | 2364 &addresses)); |
| 2365 EXPECT_FALSE(ResolveLocalHostname("foo.localhost.com", kLocalhostLookupPort, | 2365 EXPECT_FALSE(ResolveLocalHostname("foo.localhost.com", kLocalhostLookupPort, |
| 2366 &addresses)); | 2366 &addresses)); |
| 2367 EXPECT_FALSE( | 2367 EXPECT_FALSE( |
| 2368 ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses)); | 2368 ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses)); |
| 2369 } | 2369 } |
| 2370 | 2370 |
| 2371 } // namespace net | 2371 } // namespace net |
| OLD | NEW |