| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/base/host_resolver_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 HostCache* CreateDefaultCache() { | 31 HostCache* CreateDefaultCache() { |
| 32 return new HostCache( | 32 return new HostCache( |
| 33 100, // max cache entries. | 33 100, // max cache entries. |
| 34 base::TimeDelta::FromMinutes(1), | 34 base::TimeDelta::FromMinutes(1), |
| 35 base::TimeDelta::FromSeconds(0)); | 35 base::TimeDelta::FromSeconds(0)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 static const size_t kMaxJobs = 10u; | 38 static const size_t kMaxJobs = 10u; |
| 39 | 39 |
| 40 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { | 40 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { |
| 41 return new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs); | 41 return new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, |
| 42 NULL); |
| 42 } | 43 } |
| 43 | 44 |
| 44 // Helper to create a HostResolver::RequestInfo. | 45 // Helper to create a HostResolver::RequestInfo. |
| 45 HostResolver::RequestInfo CreateResolverRequest( | 46 HostResolver::RequestInfo CreateResolverRequest( |
| 46 const std::string& hostname, | 47 const std::string& hostname, |
| 47 RequestPriority priority) { | 48 RequestPriority priority) { |
| 48 HostResolver::RequestInfo info(hostname, 80); | 49 HostResolver::RequestInfo info(hostname, 80); |
| 49 info.set_priority(priority); | 50 info.set_priority(priority); |
| 50 return info; | 51 return info; |
| 51 } | 52 } |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 const struct sockaddr* sa = ainfo->ai_addr; | 323 const struct sockaddr* sa = ainfo->ai_addr; |
| 323 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; | 324 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; |
| 324 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); | 325 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); |
| 325 EXPECT_TRUE(htonl(0xc0a8012a) == sa_in->sin_addr.s_addr); | 326 EXPECT_TRUE(htonl(0xc0a8012a) == sa_in->sin_addr.s_addr); |
| 326 } | 327 } |
| 327 | 328 |
| 328 TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { | 329 TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { |
| 329 scoped_refptr<WaitingHostResolverProc> resolver_proc = | 330 scoped_refptr<WaitingHostResolverProc> resolver_proc = |
| 330 new WaitingHostResolverProc(NULL); | 331 new WaitingHostResolverProc(NULL); |
| 331 | 332 |
| 333 CapturingNetLog net_log(CapturingNetLog::kUnbounded); |
| 332 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 334 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 333 { | 335 { |
| 334 scoped_refptr<HostResolver> host_resolver( | 336 scoped_refptr<HostResolver> host_resolver( |
| 335 CreateHostResolverImpl(resolver_proc)); | 337 new HostResolverImpl(resolver_proc, |
| 338 CreateDefaultCache(), |
| 339 kMaxJobs, |
| 340 &net_log)); |
| 336 AddressList adrlist; | 341 AddressList adrlist; |
| 337 const int kPortnum = 80; | 342 const int kPortnum = 80; |
| 338 | 343 |
| 339 HostResolver::RequestInfo info("just.testing", kPortnum); | 344 HostResolver::RequestInfo info("just.testing", kPortnum); |
| 340 int err = host_resolver->Resolve(info, &adrlist, &callback_, NULL, | 345 int err = host_resolver->Resolve(info, &adrlist, &callback_, NULL, |
| 341 log.bound()); | 346 log.bound()); |
| 342 EXPECT_EQ(ERR_IO_PENDING, err); | 347 EXPECT_EQ(ERR_IO_PENDING, err); |
| 343 | 348 |
| 344 // Make sure we will exit the queue even when callback is not called. | 349 // Make sure we will exit the queue even when callback is not called. |
| 345 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 350 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 346 new MessageLoop::QuitTask(), | 351 new MessageLoop::QuitTask(), |
| 347 1000); | 352 1000); |
| 348 MessageLoop::current()->Run(); | 353 MessageLoop::current()->Run(); |
| 349 } | 354 } |
| 350 | 355 |
| 351 resolver_proc->Signal(); | 356 resolver_proc->Signal(); |
| 352 | 357 |
| 353 EXPECT_EQ(3u, log.entries().size()); | 358 EXPECT_EQ(2u, log.entries().size()); |
| 354 EXPECT_TRUE(LogContainsBeginEvent( | 359 EXPECT_TRUE(LogContainsBeginEvent( |
| 355 log.entries(), 0, NetLog::TYPE_HOST_RESOLVER_IMPL)); | 360 log.entries(), 0, NetLog::TYPE_HOST_RESOLVER_IMPL)); |
| 356 EXPECT_TRUE(LogContainsEvent( | |
| 357 log.entries(), 1, NetLog::TYPE_CANCELLED, NetLog::PHASE_NONE)); | |
| 358 EXPECT_TRUE(LogContainsEndEvent( | 361 EXPECT_TRUE(LogContainsEndEvent( |
| 359 log.entries(), 2, NetLog::TYPE_HOST_RESOLVER_IMPL)); | 362 log.entries(), 1, NetLog::TYPE_HOST_RESOLVER_IMPL)); |
| 363 |
| 364 int pos = net::ExpectLogContainsSomewhereAfter(net_log.entries(), 0, |
| 365 net::NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, |
| 366 net::NetLog::PHASE_BEGIN); |
| 367 pos = net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, |
| 368 net::NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, |
| 369 net::NetLog::PHASE_BEGIN); |
| 370 // Both Job and Request need to be cancelled. |
| 371 pos = net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, |
| 372 net::NetLog::TYPE_CANCELLED, |
| 373 net::NetLog::PHASE_NONE); |
| 374 // Don't care about order in which they end, or when the other one is |
| 375 // cancelled. |
| 376 net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, |
| 377 net::NetLog::TYPE_CANCELLED, |
| 378 net::NetLog::PHASE_NONE); |
| 379 net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, |
| 380 net::NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, |
| 381 net::NetLog::PHASE_END); |
| 382 net::ExpectLogContainsSomewhereAfter(net_log.entries(), pos + 1, |
| 383 net::NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, |
| 384 net::NetLog::PHASE_END); |
| 360 | 385 |
| 361 EXPECT_FALSE(callback_called_); | 386 EXPECT_FALSE(callback_called_); |
| 362 } | 387 } |
| 363 | 388 |
| 364 TEST_F(HostResolverImplTest, NumericIPv4Address) { | 389 TEST_F(HostResolverImplTest, NumericIPv4Address) { |
| 365 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. | 390 // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. |
| 366 | 391 |
| 367 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = | 392 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = |
| 368 new RuleBasedHostResolverProc(NULL); | 393 new RuleBasedHostResolverProc(NULL); |
| 369 resolver_proc->AllowDirectLookup("*"); | 394 resolver_proc->AllowDirectLookup("*"); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 | 771 |
| 747 TEST_F(HostResolverImplTest, StartWithinCallback) { | 772 TEST_F(HostResolverImplTest, StartWithinCallback) { |
| 748 // Use a capturing resolver_proc, since the verifier needs to know what calls | 773 // Use a capturing resolver_proc, since the verifier needs to know what calls |
| 749 // reached Resolver(). Also, the capturing resolver_proc is initially | 774 // reached Resolver(). Also, the capturing resolver_proc is initially |
| 750 // blocked. | 775 // blocked. |
| 751 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 776 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 752 new CapturingHostResolverProc(NULL); | 777 new CapturingHostResolverProc(NULL); |
| 753 | 778 |
| 754 // Turn off caching for this host resolver. | 779 // Turn off caching for this host resolver. |
| 755 scoped_refptr<HostResolver> host_resolver( | 780 scoped_refptr<HostResolver> host_resolver( |
| 756 new HostResolverImpl(resolver_proc, NULL, kMaxJobs)); | 781 new HostResolverImpl(resolver_proc, NULL, kMaxJobs, NULL)); |
| 757 | 782 |
| 758 // The class will receive callbacks for when each resolve completes. It | 783 // The class will receive callbacks for when each resolve completes. It |
| 759 // checks that the right things happened. | 784 // checks that the right things happened. |
| 760 StartWithinCallbackVerifier verifier; | 785 StartWithinCallbackVerifier verifier; |
| 761 | 786 |
| 762 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is | 787 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is |
| 763 // blocked, these should all pile up until we signal it. | 788 // blocked, these should all pile up until we signal it. |
| 764 | 789 |
| 765 ResolveRequest req1(host_resolver, "a", 80, &verifier); | 790 ResolveRequest req1(host_resolver, "a", 80, &verifier); |
| 766 ResolveRequest req2(host_resolver, "a", 81, &verifier); | 791 ResolveRequest req2(host_resolver, "a", 81, &verifier); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 EXPECT_EQ(2U, observer.cancel_log.size()); | 1068 EXPECT_EQ(2U, observer.cancel_log.size()); |
| 1044 | 1069 |
| 1045 HostResolver::RequestInfo info("host2", 60); | 1070 HostResolver::RequestInfo info("host2", 60); |
| 1046 EXPECT_TRUE(observer.cancel_log[1] == | 1071 EXPECT_TRUE(observer.cancel_log[1] == |
| 1047 CapturingObserver::StartOrCancelEntry(1, info)); | 1072 CapturingObserver::StartOrCancelEntry(1, info)); |
| 1048 } | 1073 } |
| 1049 | 1074 |
| 1050 // Test that IP address changes flush the cache. | 1075 // Test that IP address changes flush the cache. |
| 1051 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { | 1076 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { |
| 1052 scoped_refptr<HostResolver> host_resolver( | 1077 scoped_refptr<HostResolver> host_resolver( |
| 1053 new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs)); | 1078 new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs, NULL)); |
| 1054 | 1079 |
| 1055 AddressList addrlist; | 1080 AddressList addrlist; |
| 1056 | 1081 |
| 1057 // Resolve "host1". | 1082 // Resolve "host1". |
| 1058 HostResolver::RequestInfo info1("host1", 70); | 1083 HostResolver::RequestInfo info1("host1", 70); |
| 1059 TestCompletionCallback callback; | 1084 TestCompletionCallback callback; |
| 1060 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, | 1085 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, |
| 1061 BoundNetLog()); | 1086 BoundNetLog()); |
| 1062 EXPECT_EQ(ERR_IO_PENDING, rv); | 1087 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1063 EXPECT_EQ(OK, callback.WaitForResult()); | 1088 EXPECT_EQ(OK, callback.WaitForResult()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1080 | 1105 |
| 1081 // Tests that when the maximum threads is set to 1, requests are dequeued | 1106 // Tests that when the maximum threads is set to 1, requests are dequeued |
| 1082 // in order of priority. | 1107 // in order of priority. |
| 1083 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { | 1108 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { |
| 1084 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1109 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1085 new CapturingHostResolverProc(NULL); | 1110 new CapturingHostResolverProc(NULL); |
| 1086 | 1111 |
| 1087 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1112 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1088 size_t kMaxJobs = 1u; | 1113 size_t kMaxJobs = 1u; |
| 1089 scoped_refptr<HostResolver> host_resolver( | 1114 scoped_refptr<HostResolver> host_resolver( |
| 1090 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs)); | 1115 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, |
| 1116 NULL)); |
| 1091 | 1117 |
| 1092 CapturingObserver observer; | 1118 CapturingObserver observer; |
| 1093 host_resolver->AddObserver(&observer); | 1119 host_resolver->AddObserver(&observer); |
| 1094 | 1120 |
| 1095 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1121 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1096 // requests we make will not complete. | 1122 // requests we make will not complete. |
| 1097 | 1123 |
| 1098 HostResolver::RequestInfo req[] = { | 1124 HostResolver::RequestInfo req[] = { |
| 1099 CreateResolverRequest("req0", LOW), | 1125 CreateResolverRequest("req0", LOW), |
| 1100 CreateResolverRequest("req1", MEDIUM), | 1126 CreateResolverRequest("req1", MEDIUM), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 } | 1190 } |
| 1165 | 1191 |
| 1166 // Try cancelling a request which has not been attached to a job yet. | 1192 // Try cancelling a request which has not been attached to a job yet. |
| 1167 TEST_F(HostResolverImplTest, CancelPendingRequest) { | 1193 TEST_F(HostResolverImplTest, CancelPendingRequest) { |
| 1168 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1194 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1169 new CapturingHostResolverProc(NULL); | 1195 new CapturingHostResolverProc(NULL); |
| 1170 | 1196 |
| 1171 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1197 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1172 const size_t kMaxJobs = 1u; | 1198 const size_t kMaxJobs = 1u; |
| 1173 scoped_refptr<HostResolver> host_resolver( | 1199 scoped_refptr<HostResolver> host_resolver( |
| 1174 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs)); | 1200 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, |
| 1201 NULL)); |
| 1175 | 1202 |
| 1176 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1203 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1177 // requests we make will not complete. | 1204 // requests we make will not complete. |
| 1178 | 1205 |
| 1179 HostResolver::RequestInfo req[] = { | 1206 HostResolver::RequestInfo req[] = { |
| 1180 CreateResolverRequest("req0", LOWEST), | 1207 CreateResolverRequest("req0", LOWEST), |
| 1181 CreateResolverRequest("req1", HIGHEST), // Will cancel. | 1208 CreateResolverRequest("req1", HIGHEST), // Will cancel. |
| 1182 CreateResolverRequest("req2", MEDIUM), | 1209 CreateResolverRequest("req2", MEDIUM), |
| 1183 CreateResolverRequest("req3", LOW), | 1210 CreateResolverRequest("req3", LOW), |
| 1184 CreateResolverRequest("req4", HIGHEST), // Will cancel. | 1211 CreateResolverRequest("req4", HIGHEST), // Will cancel. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 } | 1253 } |
| 1227 | 1254 |
| 1228 // Test that when too many requests are enqueued, old ones start to be aborted. | 1255 // Test that when too many requests are enqueued, old ones start to be aborted. |
| 1229 TEST_F(HostResolverImplTest, QueueOverflow) { | 1256 TEST_F(HostResolverImplTest, QueueOverflow) { |
| 1230 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1257 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1231 new CapturingHostResolverProc(NULL); | 1258 new CapturingHostResolverProc(NULL); |
| 1232 | 1259 |
| 1233 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1260 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1234 const size_t kMaxOutstandingJobs = 1u; | 1261 const size_t kMaxOutstandingJobs = 1u; |
| 1235 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1262 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1236 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); | 1263 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); |
| 1237 | 1264 |
| 1238 // Only allow up to 3 requests to be enqueued at a time. | 1265 // Only allow up to 3 requests to be enqueued at a time. |
| 1239 const size_t kMaxPendingRequests = 3u; | 1266 const size_t kMaxPendingRequests = 3u; |
| 1240 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, | 1267 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, |
| 1241 kMaxOutstandingJobs, | 1268 kMaxOutstandingJobs, |
| 1242 kMaxPendingRequests); | 1269 kMaxPendingRequests); |
| 1243 | 1270 |
| 1244 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1271 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1245 // requests we make will not complete. | 1272 // requests we make will not complete. |
| 1246 | 1273 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 | 1331 |
| 1305 // Tests that after changing the default AddressFamily to IPV4, requests | 1332 // Tests that after changing the default AddressFamily to IPV4, requests |
| 1306 // with UNSPECIFIED address family map to IPV4. | 1333 // with UNSPECIFIED address family map to IPV4. |
| 1307 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { | 1334 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { |
| 1308 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1335 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1309 new CapturingHostResolverProc(new EchoingHostResolverProc); | 1336 new CapturingHostResolverProc(new EchoingHostResolverProc); |
| 1310 | 1337 |
| 1311 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1338 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1312 const size_t kMaxOutstandingJobs = 1u; | 1339 const size_t kMaxOutstandingJobs = 1u; |
| 1313 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1340 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1314 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); | 1341 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); |
| 1315 | 1342 |
| 1316 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1343 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
| 1317 | 1344 |
| 1318 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1345 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1319 // requests we make will not complete. | 1346 // requests we make will not complete. |
| 1320 | 1347 |
| 1321 HostResolver::RequestInfo req[] = { | 1348 HostResolver::RequestInfo req[] = { |
| 1322 CreateResolverRequestForAddressFamily("h1", MEDIUM, | 1349 CreateResolverRequestForAddressFamily("h1", MEDIUM, |
| 1323 ADDRESS_FAMILY_UNSPECIFIED), | 1350 ADDRESS_FAMILY_UNSPECIFIED), |
| 1324 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), | 1351 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 // This is the exact same test as SetDefaultAddressFamily_IPv4, except the order | 1399 // This is the exact same test as SetDefaultAddressFamily_IPv4, except the order |
| 1373 // of requests 0 and 1 is flipped, and the default is set to IPv6 in place of | 1400 // of requests 0 and 1 is flipped, and the default is set to IPv6 in place of |
| 1374 // IPv4. | 1401 // IPv4. |
| 1375 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { | 1402 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { |
| 1376 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1403 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1377 new CapturingHostResolverProc(new EchoingHostResolverProc); | 1404 new CapturingHostResolverProc(new EchoingHostResolverProc); |
| 1378 | 1405 |
| 1379 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1406 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1380 const size_t kMaxOutstandingJobs = 1u; | 1407 const size_t kMaxOutstandingJobs = 1u; |
| 1381 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1408 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1382 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); | 1409 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); |
| 1383 | 1410 |
| 1384 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); | 1411 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); |
| 1385 | 1412 |
| 1386 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1413 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1387 // requests we make will not complete. | 1414 // requests we make will not complete. |
| 1388 | 1415 |
| 1389 HostResolver::RequestInfo req[] = { | 1416 HostResolver::RequestInfo req[] = { |
| 1390 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), | 1417 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), |
| 1391 CreateResolverRequestForAddressFamily("h1", MEDIUM, | 1418 CreateResolverRequestForAddressFamily("h1", MEDIUM, |
| 1392 ADDRESS_FAMILY_UNSPECIFIED), | 1419 ADDRESS_FAMILY_UNSPECIFIED), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 } | 1465 } |
| 1439 | 1466 |
| 1440 // This tests that the default address family is respected for synchronous | 1467 // This tests that the default address family is respected for synchronous |
| 1441 // resolutions. | 1468 // resolutions. |
| 1442 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { | 1469 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { |
| 1443 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1470 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1444 new CapturingHostResolverProc(new EchoingHostResolverProc); | 1471 new CapturingHostResolverProc(new EchoingHostResolverProc); |
| 1445 | 1472 |
| 1446 const size_t kMaxOutstandingJobs = 10u; | 1473 const size_t kMaxOutstandingJobs = 10u; |
| 1447 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( | 1474 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1448 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); | 1475 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); |
| 1449 | 1476 |
| 1450 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1477 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
| 1451 | 1478 |
| 1452 // Unblock the resolver thread so the requests can run. | 1479 // Unblock the resolver thread so the requests can run. |
| 1453 resolver_proc->Signal(); | 1480 resolver_proc->Signal(); |
| 1454 | 1481 |
| 1455 HostResolver::RequestInfo req[] = { | 1482 HostResolver::RequestInfo req[] = { |
| 1456 CreateResolverRequestForAddressFamily("b", MEDIUM, | 1483 CreateResolverRequestForAddressFamily("b", MEDIUM, |
| 1457 ADDRESS_FAMILY_UNSPECIFIED), | 1484 ADDRESS_FAMILY_UNSPECIFIED), |
| 1458 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV6), | 1485 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV6), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); | 1517 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); |
| 1491 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); | 1518 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); |
| 1492 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); | 1519 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); |
| 1493 } | 1520 } |
| 1494 | 1521 |
| 1495 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1522 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
| 1496 | 1523 |
| 1497 } // namespace | 1524 } // namespace |
| 1498 | 1525 |
| 1499 } // namespace net | 1526 } // namespace net |
| OLD | NEW |