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/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 scoped_refptr<HttpNetworkSession> http_session_; | 174 scoped_refptr<HttpNetworkSession> http_session_; |
175 SpdySessionPool* spdy_session_pool_; | 175 SpdySessionPool* spdy_session_pool_; |
176 GURL test_url_; | 176 GURL test_url_; |
177 HostPortPair test_host_port_pair_; | 177 HostPortPair test_host_port_pair_; |
178 SpdySessionKey key_; | 178 SpdySessionKey key_; |
179 }; | 179 }; |
180 | 180 |
181 INSTANTIATE_TEST_CASE_P( | 181 INSTANTIATE_TEST_CASE_P( |
182 NextProto, | 182 NextProto, |
183 SpdySessionTest, | 183 SpdySessionTest, |
184 testing::Values(kProtoDeprecatedSPDY2, | 184 testing::Values(kProtoSPDY31, kProtoSPDY4_14, kProtoSPDY4_15)); |
185 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4_14, kProtoSPDY4_15)); | |
186 | 185 |
187 // Try to create a SPDY session that will fail during | 186 // Try to create a SPDY session that will fail during |
188 // initialization. Nothing should blow up. | 187 // initialization. Nothing should blow up. |
189 TEST_P(SpdySessionTest, InitialReadError) { | 188 TEST_P(SpdySessionTest, InitialReadError) { |
190 CreateDeterministicNetworkSession(); | 189 CreateDeterministicNetworkSession(); |
191 | 190 |
192 base::WeakPtr<SpdySession> session = TryCreateFakeSpdySessionExpectingFailure( | 191 base::WeakPtr<SpdySession> session = TryCreateFakeSpdySessionExpectingFailure( |
193 spdy_session_pool_, key_, ERR_CONNECTION_CLOSED); | 192 spdy_session_pool_, key_, ERR_CONNECTION_CLOSED); |
194 EXPECT_TRUE(session); | 193 EXPECT_TRUE(session); |
195 // Flush the read. | 194 // Flush the read. |
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1791 spdy_util_.ConstructGetHeaderBlock(url.spec())); | 1790 spdy_util_.ConstructGetHeaderBlock(url.spec())); |
1792 spdy_stream->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND); | 1791 spdy_stream->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND); |
1793 EXPECT_TRUE(spdy_stream->HasUrlFromHeaders()); | 1792 EXPECT_TRUE(spdy_stream->HasUrlFromHeaders()); |
1794 | 1793 |
1795 // Write request headers & capture resulting histogram update. | 1794 // Write request headers & capture resulting histogram update. |
1796 base::HistogramTester histogram_tester; | 1795 base::HistogramTester histogram_tester; |
1797 | 1796 |
1798 data.RunFor(1); | 1797 data.RunFor(1); |
1799 // Regression test of compression performance under the request fixture. | 1798 // Regression test of compression performance under the request fixture. |
1800 switch (spdy_util_.spdy_version()) { | 1799 switch (spdy_util_.spdy_version()) { |
1801 case SPDY2: | |
1802 histogram_tester.ExpectBucketCount( | |
1803 "Net.SpdySynStreamCompressionPercentage", 0, 1); | |
1804 break; | |
1805 case SPDY3: | 1800 case SPDY3: |
1806 histogram_tester.ExpectBucketCount( | 1801 histogram_tester.ExpectBucketCount( |
1807 "Net.SpdySynStreamCompressionPercentage", 30, 1); | 1802 "Net.SpdySynStreamCompressionPercentage", 30, 1); |
1808 break; | 1803 break; |
1809 case SPDY4: | 1804 case SPDY4: |
1810 histogram_tester.ExpectBucketCount( | 1805 histogram_tester.ExpectBucketCount( |
1811 "Net.SpdySynStreamCompressionPercentage", 82, 1); | 1806 "Net.SpdySynStreamCompressionPercentage", 82, 1); |
1812 break; | 1807 break; |
1813 case SPDY5: | 1808 case SPDY5: |
1814 histogram_tester.ExpectBucketCount( | 1809 histogram_tester.ExpectBucketCount( |
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3077 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 3072 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
3078 data.set_connect_data(connect_data); | 3073 data.set_connect_data(connect_data); |
3079 session_deps_.socket_factory->AddSocketDataProvider(&data); | 3074 session_deps_.socket_factory->AddSocketDataProvider(&data); |
3080 | 3075 |
3081 CreateNetworkSession(); | 3076 CreateNetworkSession(); |
3082 base::WeakPtr<SpdySession> session = | 3077 base::WeakPtr<SpdySession> session = |
3083 CreateFakeSpdySession(spdy_session_pool_, key_); | 3078 CreateFakeSpdySession(spdy_session_pool_, key_); |
3084 | 3079 |
3085 EXPECT_EQ(spdy_util_.spdy_version(), | 3080 EXPECT_EQ(spdy_util_.spdy_version(), |
3086 session->buffered_spdy_framer_->protocol_version()); | 3081 session->buffered_spdy_framer_->protocol_version()); |
3087 if (GetParam() == kProtoDeprecatedSPDY2) { | 3082 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, |
3088 EXPECT_EQ(SpdySession::FLOW_CONTROL_NONE, session->flow_control_state()); | 3083 session->flow_control_state()); |
3089 EXPECT_EQ(0, session->session_send_window_size_); | 3084 EXPECT_EQ(kSpdySessionInitialWindowSize, |
3090 EXPECT_EQ(0, session->session_recv_window_size_); | 3085 session->session_send_window_size_); |
3091 } else if (GetParam() == kProtoSPDY3) { | 3086 EXPECT_EQ(kSpdySessionInitialWindowSize, |
3092 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM, session->flow_control_state()); | 3087 session->session_recv_window_size_); |
3093 EXPECT_EQ(0, session->session_send_window_size_); | |
3094 EXPECT_EQ(0, session->session_recv_window_size_); | |
3095 } else { | |
3096 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, | |
3097 session->flow_control_state()); | |
3098 EXPECT_EQ(kSpdySessionInitialWindowSize, | |
3099 session->session_send_window_size_); | |
3100 EXPECT_EQ(kSpdySessionInitialWindowSize, | |
3101 session->session_recv_window_size_); | |
3102 } | |
3103 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3088 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
3104 } | 3089 } |
3105 | 3090 |
3106 // Tests the case of a non-SPDY request closing an idle SPDY session when no | 3091 // Tests the case of a non-SPDY request closing an idle SPDY session when no |
3107 // pointers to the idle session are currently held. | 3092 // pointers to the idle session are currently held. |
3108 TEST_P(SpdySessionTest, CloseOneIdleConnection) { | 3093 TEST_P(SpdySessionTest, CloseOneIdleConnection) { |
3109 ClientSocketPoolManager::set_max_sockets_per_group( | 3094 ClientSocketPoolManager::set_max_sockets_per_group( |
3110 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | 3095 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
3111 ClientSocketPoolManager::set_max_sockets_per_pool( | 3096 ClientSocketPoolManager::set_max_sockets_per_pool( |
3112 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | 3097 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3448 | 3433 |
3449 EXPECT_EQ(NULL, spdy_stream.get()); | 3434 EXPECT_EQ(NULL, spdy_stream.get()); |
3450 EXPECT_TRUE(delegate.StreamIsClosed()); | 3435 EXPECT_TRUE(delegate.StreamIsClosed()); |
3451 EXPECT_EQ(0u, session->num_active_streams()); | 3436 EXPECT_EQ(0u, session->num_active_streams()); |
3452 EXPECT_EQ(1u, session->num_created_streams()); | 3437 EXPECT_EQ(1u, session->num_created_streams()); |
3453 } | 3438 } |
3454 | 3439 |
3455 // The tests below are only for SPDY/3 and above. | 3440 // The tests below are only for SPDY/3 and above. |
3456 | 3441 |
3457 TEST_P(SpdySessionTest, UpdateStreamsSendWindowSize) { | 3442 TEST_P(SpdySessionTest, UpdateStreamsSendWindowSize) { |
3458 if (GetParam() < kProtoSPDY3) | |
3459 return; | |
3460 | |
3461 // Set SETTINGS_INITIAL_WINDOW_SIZE to a small number so that WINDOW_UPDATE | 3443 // Set SETTINGS_INITIAL_WINDOW_SIZE to a small number so that WINDOW_UPDATE |
3462 // gets sent. | 3444 // gets sent. |
3463 SettingsMap new_settings; | 3445 SettingsMap new_settings; |
3464 int32 window_size = 1; | 3446 int32 window_size = 1; |
3465 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = | 3447 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
3466 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, window_size); | 3448 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, window_size); |
3467 | 3449 |
3468 // Set up the socket so we read a SETTINGS frame that sets | 3450 // Set up the socket so we read a SETTINGS frame that sets |
3469 // INITIAL_WINDOW_SIZE. | 3451 // INITIAL_WINDOW_SIZE. |
3470 MockConnect connect_data(SYNCHRONOUS, OK); | 3452 MockConnect connect_data(SYNCHRONOUS, OK); |
(...skipping 1667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5138 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5120 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
5139 "spdy_pooling.pem"); | 5121 "spdy_pooling.pem"); |
5140 ssl_info.is_issued_by_known_root = true; | 5122 ssl_info.is_issued_by_known_root = true; |
5141 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 5123 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
5142 | 5124 |
5143 EXPECT_TRUE(SpdySession::CanPool( | 5125 EXPECT_TRUE(SpdySession::CanPool( |
5144 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5126 &tss, ssl_info, "www.example.org", "mail.example.org")); |
5145 } | 5127 } |
5146 | 5128 |
5147 } // namespace net | 5129 } // namespace net |
OLD | NEW |