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