Index: net/http/disk_cache_based_quic_server_info_unittest.cc |
diff --git a/net/http/disk_cache_based_quic_server_info_unittest.cc b/net/http/disk_cache_based_quic_server_info_unittest.cc |
index 847b3d8a16e51132a4426c386953039dada124dd..ef69b43390d51a8e7694acac6fcda6bc67492c70 100644 |
--- a/net/http/disk_cache_based_quic_server_info_unittest.cc |
+++ b/net/http/disk_cache_based_quic_server_info_unittest.cc |
@@ -14,6 +14,8 @@ |
#include "net/quic/quic_server_id.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+using std::string; |
+ |
namespace net { |
namespace { |
@@ -48,6 +50,27 @@ const MockTransaction kHostInfoTransaction2 = { |
0 |
}; |
+class DeleteCacheCompletionCallback : public net::TestCompletionCallbackBase { |
+ public: |
+ explicit DeleteCacheCompletionCallback(QuicServerInfo* server_info) |
+ : server_info_(server_info), |
+ callback_(base::Bind(&DeleteCacheCompletionCallback::OnComplete, |
+ base::Unretained(this))) {} |
+ |
+ const net::CompletionCallback& callback() const { return callback_; } |
+ |
+ private: |
+ void OnComplete(int result) { |
+ delete server_info_; |
+ SetResult(result); |
+ } |
+ |
+ QuicServerInfo* server_info_; |
+ net::CompletionCallback callback_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DeleteCacheCompletionCallback); |
+}; |
+ |
} // namespace |
// Tests that we can delete a DiskCacheBasedQuicServerInfo object in a |
@@ -582,4 +605,24 @@ TEST(DiskCacheBasedQuicServerInfo, MultiplePersistsWithoutWaiting) { |
RemoveMockTransaction(&kHostInfoTransaction1); |
} |
+// crbug.com/439209: test deletion of QuicServerInfo object in the callback |
+// doesn't crash. |
+TEST(DiskCacheBasedQuicServerInfo, DeleteServerInfoInCallback) { |
+ // Use the blocking mock backend factory to force asynchronous completion |
+ // of quic_server_info->WaitForDataReady(), so that the callback will run. |
+ MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); |
+ MockHttpCache cache(factory); |
+ QuicServerId server_id("www.verisign.com", 443, true, PRIVACY_MODE_DISABLED); |
+ QuicServerInfo* quic_server_info = |
+ new DiskCacheBasedQuicServerInfo(server_id, cache.http_cache()); |
+ // |cb| takes owndership and deletes |quic_server_info| when it is called. |
+ DeleteCacheCompletionCallback cb(quic_server_info); |
+ quic_server_info->Start(); |
+ int rv = quic_server_info->WaitForDataReady(cb.callback()); |
+ EXPECT_EQ(ERR_IO_PENDING, rv); |
+ // Now complete the backend creation and let the callback run. |
+ factory->FinishCreation(); |
+ EXPECT_EQ(OK, cb.GetResult(rv)); |
+} |
+ |
} // namespace net |