Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: net/base/host_resolver_impl_unittest.cc

Issue 1604045: Fix crash on IP address change. (Closed)
Patch Set: Merge conflict Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/host_resolver_impl.cc ('k') | net/base/mapped_host_resolver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 1036
1037 EXPECT_EQ(2U, observer.start_log.size()); 1037 EXPECT_EQ(2U, observer.start_log.size());
1038 EXPECT_EQ(0U, observer.finish_log.size()); 1038 EXPECT_EQ(0U, observer.finish_log.size());
1039 EXPECT_EQ(2U, observer.cancel_log.size()); 1039 EXPECT_EQ(2U, observer.cancel_log.size());
1040 1040
1041 HostResolver::RequestInfo info("host2", 60); 1041 HostResolver::RequestInfo info("host2", 60);
1042 EXPECT_TRUE(observer.cancel_log[1] == 1042 EXPECT_TRUE(observer.cancel_log[1] ==
1043 CapturingObserver::StartOrCancelEntry(1, info)); 1043 CapturingObserver::StartOrCancelEntry(1, info));
1044 } 1044 }
1045 1045
1046 // Test that IP address changes flush the cache.
1047 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) {
1048 MockNetworkChangeNotifier mock_network_change_notifier;
1049 scoped_refptr<HostResolver> host_resolver(
1050 new HostResolverImpl(NULL, CreateDefaultCache(),
1051 &mock_network_change_notifier,
1052 kMaxJobs));
1053
1054 AddressList addrlist;
1055
1056 // Resolve "host1".
1057 HostResolver::RequestInfo info1("host1", 70);
1058 TestCompletionCallback callback;
1059 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL);
1060 EXPECT_EQ(ERR_IO_PENDING, rv);
1061 EXPECT_EQ(OK, callback.WaitForResult());
1062
1063 // Resolve "host1" again -- this time it will be served from cache, but it
1064 // should still notify of completion.
1065 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL);
1066 ASSERT_EQ(OK, rv); // Should complete synchronously.
1067
1068 // Flush cache by triggering an IP address change.
1069 mock_network_change_notifier.NotifyIPAddressChange();
1070
1071 // Resolve "host1" again -- this time it won't be served from cache, so it
1072 // will complete asynchronously.
1073 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL);
1074 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously.
1075 EXPECT_EQ(OK, callback.WaitForResult());
1076 }
1077
1046 // Tests that when the maximum threads is set to 1, requests are dequeued 1078 // Tests that when the maximum threads is set to 1, requests are dequeued
1047 // in order of priority. 1079 // in order of priority.
1048 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { 1080 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) {
1049 scoped_refptr<CapturingHostResolverProc> resolver_proc = 1081 scoped_refptr<CapturingHostResolverProc> resolver_proc =
1050 new CapturingHostResolverProc(NULL); 1082 new CapturingHostResolverProc(NULL);
1051 1083
1052 // This HostResolverImpl will only allow 1 outstanding resolve at a time. 1084 // This HostResolverImpl will only allow 1 outstanding resolve at a time.
1053 size_t kMaxJobs = 1u; 1085 size_t kMaxJobs = 1u;
1054 scoped_refptr<HostResolver> host_resolver( 1086 scoped_refptr<HostResolver> host_resolver(
1055 new HostResolverImpl(resolver_proc, CreateDefaultCache(), 1087 new HostResolverImpl(resolver_proc, CreateDefaultCache(),
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); 1493 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head()));
1462 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); 1494 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head()));
1463 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); 1495 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head()));
1464 } 1496 }
1465 1497
1466 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. 1498 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags.
1467 1499
1468 } // namespace 1500 } // namespace
1469 1501
1470 } // namespace net 1502 } // namespace net
OLDNEW
« no previous file with comments | « net/base/host_resolver_impl.cc ('k') | net/base/mapped_host_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698