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_ack_notifier.h" | 7 #include "net/quic/quic_ack_notifier.h" |
8 #include "net/quic/quic_connection.h" | 8 #include "net/quic/quic_connection.h" |
9 #include "net/quic/quic_spdy_compressor.h" | 9 #include "net/quic/quic_spdy_compressor.h" |
10 #include "net/quic/quic_spdy_decompressor.h" | 10 #include "net/quic/quic_spdy_decompressor.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 : ReliableQuicStream(id, session), | 43 : ReliableQuicStream(id, session), |
44 should_process_data_(should_process_data) {} | 44 should_process_data_(should_process_data) {} |
45 | 45 |
46 virtual uint32 ProcessData(const char* data, uint32 data_len) OVERRIDE { | 46 virtual uint32 ProcessData(const char* data, uint32 data_len) OVERRIDE { |
47 EXPECT_NE(0u, data_len); | 47 EXPECT_NE(0u, data_len); |
48 DVLOG(1) << "ProcessData data_len: " << data_len; | 48 DVLOG(1) << "ProcessData data_len: " << data_len; |
49 data_ += string(data, data_len); | 49 data_ += string(data, data_len); |
50 return should_process_data_ ? data_len : 0; | 50 return should_process_data_ ? data_len : 0; |
51 } | 51 } |
52 | 52 |
53 using ReliableQuicStream::WriteData; | 53 using ReliableQuicStream::WriteOrBufferData; |
54 using ReliableQuicStream::CloseReadSide; | 54 using ReliableQuicStream::CloseReadSide; |
55 using ReliableQuicStream::CloseWriteSide; | 55 using ReliableQuicStream::CloseWriteSide; |
56 | 56 |
57 const string& data() const { return data_; } | 57 const string& data() const { return data_; } |
58 | 58 |
59 private: | 59 private: |
60 bool should_process_data_; | 60 bool should_process_data_; |
61 string data_; | 61 string data_; |
62 }; | 62 }; |
63 | 63 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 TEST_F(ReliableQuicStreamTest, WriteAllData) { | 122 TEST_F(ReliableQuicStreamTest, WriteAllData) { |
123 Initialize(kShouldProcessData); | 123 Initialize(kShouldProcessData); |
124 | 124 |
125 connection_->options()->max_packet_length = | 125 connection_->options()->max_packet_length = |
126 1 + QuicPacketCreator::StreamFramePacketOverhead( | 126 1 + QuicPacketCreator::StreamFramePacketOverhead( |
127 connection_->version(), PACKET_8BYTE_GUID, !kIncludeVersion, | 127 connection_->version(), PACKET_8BYTE_GUID, !kIncludeVersion, |
128 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); | 128 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); |
129 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( | 129 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( |
130 Return(QuicConsumedData(kDataLen, true))); | 130 Return(QuicConsumedData(kDataLen, true))); |
131 EXPECT_EQ(kDataLen, stream_->WriteData(kData1, false).bytes_consumed); | 131 stream_->WriteOrBufferData(kData1, false); |
132 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); | 132 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); |
133 } | 133 } |
134 | 134 |
135 // TODO(rtenneti): Death tests crash on OS_ANDROID. | 135 // TODO(rtenneti): Death tests crash on OS_ANDROID. |
136 #if GTEST_HAS_DEATH_TEST && !defined(NDEBUG) && !defined(OS_ANDROID) | 136 #if GTEST_HAS_DEATH_TEST && !defined(NDEBUG) && !defined(OS_ANDROID) |
137 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) { | 137 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) { |
138 Initialize(kShouldProcessData); | 138 Initialize(kShouldProcessData); |
139 | 139 |
140 // Write no data and no fin. If we consume nothing we should not be write | 140 // Write no data and no fin. If we consume nothing we should not be write |
141 // blocked. | 141 // blocked. |
142 EXPECT_DEBUG_DEATH({ | 142 EXPECT_DEBUG_DEATH({ |
143 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( | 143 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( |
144 Return(QuicConsumedData(0, false))); | 144 Return(QuicConsumedData(0, false))); |
145 stream_->WriteData(StringPiece(), false); | 145 stream_->WriteOrBufferData(StringPiece(), false); |
146 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); | 146 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); |
147 }, ""); | 147 }, ""); |
148 } | 148 } |
149 #endif // GTEST_HAS_DEATH_TEST && !defined(NDEBUG) && !defined(OS_ANDROID) | 149 #endif // GTEST_HAS_DEATH_TEST && !defined(NDEBUG) && !defined(OS_ANDROID) |
150 | 150 |
151 TEST_F(ReliableQuicStreamTest, BlockIfOnlySomeDataConsumed) { | 151 TEST_F(ReliableQuicStreamTest, BlockIfOnlySomeDataConsumed) { |
152 Initialize(kShouldProcessData); | 152 Initialize(kShouldProcessData); |
153 | 153 |
154 // Write some data and no fin. If we consume some but not all of the data, | 154 // Write some data and no fin. If we consume some but not all of the data, |
155 // we should be write blocked a not all the data was consumed. | 155 // we should be write blocked a not all the data was consumed. |
156 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( | 156 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( |
157 Return(QuicConsumedData(1, false))); | 157 Return(QuicConsumedData(1, false))); |
158 stream_->WriteData(StringPiece(kData1, 2), false); | 158 stream_->WriteOrBufferData(StringPiece(kData1, 2), false); |
159 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); | 159 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
160 } | 160 } |
161 | 161 |
162 | 162 |
163 TEST_F(ReliableQuicStreamTest, BlockIfFinNotConsumedWithData) { | 163 TEST_F(ReliableQuicStreamTest, BlockIfFinNotConsumedWithData) { |
164 Initialize(kShouldProcessData); | 164 Initialize(kShouldProcessData); |
165 | 165 |
166 // Write some data and no fin. If we consume all the data but not the fin, | 166 // Write some data and no fin. If we consume all the data but not the fin, |
167 // we should be write blocked because the fin was not consumed. | 167 // we should be write blocked because the fin was not consumed. |
168 // (This should never actually happen as the fin should be sent out with the | 168 // (This should never actually happen as the fin should be sent out with the |
169 // last data) | 169 // last data) |
170 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( | 170 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( |
171 Return(QuicConsumedData(2, false))); | 171 Return(QuicConsumedData(2, false))); |
172 stream_->WriteData(StringPiece(kData1, 2), true); | 172 stream_->WriteOrBufferData(StringPiece(kData1, 2), true); |
173 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); | 173 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
174 } | 174 } |
175 | 175 |
176 TEST_F(ReliableQuicStreamTest, BlockIfSoloFinNotConsumed) { | 176 TEST_F(ReliableQuicStreamTest, BlockIfSoloFinNotConsumed) { |
177 Initialize(kShouldProcessData); | 177 Initialize(kShouldProcessData); |
178 | 178 |
179 // Write no data and a fin. If we consume nothing we should be write blocked, | 179 // Write no data and a fin. If we consume nothing we should be write blocked, |
180 // as the fin was not consumed. | 180 // as the fin was not consumed. |
181 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( | 181 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( |
182 Return(QuicConsumedData(0, false))); | 182 Return(QuicConsumedData(0, false))); |
183 stream_->WriteData(StringPiece(), true); | 183 stream_->WriteOrBufferData(StringPiece(), true); |
184 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); | 184 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
185 } | 185 } |
186 | 186 |
187 TEST_F(ReliableQuicStreamTest, WriteData) { | 187 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { |
188 Initialize(kShouldProcessData); | 188 Initialize(kShouldProcessData); |
189 | 189 |
190 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); | 190 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); |
191 connection_->options()->max_packet_length = | 191 connection_->options()->max_packet_length = |
192 1 + QuicPacketCreator::StreamFramePacketOverhead( | 192 1 + QuicPacketCreator::StreamFramePacketOverhead( |
193 connection_->version(), PACKET_8BYTE_GUID, !kIncludeVersion, | 193 connection_->version(), PACKET_8BYTE_GUID, !kIncludeVersion, |
194 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); | 194 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); |
195 EXPECT_CALL(*session_, WritevData(_, _, 1, _, _, _)).WillOnce( | 195 EXPECT_CALL(*session_, WritevData(_, _, 1, _, _, _)).WillOnce( |
196 Return(QuicConsumedData(kDataLen - 1, false))); | 196 Return(QuicConsumedData(kDataLen - 1, false))); |
197 // The return will be kDataLen, because the last byte gets buffered. | 197 stream_->WriteOrBufferData(kData1, false); |
198 EXPECT_EQ(kDataLen, stream_->WriteData(kData1, false).bytes_consumed); | |
199 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); | 198 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); |
200 | 199 |
201 // Queue a bytes_consumed write. | 200 // Queue a bytes_consumed write. |
202 EXPECT_EQ(kDataLen, stream_->WriteData(kData2, false).bytes_consumed); | 201 stream_->WriteOrBufferData(kData2, false); |
203 | 202 |
204 // Make sure we get the tail of the first write followed by the bytes_consumed | 203 // Make sure we get the tail of the first write followed by the bytes_consumed |
205 InSequence s; | 204 InSequence s; |
206 EXPECT_CALL(*session_, WritevData(_, _, 1, _, _, _)). | 205 EXPECT_CALL(*session_, WritevData(_, _, 1, _, _, _)). |
207 WillOnce(Return(QuicConsumedData(1, false))); | 206 WillOnce(Return(QuicConsumedData(1, false))); |
208 EXPECT_CALL(*session_, WritevData(_, _, 1, _, _, _)). | 207 EXPECT_CALL(*session_, WritevData(_, _, 1, _, _, _)). |
209 WillOnce(Return(QuicConsumedData(kDataLen - 2, false))); | 208 WillOnce(Return(QuicConsumedData(kDataLen - 2, false))); |
210 stream_->OnCanWrite(); | 209 stream_->OnCanWrite(); |
211 | 210 |
212 // And finally the end of the bytes_consumed. | 211 // And finally the end of the bytes_consumed. |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_HEADER_ID)) | 556 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_HEADER_ID)) |
558 .Times(0); | 557 .Times(0); |
559 QuicStreamFrame frame2(stream_->id(), false, compressed_headers.length(), | 558 QuicStreamFrame frame2(stream_->id(), false, compressed_headers.length(), |
560 MakeIOVector("body data")); | 559 MakeIOVector("body data")); |
561 stream_->OnStreamFrame(frame2); | 560 stream_->OnStreamFrame(frame2); |
562 } | 561 } |
563 | 562 |
564 } // namespace | 563 } // namespace |
565 } // namespace test | 564 } // namespace test |
566 } // namespace net | 565 } // namespace net |
OLD | NEW |