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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 4393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4404 EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings( | 4404 EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings( |
4405 host_port_pair).size()); | 4405 host_port_pair).size()); |
4406 | 4406 |
4407 // Construct the initial SETTINGS frame. | 4407 // Construct the initial SETTINGS frame. |
4408 SettingsMap initial_settings; | 4408 SettingsMap initial_settings; |
4409 initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = | 4409 initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
4410 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); | 4410 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
4411 scoped_ptr<SpdyFrame> initial_settings_frame( | 4411 scoped_ptr<SpdyFrame> initial_settings_frame( |
4412 spdy_util_.ConstructSpdySettings(initial_settings)); | 4412 spdy_util_.ConstructSpdySettings(initial_settings)); |
4413 | 4413 |
4414 // Construct the initial window update. | |
4415 scoped_ptr<SpdyFrame> initial_window_update( | |
4416 spdy_util_.ConstructSpdyWindowUpdate( | |
4417 kSessionFlowControlStreamId, | |
4418 kDefaultInitialRecvWindowSize - | |
4419 SpdySession::GetInitialWindowSize(GetParam().protocol))); | |
4420 | |
4421 // Construct the persisted SETTINGS frame. | 4414 // Construct the persisted SETTINGS frame. |
4422 const SettingsMap& settings = | 4415 const SettingsMap& settings = |
4423 spdy_session_pool->http_server_properties()->GetSpdySettings( | 4416 spdy_session_pool->http_server_properties()->GetSpdySettings( |
4424 host_port_pair); | 4417 host_port_pair); |
4425 scoped_ptr<SpdyFrame> settings_frame( | 4418 scoped_ptr<SpdyFrame> settings_frame( |
4426 spdy_util_.ConstructSpdySettings(settings)); | 4419 spdy_util_.ConstructSpdySettings(settings)); |
4427 | 4420 |
4428 // Construct the request. | 4421 // Construct the request. |
4429 scoped_ptr<SpdyFrame> req( | 4422 scoped_ptr<SpdyFrame> req( |
4430 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 4423 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
4431 | 4424 |
4432 std::vector<MockWrite> writes; | 4425 std::vector<MockWrite> writes; |
4433 if ((GetParam().protocol >= kProtoSPDY4MinimumVersion) && | 4426 if ((GetParam().protocol >= kProtoSPDY4MinimumVersion) && |
4434 (GetParam().protocol <= kProtoSPDY4MaximumVersion)) { | 4427 (GetParam().protocol <= kProtoSPDY4MaximumVersion)) { |
4435 writes.push_back( | 4428 writes.push_back( |
4436 MockWrite(ASYNC, | 4429 MockWrite(ASYNC, |
4437 kHttp2ConnectionHeaderPrefix, | 4430 kHttp2ConnectionHeaderPrefix, |
4438 kHttp2ConnectionHeaderPrefixSize)); | 4431 kHttp2ConnectionHeaderPrefixSize)); |
4439 } | 4432 } |
4440 writes.push_back(CreateMockWrite(*initial_settings_frame)); | 4433 writes.push_back(CreateMockWrite(*initial_settings_frame)); |
4441 if (GetParam().protocol >= kProtoSPDY31) { | |
4442 writes.push_back(CreateMockWrite(*initial_window_update)); | |
4443 } | |
4444 writes.push_back(CreateMockWrite(*settings_frame)); | 4434 writes.push_back(CreateMockWrite(*settings_frame)); |
4445 writes.push_back(CreateMockWrite(*req)); | 4435 writes.push_back(CreateMockWrite(*req)); |
4446 | 4436 |
4447 // Construct the reply. | 4437 // Construct the reply. |
4448 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); | 4438 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
4449 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; | 4439 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
4450 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | 4440 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
4451 scoped_ptr<SpdyFrame> reply( | 4441 scoped_ptr<SpdyFrame> reply( |
4452 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); | 4442 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); |
4453 | 4443 |
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6141 | 6131 |
6142 rv = callback.WaitForResult(); | 6132 rv = callback.WaitForResult(); |
6143 EXPECT_EQ(OK, rv); | 6133 EXPECT_EQ(OK, rv); |
6144 | 6134 |
6145 helper.VerifyDataConsumed(); | 6135 helper.VerifyDataConsumed(); |
6146 } | 6136 } |
6147 | 6137 |
6148 // Test that received data frames and sent WINDOW_UPDATE frames change | 6138 // Test that received data frames and sent WINDOW_UPDATE frames change |
6149 // the recv_window_size_ correctly. | 6139 // the recv_window_size_ correctly. |
6150 TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { | 6140 TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { |
6151 const int32 initial_window_size = | 6141 const int32 default_initial_window_size = |
6152 SpdySession::GetInitialWindowSize(GetParam().protocol); | 6142 SpdySession::GetInitialWindowSize(GetParam().protocol); |
6153 // Amount of body required to trigger a sent window update. | 6143 // Session level maximum window size that is more than twice the default |
6154 const size_t kTargetSize = initial_window_size / 2 + 1; | 6144 // initial window size so that an initial window update is sent. |
| 6145 const int32 session_max_recv_window_size = 5 * 64 * 1024; |
| 6146 ASSERT_LT(2 * default_initial_window_size, session_max_recv_window_size); |
| 6147 // Stream level maximum window size that is less than the session level |
| 6148 // maximum window size so that we test for confusion between the two. |
| 6149 const int32 stream_max_recv_window_size = 4 * 64 * 1024; |
| 6150 ASSERT_GT(session_max_recv_window_size, stream_max_recv_window_size); |
| 6151 // Size of body to be sent. Has to be less than or equal to both window sizes |
| 6152 // so that we do not run out of receiving window. Also has to be greater than |
| 6153 // half of them so that it triggers both a session level and a stream level |
| 6154 // window update frame. |
| 6155 const int32 kTargetSize = 3 * 64 * 1024; |
| 6156 ASSERT_GE(session_max_recv_window_size, kTargetSize); |
| 6157 ASSERT_GE(stream_max_recv_window_size, kTargetSize); |
| 6158 ASSERT_LT(session_max_recv_window_size / 2, kTargetSize); |
| 6159 ASSERT_LT(stream_max_recv_window_size / 2, kTargetSize); |
| 6160 // Size of each DATA frame. |
| 6161 const int32 kChunkSize = 4096; |
| 6162 // Size of window updates. |
| 6163 ASSERT_EQ(0, session_max_recv_window_size / 2 % kChunkSize); |
| 6164 const int32 session_window_update_delta = |
| 6165 session_max_recv_window_size / 2 + kChunkSize; |
| 6166 ASSERT_EQ(0, stream_max_recv_window_size / 2 % kChunkSize); |
| 6167 const int32 stream_window_update_delta = |
| 6168 stream_max_recv_window_size / 2 + kChunkSize; |
6155 | 6169 |
| 6170 SettingsMap initial_settings; |
| 6171 initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 6172 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 6173 initial_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
| 6174 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, stream_max_recv_window_size); |
| 6175 scoped_ptr<SpdyFrame> initial_settings_frame( |
| 6176 spdy_util_.ConstructSpdySettings(initial_settings)); |
| 6177 scoped_ptr<SpdyFrame> initial_window_update( |
| 6178 spdy_util_.ConstructSpdyWindowUpdate( |
| 6179 kSessionFlowControlStreamId, |
| 6180 session_max_recv_window_size - default_initial_window_size)); |
6156 scoped_ptr<SpdyFrame> req( | 6181 scoped_ptr<SpdyFrame> req( |
6157 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 6182 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
6158 scoped_ptr<SpdyFrame> session_window_update( | 6183 scoped_ptr<SpdyFrame> session_window_update( |
6159 spdy_util_.ConstructSpdyWindowUpdate(0, kTargetSize)); | 6184 spdy_util_.ConstructSpdyWindowUpdate(0, session_window_update_delta)); |
6160 scoped_ptr<SpdyFrame> window_update( | 6185 scoped_ptr<SpdyFrame> stream_window_update( |
6161 spdy_util_.ConstructSpdyWindowUpdate(1, kTargetSize)); | 6186 spdy_util_.ConstructSpdyWindowUpdate(1, stream_window_update_delta)); |
6162 | 6187 |
6163 std::vector<MockWrite> writes; | 6188 std::vector<MockWrite> writes; |
| 6189 if ((GetParam().protocol >= kProtoSPDY4MinimumVersion) && |
| 6190 (GetParam().protocol <= kProtoSPDY4MaximumVersion)) { |
| 6191 writes.push_back(MockWrite(ASYNC, kHttp2ConnectionHeaderPrefix, |
| 6192 kHttp2ConnectionHeaderPrefixSize, 0)); |
| 6193 } |
| 6194 writes.push_back(CreateMockWrite(*initial_settings_frame)); |
| 6195 writes.push_back(CreateMockWrite(*initial_window_update)); |
6164 writes.push_back(CreateMockWrite(*req)); | 6196 writes.push_back(CreateMockWrite(*req)); |
6165 if (GetParam().protocol >= kProtoSPDY31) | 6197 writes.push_back(CreateMockWrite(*session_window_update)); |
6166 writes.push_back(CreateMockWrite(*session_window_update)); | 6198 writes.push_back(CreateMockWrite(*stream_window_update)); |
6167 writes.push_back(CreateMockWrite(*window_update)); | |
6168 | 6199 |
6169 std::vector<MockRead> reads; | 6200 std::vector<MockRead> reads; |
6170 scoped_ptr<SpdyFrame> resp( | 6201 scoped_ptr<SpdyFrame> resp( |
6171 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 6202 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
6172 reads.push_back(CreateMockRead(*resp)); | 6203 reads.push_back(CreateMockRead(*resp)); |
6173 | 6204 |
6174 ScopedVector<SpdyFrame> body_frames; | 6205 ScopedVector<SpdyFrame> body_frames; |
6175 const std::string body_data(4096, 'x'); | 6206 const std::string body_data(kChunkSize, 'x'); |
6176 for (size_t remaining = kTargetSize; remaining != 0;) { | 6207 for (size_t remaining = kTargetSize; remaining != 0;) { |
6177 size_t frame_size = std::min(remaining, body_data.size()); | 6208 size_t frame_size = std::min(remaining, body_data.size()); |
6178 body_frames.push_back(spdy_util_.ConstructSpdyBodyFrame( | 6209 body_frames.push_back(spdy_util_.ConstructSpdyBodyFrame( |
6179 1, body_data.data(), frame_size, false)); | 6210 1, body_data.data(), frame_size, false)); |
6180 reads.push_back(CreateMockRead(*body_frames.back())); | 6211 reads.push_back(CreateMockRead(*body_frames.back())); |
6181 remaining -= frame_size; | 6212 remaining -= frame_size; |
6182 } | 6213 } |
6183 reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 0)); // Yield. | 6214 reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 0)); // Yield. |
6184 | 6215 |
6185 DelayedSocketData data(1, vector_as_array(&reads), reads.size(), | 6216 DelayedSocketData data(2, vector_as_array(&reads), reads.size(), |
6186 vector_as_array(&writes), writes.size()); | 6217 vector_as_array(&writes), writes.size()); |
6187 | 6218 |
6188 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 6219 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
6189 BoundNetLog(), GetParam(), NULL); | 6220 BoundNetLog(), GetParam(), NULL); |
6190 helper.AddData(&data); | 6221 helper.AddData(&data); |
6191 helper.RunPreTestSetup(); | 6222 helper.RunPreTestSetup(); |
| 6223 |
| 6224 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 6225 SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 6226 pool_peer.SetEnableSendingInitialData(true); |
| 6227 pool_peer.SetSessionMaxRecvWindowSize(session_max_recv_window_size); |
| 6228 pool_peer.SetStreamInitialRecvWindowSize(stream_max_recv_window_size); |
| 6229 |
6192 HttpNetworkTransaction* trans = helper.trans(); | 6230 HttpNetworkTransaction* trans = helper.trans(); |
6193 | |
6194 TestCompletionCallback callback; | 6231 TestCompletionCallback callback; |
6195 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 6232 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
6196 | 6233 |
6197 EXPECT_EQ(ERR_IO_PENDING, rv); | 6234 EXPECT_EQ(ERR_IO_PENDING, rv); |
6198 rv = callback.WaitForResult(); | 6235 rv = callback.WaitForResult(); |
6199 EXPECT_EQ(OK, rv); | 6236 EXPECT_EQ(OK, rv); |
6200 | 6237 |
6201 SpdyHttpStream* stream = | 6238 SpdyHttpStream* stream = |
6202 static_cast<SpdyHttpStream*>(trans->stream_.get()); | 6239 static_cast<SpdyHttpStream*>(trans->stream_.get()); |
6203 ASSERT_TRUE(stream != NULL); | 6240 ASSERT_TRUE(stream != NULL); |
6204 ASSERT_TRUE(stream->stream() != NULL); | 6241 ASSERT_TRUE(stream->stream() != NULL); |
6205 | 6242 |
6206 // All data has been read, but not consumed. The window reflects this. | 6243 // All data has been read, but not consumed. The window reflects this. |
6207 EXPECT_EQ(static_cast<int>(initial_window_size - kTargetSize), | 6244 EXPECT_EQ(static_cast<int>(stream_max_recv_window_size - kTargetSize), |
6208 stream->stream()->recv_window_size()); | 6245 stream->stream()->recv_window_size()); |
6209 | 6246 |
6210 const HttpResponseInfo* response = trans->GetResponseInfo(); | 6247 const HttpResponseInfo* response = trans->GetResponseInfo(); |
6211 ASSERT_TRUE(response != NULL); | 6248 ASSERT_TRUE(response != NULL); |
6212 ASSERT_TRUE(response->headers.get() != NULL); | 6249 ASSERT_TRUE(response->headers.get() != NULL); |
6213 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 6250 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
6214 EXPECT_TRUE(response->was_fetched_via_spdy); | 6251 EXPECT_TRUE(response->was_fetched_via_spdy); |
6215 | 6252 |
6216 // Issue a read which will cause a WINDOW_UPDATE to be sent and window | 6253 // Issue a read which will cause a WINDOW_UPDATE to be sent and window |
6217 // size increased to default. | 6254 // size increased to default. |
6218 scoped_refptr<IOBuffer> buf(new IOBuffer(kTargetSize)); | 6255 scoped_refptr<IOBuffer> buf(new IOBuffer(kTargetSize)); |
6219 EXPECT_EQ(static_cast<int>(kTargetSize), | 6256 EXPECT_EQ(static_cast<int>(kTargetSize), |
6220 trans->Read(buf.get(), kTargetSize, CompletionCallback())); | 6257 trans->Read(buf.get(), kTargetSize, CompletionCallback())); |
6221 EXPECT_EQ(static_cast<int>(initial_window_size), | 6258 EXPECT_EQ(static_cast<int>(stream_max_recv_window_size), |
6222 stream->stream()->recv_window_size()); | 6259 stream->stream()->recv_window_size()); |
6223 EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); | 6260 EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); |
6224 | 6261 |
6225 // Allow scheduled WINDOW_UPDATE frames to write. | 6262 // Allow scheduled WINDOW_UPDATE frames to write. |
6226 base::RunLoop().RunUntilIdle(); | 6263 base::RunLoop().RunUntilIdle(); |
6227 helper.VerifyDataConsumed(); | 6264 helper.VerifyDataConsumed(); |
6228 } | 6265 } |
6229 | 6266 |
6230 // Test that WINDOW_UPDATE frame causing overflow is handled correctly. | 6267 // Test that WINDOW_UPDATE frame causing overflow is handled correctly. |
6231 TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { | 6268 TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6812 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { | 6849 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
6813 scoped_ptr<SSLSocketDataProvider> ssl_provider( | 6850 scoped_ptr<SSLSocketDataProvider> ssl_provider( |
6814 new SSLSocketDataProvider(ASYNC, OK)); | 6851 new SSLSocketDataProvider(ASYNC, OK)); |
6815 // Set to TLS_RSA_WITH_NULL_MD5 | 6852 // Set to TLS_RSA_WITH_NULL_MD5 |
6816 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | 6853 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
6817 | 6854 |
6818 RunTLSUsageCheckTest(ssl_provider.Pass()); | 6855 RunTLSUsageCheckTest(ssl_provider.Pass()); |
6819 } | 6856 } |
6820 | 6857 |
6821 } // namespace net | 6858 } // namespace net |
OLD | NEW |