diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-17 02:11:03 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-17 02:11:03 +0000 |
commit | eb255d3bd77fa891cd909d5779763a3e028759d2 (patch) | |
tree | d20650c59eb2150f73f27173e0325a05fa288836 /net/base/host_resolver_unittest.cc | |
parent | c8220644056dfdb2d48f5d00578888a00ca02fe7 (diff) | |
download | chromium_src-eb255d3bd77fa891cd909d5779763a3e028759d2.zip chromium_src-eb255d3bd77fa891cd909d5779763a3e028759d2.tar.gz chromium_src-eb255d3bd77fa891cd909d5779763a3e028759d2.tar.bz2 |
Re-land another subset of r18520.
This particular subset should be a no-op: It adds an unused interface method (OnResolutionCancelled), and an unused test (CancelObserver), and lastly renames Cancel --> MarkAsCanceled().
The code in "dns_global.cc" is also unused since it is unreachable.
The original code review that this belongs to is:<http://codereview.chromium.org/125171>. (BUG=14138)
The original was backed out because of a valgrind linux error (BUG=14218), so I am now re-landing in smaller chunks to identify where the problem resides.
Review URL: http://codereview.chromium.org/126253
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18581 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/host_resolver_unittest.cc')
-rw-r--r-- | net/base/host_resolver_unittest.cc | 107 |
1 files changed, 99 insertions, 8 deletions
diff --git a/net/base/host_resolver_unittest.cc b/net/base/host_resolver_unittest.cc index 195b2fb..62281f0 100644 --- a/net/base/host_resolver_unittest.cc +++ b/net/base/host_resolver_unittest.cc @@ -702,7 +702,7 @@ class CapturingObserver : public net::HostResolver::Observer { // DnsResolutionObserver methods: virtual void OnStartResolution(int id, const net::HostResolver::RequestInfo& info) { - start_log.push_back(StartEntry(id, info)); + start_log.push_back(StartOrCancelEntry(id, info)); } virtual void OnFinishResolutionWithStatus( @@ -712,12 +712,17 @@ class CapturingObserver : public net::HostResolver::Observer { finish_log.push_back(FinishEntry(id, was_resolved, info)); } + virtual void OnCancelResolution(int id, + const net::HostResolver::RequestInfo& info) { + cancel_log.push_back(StartOrCancelEntry(id, info)); + } + // Tuple (id, info). - struct StartEntry { - StartEntry(int id, const net::HostResolver::RequestInfo& info) + struct StartOrCancelEntry { + StartOrCancelEntry(int id, const net::HostResolver::RequestInfo& info) : id(id), info(info) {} - bool operator==(const StartEntry& other) const { + bool operator==(const StartOrCancelEntry& other) const { return id == other.id && info == other.info; } @@ -742,11 +747,14 @@ class CapturingObserver : public net::HostResolver::Observer { net::HostResolver::RequestInfo info; }; - std::vector<StartEntry> start_log; + 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. TEST_F(HostResolverTest, Observers) { net::HostResolver host_resolver; @@ -763,8 +771,9 @@ TEST_F(HostResolverTest, Observers) { EXPECT_EQ(1U, observer.start_log.size()); EXPECT_EQ(1U, observer.finish_log.size()); + EXPECT_EQ(0U, observer.cancel_log.size()); EXPECT_TRUE(observer.start_log[0] == - CapturingObserver::StartEntry(0, info1)); + CapturingObserver::StartOrCancelEntry(0, info1)); EXPECT_TRUE(observer.finish_log[0] == CapturingObserver::FinishEntry(0, true, info1)); @@ -776,8 +785,9 @@ TEST_F(HostResolverTest, Observers) { EXPECT_EQ(2U, observer.start_log.size()); EXPECT_EQ(2U, observer.finish_log.size()); + EXPECT_EQ(0U, observer.cancel_log.size()); EXPECT_TRUE(observer.start_log[1] == - CapturingObserver::StartEntry(1, info1)); + CapturingObserver::StartOrCancelEntry(1, info1)); EXPECT_TRUE(observer.finish_log[1] == CapturingObserver::FinishEntry(1, true, info1)); @@ -789,7 +799,9 @@ TEST_F(HostResolverTest, Observers) { EXPECT_EQ(3U, observer.start_log.size()); EXPECT_EQ(3U, observer.finish_log.size()); - EXPECT_TRUE(observer.start_log[2] == CapturingObserver::StartEntry(2, info2)); + EXPECT_EQ(0U, observer.cancel_log.size()); + EXPECT_TRUE(observer.start_log[2] == + CapturingObserver::StartOrCancelEntry(2, info2)); EXPECT_TRUE(observer.finish_log[2] == CapturingObserver::FinishEntry(2, true, info2)); @@ -803,6 +815,85 @@ TEST_F(HostResolverTest, Observers) { // No effect this time, since observer was removed. EXPECT_EQ(3U, observer.start_log.size()); EXPECT_EQ(3U, observer.finish_log.size()); + EXPECT_EQ(0U, observer.cancel_log.size()); +} + +// Tests that observers are sent OnCancelResolution() whenever a request is +// cancelled. There are two ways to cancel a request: +// (1) Delete the HostResolver while job is outstanding. +// (2) Call HostResolver::CancelRequest() while a request is outstanding. +TEST_F(HostResolverTest, DISABLED_CancellationObserver) { + // Set a blocking mapper so we control when the resolver thread finishes. + scoped_refptr<WaitingHostMapper> mapper = new WaitingHostMapper(); + ScopedHostMapper scoped_mapper(mapper.get()); + + CapturingObserver observer; + { + // Create a host resolver and attach an observer. + net::HostResolver host_resolver; + host_resolver.AddObserver(&observer); + + TestCompletionCallback callback; + + EXPECT_EQ(0U, observer.start_log.size()); + EXPECT_EQ(0U, observer.finish_log.size()); + EXPECT_EQ(0U, observer.cancel_log.size()); + + // Start an async resolve for (host1:70). + net::HostResolver::RequestInfo info1("host1", 70); + net::HostResolver::Request* req = NULL; + net::AddressList addrlist; + int rv = host_resolver.Resolve(info1, &addrlist, &callback, &req); + EXPECT_EQ(net::ERR_IO_PENDING, rv); + EXPECT_TRUE(NULL != req); + + EXPECT_EQ(1U, observer.start_log.size()); + EXPECT_EQ(0U, observer.finish_log.size()); + EXPECT_EQ(0U, observer.cancel_log.size()); + + EXPECT_TRUE(observer.start_log[0] == + CapturingObserver::StartOrCancelEntry(0, info1)); + + // Cancel the request (host mapper is blocked so it cant be finished yet). + host_resolver.CancelRequest(req); + + EXPECT_EQ(1U, observer.start_log.size()); + EXPECT_EQ(0U, observer.finish_log.size()); + EXPECT_EQ(1U, observer.cancel_log.size()); + + EXPECT_TRUE(observer.cancel_log[0] == + CapturingObserver::StartOrCancelEntry(0, info1)); + + // Start an async request for (host2:60) + net::HostResolver::RequestInfo info2("host2", 60); + rv = host_resolver.Resolve(info2, &addrlist, &callback, NULL); + EXPECT_EQ(net::ERR_IO_PENDING, rv); + EXPECT_TRUE(NULL != req); + + EXPECT_EQ(2U, observer.start_log.size()); + EXPECT_EQ(0U, observer.finish_log.size()); + EXPECT_EQ(1U, observer.cancel_log.size()); + + EXPECT_TRUE(observer.start_log[1] == + CapturingObserver::StartOrCancelEntry(1, info2)); + + // Upon exiting this scope, HostResolver is destroyed, so all requests are + // implicitly cancelled. + } + + // Check that destroying the HostResolver sent a notification for + // cancellation of host2:60 request. + + EXPECT_EQ(2U, observer.start_log.size()); + EXPECT_EQ(0U, observer.finish_log.size()); + EXPECT_EQ(2U, observer.cancel_log.size()); + + net::HostResolver::RequestInfo info("host2", 60); + EXPECT_TRUE(observer.cancel_log[1] == + CapturingObserver::StartOrCancelEntry(1, info)); + + // Unblock the host mapper to let the worker threads finish. + mapper->Signal(); } } // namespace |