| 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/quic/reliable_quic_stream.h" | 5 #include "net/quic/reliable_quic_stream.h" |
| 6 | 6 |
| 7 #include "net/quic/quic_connection.h" | 7 #include "net/quic/quic_connection.h" |
| 8 #include "net/quic/quic_spdy_compressor.h" | 8 #include "net/quic/quic_spdy_compressor.h" |
| 9 #include "net/quic/quic_spdy_decompressor.h" | 9 #include "net/quic/quic_spdy_decompressor.h" |
| 10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 scoped_ptr<TestStream> stream2_; | 87 scoped_ptr<TestStream> stream2_; |
| 88 scoped_ptr<QuicSpdyCompressor> compressor_; | 88 scoped_ptr<QuicSpdyCompressor> compressor_; |
| 89 scoped_ptr<QuicSpdyDecompressor> decompressor_; | 89 scoped_ptr<QuicSpdyDecompressor> decompressor_; |
| 90 SpdyHeaderBlock headers_; | 90 SpdyHeaderBlock headers_; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 TEST_F(ReliableQuicStreamTest, WriteAllData) { | 93 TEST_F(ReliableQuicStreamTest, WriteAllData) { |
| 94 Initialize(kShouldProcessData); | 94 Initialize(kShouldProcessData); |
| 95 | 95 |
| 96 connection_->options()->max_packet_length = | 96 connection_->options()->max_packet_length = |
| 97 1 + QuicPacketCreator::StreamFramePacketOverhead(1, !kIncludeVersion); | 97 1 + QuicPacketCreator::StreamFramePacketOverhead( |
| 98 1, PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP); |
| 98 // TODO(rch): figure out how to get StrEq working here. | 99 // TODO(rch): figure out how to get StrEq working here. |
| 99 //EXPECT_CALL(*session_, WriteData(kStreamId, StrEq(kData1), _, _)).WillOnce( | 100 //EXPECT_CALL(*session_, WriteData(kStreamId, StrEq(kData1), _, _)).WillOnce( |
| 100 EXPECT_CALL(*session_, WriteData(kStreamId, _, _, _)).WillOnce( | 101 EXPECT_CALL(*session_, WriteData(kStreamId, _, _, _)).WillOnce( |
| 101 Return(QuicConsumedData(kDataLen, true))); | 102 Return(QuicConsumedData(kDataLen, true))); |
| 102 EXPECT_EQ(kDataLen, stream_->WriteData(kData1, false).bytes_consumed); | 103 EXPECT_EQ(kDataLen, stream_->WriteData(kData1, false).bytes_consumed); |
| 103 } | 104 } |
| 104 | 105 |
| 105 TEST_F(ReliableQuicStreamTest, WriteData) { | 106 TEST_F(ReliableQuicStreamTest, WriteData) { |
| 106 Initialize(kShouldProcessData); | 107 Initialize(kShouldProcessData); |
| 107 | 108 |
| 108 connection_->options()->max_packet_length = | 109 connection_->options()->max_packet_length = |
| 109 1 + QuicPacketCreator::StreamFramePacketOverhead(1, !kIncludeVersion); | 110 1 + QuicPacketCreator::StreamFramePacketOverhead( |
| 111 1, PACKET_8BYTE_GUID, !kIncludeVersion, NOT_IN_FEC_GROUP); |
| 110 // TODO(rch): figure out how to get StrEq working here. | 112 // TODO(rch): figure out how to get StrEq working here. |
| 111 //EXPECT_CALL(*session_, WriteData(_, StrEq(kData1), _, _)).WillOnce( | 113 //EXPECT_CALL(*session_, WriteData(_, StrEq(kData1), _, _)).WillOnce( |
| 112 EXPECT_CALL(*session_, WriteData(_, _, _, _)).WillOnce( | 114 EXPECT_CALL(*session_, WriteData(_, _, _, _)).WillOnce( |
| 113 Return(QuicConsumedData(kDataLen - 1, false))); | 115 Return(QuicConsumedData(kDataLen - 1, false))); |
| 114 // The return will be kDataLen, because the last byte gets buffered. | 116 // The return will be kDataLen, because the last byte gets buffered. |
| 115 EXPECT_EQ(kDataLen, stream_->WriteData(kData1, false).bytes_consumed); | 117 EXPECT_EQ(kDataLen, stream_->WriteData(kData1, false).bytes_consumed); |
| 116 | 118 |
| 117 // Queue a bytes_consumed write. | 119 // Queue a bytes_consumed write. |
| 118 EXPECT_EQ(kDataLen, stream_->WriteData(kData2, false).bytes_consumed); | 120 EXPECT_EQ(kDataLen, stream_->WriteData(kData2, false).bytes_consumed); |
| 119 | 121 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 stream2_->OnStreamFrame(frame2); | 304 stream2_->OnStreamFrame(frame2); |
| 303 EXPECT_EQ("", stream_->data()); | 305 EXPECT_EQ("", stream_->data()); |
| 304 | 306 |
| 305 stream_->OnStreamFrame(frame1); | 307 stream_->OnStreamFrame(frame1); |
| 306 EXPECT_EQ(decompressed_headers1, stream_->data()); | 308 EXPECT_EQ(decompressed_headers1, stream_->data()); |
| 307 | 309 |
| 308 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); | 310 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); |
| 309 stream2_->OnDecompressorAvailable(); | 311 stream2_->OnDecompressorAvailable(); |
| 310 EXPECT_EQ(decompressed_headers2, stream2_->data()); | 312 EXPECT_EQ(decompressed_headers2, stream2_->data()); |
| 311 } | 313 } |
| 314 |
| 312 TEST_F(ReliableQuicStreamTest, ProcessHeadersDelay) { | 315 TEST_F(ReliableQuicStreamTest, ProcessHeadersDelay) { |
| 313 Initialize(!kShouldProcessData); | 316 Initialize(!kShouldProcessData); |
| 314 | 317 |
| 315 string compressed_headers = compressor_->CompressHeaders(headers_); | 318 string compressed_headers = compressor_->CompressHeaders(headers_); |
| 316 QuicStreamFrame frame1(stream_->id(), false, 0, compressed_headers); | 319 QuicStreamFrame frame1(stream_->id(), false, 0, compressed_headers); |
| 317 string decompressed_headers = | 320 string decompressed_headers = |
| 318 SpdyUtils::SerializeUncompressedHeaders(headers_); | 321 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 319 | 322 |
| 320 // Send the headers to the stream and verify they were decompressed. | 323 // Send the headers to the stream and verify they were decompressed. |
| 321 stream_->OnStreamFrame(frame1); | 324 stream_->OnStreamFrame(frame1); |
| 322 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); | 325 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); |
| 323 | 326 |
| 324 // Verify that we are now able to handle the body data, | 327 // Verify that we are now able to handle the body data, |
| 325 // even though the stream has not processed the headers. | 328 // even though the stream has not processed the headers. |
| 326 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_HEADER_ID)) | 329 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_HEADER_ID)) |
| 327 .Times(0); | 330 .Times(0); |
| 328 QuicStreamFrame frame2(stream_->id(), false, compressed_headers.length(), | 331 QuicStreamFrame frame2(stream_->id(), false, compressed_headers.length(), |
| 329 "body data"); | 332 "body data"); |
| 330 stream_->OnStreamFrame(frame2); | 333 stream_->OnStreamFrame(frame2); |
| 331 } | 334 } |
| 332 | 335 |
| 333 } // namespace | 336 } // namespace |
| 334 } // namespace test | 337 } // namespace test |
| 335 } // namespace net | 338 } // namespace net |
| OLD | NEW |