OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 | 1032 |
1033 EXPECT_EQ(2U, observer.start_log.size()); | 1033 EXPECT_EQ(2U, observer.start_log.size()); |
1034 EXPECT_EQ(0U, observer.finish_log.size()); | 1034 EXPECT_EQ(0U, observer.finish_log.size()); |
1035 EXPECT_EQ(2U, observer.cancel_log.size()); | 1035 EXPECT_EQ(2U, observer.cancel_log.size()); |
1036 | 1036 |
1037 HostResolver::RequestInfo info("host2", 60); | 1037 HostResolver::RequestInfo info("host2", 60); |
1038 EXPECT_TRUE(observer.cancel_log[1] == | 1038 EXPECT_TRUE(observer.cancel_log[1] == |
1039 CapturingObserver::StartOrCancelEntry(1, info)); | 1039 CapturingObserver::StartOrCancelEntry(1, info)); |
1040 } | 1040 } |
1041 | 1041 |
1042 // Test that IP address changes flush the cache. | |
1043 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { | |
1044 MockNetworkChangeNotifier mock_network_change_notifier; | |
1045 scoped_refptr<HostResolver> host_resolver( | |
1046 new HostResolverImpl(NULL, CreateDefaultCache(), | |
1047 &mock_network_change_notifier, | |
1048 kMaxJobs)); | |
1049 | |
1050 AddressList addrlist; | |
1051 | |
1052 // Resolve "host1". | |
1053 HostResolver::RequestInfo info1("host1", 70); | |
1054 TestCompletionCallback callback; | |
1055 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL); | |
1056 EXPECT_EQ(ERR_IO_PENDING, rv); | |
1057 EXPECT_EQ(OK, callback.WaitForResult()); | |
1058 | |
1059 // Resolve "host1" again -- this time it will be served from cache, but it | |
1060 // should still notify of completion. | |
1061 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL); | |
1062 ASSERT_EQ(OK, rv); // Should complete synchronously. | |
1063 | |
1064 // Flush cache by triggering an IP address change. | |
1065 mock_network_change_notifier.NotifyIPAddressChange(); | |
1066 | |
1067 // Resolve "host1" again -- this time it won't be served from cache, so it | |
1068 // will complete asynchronously. | |
1069 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL); | |
1070 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. | |
1071 EXPECT_EQ(OK, callback.WaitForResult()); | |
1072 } | |
1073 | |
1074 // Tests that when the maximum threads is set to 1, requests are dequeued | 1042 // Tests that when the maximum threads is set to 1, requests are dequeued |
1075 // in order of priority. | 1043 // in order of priority. |
1076 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { | 1044 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { |
1077 scoped_refptr<CapturingHostResolverProc> resolver_proc = | 1045 scoped_refptr<CapturingHostResolverProc> resolver_proc = |
1078 new CapturingHostResolverProc(NULL); | 1046 new CapturingHostResolverProc(NULL); |
1079 | 1047 |
1080 // This HostResolverImpl will only allow 1 outstanding resolve at a time. | 1048 // This HostResolverImpl will only allow 1 outstanding resolve at a time. |
1081 size_t kMaxJobs = 1u; | 1049 size_t kMaxJobs = 1u; |
1082 scoped_refptr<HostResolver> host_resolver( | 1050 scoped_refptr<HostResolver> host_resolver( |
1083 new HostResolverImpl(resolver_proc, CreateDefaultCache(), | 1051 new HostResolverImpl(resolver_proc, CreateDefaultCache(), |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 // z = value of address family | 1455 // z = value of address family |
1488 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[0].head())); | 1456 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[0].head())); |
1489 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); | 1457 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); |
1490 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); | 1458 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); |
1491 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); | 1459 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); |
1492 } | 1460 } |
1493 | 1461 |
1494 } // namespace | 1462 } // namespace |
1495 | 1463 |
1496 } // namespace net | 1464 } // namespace net |
OLD | NEW |