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 4398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4409 SettingsMap initial_settings; | 4409 SettingsMap initial_settings; |
4410 initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = | 4410 initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
4411 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); | 4411 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
4412 scoped_ptr<SpdyFrame> initial_settings_frame( | 4412 scoped_ptr<SpdyFrame> initial_settings_frame( |
4413 spdy_util_.ConstructSpdySettings(initial_settings)); | 4413 spdy_util_.ConstructSpdySettings(initial_settings)); |
4414 | 4414 |
4415 // Construct the initial window update. | 4415 // Construct the initial window update. |
4416 scoped_ptr<SpdyFrame> initial_window_update( | 4416 scoped_ptr<SpdyFrame> initial_window_update( |
4417 spdy_util_.ConstructSpdyWindowUpdate( | 4417 spdy_util_.ConstructSpdyWindowUpdate( |
4418 kSessionFlowControlStreamId, | 4418 kSessionFlowControlStreamId, |
4419 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | 4419 kDefaultInitialRecvWindowSize - |
| 4420 SpdySession::GetInitialWindowSize(GetParam().protocol))); |
4420 | 4421 |
4421 // Construct the persisted SETTINGS frame. | 4422 // Construct the persisted SETTINGS frame. |
4422 const SettingsMap& settings = | 4423 const SettingsMap& settings = |
4423 spdy_session_pool->http_server_properties()->GetSpdySettings( | 4424 spdy_session_pool->http_server_properties()->GetSpdySettings( |
4424 host_port_pair); | 4425 host_port_pair); |
4425 scoped_ptr<SpdyFrame> settings_frame( | 4426 scoped_ptr<SpdyFrame> settings_frame( |
4426 spdy_util_.ConstructSpdySettings(settings)); | 4427 spdy_util_.ConstructSpdySettings(settings)); |
4427 | 4428 |
4428 // Construct the request. | 4429 // Construct the request. |
4429 scoped_ptr<SpdyFrame> req( | 4430 scoped_ptr<SpdyFrame> req( |
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5902 TestCompletionCallback callback; | 5903 TestCompletionCallback callback; |
5903 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 5904 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
5904 | 5905 |
5905 EXPECT_EQ(ERR_IO_PENDING, rv); | 5906 EXPECT_EQ(ERR_IO_PENDING, rv); |
5906 | 5907 |
5907 data.RunFor(11); | 5908 data.RunFor(11); |
5908 | 5909 |
5909 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); | 5910 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
5910 ASSERT_TRUE(stream != NULL); | 5911 ASSERT_TRUE(stream != NULL); |
5911 ASSERT_TRUE(stream->stream() != NULL); | 5912 ASSERT_TRUE(stream->stream() != NULL); |
5912 EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize) + | 5913 EXPECT_EQ( |
5913 kDeltaWindowSize * kDeltaCount - | 5914 static_cast<int>(SpdySession::GetInitialWindowSize(GetParam().protocol)) + |
5914 kMaxSpdyFrameChunkSize * kFrameCount, | 5915 kDeltaWindowSize * kDeltaCount - kMaxSpdyFrameChunkSize * kFrameCount, |
5915 stream->stream()->send_window_size()); | 5916 stream->stream()->send_window_size()); |
5916 | 5917 |
5917 data.RunFor(1); | 5918 data.RunFor(1); |
5918 | 5919 |
5919 rv = callback.WaitForResult(); | 5920 rv = callback.WaitForResult(); |
5920 EXPECT_EQ(OK, rv); | 5921 EXPECT_EQ(OK, rv); |
5921 | 5922 |
5922 helper.VerifyDataConsumed(); | 5923 helper.VerifyDataConsumed(); |
5923 } | 5924 } |
5924 | 5925 |
5925 // Test that received data frames and sent WINDOW_UPDATE frames change | 5926 // Test that received data frames and sent WINDOW_UPDATE frames change |
5926 // the recv_window_size_ correctly. | 5927 // the recv_window_size_ correctly. |
5927 TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { | 5928 TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { |
| 5929 const int32 initial_window_size = |
| 5930 SpdySession::GetInitialWindowSize(GetParam().protocol); |
5928 // Amount of body required to trigger a sent window update. | 5931 // Amount of body required to trigger a sent window update. |
5929 const size_t kTargetSize = kSpdyStreamInitialWindowSize / 2 + 1; | 5932 const size_t kTargetSize = initial_window_size / 2 + 1; |
5930 | 5933 |
5931 scoped_ptr<SpdyFrame> req( | 5934 scoped_ptr<SpdyFrame> req( |
5932 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 5935 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
5933 scoped_ptr<SpdyFrame> session_window_update( | 5936 scoped_ptr<SpdyFrame> session_window_update( |
5934 spdy_util_.ConstructSpdyWindowUpdate(0, kTargetSize)); | 5937 spdy_util_.ConstructSpdyWindowUpdate(0, kTargetSize)); |
5935 scoped_ptr<SpdyFrame> window_update( | 5938 scoped_ptr<SpdyFrame> window_update( |
5936 spdy_util_.ConstructSpdyWindowUpdate(1, kTargetSize)); | 5939 spdy_util_.ConstructSpdyWindowUpdate(1, kTargetSize)); |
5937 | 5940 |
5938 std::vector<MockWrite> writes; | 5941 std::vector<MockWrite> writes; |
5939 writes.push_back(CreateMockWrite(*req)); | 5942 writes.push_back(CreateMockWrite(*req)); |
5940 if (GetParam().protocol >= kProtoSPDY31) | 5943 if (GetParam().protocol >= kProtoSPDY31) |
5941 writes.push_back(CreateMockWrite(*session_window_update)); | 5944 writes.push_back(CreateMockWrite(*session_window_update)); |
5942 writes.push_back(CreateMockWrite(*window_update)); | 5945 writes.push_back(CreateMockWrite(*window_update)); |
5943 | 5946 |
5944 std::vector<MockRead> reads; | 5947 std::vector<MockRead> reads; |
5945 scoped_ptr<SpdyFrame> resp( | 5948 scoped_ptr<SpdyFrame> resp( |
5946 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 5949 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
5947 reads.push_back(CreateMockRead(*resp)); | 5950 reads.push_back(CreateMockRead(*resp)); |
5948 | 5951 |
5949 ScopedVector<SpdyFrame> body_frames; | 5952 ScopedVector<SpdyFrame> body_frames; |
5950 const std::string body_data(4096, 'x'); | 5953 const std::string body_data(4096, 'x'); |
5951 for (size_t remaining = kTargetSize; remaining != 0;) { | 5954 for (size_t remaining = kTargetSize; remaining != 0;) { |
5952 size_t frame_size = std::min(remaining, body_data.size()); | 5955 size_t frame_size = std::min(remaining, body_data.size()); |
5953 body_frames.push_back(spdy_util_.ConstructSpdyBodyFrame( | 5956 body_frames.push_back(spdy_util_.ConstructSpdyBodyFrame( |
5954 1, body_data.data(), frame_size, false)); | 5957 1, body_data.data(), frame_size, false)); |
5955 reads.push_back(CreateMockRead(*body_frames.back())); | 5958 reads.push_back(CreateMockRead(*body_frames.back())); |
5956 remaining -= frame_size; | 5959 remaining -= frame_size; |
5957 } | 5960 } |
5958 reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 0)); // Yield. | 5961 reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 0)); // Yield. |
5959 | 5962 |
5960 DelayedSocketData data(1, vector_as_array(&reads), reads.size(), | 5963 DelayedSocketData data(1, vector_as_array(&reads), reads.size(), |
5961 vector_as_array(&writes), writes.size()); | 5964 vector_as_array(&writes), writes.size()); |
5962 | 5965 |
5963 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 5966 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
5964 BoundNetLog(), GetParam(), NULL); | 5967 BoundNetLog(), GetParam(), NULL); |
5965 helper.AddData(&data); | 5968 helper.AddData(&data); |
5966 helper.RunPreTestSetup(); | 5969 helper.RunPreTestSetup(); |
5967 HttpNetworkTransaction* trans = helper.trans(); | 5970 HttpNetworkTransaction* trans = helper.trans(); |
5968 | 5971 |
5969 TestCompletionCallback callback; | 5972 TestCompletionCallback callback; |
5970 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 5973 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
5971 | 5974 |
5972 EXPECT_EQ(ERR_IO_PENDING, rv); | 5975 EXPECT_EQ(ERR_IO_PENDING, rv); |
5973 rv = callback.WaitForResult(); | 5976 rv = callback.WaitForResult(); |
5974 EXPECT_EQ(OK, rv); | 5977 EXPECT_EQ(OK, rv); |
5975 | 5978 |
5976 SpdyHttpStream* stream = | 5979 SpdyHttpStream* stream = |
5977 static_cast<SpdyHttpStream*>(trans->stream_.get()); | 5980 static_cast<SpdyHttpStream*>(trans->stream_.get()); |
5978 ASSERT_TRUE(stream != NULL); | 5981 ASSERT_TRUE(stream != NULL); |
5979 ASSERT_TRUE(stream->stream() != NULL); | 5982 ASSERT_TRUE(stream->stream() != NULL); |
5980 | 5983 |
5981 // All data has been read, but not consumed. The window reflects this. | 5984 // All data has been read, but not consumed. The window reflects this. |
5982 EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize - kTargetSize), | 5985 EXPECT_EQ(static_cast<int>(initial_window_size - kTargetSize), |
5983 stream->stream()->recv_window_size()); | 5986 stream->stream()->recv_window_size()); |
5984 | 5987 |
5985 const HttpResponseInfo* response = trans->GetResponseInfo(); | 5988 const HttpResponseInfo* response = trans->GetResponseInfo(); |
5986 ASSERT_TRUE(response != NULL); | 5989 ASSERT_TRUE(response != NULL); |
5987 ASSERT_TRUE(response->headers.get() != NULL); | 5990 ASSERT_TRUE(response->headers.get() != NULL); |
5988 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 5991 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
5989 EXPECT_TRUE(response->was_fetched_via_spdy); | 5992 EXPECT_TRUE(response->was_fetched_via_spdy); |
5990 | 5993 |
5991 // Issue a read which will cause a WINDOW_UPDATE to be sent and window | 5994 // Issue a read which will cause a WINDOW_UPDATE to be sent and window |
5992 // size increased to default. | 5995 // size increased to default. |
5993 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kTargetSize)); | 5996 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kTargetSize)); |
5994 EXPECT_EQ(static_cast<int>(kTargetSize), | 5997 EXPECT_EQ(static_cast<int>(kTargetSize), |
5995 trans->Read(buf.get(), kTargetSize, CompletionCallback())); | 5998 trans->Read(buf.get(), kTargetSize, CompletionCallback())); |
5996 EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize), | 5999 EXPECT_EQ(static_cast<int>(initial_window_size), |
5997 stream->stream()->recv_window_size()); | 6000 stream->stream()->recv_window_size()); |
5998 EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); | 6001 EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); |
5999 | 6002 |
6000 // Allow scheduled WINDOW_UPDATE frames to write. | 6003 // Allow scheduled WINDOW_UPDATE frames to write. |
6001 base::RunLoop().RunUntilIdle(); | 6004 base::RunLoop().RunUntilIdle(); |
6002 helper.VerifyDataConsumed(); | 6005 helper.VerifyDataConsumed(); |
6003 } | 6006 } |
6004 | 6007 |
6005 // Test that WINDOW_UPDATE frame causing overflow is handled correctly. | 6008 // Test that WINDOW_UPDATE frame causing overflow is handled correctly. |
6006 TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { | 6009 TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6076 // also contains a FIN flag. DelayedSocketData is used to enforce all | 6079 // also contains a FIN flag. DelayedSocketData is used to enforce all |
6077 // writes go through before a read could happen. However, the last frame | 6080 // writes go through before a read could happen. However, the last frame |
6078 // ("hello!") is not supposed to go through since by the time its turn | 6081 // ("hello!") is not supposed to go through since by the time its turn |
6079 // arrives, window size is 0. At this point MessageLoop::Run() called via | 6082 // arrives, window size is 0. At this point MessageLoop::Run() called via |
6080 // callback would block. Therefore we call MessageLoop::RunUntilIdle() | 6083 // callback would block. Therefore we call MessageLoop::RunUntilIdle() |
6081 // which returns after performing all possible writes. We use DCHECKS to | 6084 // which returns after performing all possible writes. We use DCHECKS to |
6082 // ensure that last data frame is still there and stream has stalled. | 6085 // ensure that last data frame is still there and stream has stalled. |
6083 // After that, next read is artifically enforced, which causes a | 6086 // After that, next read is artifically enforced, which causes a |
6084 // WINDOW_UPDATE to be read and I/O process resumes. | 6087 // WINDOW_UPDATE to be read and I/O process resumes. |
6085 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) { | 6088 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) { |
| 6089 const int32 initial_window_size = |
| 6090 SpdySession::GetInitialWindowSize(GetParam().protocol); |
6086 // Number of frames we need to send to zero out the window size: data | 6091 // Number of frames we need to send to zero out the window size: data |
6087 // frames plus SYN_STREAM plus the last data frame; also we need another | 6092 // frames plus SYN_STREAM plus the last data frame; also we need another |
6088 // data frame that we will send once the WINDOW_UPDATE is received, | 6093 // data frame that we will send once the WINDOW_UPDATE is received, |
6089 // therefore +3. | 6094 // therefore +3. |
6090 size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; | 6095 size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
6091 | 6096 |
6092 // Calculate last frame's size; 0 size data frame is legal. | 6097 // Calculate last frame's size; 0 size data frame is legal. |
6093 size_t last_frame_size = | 6098 size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
6094 kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; | |
6095 | 6099 |
6096 // Construct content for a data frame of maximum size. | 6100 // Construct content for a data frame of maximum size. |
6097 std::string content(kMaxSpdyFrameChunkSize, 'a'); | 6101 std::string content(kMaxSpdyFrameChunkSize, 'a'); |
6098 | 6102 |
6099 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( | 6103 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
6100 kRequestUrl, 1, kSpdyStreamInitialWindowSize + kUploadDataSize, | 6104 kRequestUrl, 1, initial_window_size + kUploadDataSize, LOWEST, NULL, 0)); |
6101 LOWEST, NULL, 0)); | |
6102 | 6105 |
6103 // Full frames. | 6106 // Full frames. |
6104 scoped_ptr<SpdyFrame> body1( | 6107 scoped_ptr<SpdyFrame> body1( |
6105 spdy_util_.ConstructSpdyBodyFrame( | 6108 spdy_util_.ConstructSpdyBodyFrame( |
6106 1, content.c_str(), content.size(), false)); | 6109 1, content.c_str(), content.size(), false)); |
6107 | 6110 |
6108 // Last frame to zero out the window size. | 6111 // Last frame to zero out the window size. |
6109 scoped_ptr<SpdyFrame> body2( | 6112 scoped_ptr<SpdyFrame> body2( |
6110 spdy_util_.ConstructSpdyBodyFrame( | 6113 spdy_util_.ConstructSpdyBodyFrame( |
6111 1, content.c_str(), last_frame_size, false)); | 6114 1, content.c_str(), last_frame_size, false)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6144 // above. | 6147 // above. |
6145 size_t read_offset = (GetParam().protocol >= kProtoSPDY31) ? 0 : 2; | 6148 size_t read_offset = (GetParam().protocol >= kProtoSPDY31) ? 0 : 2; |
6146 size_t num_reads = arraysize(reads) - read_offset; | 6149 size_t num_reads = arraysize(reads) - read_offset; |
6147 | 6150 |
6148 // Force all writes to happen before any read, last write will not | 6151 // Force all writes to happen before any read, last write will not |
6149 // actually queue a frame, due to window size being 0. | 6152 // actually queue a frame, due to window size being 0. |
6150 DelayedSocketData data(num_writes, reads + read_offset, num_reads, | 6153 DelayedSocketData data(num_writes, reads + read_offset, num_reads, |
6151 writes.get(), num_writes); | 6154 writes.get(), num_writes); |
6152 | 6155 |
6153 ScopedVector<UploadElementReader> element_readers; | 6156 ScopedVector<UploadElementReader> element_readers; |
6154 std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); | 6157 std::string upload_data_string(initial_window_size, 'a'); |
6155 upload_data_string.append(kUploadData, kUploadDataSize); | 6158 upload_data_string.append(kUploadData, kUploadDataSize); |
6156 element_readers.push_back(new UploadBytesElementReader( | 6159 element_readers.push_back(new UploadBytesElementReader( |
6157 upload_data_string.c_str(), upload_data_string.size())); | 6160 upload_data_string.c_str(), upload_data_string.size())); |
6158 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); | 6161 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
6159 | 6162 |
6160 HttpRequestInfo request; | 6163 HttpRequestInfo request; |
6161 request.method = "POST"; | 6164 request.method = "POST"; |
6162 request.url = GURL("http://www.google.com/"); | 6165 request.url = GURL("http://www.google.com/"); |
6163 request.upload_data_stream = &upload_data_stream; | 6166 request.upload_data_stream = &upload_data_stream; |
6164 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 6167 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
(...skipping 22 matching lines...) Expand all Loading... |
6187 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); | 6190 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
6188 | 6191 |
6189 data.ForceNextRead(); // Read in WINDOW_UPDATE frame. | 6192 data.ForceNextRead(); // Read in WINDOW_UPDATE frame. |
6190 rv = callback.WaitForResult(); | 6193 rv = callback.WaitForResult(); |
6191 helper.VerifyDataConsumed(); | 6194 helper.VerifyDataConsumed(); |
6192 } | 6195 } |
6193 | 6196 |
6194 // Test we correctly handle the case where the SETTINGS frame results in | 6197 // Test we correctly handle the case where the SETTINGS frame results in |
6195 // unstalling the send window. | 6198 // unstalling the send window. |
6196 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { | 6199 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { |
| 6200 const int32 initial_window_size = |
| 6201 SpdySession::GetInitialWindowSize(GetParam().protocol); |
| 6202 |
6197 // Number of frames we need to send to zero out the window size: data | 6203 // Number of frames we need to send to zero out the window size: data |
6198 // frames plus SYN_STREAM plus the last data frame; also we need another | 6204 // frames plus SYN_STREAM plus the last data frame; also we need another |
6199 // data frame that we will send once the SETTING is received, therefore +3. | 6205 // data frame that we will send once the SETTING is received, therefore +3. |
6200 size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; | 6206 size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
6201 | 6207 |
6202 // Calculate last frame's size; 0 size data frame is legal. | 6208 // Calculate last frame's size; 0 size data frame is legal. |
6203 size_t last_frame_size = | 6209 size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
6204 kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; | |
6205 | 6210 |
6206 // Construct content for a data frame of maximum size. | 6211 // Construct content for a data frame of maximum size. |
6207 std::string content(kMaxSpdyFrameChunkSize, 'a'); | 6212 std::string content(kMaxSpdyFrameChunkSize, 'a'); |
6208 | 6213 |
6209 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( | 6214 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
6210 kRequestUrl, 1, kSpdyStreamInitialWindowSize + kUploadDataSize, | 6215 kRequestUrl, 1, initial_window_size + kUploadDataSize, LOWEST, NULL, 0)); |
6211 LOWEST, NULL, 0)); | |
6212 | 6216 |
6213 // Full frames. | 6217 // Full frames. |
6214 scoped_ptr<SpdyFrame> body1( | 6218 scoped_ptr<SpdyFrame> body1( |
6215 spdy_util_.ConstructSpdyBodyFrame( | 6219 spdy_util_.ConstructSpdyBodyFrame( |
6216 1, content.c_str(), content.size(), false)); | 6220 1, content.c_str(), content.size(), false)); |
6217 | 6221 |
6218 // Last frame to zero out the window size. | 6222 // Last frame to zero out the window size. |
6219 scoped_ptr<SpdyFrame> body2( | 6223 scoped_ptr<SpdyFrame> body2( |
6220 spdy_util_.ConstructSpdyBodyFrame( | 6224 spdy_util_.ConstructSpdyBodyFrame( |
6221 1, content.c_str(), last_frame_size, false)); | 6225 1, content.c_str(), last_frame_size, false)); |
6222 | 6226 |
6223 // Data frame to be sent once SETTINGS frame is received. | 6227 // Data frame to be sent once SETTINGS frame is received. |
6224 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 6228 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
6225 | 6229 |
6226 // Fill in mock reads/writes. | 6230 // Fill in mock reads/writes. |
6227 std::vector<MockRead> reads; | 6231 std::vector<MockRead> reads; |
6228 std::vector<MockWrite> writes; | 6232 std::vector<MockWrite> writes; |
6229 size_t i = 0; | 6233 size_t i = 0; |
6230 writes.push_back(CreateMockWrite(*req, i++)); | 6234 writes.push_back(CreateMockWrite(*req, i++)); |
6231 while (i < num_writes - 2) | 6235 while (i < num_writes - 2) |
6232 writes.push_back(CreateMockWrite(*body1, i++)); | 6236 writes.push_back(CreateMockWrite(*body1, i++)); |
6233 writes.push_back(CreateMockWrite(*body2, i++)); | 6237 writes.push_back(CreateMockWrite(*body2, i++)); |
6234 | 6238 |
6235 // Construct read frame for SETTINGS that gives enough space to upload the | 6239 // Construct read frame for SETTINGS that gives enough space to upload the |
6236 // rest of the data. | 6240 // rest of the data. |
6237 SettingsMap settings; | 6241 SettingsMap settings; |
6238 settings[SETTINGS_INITIAL_WINDOW_SIZE] = | 6242 settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
6239 SettingsFlagsAndValue( | 6243 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size * 2); |
6240 SETTINGS_FLAG_NONE, kSpdyStreamInitialWindowSize * 2); | |
6241 scoped_ptr<SpdyFrame> settings_frame_large( | 6244 scoped_ptr<SpdyFrame> settings_frame_large( |
6242 spdy_util_.ConstructSpdySettings(settings)); | 6245 spdy_util_.ConstructSpdySettings(settings)); |
6243 | 6246 |
6244 reads.push_back(CreateMockRead(*settings_frame_large, i++)); | 6247 reads.push_back(CreateMockRead(*settings_frame_large, i++)); |
6245 | 6248 |
6246 scoped_ptr<SpdyFrame> session_window_update( | 6249 scoped_ptr<SpdyFrame> session_window_update( |
6247 spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); | 6250 spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); |
6248 if (GetParam().protocol >= kProtoSPDY31) | 6251 if (GetParam().protocol >= kProtoSPDY31) |
6249 reads.push_back(CreateMockRead(*session_window_update, i++)); | 6252 reads.push_back(CreateMockRead(*session_window_update, i++)); |
6250 | 6253 |
6251 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); | 6254 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
6252 writes.push_back(CreateMockWrite(*settings_ack, i++)); | 6255 writes.push_back(CreateMockWrite(*settings_ack, i++)); |
6253 | 6256 |
6254 writes.push_back(CreateMockWrite(*body3, i++)); | 6257 writes.push_back(CreateMockWrite(*body3, i++)); |
6255 | 6258 |
6256 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 6259 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
6257 reads.push_back(CreateMockRead(*reply, i++)); | 6260 reads.push_back(CreateMockRead(*reply, i++)); |
6258 reads.push_back(CreateMockRead(*body2, i++)); | 6261 reads.push_back(CreateMockRead(*body2, i++)); |
6259 reads.push_back(CreateMockRead(*body3, i++)); | 6262 reads.push_back(CreateMockRead(*body3, i++)); |
6260 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF | 6263 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
6261 | 6264 |
6262 // Force all writes to happen before any read, last write will not | 6265 // Force all writes to happen before any read, last write will not |
6263 // actually queue a frame, due to window size being 0. | 6266 // actually queue a frame, due to window size being 0. |
6264 DeterministicSocketData data(vector_as_array(&reads), reads.size(), | 6267 DeterministicSocketData data(vector_as_array(&reads), reads.size(), |
6265 vector_as_array(&writes), writes.size()); | 6268 vector_as_array(&writes), writes.size()); |
6266 | 6269 |
6267 ScopedVector<UploadElementReader> element_readers; | 6270 ScopedVector<UploadElementReader> element_readers; |
6268 std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); | 6271 std::string upload_data_string(initial_window_size, 'a'); |
6269 upload_data_string.append(kUploadData, kUploadDataSize); | 6272 upload_data_string.append(kUploadData, kUploadDataSize); |
6270 element_readers.push_back(new UploadBytesElementReader( | 6273 element_readers.push_back(new UploadBytesElementReader( |
6271 upload_data_string.c_str(), upload_data_string.size())); | 6274 upload_data_string.c_str(), upload_data_string.size())); |
6272 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); | 6275 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
6273 | 6276 |
6274 HttpRequestInfo request; | 6277 HttpRequestInfo request; |
6275 request.method = "POST"; | 6278 request.method = "POST"; |
6276 request.url = GURL("http://www.google.com/"); | 6279 request.url = GURL("http://www.google.com/"); |
6277 request.upload_data_stream = &upload_data_stream; | 6280 request.upload_data_stream = &upload_data_stream; |
6278 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 6281 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
(...skipping 26 matching lines...) Expand all Loading... |
6305 data.RunFor(7); // Read in SETTINGS frame to unstall. | 6308 data.RunFor(7); // Read in SETTINGS frame to unstall. |
6306 rv = callback.WaitForResult(); | 6309 rv = callback.WaitForResult(); |
6307 helper.VerifyDataConsumed(); | 6310 helper.VerifyDataConsumed(); |
6308 // If stream is NULL, that means it was unstalled and closed. | 6311 // If stream is NULL, that means it was unstalled and closed. |
6309 EXPECT_TRUE(stream->stream() == NULL); | 6312 EXPECT_TRUE(stream->stream() == NULL); |
6310 } | 6313 } |
6311 | 6314 |
6312 // Test we correctly handle the case where the SETTINGS frame results in a | 6315 // Test we correctly handle the case where the SETTINGS frame results in a |
6313 // negative send window size. | 6316 // negative send window size. |
6314 TEST_P(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { | 6317 TEST_P(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { |
| 6318 const int32 initial_window_size = |
| 6319 SpdySession::GetInitialWindowSize(GetParam().protocol); |
6315 // Number of frames we need to send to zero out the window size: data | 6320 // Number of frames we need to send to zero out the window size: data |
6316 // frames plus SYN_STREAM plus the last data frame; also we need another | 6321 // frames plus SYN_STREAM plus the last data frame; also we need another |
6317 // data frame that we will send once the SETTING is received, therefore +3. | 6322 // data frame that we will send once the SETTING is received, therefore +3. |
6318 size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; | 6323 size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
6319 | 6324 |
6320 // Calculate last frame's size; 0 size data frame is legal. | 6325 // Calculate last frame's size; 0 size data frame is legal. |
6321 size_t last_frame_size = | 6326 size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
6322 kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; | |
6323 | 6327 |
6324 // Construct content for a data frame of maximum size. | 6328 // Construct content for a data frame of maximum size. |
6325 std::string content(kMaxSpdyFrameChunkSize, 'a'); | 6329 std::string content(kMaxSpdyFrameChunkSize, 'a'); |
6326 | 6330 |
6327 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( | 6331 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
6328 kRequestUrl, 1, kSpdyStreamInitialWindowSize + kUploadDataSize, | 6332 kRequestUrl, 1, initial_window_size + kUploadDataSize, LOWEST, NULL, 0)); |
6329 LOWEST, NULL, 0)); | |
6330 | 6333 |
6331 // Full frames. | 6334 // Full frames. |
6332 scoped_ptr<SpdyFrame> body1( | 6335 scoped_ptr<SpdyFrame> body1( |
6333 spdy_util_.ConstructSpdyBodyFrame( | 6336 spdy_util_.ConstructSpdyBodyFrame( |
6334 1, content.c_str(), content.size(), false)); | 6337 1, content.c_str(), content.size(), false)); |
6335 | 6338 |
6336 // Last frame to zero out the window size. | 6339 // Last frame to zero out the window size. |
6337 scoped_ptr<SpdyFrame> body2( | 6340 scoped_ptr<SpdyFrame> body2( |
6338 spdy_util_.ConstructSpdyBodyFrame( | 6341 spdy_util_.ConstructSpdyBodyFrame( |
6339 1, content.c_str(), last_frame_size, false)); | 6342 1, content.c_str(), last_frame_size, false)); |
6340 | 6343 |
6341 // Data frame to be sent once SETTINGS frame is received. | 6344 // Data frame to be sent once SETTINGS frame is received. |
6342 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 6345 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
6343 | 6346 |
6344 // Fill in mock reads/writes. | 6347 // Fill in mock reads/writes. |
6345 std::vector<MockRead> reads; | 6348 std::vector<MockRead> reads; |
6346 std::vector<MockWrite> writes; | 6349 std::vector<MockWrite> writes; |
6347 size_t i = 0; | 6350 size_t i = 0; |
6348 writes.push_back(CreateMockWrite(*req, i++)); | 6351 writes.push_back(CreateMockWrite(*req, i++)); |
6349 while (i < num_writes - 2) | 6352 while (i < num_writes - 2) |
6350 writes.push_back(CreateMockWrite(*body1, i++)); | 6353 writes.push_back(CreateMockWrite(*body1, i++)); |
6351 writes.push_back(CreateMockWrite(*body2, i++)); | 6354 writes.push_back(CreateMockWrite(*body2, i++)); |
6352 | 6355 |
6353 // Construct read frame for SETTINGS that makes the send_window_size | 6356 // Construct read frame for SETTINGS that makes the send_window_size |
6354 // negative. | 6357 // negative. |
6355 SettingsMap new_settings; | 6358 SettingsMap new_settings; |
6356 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = | 6359 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
6357 SettingsFlagsAndValue( | 6360 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size / 2); |
6358 SETTINGS_FLAG_NONE, kSpdyStreamInitialWindowSize / 2); | |
6359 scoped_ptr<SpdyFrame> settings_frame_small( | 6361 scoped_ptr<SpdyFrame> settings_frame_small( |
6360 spdy_util_.ConstructSpdySettings(new_settings)); | 6362 spdy_util_.ConstructSpdySettings(new_settings)); |
6361 // Construct read frames for WINDOW_UPDATE that makes the send_window_size | 6363 // Construct read frames for WINDOW_UPDATE that makes the send_window_size |
6362 // positive. | 6364 // positive. |
6363 scoped_ptr<SpdyFrame> session_window_update_init_size( | 6365 scoped_ptr<SpdyFrame> session_window_update_init_size( |
6364 spdy_util_.ConstructSpdyWindowUpdate(0, kSpdyStreamInitialWindowSize)); | 6366 spdy_util_.ConstructSpdyWindowUpdate(0, initial_window_size)); |
6365 scoped_ptr<SpdyFrame> window_update_init_size( | 6367 scoped_ptr<SpdyFrame> window_update_init_size( |
6366 spdy_util_.ConstructSpdyWindowUpdate(1, kSpdyStreamInitialWindowSize)); | 6368 spdy_util_.ConstructSpdyWindowUpdate(1, initial_window_size)); |
6367 | 6369 |
6368 reads.push_back(CreateMockRead(*settings_frame_small, i++)); | 6370 reads.push_back(CreateMockRead(*settings_frame_small, i++)); |
6369 reads.push_back(CreateMockRead(*session_window_update_init_size, i++)); | 6371 reads.push_back(CreateMockRead(*session_window_update_init_size, i++)); |
6370 reads.push_back(CreateMockRead(*window_update_init_size, i++)); | 6372 reads.push_back(CreateMockRead(*window_update_init_size, i++)); |
6371 | 6373 |
6372 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); | 6374 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
6373 writes.push_back(CreateMockWrite(*settings_ack, i++)); | 6375 writes.push_back(CreateMockWrite(*settings_ack, i++)); |
6374 | 6376 |
6375 writes.push_back(CreateMockWrite(*body3, i++)); | 6377 writes.push_back(CreateMockWrite(*body3, i++)); |
6376 | 6378 |
6377 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 6379 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
6378 reads.push_back(CreateMockRead(*reply, i++)); | 6380 reads.push_back(CreateMockRead(*reply, i++)); |
6379 reads.push_back(CreateMockRead(*body2, i++)); | 6381 reads.push_back(CreateMockRead(*body2, i++)); |
6380 reads.push_back(CreateMockRead(*body3, i++)); | 6382 reads.push_back(CreateMockRead(*body3, i++)); |
6381 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF | 6383 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
6382 | 6384 |
6383 // Force all writes to happen before any read, last write will not | 6385 // Force all writes to happen before any read, last write will not |
6384 // actually queue a frame, due to window size being 0. | 6386 // actually queue a frame, due to window size being 0. |
6385 DeterministicSocketData data(vector_as_array(&reads), reads.size(), | 6387 DeterministicSocketData data(vector_as_array(&reads), reads.size(), |
6386 vector_as_array(&writes), writes.size()); | 6388 vector_as_array(&writes), writes.size()); |
6387 | 6389 |
6388 ScopedVector<UploadElementReader> element_readers; | 6390 ScopedVector<UploadElementReader> element_readers; |
6389 std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); | 6391 std::string upload_data_string(initial_window_size, 'a'); |
6390 upload_data_string.append(kUploadData, kUploadDataSize); | 6392 upload_data_string.append(kUploadData, kUploadDataSize); |
6391 element_readers.push_back(new UploadBytesElementReader( | 6393 element_readers.push_back(new UploadBytesElementReader( |
6392 upload_data_string.c_str(), upload_data_string.size())); | 6394 upload_data_string.c_str(), upload_data_string.size())); |
6393 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); | 6395 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
6394 | 6396 |
6395 HttpRequestInfo request; | 6397 HttpRequestInfo request; |
6396 request.method = "POST"; | 6398 request.method = "POST"; |
6397 request.url = GURL("http://www.google.com/"); | 6399 request.url = GURL("http://www.google.com/"); |
6398 request.upload_data_stream = &upload_data_stream; | 6400 request.upload_data_stream = &upload_data_stream; |
6399 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 6401 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6589 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { | 6591 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
6590 scoped_ptr<SSLSocketDataProvider> ssl_provider( | 6592 scoped_ptr<SSLSocketDataProvider> ssl_provider( |
6591 new SSLSocketDataProvider(ASYNC, OK)); | 6593 new SSLSocketDataProvider(ASYNC, OK)); |
6592 // Set to TLS_RSA_WITH_NULL_MD5 | 6594 // Set to TLS_RSA_WITH_NULL_MD5 |
6593 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | 6595 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
6594 | 6596 |
6595 RunTLSUsageCheckTest(ssl_provider.Pass()); | 6597 RunTLSUsageCheckTest(ssl_provider.Pass()); |
6596 } | 6598 } |
6597 | 6599 |
6598 } // namespace net | 6600 } // namespace net |
OLD | NEW |