diff options
author | erikchen@google.com <erikchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-21 16:59:59 +0000 |
---|---|---|
committer | erikchen@google.com <erikchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-21 16:59:59 +0000 |
commit | 30c942b07906bc38fda3f88ae43d6dc106de0c46 (patch) | |
tree | 6973e0c6acc8994bc391e7892e3207c0a5b316b9 /net/spdy | |
parent | b1e18a418625f8b005d3854e336893ea629c9e9b (diff) | |
download | chromium_src-30c942b07906bc38fda3f88ae43d6dc106de0c46.zip chromium_src-30c942b07906bc38fda3f88ae43d6dc106de0c46.tar.gz chromium_src-30c942b07906bc38fda3f88ae43d6dc106de0c46.tar.bz2 |
Fixed memory leak in SpdyHttpStreamTest. Removed suppressions.
Also cleaned up spdy unit tests a bit.
TEST=SpdyHttpStreamTest should have no memleaks in valgrind.
BUG=48865, 47950, 46886
Review URL: http://codereview.chromium.org/3033012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53200 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r-- | net/spdy/spdy_framer.h | 2 | ||||
-rw-r--r-- | net/spdy/spdy_http_stream_unittest.cc | 134 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 114 | ||||
-rw-r--r-- | net/spdy/spdy_session_unittest.cc | 52 | ||||
-rw-r--r-- | net/spdy/spdy_stream_unittest.cc | 58 | ||||
-rw-r--r-- | net/spdy/spdy_test_util.h | 55 |
6 files changed, 131 insertions, 284 deletions
diff --git a/net/spdy/spdy_framer.h b/net/spdy/spdy_framer.h index 1122474..f188373 100644 --- a/net/spdy/spdy_framer.h +++ b/net/spdy/spdy_framer.h @@ -29,6 +29,7 @@ class HttpNetworkTransactionTest; class SpdyNetworkTransactionTest; class SpdySessionTest; class SpdyStreamTest; +class SpdyHttpStreamTest; } namespace spdy { @@ -249,6 +250,7 @@ class SpdyFramer { friend class net::HttpNetworkTransactionTest; friend class net::HttpNetworkLayer; // This is temporary for the server. friend class net::SpdySessionTest; + friend class net::SpdyHttpStreamTest; friend class net::SpdyStreamTest; friend class test::TestSpdyVisitor; friend void test::FramerSetEnableCompressionHelper(SpdyFramer* framer, diff --git a/net/spdy/spdy_http_stream_unittest.cc b/net/spdy/spdy_http_stream_unittest.cc index 5fab0e2..65a8068 100644 --- a/net/spdy/spdy_http_stream_unittest.cc +++ b/net/spdy/spdy_http_stream_unittest.cc @@ -3,113 +3,56 @@ // found in the LICENSE file. #include "net/spdy/spdy_http_stream.h" -#include "base/ref_counted.h" -#include "base/time.h" -#include "net/base/mock_host_resolver.h" -#include "net/base/net_errors.h" -#include "net/base/net_log.h" -#include "net/base/ssl_config_service.h" -#include "net/base/ssl_config_service_defaults.h" -#include "net/base/test_completion_callback.h" -#include "net/http/http_auth_handler_factory.h" -#include "net/http/http_network_session.h" -#include "net/http/http_request_info.h" -#include "net/http/http_response_info.h" -#include "net/proxy/proxy_service.h" -#include "net/socket/socket_test_util.h" #include "net/spdy/spdy_session.h" -#include "net/spdy/spdy_session_pool.h" +#include "net/spdy/spdy_test_util.h" #include "testing/gtest/include/gtest/gtest.h" namespace net { -class SpdySessionPoolPeer { - public: - explicit SpdySessionPoolPeer(const scoped_refptr<SpdySessionPool>& pool) - : pool_(pool) {} - - void RemoveSpdySession(const scoped_refptr<SpdySession>& session) { - pool_->Remove(session); - } - - private: - const scoped_refptr<SpdySessionPool> pool_; - - DISALLOW_COPY_AND_ASSIGN(SpdySessionPoolPeer); -}; - -namespace { - -// Create a proxy service which fails on all requests (falls back to direct). -ProxyService* CreateNullProxyService() { - return ProxyService::CreateNull(); -} - -// Helper to manage the lifetimes of the dependencies for a -// SpdyNetworkTransaction. -class SessionDependencies { - public: - // Default set of dependencies -- "null" proxy service. - SessionDependencies() - : host_resolver(new MockHostResolver), - proxy_service(CreateNullProxyService()), - ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool()) {} - - // Custom proxy service dependency. - explicit SessionDependencies(ProxyService* proxy_service) - : host_resolver(new MockHostResolver), - proxy_service(proxy_service), - ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool()) {} - - scoped_refptr<MockHostResolverBase> host_resolver; - scoped_refptr<ProxyService> proxy_service; - scoped_refptr<SSLConfigService> ssl_config_service; - MockClientSocketFactory socket_factory; - scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; - scoped_refptr<SpdySessionPool> spdy_session_pool; -}; - -HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { - return new HttpNetworkSession(session_deps->host_resolver, - session_deps->proxy_service, - &session_deps->socket_factory, - session_deps->ssl_config_service, - session_deps->spdy_session_pool, - session_deps->http_auth_handler_factory.get(), - NULL, - NULL); -} - class SpdyHttpStreamTest : public testing::Test { protected: - SpdyHttpStreamTest() - : session_(CreateSession(&session_deps_)), - pool_peer_(session_->spdy_session_pool()) {} + SpdyHttpStreamTest(){} - scoped_refptr<SpdySession> CreateSpdySession() { - HostPortPair host_port_pair("www.google.com", 80); - scoped_refptr<SpdySession> session( - session_->spdy_session_pool()->Get( - host_port_pair, session_, BoundNetLog())); - return session; + void EnableCompression(bool enabled) { + spdy::SpdyFramer::set_enable_compression_default(enabled); } virtual void TearDown() { MessageLoop::current()->RunAllPending(); } - - SessionDependencies session_deps_; - scoped_refptr<HttpNetworkSession> session_; - SpdySessionPoolPeer pool_peer_; }; -// Needs fixing, see http://crbug.com/28622 TEST_F(SpdyHttpStreamTest, SendRequest) { - scoped_refptr<SpdySession> session(CreateSpdySession()); + EnableCompression(false); + SpdySession::SetSSLMode(false); + + SpdySessionDependencies session_deps; + scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); + MockWrite writes[] = { + CreateMockWrite(*req.get(), 1), + }; + MockRead reads[] = { + MockRead(false, 0, 2) // EOF + }; + scoped_refptr<OrderedSocketData> data( + new OrderedSocketData(reads, arraysize(reads), + writes, arraysize(writes))); + session_deps.socket_factory.AddSocketDataProvider(data.get()); + + scoped_refptr<HttpNetworkSession> http_session( + SpdySessionDependencies::SpdyCreateSession(&session_deps)); + scoped_refptr<SpdySessionPool> spdy_session_pool( + http_session->spdy_session_pool()); + HostPortPair host_port_pair("www.google.com", 80); + scoped_refptr<SpdySession> session = + spdy_session_pool->Get( + host_port_pair, http_session.get(), BoundNetLog()); + scoped_refptr<TCPSocketParams> tcp_params = + new TCPSocketParams(host_port_pair.host, host_port_pair.port, + MEDIUM, GURL(), false); + int rv = session->Connect(host_port_pair.host, tcp_params, MEDIUM); + ASSERT_EQ(OK, rv); + HttpRequestInfo request; request.method = "GET"; request.url = GURL("http://www.google.com/"); @@ -122,15 +65,12 @@ TEST_F(SpdyHttpStreamTest, SendRequest) { http_stream->InitializeRequest(base::Time::Now(), NULL); EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(&response, &callback)); - - // Need to manually remove the spdy session since normally it gets removed on - // socket close/error, but we aren't communicating over a socket here. - pool_peer_.RemoveSpdySession(session); + MessageLoop::current()->RunAllPending(); + EXPECT_TRUE(spdy_session_pool->HasSession(host_port_pair)); + spdy_session_pool->Remove(session); } // TODO(willchan): Write a longer test for SpdyStream that exercises all // methods. -} // namespace - } // namespace net diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index b71b0ce..7dbc12c 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -2,26 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "net/spdy/spdy_network_transaction.h" - -#include "base/basictypes.h" -#include "base/ref_counted.h" -#include "base/string_util.h" -#include "net/base/completion_callback.h" -#include "net/base/mock_host_resolver.h" #include "net/base/net_log_unittest.h" -#include "net/base/request_priority.h" -#include "net/base/ssl_config_service_defaults.h" -#include "net/base/test_completion_callback.h" -#include "net/base/upload_data.h" -#include "net/http/http_auth_handler_factory.h" -#include "net/http/http_network_session.h" #include "net/http/http_transaction_unittest.h" -#include "net/proxy/proxy_config_service_fixed.h" -#include "net/socket/socket_test_util.h" -#include "net/spdy/spdy_framer.h" #include "net/spdy/spdy_http_stream.h" -#include "net/spdy/spdy_protocol.h" +#include "net/spdy/spdy_network_transaction.h" #include "net/spdy/spdy_test_util.h" #include "testing/platform_test.h" @@ -62,59 +46,13 @@ class SpdyNetworkTransactionTest : public PlatformTest { class StartTransactionCallback; class DeleteSessionCallback; - // Helper to manage the lifetimes of the dependencies for a - // HttpNetworkTransaction. - class SessionDependencies { - public: - // Default set of dependencies -- "null" proxy service. - SessionDependencies() - : host_resolver(new MockHostResolver), - proxy_service(ProxyService::CreateNull()), - ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool()) { - // Note: The CancelledTransaction test does cleanup by running all - // tasks in the message loop (RunAllPending). Unfortunately, that - // doesn't clean up tasks on the host resolver thread; and - // TCPConnectJob is currently not cancellable. Using synchronous - // lookups allows the test to shutdown cleanly. Until we have - // cancellable TCPConnectJobs, use synchronous lookups. - host_resolver->set_synchronous_mode(true); - } - - // Custom proxy service dependency. - explicit SessionDependencies(ProxyService* proxy_service) - : host_resolver(new MockHostResolver), - proxy_service(proxy_service), - ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool()) {} - - scoped_refptr<MockHostResolverBase> host_resolver; - scoped_refptr<ProxyService> proxy_service; - scoped_refptr<SSLConfigService> ssl_config_service; - MockClientSocketFactory socket_factory; - scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; - scoped_refptr<SpdySessionPool> spdy_session_pool; - }; - - static HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { - return new HttpNetworkSession(session_deps->host_resolver, - session_deps->proxy_service, - &session_deps->socket_factory, - session_deps->ssl_config_service, - session_deps->spdy_session_pool, - session_deps->http_auth_handler_factory.get(), - NULL, - NULL); - } - // A helper class that handles all the initial npn/ssl setup. class NormalSpdyTransactionHelper { public: NormalSpdyTransactionHelper(const HttpRequestInfo& request, const BoundNetLog& log) - : request_(request), session_(CreateSession(&session_deps_)), + : request_(request), + session_(SpdySessionDependencies::SpdyCreateSession(&session_deps_)), log_(log), add_data_allowed_(true) {} void RunPreTestSetup() { @@ -265,7 +203,7 @@ class SpdyNetworkTransactionTest : public PlatformTest { typedef std::vector<StaticSocketDataProvider*> DataVector; typedef std::vector<linked_ptr<SSLSocketDataProvider> > SSLVector; HttpRequestInfo request_; - SessionDependencies session_deps_; + SpdySessionDependencies session_deps_; scoped_refptr<HttpNetworkSession> session_; TransactionHelperResult output_; scoped_ptr<StaticSocketDataProvider> first_transaction_; @@ -302,9 +240,9 @@ class SpdyNetworkTransactionTest : public PlatformTest { // Verify HttpNetworkTransaction constructor. TEST_F(SpdyNetworkTransactionTest, Constructor) { - SessionDependencies session_deps; + SpdySessionDependencies session_deps; scoped_refptr<HttpNetworkSession> session = - CreateSession(&session_deps); + SpdySessionDependencies::SpdyCreateSession(&session_deps); scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); } @@ -385,8 +323,9 @@ TEST_F(SpdyNetworkTransactionTest, ThreeGets) { BoundNetLog log; TransactionHelperResult out; { - SessionDependencies session_deps; - HttpNetworkSession* session = CreateSession(&session_deps); + SpdySessionDependencies session_deps; + HttpNetworkSession* session = + SpdySessionDependencies::SpdyCreateSession(&session_deps); SpdySession::SetSSLMode(false); scoped_ptr<SpdyNetworkTransaction> trans1( new SpdyNetworkTransaction(session)); @@ -494,8 +433,9 @@ TEST_F(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { BoundNetLog log; TransactionHelperResult out; { - SessionDependencies session_deps; - HttpNetworkSession* session = CreateSession(&session_deps); + SpdySessionDependencies session_deps; + HttpNetworkSession* session = + SpdySessionDependencies::SpdyCreateSession(&session_deps); SpdySession::SetSSLMode(false); scoped_ptr<SpdyNetworkTransaction> trans1( new SpdyNetworkTransaction(session)); @@ -628,8 +568,9 @@ TEST_F(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { BoundNetLog log; TransactionHelperResult out; { - SessionDependencies session_deps; - HttpNetworkSession* session = CreateSession(&session_deps); + SpdySessionDependencies session_deps; + HttpNetworkSession* session = + SpdySessionDependencies::SpdyCreateSession(&session_deps); SpdySession::SetSSLMode(false); scoped_ptr<SpdyNetworkTransaction> trans1( new SpdyNetworkTransaction(session)); @@ -768,8 +709,9 @@ TEST_F(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { BoundNetLog log; TransactionHelperResult out; { - SessionDependencies session_deps; - HttpNetworkSession* session = CreateSession(&session_deps); + SpdySessionDependencies session_deps; + HttpNetworkSession* session = + SpdySessionDependencies::SpdyCreateSession(&session_deps); SpdySession::SetSSLMode(false); scoped_ptr<SpdyNetworkTransaction> trans1( new SpdyNetworkTransaction(session)); @@ -1000,8 +942,9 @@ TEST_F(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { // Test that WINDOW_UPDATE frames change window_size correctly. TEST_F(SpdyNetworkTransactionTest, WindowUpdate) { - SessionDependencies session_deps; - scoped_refptr<HttpNetworkSession> session = CreateSession(&session_deps); + SpdySessionDependencies session_deps; + scoped_refptr<HttpNetworkSession> session = + SpdySessionDependencies::SpdyCreateSession(&session_deps); // We disable SSL for this test. SpdySession::SetSSLMode(false); @@ -1062,8 +1005,9 @@ TEST_F(SpdyNetworkTransactionTest, WindowUpdate) { // Test that WINDOW_UPDATE frame causing overflow is handled correctly. TEST_F(SpdyNetworkTransactionTest, WindowUpdateOverflow) { - SessionDependencies session_deps; - scoped_refptr<HttpNetworkSession> session = CreateSession(&session_deps); + SpdySessionDependencies session_deps; + scoped_refptr<HttpNetworkSession> session = + SpdySessionDependencies::SpdyCreateSession(&session_deps); // We disable SSL for this test. SpdySession::SetSSLMode(false); @@ -1156,7 +1100,7 @@ TEST_F(SpdyNetworkTransactionTest, CancelledTransaction) { EXPECT_EQ(ERR_IO_PENDING, rv); helper.ResetTrans(); // Cancel the transaction. - // Flush the MessageLoop while the SessionDependencies (in particular, the + // Flush the MessageLoop while the SpdySessionDependencies (in particular, the // MockClientSocketFactory) are still alive. MessageLoop::current()->RunAllPending(); helper.VerifyDataNotConsumed(); @@ -1890,7 +1834,7 @@ TEST_F(SpdyNetworkTransactionTest, BufferFull) { out.response_data.swap(content); - // Flush the MessageLoop while the SessionDependencies (in particular, the + // Flush the MessageLoop while the SpdySessionDependencies (in particular, the // MockClientSocketFactory) are still alive. MessageLoop::current()->RunAllPending(); @@ -2054,7 +1998,7 @@ TEST_F(SpdyNetworkTransactionTest, Buffering) { out.response_data.swap(content); - // Flush the MessageLoop while the SessionDependencies (in particular, the + // Flush the MessageLoop while the SpdySessionDependencies (in particular, the // MockClientSocketFactory) are still alive. MessageLoop::current()->RunAllPending(); @@ -2145,7 +2089,7 @@ TEST_F(SpdyNetworkTransactionTest, BufferedAll) { out.response_data.swap(content); - // Flush the MessageLoop while the SessionDependencies (in particular, the + // Flush the MessageLoop while the SpdySessionDependencies (in particular, the // MockClientSocketFactory) are still alive. MessageLoop::current()->RunAllPending(); @@ -2239,7 +2183,7 @@ TEST_F(SpdyNetworkTransactionTest, BufferedClosed) { out.response_data.swap(content); - // Flush the MessageLoop while the SessionDependencies (in particular, the + // Flush the MessageLoop while the SpdySessionDependencies (in particular, the // MockClientSocketFactory) are still alive. MessageLoop::current()->RunAllPending(); diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc index 195fb10..c012347 100644 --- a/net/spdy/spdy_session_unittest.cc +++ b/net/spdy/spdy_session_unittest.cc @@ -3,18 +3,7 @@ // found in the LICENSE file. #include "net/spdy/spdy_io_buffer.h" - -#include "googleurl/src/gurl.h" -#include "net/base/mock_host_resolver.h" -#include "net/base/ssl_config_service_defaults.h" -#include "net/base/test_completion_callback.h" -#include "net/http/http_network_session.h" -#include "net/http/http_response_info.h" -#include "net/proxy/proxy_service.h" -#include "net/socket/socket_test_util.h" -#include "net/spdy/spdy_http_stream.h" #include "net/spdy/spdy_session.h" -#include "net/spdy/spdy_session_pool.h" #include "net/spdy/spdy_stream.h" #include "net/spdy/spdy_test_util.h" #include "testing/platform_test.h" @@ -31,37 +20,6 @@ class SpdySessionTest : public PlatformTest { }; namespace { - -// Helper to manage the lifetimes of the dependencies for a -// SpdyNetworkTransaction. -class SessionDependencies { - public: - // Default set of dependencies -- "null" proxy service. - SessionDependencies() - : host_resolver(new MockHostResolver), - proxy_service(ProxyService::CreateNull()), - ssl_config_service(new SSLConfigServiceDefaults), - spdy_session_pool(new SpdySessionPool()) { - } - - scoped_refptr<MockHostResolverBase> host_resolver; - scoped_refptr<ProxyService> proxy_service; - scoped_refptr<SSLConfigService> ssl_config_service; - MockClientSocketFactory socket_factory; - scoped_refptr<SpdySessionPool> spdy_session_pool; -}; - -HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { - return new HttpNetworkSession(session_deps->host_resolver, - session_deps->proxy_service, - &session_deps->socket_factory, - session_deps->ssl_config_service, - session_deps->spdy_session_pool, - NULL, - NULL, - NULL); -} - // Test the SpdyIOBuffer class. TEST_F(SpdySessionTest, SpdyIOBuffer) { std::priority_queue<SpdyIOBuffer> queue_; @@ -100,7 +58,7 @@ TEST_F(SpdySessionTest, SpdyIOBuffer) { } TEST_F(SpdySessionTest, GoAway) { - SessionDependencies session_deps; + SpdySessionDependencies session_deps; session_deps.host_resolver->set_synchronous_mode(true); MockConnect connect_data(false, OK); @@ -116,7 +74,8 @@ TEST_F(SpdySessionTest, GoAway) { SSLSocketDataProvider ssl(false, OK); session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); - scoped_refptr<HttpNetworkSession> http_session(CreateSession(&session_deps)); + scoped_refptr<HttpNetworkSession> http_session( + SpdySessionDependencies::SpdyCreateSession(&session_deps)); const std::string kTestHost("www.foo.com"); const int kTestPort = 80; @@ -160,7 +119,7 @@ TEST_F(SpdySessionTest, GetActivePushStream) { spdy::SpdyFramer framer; SpdySessionTest::TurnOffCompression(); - SessionDependencies session_deps; + SpdySessionDependencies session_deps; session_deps.host_resolver->set_synchronous_mode(true); MockConnect connect_data(false, OK); @@ -181,7 +140,8 @@ TEST_F(SpdySessionTest, GetActivePushStream) { SSLSocketDataProvider ssl(false, OK); session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); - scoped_refptr<HttpNetworkSession> http_session(CreateSession(&session_deps)); + scoped_refptr<HttpNetworkSession> http_session( + SpdySessionDependencies::SpdyCreateSession(&session_deps)); const std::string kTestHost("www.foo.com"); const int kTestPort = 80; diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc index e668789..4daad96 100644 --- a/net/spdy/spdy_stream_unittest.cc +++ b/net/spdy/spdy_stream_unittest.cc @@ -4,22 +4,7 @@ #include "net/spdy/spdy_stream.h" #include "base/ref_counted.h" -#include "base/time.h" -#include "net/base/mock_host_resolver.h" -#include "net/base/net_errors.h" -#include "net/base/net_log.h" -#include "net/base/ssl_config_service.h" -#include "net/base/ssl_config_service_defaults.h" -#include "net/base/test_completion_callback.h" -#include "net/http/http_auth_handler_factory.h" -#include "net/http/http_network_session.h" -#include "net/http/http_request_info.h" -#include "net/http/http_response_info.h" -#include "net/proxy/proxy_service.h" -#include "net/socket/socket_test_util.h" -#include "net/spdy/spdy_framer.h" #include "net/spdy/spdy_session.h" -#include "net/spdy/spdy_session_pool.h" #include "net/spdy/spdy_test_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -48,45 +33,6 @@ ProxyService* CreateNullProxyService() { return ProxyService::CreateNull(); } -// Helper to manage the lifetimes of the dependencies for a -// SpdyNetworkTransaction. -class SessionDependencies { - public: - // Default set of dependencies -- "null" proxy service. - SessionDependencies() - : host_resolver(new MockHostResolver), - proxy_service(CreateNullProxyService()), - ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool()) {} - - // Custom proxy service dependency. - explicit SessionDependencies(ProxyService* proxy_service) - : host_resolver(new MockHostResolver), - proxy_service(proxy_service), - ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool()) {} - - scoped_refptr<MockHostResolverBase> host_resolver; - scoped_refptr<ProxyService> proxy_service; - scoped_refptr<SSLConfigService> ssl_config_service; - MockClientSocketFactory socket_factory; - scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; - scoped_refptr<SpdySessionPool> spdy_session_pool; -}; - -HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { - return new HttpNetworkSession(session_deps->host_resolver, - session_deps->proxy_service, - &session_deps->socket_factory, - session_deps->ssl_config_service, - session_deps->spdy_session_pool, - session_deps->http_auth_handler_factory.get(), - NULL, - NULL); -} - class TestSpdyStreamDelegate : public SpdyStream::Delegate { public: TestSpdyStreamDelegate(SpdyStream* stream, @@ -186,9 +132,9 @@ class SpdyStreamTest : public testing::Test { }; TEST_F(SpdyStreamTest, SendDataAfterOpen) { - SessionDependencies session_deps; + SpdySessionDependencies session_deps; - session_ = CreateSession(&session_deps); + session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); const SpdyHeaderInfo kSynStartHeader = { diff --git a/net/spdy/spdy_test_util.h b/net/spdy/spdy_test_util.h index 7549b15..6e7a8d0 100644 --- a/net/spdy/spdy_test_util.h +++ b/net/spdy/spdy_test_util.h @@ -6,9 +6,15 @@ #define NET_SPDY_SPDY_TEST_UTIL_H_ #include "base/basictypes.h" +#include "net/base/mock_host_resolver.h" #include "net/base/request_priority.h" +#include "net/base/ssl_config_service_defaults.h" +#include "net/http/http_auth_handler_factory.h" +#include "net/http/http_network_session.h" +#include "net/proxy/proxy_service.h" #include "net/socket/socket_test_util.h" #include "net/spdy/spdy_framer.h" +#include "net/spdy/spdy_session_pool.h" namespace net { @@ -195,6 +201,55 @@ MockRead CreateMockRead(const spdy::SpdyFrame& resp, int seq); int CombineFrames(const spdy::SpdyFrame** frames, int num_frames, char* buff, int buff_len); +// Helper to manage the lifetimes of the dependencies for a +// HttpNetworkTransaction. +class SpdySessionDependencies { + public: + // Default set of dependencies -- "null" proxy service. + SpdySessionDependencies() + : host_resolver(new MockHostResolver), + proxy_service(ProxyService::CreateNull()), + ssl_config_service(new SSLConfigServiceDefaults), + http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), + spdy_session_pool(new SpdySessionPool()) { + // Note: The CancelledTransaction test does cleanup by running all + // tasks in the message loop (RunAllPending). Unfortunately, that + // doesn't clean up tasks on the host resolver thread; and + // TCPConnectJob is currently not cancellable. Using synchronous + // lookups allows the test to shutdown cleanly. Until we have + // cancellable TCPConnectJobs, use synchronous lookups. + host_resolver->set_synchronous_mode(true); + } + + // Custom proxy service dependency. + explicit SpdySessionDependencies(ProxyService* proxy_service) + : host_resolver(new MockHostResolver), + proxy_service(proxy_service), + ssl_config_service(new SSLConfigServiceDefaults), + http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), + spdy_session_pool(new SpdySessionPool()) {} + + scoped_refptr<MockHostResolverBase> host_resolver; + scoped_refptr<ProxyService> proxy_service; + scoped_refptr<SSLConfigService> ssl_config_service; + MockClientSocketFactory socket_factory; + scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; + scoped_refptr<SpdySessionPool> spdy_session_pool; + + static HttpNetworkSession* SpdyCreateSession( + SpdySessionDependencies* session_deps) { + return new HttpNetworkSession(session_deps->host_resolver, + session_deps->proxy_service, + &session_deps->socket_factory, + session_deps->ssl_config_service, + session_deps->spdy_session_pool, + session_deps->http_auth_handler_factory.get(), + NULL, + NULL); +} +}; + + } // namespace net #endif // NET_SPDY_SPDY_TEST_UTIL_H_ |