diff options
author | agayev@chromium.org <agayev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-20 20:16:26 +0000 |
---|---|---|
committer | agayev@chromium.org <agayev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-20 20:16:26 +0000 |
commit | de093d1f62f204fc02d8f693bc88fd99f1d74171 (patch) | |
tree | b3a6ffa4fac912743c102c067d8f3c5e747e199a /net/base/host_resolver_impl_unittest.cc | |
parent | 5728fef191336ccbfbc910fc851cbe814862b6e6 (diff) | |
download | chromium_src-de093d1f62f204fc02d8f693bc88fd99f1d74171.zip chromium_src-de093d1f62f204fc02d8f693bc88fd99f1d74171.tar.gz chromium_src-de093d1f62f204fc02d8f693bc88fd99f1d74171.tar.bz2 |
Revert 93237 - Implement AsyncHostResolver, an asynchronous HostResolver.
BUG=60149
TEST=net_unittests --gtest_filter="AsyncHostResolverTest*"
Review URL: http://codereview.chromium.org/7342046
TBR=agayev@chromium.org
Review URL: http://codereview.chromium.org/7466010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93240 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 | 94 |
1 files changed, 80 insertions, 14 deletions
diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc index a833599..52b7f89 100644 --- a/net/base/host_resolver_impl_unittest.cc +++ b/net/base/host_resolver_impl_unittest.cc @@ -16,7 +16,6 @@ #include "base/time.h" #include "net/base/address_list.h" #include "net/base/completion_callback.h" -#include "net/base/dns_test_util.h" #include "net/base/mock_host_resolver.h" #include "net/base/net_errors.h" #include "net/base/net_log_unittest.h" @@ -980,6 +979,73 @@ TEST_F(HostResolverImplTest, BypassCache) { MessageLoop::current()->Run(); } +bool operator==(const HostResolver::RequestInfo& a, + const HostResolver::RequestInfo& b) { + return a.hostname() == b.hostname() && + a.port() == b.port() && + a.allow_cached_response() == b.allow_cached_response() && + a.priority() == b.priority() && + a.is_speculative() == b.is_speculative() && + a.referrer() == b.referrer(); +} + +// Observer that just makes note of how it was called. The test code can then +// inspect to make sure it was called with the right parameters. +class CapturingObserver : public HostResolver::Observer { + public: + // DnsResolutionObserver methods: + virtual void OnStartResolution(int id, + const HostResolver::RequestInfo& info) { + start_log.push_back(StartOrCancelEntry(id, info)); + } + + virtual void OnFinishResolutionWithStatus( + int id, + bool was_resolved, + const HostResolver::RequestInfo& info) { + finish_log.push_back(FinishEntry(id, was_resolved, info)); + } + + virtual void OnCancelResolution(int id, + const HostResolver::RequestInfo& info) { + cancel_log.push_back(StartOrCancelEntry(id, info)); + } + + // Tuple (id, info). + struct StartOrCancelEntry { + StartOrCancelEntry(int id, const HostResolver::RequestInfo& info) + : id(id), info(info) {} + + bool operator==(const StartOrCancelEntry& other) const { + return id == other.id && info == other.info; + } + + int id; + HostResolver::RequestInfo info; + }; + + // Tuple (id, was_resolved, info). + struct FinishEntry { + FinishEntry(int id, bool was_resolved, + const HostResolver::RequestInfo& info) + : id(id), was_resolved(was_resolved), info(info) {} + + bool operator==(const FinishEntry& other) const { + return id == other.id && + was_resolved == other.was_resolved && + info == other.info; + } + + int id; + bool was_resolved; + HostResolver::RequestInfo info; + }; + + std::vector<StartOrCancelEntry> start_log; + std::vector<FinishEntry> finish_log; + std::vector<StartOrCancelEntry> cancel_log; +}; + // Test that registering, unregistering, and notifying of observers works. // Does not test the cancellation notification since all resolves are // synchronous. @@ -987,7 +1053,7 @@ TEST_F(HostResolverImplTest, Observers) { scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(NULL)); - TestHostResolverObserver observer; + CapturingObserver observer; host_resolver->AddObserver(&observer); @@ -1012,9 +1078,9 @@ TEST_F(HostResolverImplTest, Observers) { EXPECT_EQ(1U, observer.finish_log.size()); EXPECT_EQ(0U, observer.cancel_log.size()); EXPECT_TRUE(observer.start_log[0] == - TestHostResolverObserver::StartOrCancelEntry(0, info1)); + CapturingObserver::StartOrCancelEntry(0, info1)); EXPECT_TRUE(observer.finish_log[0] == - TestHostResolverObserver::FinishEntry(0, true, info1)); + CapturingObserver::FinishEntry(0, true, info1)); // Resolve "host1" again -- this time it will be served from cache, but it // should still notify of completion. @@ -1026,9 +1092,9 @@ TEST_F(HostResolverImplTest, Observers) { EXPECT_EQ(2U, observer.finish_log.size()); EXPECT_EQ(0U, observer.cancel_log.size()); EXPECT_TRUE(observer.start_log[1] == - TestHostResolverObserver::StartOrCancelEntry(1, info1)); + CapturingObserver::StartOrCancelEntry(1, info1)); EXPECT_TRUE(observer.finish_log[1] == - TestHostResolverObserver::FinishEntry(1, true, info1)); + CapturingObserver::FinishEntry(1, true, info1)); // Resolve "host2", setting referrer to "http://foobar.com" HostResolver::RequestInfo info2(HostPortPair("host2", 70)); @@ -1040,9 +1106,9 @@ TEST_F(HostResolverImplTest, Observers) { EXPECT_EQ(3U, observer.finish_log.size()); EXPECT_EQ(0U, observer.cancel_log.size()); EXPECT_TRUE(observer.start_log[2] == - TestHostResolverObserver::StartOrCancelEntry(2, info2)); + CapturingObserver::StartOrCancelEntry(2, info2)); EXPECT_TRUE(observer.finish_log[2] == - TestHostResolverObserver::FinishEntry(2, true, info2)); + CapturingObserver::FinishEntry(2, true, info2)); // Unregister the observer. host_resolver->RemoveObserver(&observer); @@ -1062,7 +1128,7 @@ TEST_F(HostResolverImplTest, Observers) { // (1) Delete the HostResolver while job is outstanding. // (2) Call HostResolver::CancelRequest() while a request is outstanding. TEST_F(HostResolverImplTest, CancellationObserver) { - TestHostResolverObserver observer; + CapturingObserver observer; { // Create a host resolver and attach an observer. scoped_ptr<HostResolver> host_resolver( @@ -1089,7 +1155,7 @@ TEST_F(HostResolverImplTest, CancellationObserver) { EXPECT_EQ(0U, observer.cancel_log.size()); EXPECT_TRUE(observer.start_log[0] == - TestHostResolverObserver::StartOrCancelEntry(0, info1)); + CapturingObserver::StartOrCancelEntry(0, info1)); // Cancel the request. host_resolver->CancelRequest(req); @@ -1099,7 +1165,7 @@ TEST_F(HostResolverImplTest, CancellationObserver) { EXPECT_EQ(1U, observer.cancel_log.size()); EXPECT_TRUE(observer.cancel_log[0] == - TestHostResolverObserver::StartOrCancelEntry(0, info1)); + CapturingObserver::StartOrCancelEntry(0, info1)); // Start an async request for (host2:60) HostResolver::RequestInfo info2(HostPortPair("host2", 60)); @@ -1113,7 +1179,7 @@ TEST_F(HostResolverImplTest, CancellationObserver) { EXPECT_EQ(1U, observer.cancel_log.size()); EXPECT_TRUE(observer.start_log[1] == - TestHostResolverObserver::StartOrCancelEntry(1, info2)); + CapturingObserver::StartOrCancelEntry(1, info2)); // Upon exiting this scope, HostResolver is destroyed, so all requests are // implicitly cancelled. @@ -1128,7 +1194,7 @@ TEST_F(HostResolverImplTest, CancellationObserver) { HostResolver::RequestInfo info(HostPortPair("host2", 60)); EXPECT_TRUE(observer.cancel_log[1] == - TestHostResolverObserver::StartOrCancelEntry(1, info)); + CapturingObserver::StartOrCancelEntry(1, info)); } // Test that IP address changes flush the cache. @@ -1298,7 +1364,7 @@ TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, kRetryAttempts, NULL)); - TestHostResolverObserver observer; + CapturingObserver observer; host_resolver->AddObserver(&observer); // Note that at this point the CapturingHostResolverProc is blocked, so any |