diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 16:52:15 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 16:52:15 +0000 |
commit | cfefb8611bb217d2e4d8af84640a91d501616e60 (patch) | |
tree | c72fbd120f4e33a9674b1e3575e587ea89ef47bd /net/base/host_resolver_impl_unittest.cc | |
parent | 80f6e421502c5b24d306550480b9b0f29e1b26f6 (diff) | |
download | chromium_src-cfefb8611bb217d2e4d8af84640a91d501616e60.zip chromium_src-cfefb8611bb217d2e4d8af84640a91d501616e60.tar.gz chromium_src-cfefb8611bb217d2e4d8af84640a91d501616e60.tar.bz2 |
Abort host resolution requests with ERR_ABORTED on ip address change.
BUG=53386
Review URL: http://codereview.chromium.org/3277002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58007 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/host_resolver_impl_unittest.cc')
-rw-r--r-- | net/base/host_resolver_impl_unittest.cc | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc index a78d1c0..8cd1dd5 100644 --- a/net/base/host_resolver_impl_unittest.cc +++ b/net/base/host_resolver_impl_unittest.cc @@ -1103,6 +1103,83 @@ TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { EXPECT_EQ(OK, callback.WaitForResult()); } +// Test that IP address changes send ERR_ABORTED to pending requests. +TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { + scoped_refptr<HostResolver> host_resolver( + new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs, NULL)); + + // Resolve "host1". + HostResolver::RequestInfo info("host1", 70); + TestCompletionCallback callback; + AddressList addrlist; + int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, + BoundNetLog()); + EXPECT_EQ(ERR_IO_PENDING, rv); + + // Triggering an IP address change. + NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); + MessageLoop::current()->RunAllPending(); // Notification happens async. + + EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); + + // Resolve "host1" again, should not be cached, so should be async. + rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, BoundNetLog()); + ASSERT_EQ(ERR_IO_PENDING, rv); +} + +class ResolveWithinCallback : public CallbackRunner< Tuple1<int> > { + public: + ResolveWithinCallback( + const scoped_refptr<HostResolver>& host_resolver, + const HostResolver::RequestInfo& info) + : host_resolver_(host_resolver), + info_(info) { + DCHECK(host_resolver.get()); + } + + virtual void RunWithParams(const Tuple1<int>& params) { + callback_.RunWithParams(params); + EXPECT_EQ(ERR_IO_PENDING, + host_resolver_->Resolve(info_, &addrlist_, &nested_callback_, + NULL, BoundNetLog())); + } + + int WaitForResult() { + return callback_.WaitForResult(); + } + + int WaitForNestedResult() { + return nested_callback_.WaitForResult(); + } + + private: + const scoped_refptr<HostResolver> host_resolver_; + const HostResolver::RequestInfo info_; + AddressList addrlist_; + TestCompletionCallback callback_; + TestCompletionCallback nested_callback_; +}; + +TEST_F(HostResolverImplTest, OnlyAbortExistingRequestsOnIPAddressChange) { + scoped_refptr<HostResolver> host_resolver( + new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs, NULL)); + + // Resolve "host1". + HostResolver::RequestInfo info("host1", 70); + ResolveWithinCallback callback(host_resolver, info); + AddressList addrlist; + int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, + BoundNetLog()); + EXPECT_EQ(ERR_IO_PENDING, rv); + + // Triggering an IP address change. + NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); + MessageLoop::current()->RunAllPending(); // Notification happens async. + + EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); + EXPECT_EQ(OK, callback.WaitForNestedResult()); +} + // Tests that when the maximum threads is set to 1, requests are dequeued // in order of priority. TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { |