diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-24 21:42:10 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-24 21:42:10 +0000 |
commit | 40f1cc31488946d67d32500c0593f6c37afe2774 (patch) | |
tree | ee6e8b8c93d6ec0a81f3b8dc664985ef80d131a5 /net/http/http_cache_unittest.cc | |
parent | f0f1db697fe2ff3501611c6a024eaa8d619767ac (diff) | |
download | chromium_src-40f1cc31488946d67d32500c0593f6c37afe2774.zip chromium_src-40f1cc31488946d67d32500c0593f6c37afe2774.tar.gz chromium_src-40f1cc31488946d67d32500c0593f6c37afe2774.tar.bz2 |
Reland r97821. DiskCacheBasedSSLHostInfo needs to be declared with
NET_EXPORT_PRIVATE for the shared builds.
Do not call callback->Run() until we are about to return from this
object because callback->Run() may cause this object to be deleted.
Previously we were calling callback->Run() in DoWaitForDataReadyDone(),
which returns to the do-while loop in DoLoop(). The do-while loop
reads the state_ member. If the object was deleted in callback->Run(),
we would be reading state_ after free.
Miscellaneous cleanups: omit net::, and use the assign() method of
std::string to avoid constructing a temporary object.
R=agl@chromium.org,rvargas@chromium.org
BUG=84426
TEST=net_unittests --gtest_filter=DiskCacheBasedSSLHostInfo.DeleteInCallback
Review URL: http://codereview.chromium.org/7715007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98119 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_cache_unittest.cc')
-rw-r--r-- | net/http/http_cache_unittest.cc | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index dceabf8..6ea1be2 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -16,7 +16,9 @@ #include "net/base/net_errors.h" #include "net/base/net_log_unittest.h" #include "net/base/ssl_cert_request_info.h" +#include "net/base/ssl_config_service.h" #include "net/disk_cache/disk_cache.h" +#include "net/http/disk_cache_based_ssl_host_info.h" #include "net/http/http_byte_range.h" #include "net/http/http_request_headers.h" #include "net/http/http_request_info.h" @@ -1038,7 +1040,7 @@ struct Context { //----------------------------------------------------------------------------- -// tests +// HttpCache tests TEST(HttpCache, CreateThenDestroy) { MockHttpCache cache; @@ -5180,3 +5182,41 @@ TEST(HttpCache, TruncatedByContentLength2) { EXPECT_TRUE(truncated); entry->Close(); } + +//----------------------------------------------------------------------------- +// DiskCacheBasedSSLHostInfo tests + +class DeleteSSLHostInfoCompletionCallback : public TestCompletionCallback { + public: + explicit DeleteSSLHostInfoCompletionCallback(net::SSLHostInfo* ssl_host_info) + : ssl_host_info_(ssl_host_info) {} + + virtual void RunWithParams(const Tuple1<int>& params) { + delete ssl_host_info_; + TestCompletionCallback::RunWithParams(params); + } + + private: + net::SSLHostInfo* ssl_host_info_; +}; + +// Tests that we can delete a DiskCacheBasedSSLHostInfo object in a +// completion callback for DiskCacheBasedSSLHostInfo::WaitForDataReady. +TEST(DiskCacheBasedSSLHostInfo, DeleteInCallback) { + net::CertVerifier cert_verifier; + // Use the blocking mock backend factory to force asynchronous completion + // of ssl_host_info->WaitForDataReady(), so that the callback will run. + MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); + MockHttpCache cache(factory); + net::SSLConfig ssl_config; + net::SSLHostInfo* ssl_host_info = + new net::DiskCacheBasedSSLHostInfo("https://www.verisign.com", ssl_config, + &cert_verifier, cache.http_cache()); + ssl_host_info->Start(); + DeleteSSLHostInfoCompletionCallback callback(ssl_host_info); + int rv = ssl_host_info->WaitForDataReady(&callback); + EXPECT_EQ(net::ERR_IO_PENDING, rv); + // Now complete the backend creation and let the callback run. + factory->FinishCreation(); + EXPECT_EQ(net::OK, callback.GetResult(rv)); +} |