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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/host_resolver_impl_unittest.cc
diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc
index e9a721c5d4f497173dbfad5a3107d463c26e8e91..a17fb6a8b2b90c520ab158b1925f15977ea65d58 100644
--- a/net/base/host_resolver_impl_unittest.cc
+++ b/net/base/host_resolver_impl_unittest.cc
@@ -1043,6 +1043,38 @@ TEST_F(HostResolverImplTest, CancellationObserver) {
CapturingObserver::StartOrCancelEntry(1, info));
}
+// Test that IP address changes flush the cache.
+TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) {
+ MockNetworkChangeNotifier mock_network_change_notifier;
+ scoped_refptr<HostResolver> host_resolver(
+ new HostResolverImpl(NULL, CreateDefaultCache(),
+ &mock_network_change_notifier,
+ kMaxJobs));
+
+ AddressList addrlist;
+
+ // Resolve "host1".
+ HostResolver::RequestInfo info1("host1", 70);
+ TestCompletionCallback callback;
+ int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ EXPECT_EQ(OK, callback.WaitForResult());
+
+ // Resolve "host1" again -- this time it will be served from cache, but it
+ // should still notify of completion.
+ rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL);
+ ASSERT_EQ(OK, rv); // Should complete synchronously.
+
+ // Flush cache by triggering an IP address change.
+ mock_network_change_notifier.NotifyIPAddressChange();
+
+ // Resolve "host1" again -- this time it won't be served from cache, so it
+ // will complete asynchronously.
+ rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL);
+ ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously.
+ EXPECT_EQ(OK, callback.WaitForResult());
+}
+
// Tests that when the maximum threads is set to 1, requests are dequeued
// in order of priority.
TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) {
« 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