| 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" |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
| 14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 15 #include "net/base/mock_host_resolver.h" | 15 #include "net/base/mock_host_resolver.h" |
| 16 #include "net/base/mock_network_change_notifier.h" | |
| 17 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 18 #include "net/base/net_log_unittest.h" | 17 #include "net/base/net_log_unittest.h" |
| 19 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 20 #include "net/base/sys_addrinfo.h" | 19 #include "net/base/sys_addrinfo.h" |
| 21 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 22 |
| 24 // TODO(eroman): | 23 // TODO(eroman): |
| 25 // - Test mixing async with sync (in particular how does sync update the | 24 // - Test mixing async with sync (in particular how does sync update the |
| 26 // cache while an async is already pending). | 25 // cache while an async is already pending). |
| 27 | 26 |
| 28 namespace net { | 27 namespace net { |
| 29 | 28 |
| 30 namespace { | 29 namespace { |
| 31 | 30 |
| 32 HostCache* CreateDefaultCache() { | 31 HostCache* CreateDefaultCache() { |
| 33 return new HostCache( | 32 return new HostCache( |
| 34 100, // max cache entries. | 33 100, // max cache entries. |
| 35 base::TimeDelta::FromMinutes(1), | 34 base::TimeDelta::FromMinutes(1), |
| 36 base::TimeDelta::FromSeconds(0)); | 35 base::TimeDelta::FromSeconds(0)); |
| 37 } | 36 } |
| 38 | 37 |
| 39 static const size_t kMaxJobs = 10u; | 38 static const size_t kMaxJobs = 10u; |
| 40 | 39 |
| 41 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { | 40 HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { |
| 42 return new HostResolverImpl( | 41 return new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs); |
| 43 resolver_proc, | |
| 44 CreateDefaultCache(), | |
| 45 NULL, // network_change_notifier | |
| 46 kMaxJobs); | |
| 47 } | 42 } |
| 48 | 43 |
| 49 // Helper to create a HostResolver::RequestInfo. | 44 // Helper to create a HostResolver::RequestInfo. |
| 50 HostResolver::RequestInfo CreateResolverRequest( | 45 HostResolver::RequestInfo CreateResolverRequest( |
| 51 const std::string& hostname, | 46 const std::string& hostname, |
| 52 RequestPriority priority) { | 47 RequestPriority priority) { |
| 53 HostResolver::RequestInfo info(hostname, 80); | 48 HostResolver::RequestInfo info(hostname, 80); |
| 54 info.set_priority(priority); | 49 info.set_priority(priority); |
| 55 return info; | 50 return info; |
| 56 } | 51 } |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 | 736 |
| 742 TEST_F(HostResolverImplTest, StartWithinCallback) { | 737 TEST_F(HostResolverImplTest, StartWithinCallback) { |
| 743 // Use a capturing resolver_proc, since the verifier needs to know what calls | 738 // Use a capturing resolver_proc, since the verifier needs to know what calls |
| 744 // reached Resolver(). Also, the capturing resolver_proc is initially | 739 // reached Resolver(). Also, the capturing resolver_proc is initially |
| 745 // blocked. | 740 // blocked. |
| 746 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 741 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 747 new CapturingHostResolverProc(NULL); | 742 new CapturingHostResolverProc(NULL); |
| 748 | 743 |
| 749 // Turn off caching for this host resolver. | 744 // Turn off caching for this host resolver. |
| 750 scoped_refptr<HostResolver> host_resolver( | 745 scoped_refptr<HostResolver> host_resolver( |
| 751 new HostResolverImpl(resolver_proc, NULL, NULL, kMaxJobs)); | 746 new HostResolverImpl(resolver_proc, NULL, kMaxJobs)); |
| 752 | 747 |
| 753 // The class will receive callbacks for when each resolve completes. It | 748 // The class will receive callbacks for when each resolve completes. It |
| 754 // checks that the right things happened. | 749 // checks that the right things happened. |
| 755 StartWithinCallbackVerifier verifier; | 750 StartWithinCallbackVerifier verifier; |
| 756 | 751 |
| 757 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is | 752 // Start 4 requests, duplicating hosts "a". Since the resolver_proc is |
| 758 // blocked, these should all pile up until we signal it. | 753 // blocked, these should all pile up until we signal it. |
| 759 | 754 |
| 760 ResolveRequest req1(host_resolver, "a", 80, &verifier); | 755 ResolveRequest req1(host_resolver, "a", 80, &verifier); |
| 761 ResolveRequest req2(host_resolver, "a", 81, &verifier); | 756 ResolveRequest req2(host_resolver, "a", 81, &verifier); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 EXPECT_EQ(0U, observer.finish_log.size()); | 1032 EXPECT_EQ(0U, observer.finish_log.size()); |
| 1038 EXPECT_EQ(2U, observer.cancel_log.size()); | 1033 EXPECT_EQ(2U, observer.cancel_log.size()); |
| 1039 | 1034 |
| 1040 HostResolver::RequestInfo info("host2", 60); | 1035 HostResolver::RequestInfo info("host2", 60); |
| 1041 EXPECT_TRUE(observer.cancel_log[1] == | 1036 EXPECT_TRUE(observer.cancel_log[1] == |
| 1042 CapturingObserver::StartOrCancelEntry(1, info)); | 1037 CapturingObserver::StartOrCancelEntry(1, info)); |
| 1043 } | 1038 } |
| 1044 | 1039 |
| 1045 // Test that IP address changes flush the cache. | 1040 // Test that IP address changes flush the cache. |
| 1046 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { | 1041 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { |
| 1047 MockNetworkChangeNotifier mock_network_change_notifier; | |
| 1048 scoped_refptr<HostResolver> host_resolver( | 1042 scoped_refptr<HostResolver> host_resolver( |
| 1049 new HostResolverImpl(NULL, CreateDefaultCache(), | 1043 new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs)); |
| 1050 &mock_network_change_notifier, | |
| 1051 kMaxJobs)); | |
| 1052 | 1044 |
| 1053 AddressList addrlist; | 1045 AddressList addrlist; |
| 1054 | 1046 |
| 1055 // Resolve "host1". | 1047 // Resolve "host1". |
| 1056 HostResolver::RequestInfo info1("host1", 70); | 1048 HostResolver::RequestInfo info1("host1", 70); |
| 1057 TestCompletionCallback callback; | 1049 TestCompletionCallback callback; |
| 1058 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, | 1050 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, |
| 1059 BoundNetLog()); | 1051 BoundNetLog()); |
| 1060 EXPECT_EQ(ERR_IO_PENDING, rv); | 1052 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1061 EXPECT_EQ(OK, callback.WaitForResult()); | 1053 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1062 | 1054 |
| 1063 // Resolve "host1" again -- this time it will be served from cache, but it | 1055 // Resolve "host1" again -- this time it will be served from cache, but it |
| 1064 // should still notify of completion. | 1056 // should still notify of completion. |
| 1065 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog()); | 1057 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog()); |
| 1066 ASSERT_EQ(OK, rv); // Should complete synchronously. | 1058 ASSERT_EQ(OK, rv); // Should complete synchronously. |
| 1067 | 1059 |
| 1068 // Flush cache by triggering an IP address change. | 1060 // Flush cache by triggering an IP address change. |
| 1069 mock_network_change_notifier.NotifyIPAddressChange(); | 1061 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 1062 MessageLoop::current()->RunAllPending(); // Notification happens async. |
| 1070 | 1063 |
| 1071 // 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 |
| 1072 // will complete asynchronously. | 1065 // will complete asynchronously. |
| 1073 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog()); | 1066 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog()); |
| 1074 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. | 1067 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. |
| 1075 EXPECT_EQ(OK, callback.WaitForResult()); | 1068 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1076 } | 1069 } |
| 1077 | 1070 |
| 1078 // Tests that when the maximum threads is set to 1, requests are dequeued | 1071 // Tests that when the maximum threads is set to 1, requests are dequeued |
| 1079 // in order of priority. | 1072 // in order of priority. |
| 1080 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { | 1073 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { |
| 1081 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1074 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1082 new CapturingHostResolverProc(NULL); | 1075 new CapturingHostResolverProc(NULL); |
| 1083 | 1076 |
| 1084 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1077 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1085 size_t kMaxJobs = 1u; | 1078 size_t kMaxJobs = 1u; |
| 1086 scoped_refptr<HostResolver> host_resolver( | 1079 scoped_refptr<HostResolver> host_resolver( |
| 1087 new HostResolverImpl(resolver_proc, CreateDefaultCache(), | 1080 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs)); |
| 1088 NULL, kMaxJobs)); | |
| 1089 | 1081 |
| 1090 CapturingObserver observer; | 1082 CapturingObserver observer; |
| 1091 host_resolver->AddObserver(&observer); | 1083 host_resolver->AddObserver(&observer); |
| 1092 | 1084 |
| 1093 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1085 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1094 // requests we make will not complete. | 1086 // requests we make will not complete. |
| 1095 | 1087 |
| 1096 HostResolver::RequestInfo req[] = { | 1088 HostResolver::RequestInfo req[] = { |
| 1097 CreateResolverRequest("req0", LOW), | 1089 CreateResolverRequest("req0", LOW), |
| 1098 CreateResolverRequest("req1", MEDIUM), | 1090 CreateResolverRequest("req1", MEDIUM), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 } | 1154 } |
| 1163 | 1155 |
| 1164 // Try cancelling a request which has not been attached to a job yet. | 1156 // Try cancelling a request which has not been attached to a job yet. |
| 1165 TEST_F(HostResolverImplTest, CancelPendingRequest) { | 1157 TEST_F(HostResolverImplTest, CancelPendingRequest) { |
| 1166 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1158 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1167 new CapturingHostResolverProc(NULL); | 1159 new CapturingHostResolverProc(NULL); |
| 1168 | 1160 |
| 1169 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1161 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1170 const size_t kMaxJobs = 1u; | 1162 const size_t kMaxJobs = 1u; |
| 1171 scoped_refptr<HostResolver> host_resolver( | 1163 scoped_refptr<HostResolver> host_resolver( |
| 1172 new HostResolverImpl(resolver_proc, CreateDefaultCache(), | 1164 new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs)); |
| 1173 NULL, kMaxJobs)); | |
| 1174 | 1165 |
| 1175 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1166 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1176 // requests we make will not complete. | 1167 // requests we make will not complete. |
| 1177 | 1168 |
| 1178 HostResolver::RequestInfo req[] = { | 1169 HostResolver::RequestInfo req[] = { |
| 1179 CreateResolverRequest("req0", LOWEST), | 1170 CreateResolverRequest("req0", LOWEST), |
| 1180 CreateResolverRequest("req1", HIGHEST), // Will cancel. | 1171 CreateResolverRequest("req1", HIGHEST), // Will cancel. |
| 1181 CreateResolverRequest("req2", MEDIUM), | 1172 CreateResolverRequest("req2", MEDIUM), |
| 1182 CreateResolverRequest("req3", LOW), | 1173 CreateResolverRequest("req3", LOW), |
| 1183 CreateResolverRequest("req4", HIGHEST), // Will cancel. | 1174 CreateResolverRequest("req4", HIGHEST), // Will cancel. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 EXPECT_EQ("req3", capture_list[3].hostname); | 1215 EXPECT_EQ("req3", capture_list[3].hostname); |
| 1225 } | 1216 } |
| 1226 | 1217 |
| 1227 // Test that when too many requests are enqueued, old ones start to be aborted. | 1218 // Test that when too many requests are enqueued, old ones start to be aborted. |
| 1228 TEST_F(HostResolverImplTest, QueueOverflow) { | 1219 TEST_F(HostResolverImplTest, QueueOverflow) { |
| 1229 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1220 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1230 new CapturingHostResolverProc(NULL); | 1221 new CapturingHostResolverProc(NULL); |
| 1231 | 1222 |
| 1232 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1223 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1233 const size_t kMaxOutstandingJobs = 1u; | 1224 const size_t kMaxOutstandingJobs = 1u; |
| 1234 scoped_refptr<HostResolverImpl> host_resolver( | 1225 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1235 new HostResolverImpl(resolver_proc, CreateDefaultCache(), | 1226 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); |
| 1236 NULL, kMaxOutstandingJobs)); | |
| 1237 | 1227 |
| 1238 // Only allow up to 3 requests to be enqueued at a time. | 1228 // Only allow up to 3 requests to be enqueued at a time. |
| 1239 const size_t kMaxPendingRequests = 3u; | 1229 const size_t kMaxPendingRequests = 3u; |
| 1240 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, | 1230 host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL, |
| 1241 kMaxOutstandingJobs, | 1231 kMaxOutstandingJobs, |
| 1242 kMaxPendingRequests); | 1232 kMaxPendingRequests); |
| 1243 | 1233 |
| 1244 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1234 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1245 // requests we make will not complete. | 1235 // requests we make will not complete. |
| 1246 | 1236 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 } | 1293 } |
| 1304 | 1294 |
| 1305 // Tests that after changing the default AddressFamily to IPV4, requests | 1295 // Tests that after changing the default AddressFamily to IPV4, requests |
| 1306 // with UNSPECIFIED address family map to IPV4. | 1296 // with UNSPECIFIED address family map to IPV4. |
| 1307 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { | 1297 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { |
| 1308 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1298 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1309 new CapturingHostResolverProc(new EchoingHostResolverProc); | 1299 new CapturingHostResolverProc(new EchoingHostResolverProc); |
| 1310 | 1300 |
| 1311 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1301 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1312 const size_t kMaxOutstandingJobs = 1u; | 1302 const size_t kMaxOutstandingJobs = 1u; |
| 1313 scoped_refptr<HostResolverImpl> host_resolver( | 1303 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1314 new HostResolverImpl(resolver_proc, CreateDefaultCache(), | 1304 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); |
| 1315 NULL, kMaxOutstandingJobs)); | |
| 1316 | 1305 |
| 1317 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1306 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
| 1318 | 1307 |
| 1319 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1308 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1320 // requests we make will not complete. | 1309 // requests we make will not complete. |
| 1321 | 1310 |
| 1322 HostResolver::RequestInfo req[] = { | 1311 HostResolver::RequestInfo req[] = { |
| 1323 CreateResolverRequestForAddressFamily("h1", MEDIUM, | 1312 CreateResolverRequestForAddressFamily("h1", MEDIUM, |
| 1324 ADDRESS_FAMILY_UNSPECIFIED), | 1313 ADDRESS_FAMILY_UNSPECIFIED), |
| 1325 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), | 1314 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 | 1361 |
| 1373 // This is the exact same test as SetDefaultAddressFamily_IPv4, except the order | 1362 // This is the exact same test as SetDefaultAddressFamily_IPv4, except the order |
| 1374 // of requests 0 and 1 is flipped, and the default is set to IPv6 in place of | 1363 // of requests 0 and 1 is flipped, and the default is set to IPv6 in place of |
| 1375 // IPv4. | 1364 // IPv4. |
| 1376 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { | 1365 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { |
| 1377 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1366 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1378 new CapturingHostResolverProc(new EchoingHostResolverProc); | 1367 new CapturingHostResolverProc(new EchoingHostResolverProc); |
| 1379 | 1368 |
| 1380 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1369 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
| 1381 const size_t kMaxOutstandingJobs = 1u; | 1370 const size_t kMaxOutstandingJobs = 1u; |
| 1382 scoped_refptr<HostResolverImpl> host_resolver( | 1371 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1383 new HostResolverImpl(resolver_proc, CreateDefaultCache(), | 1372 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); |
| 1384 NULL, kMaxOutstandingJobs)); | |
| 1385 | 1373 |
| 1386 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); | 1374 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); |
| 1387 | 1375 |
| 1388 // Note that at this point the CapturingHostResolverProc is blocked, so any | 1376 // Note that at this point the CapturingHostResolverProc is blocked, so any |
| 1389 // requests we make will not complete. | 1377 // requests we make will not complete. |
| 1390 | 1378 |
| 1391 HostResolver::RequestInfo req[] = { | 1379 HostResolver::RequestInfo req[] = { |
| 1392 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), | 1380 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), |
| 1393 CreateResolverRequestForAddressFamily("h1", MEDIUM, | 1381 CreateResolverRequestForAddressFamily("h1", MEDIUM, |
| 1394 ADDRESS_FAMILY_UNSPECIFIED), | 1382 ADDRESS_FAMILY_UNSPECIFIED), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1439 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[2].head())); | 1427 EXPECT_EQ("192.2.104.1", NetAddressToString(addrlist[2].head())); |
| 1440 } | 1428 } |
| 1441 | 1429 |
| 1442 // This tests that the default address family is respected for synchronous | 1430 // This tests that the default address family is respected for synchronous |
| 1443 // resolutions. | 1431 // resolutions. |
| 1444 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { | 1432 TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { |
| 1445 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1433 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
| 1446 new CapturingHostResolverProc(new EchoingHostResolverProc); | 1434 new CapturingHostResolverProc(new EchoingHostResolverProc); |
| 1447 | 1435 |
| 1448 const size_t kMaxOutstandingJobs = 10u; | 1436 const size_t kMaxOutstandingJobs = 10u; |
| 1449 scoped_refptr<HostResolverImpl> host_resolver( | 1437 scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( |
| 1450 new HostResolverImpl(resolver_proc, CreateDefaultCache(), | 1438 resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); |
| 1451 NULL, kMaxOutstandingJobs)); | |
| 1452 | 1439 |
| 1453 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); | 1440 host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); |
| 1454 | 1441 |
| 1455 // Unblock the resolver thread so the requests can run. | 1442 // Unblock the resolver thread so the requests can run. |
| 1456 resolver_proc->Signal(); | 1443 resolver_proc->Signal(); |
| 1457 | 1444 |
| 1458 HostResolver::RequestInfo req[] = { | 1445 HostResolver::RequestInfo req[] = { |
| 1459 CreateResolverRequestForAddressFamily("b", MEDIUM, | 1446 CreateResolverRequestForAddressFamily("b", MEDIUM, |
| 1460 ADDRESS_FAMILY_UNSPECIFIED), | 1447 ADDRESS_FAMILY_UNSPECIFIED), |
| 1461 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV6), | 1448 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV6), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); | 1480 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); |
| 1494 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); | 1481 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); |
| 1495 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); | 1482 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); |
| 1496 } | 1483 } |
| 1497 | 1484 |
| 1498 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. | 1485 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
| 1499 | 1486 |
| 1500 } // namespace | 1487 } // namespace |
| 1501 | 1488 |
| 1502 } // namespace net | 1489 } // namespace net |
| OLD | NEW |