OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 2832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2843 EXPECT_TRUE(pool->IsStalled()); | 2843 EXPECT_TRUE(pool->IsStalled()); |
2844 | 2844 |
2845 // The socket pool should close the connection asynchronously and establish a | 2845 // The socket pool should close the connection asynchronously and establish a |
2846 // new connection. | 2846 // new connection. |
2847 EXPECT_EQ(OK, callback3.WaitForResult()); | 2847 EXPECT_EQ(OK, callback3.WaitForResult()); |
2848 EXPECT_FALSE(pool->IsStalled()); | 2848 EXPECT_FALSE(pool->IsStalled()); |
2849 EXPECT_TRUE(session1 == NULL); | 2849 EXPECT_TRUE(session1 == NULL); |
2850 EXPECT_TRUE(session2 == NULL); | 2850 EXPECT_TRUE(session2 == NULL); |
2851 } | 2851 } |
2852 | 2852 |
2853 // Tests that a non-SPDY request can't close a SPDY session that's currently in | 2853 // Tests that when a SPDY session becomes idle, it closes itself if there is |
2854 // use. | 2854 // a lower layer pool stalled on the per-pool socket limit. |
2855 TEST_P(SpdySessionTest, CloseOneIdleConnectionFailsWhenSessionInUse) { | 2855 TEST_P(SpdySessionTest, CloseSessionOnIdleWhenPoolStalled) { |
2856 ClientSocketPoolManager::set_max_sockets_per_group( | 2856 ClientSocketPoolManager::set_max_sockets_per_group( |
2857 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | 2857 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
2858 ClientSocketPoolManager::set_max_sockets_per_pool( | 2858 ClientSocketPoolManager::set_max_sockets_per_pool( |
2859 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | 2859 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
2860 | 2860 |
2861 MockConnect connect_data(SYNCHRONOUS, OK); | 2861 MockConnect connect_data(SYNCHRONOUS, OK); |
2862 MockRead reads[] = { | 2862 MockRead reads[] = { |
2863 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 2863 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
2864 }; | 2864 }; |
2865 scoped_ptr<SpdyFrame> req1( | 2865 scoped_ptr<SpdyFrame> req1( |
2866 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2866 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
2867 scoped_ptr<SpdyFrame> cancel1( | 2867 scoped_ptr<SpdyFrame> cancel1( |
2868 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 2868 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
2869 MockWrite writes[] = { | 2869 MockWrite writes[] = { |
2870 CreateMockWrite(*req1, 1), | 2870 CreateMockWrite(*req1, 1), |
2871 CreateMockWrite(*cancel1, 1), | 2871 CreateMockWrite(*cancel1, 1), |
2872 }; | 2872 }; |
2873 StaticSocketDataProvider data(reads, arraysize(reads), | 2873 StaticSocketDataProvider data(reads, arraysize(reads), |
2874 writes, arraysize(writes)); | 2874 writes, arraysize(writes)); |
2875 data.set_connect_data(connect_data); | 2875 data.set_connect_data(connect_data); |
2876 session_deps_.socket_factory->AddSocketDataProvider(&data); | 2876 session_deps_.socket_factory->AddSocketDataProvider(&data); |
2877 | 2877 |
| 2878 MockRead http_reads[] = { |
| 2879 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 2880 }; |
| 2881 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 2882 NULL, 0); |
| 2883 http_data.set_connect_data(connect_data); |
| 2884 session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 2885 |
| 2886 |
2878 CreateNetworkSession(); | 2887 CreateNetworkSession(); |
2879 | 2888 |
2880 TransportClientSocketPool* pool = | 2889 TransportClientSocketPool* pool = |
2881 http_session_->GetTransportSocketPool( | 2890 http_session_->GetTransportSocketPool( |
2882 HttpNetworkSession::NORMAL_SOCKET_POOL); | 2891 HttpNetworkSession::NORMAL_SOCKET_POOL); |
2883 | 2892 |
2884 // Create a SPDY session. | 2893 // Create a SPDY session. |
2885 GURL url1("http://www.google.com"); | 2894 GURL url1("http://www.google.com"); |
2886 SpdySessionKey key1(HostPortPair(url1.host(), 80), | 2895 SpdySessionKey key1(HostPortPair(url1.host(), 80), |
2887 ProxyServer::Direct(), kPrivacyModeDisabled); | 2896 ProxyServer::Direct(), kPrivacyModeDisabled); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2922 callback2.callback(), pool, BoundNetLog())); | 2931 callback2.callback(), pool, BoundNetLog())); |
2923 EXPECT_TRUE(pool->IsStalled()); | 2932 EXPECT_TRUE(pool->IsStalled()); |
2924 | 2933 |
2925 // Running the message loop should cause the socket pool to ask the SPDY | 2934 // Running the message loop should cause the socket pool to ask the SPDY |
2926 // session to close an idle socket, but since the socket is in use, nothing | 2935 // session to close an idle socket, but since the socket is in use, nothing |
2927 // happens. | 2936 // happens. |
2928 base::RunLoop().RunUntilIdle(); | 2937 base::RunLoop().RunUntilIdle(); |
2929 EXPECT_TRUE(pool->IsStalled()); | 2938 EXPECT_TRUE(pool->IsStalled()); |
2930 EXPECT_FALSE(callback2.have_result()); | 2939 EXPECT_FALSE(callback2.have_result()); |
2931 | 2940 |
2932 // Cancelling the request should still not release the session's socket, | 2941 // Cancelling the request should result in the session's socket being |
2933 // since the session is still kept alive by the SpdySessionPool. | 2942 // closed, since the pool is stalled. |
2934 ASSERT_TRUE(spdy_stream1.get()); | 2943 ASSERT_TRUE(spdy_stream1.get()); |
2935 spdy_stream1->Cancel(); | 2944 spdy_stream1->Cancel(); |
2936 base::RunLoop().RunUntilIdle(); | 2945 base::RunLoop().RunUntilIdle(); |
2937 EXPECT_TRUE(pool->IsStalled()); | 2946 ASSERT_FALSE(pool->IsStalled()); |
2938 EXPECT_FALSE(callback2.have_result()); | 2947 EXPECT_EQ(OK, callback2.WaitForResult()); |
2939 EXPECT_TRUE(session1 != NULL); | |
2940 } | 2948 } |
2941 | 2949 |
2942 // Verify that SpdySessionKey and therefore SpdySession is different when | 2950 // Verify that SpdySessionKey and therefore SpdySession is different when |
2943 // privacy mode is enabled or disabled. | 2951 // privacy mode is enabled or disabled. |
2944 TEST_P(SpdySessionTest, SpdySessionKeyPrivacyMode) { | 2952 TEST_P(SpdySessionTest, SpdySessionKeyPrivacyMode) { |
2945 CreateDeterministicNetworkSession(); | 2953 CreateDeterministicNetworkSession(); |
2946 | 2954 |
2947 HostPortPair host_port_pair("www.google.com", 443); | 2955 HostPortPair host_port_pair("www.google.com", 443); |
2948 SpdySessionKey key_privacy_enabled(host_port_pair, ProxyServer::Direct(), | 2956 SpdySessionKey key_privacy_enabled(host_port_pair, ProxyServer::Direct(), |
2949 kPrivacyModeEnabled); | 2957 kPrivacyModeEnabled); |
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4197 EXPECT_TRUE(delegate1.send_headers_completed()); | 4205 EXPECT_TRUE(delegate1.send_headers_completed()); |
4198 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); | 4206 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); |
4199 | 4207 |
4200 EXPECT_TRUE(delegate2.send_headers_completed()); | 4208 EXPECT_TRUE(delegate2.send_headers_completed()); |
4201 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); | 4209 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); |
4202 | 4210 |
4203 EXPECT_TRUE(data.at_write_eof()); | 4211 EXPECT_TRUE(data.at_write_eof()); |
4204 } | 4212 } |
4205 | 4213 |
4206 } // namespace net | 4214 } // namespace net |
OLD | NEW |