Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: net/quic/core/quic_stream_test.cc

Issue 2740453006: Add QuicStringPiece which is actually StringPiece. (Closed)
Patch Set: fix compile error and rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_stream_sequencer_test.cc ('k') | net/quic/core/quic_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/core/quic_stream.h" 5 #include "net/quic/core/quic_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "net/quic/core/quic_connection.h" 9 #include "net/quic/core/quic_connection.h"
10 #include "net/quic/core/quic_flags.h" 10 #include "net/quic/core/quic_flags.h"
11 #include "net/quic/core/quic_utils.h" 11 #include "net/quic/core/quic_utils.h"
12 #include "net/quic/core/quic_write_blocked_list.h" 12 #include "net/quic/core/quic_write_blocked_list.h"
13 #include "net/quic/core/spdy_utils.h" 13 #include "net/quic/core/spdy_utils.h"
14 #include "net/quic/platform/api/quic_logging.h" 14 #include "net/quic/platform/api/quic_logging.h"
15 #include "net/quic/platform/api/quic_ptr_util.h" 15 #include "net/quic/platform/api/quic_ptr_util.h"
16 #include "net/quic/test_tools/quic_config_peer.h" 16 #include "net/quic/test_tools/quic_config_peer.h"
17 #include "net/quic/test_tools/quic_connection_peer.h" 17 #include "net/quic/test_tools/quic_connection_peer.h"
18 #include "net/quic/test_tools/quic_flow_controller_peer.h" 18 #include "net/quic/test_tools/quic_flow_controller_peer.h"
19 #include "net/quic/test_tools/quic_session_peer.h" 19 #include "net/quic/test_tools/quic_session_peer.h"
20 #include "net/quic/test_tools/quic_stream_peer.h" 20 #include "net/quic/test_tools/quic_stream_peer.h"
21 #include "net/quic/test_tools/quic_test_utils.h" 21 #include "net/quic/test_tools/quic_test_utils.h"
22 #include "net/test/gtest_util.h" 22 #include "net/test/gtest_util.h"
23 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gmock_mutant.h" 24 #include "testing/gmock_mutant.h"
25 25
26 using base::StringPiece;
27 using std::string; 26 using std::string;
28 using testing::AnyNumber; 27 using testing::AnyNumber;
29 using testing::AtLeast; 28 using testing::AtLeast;
30 using testing::CreateFunctor; 29 using testing::CreateFunctor;
31 using testing::InSequence; 30 using testing::InSequence;
32 using testing::Invoke; 31 using testing::Invoke;
33 using testing::DoAll; 32 using testing::DoAll;
34 using testing::Return; 33 using testing::Return;
35 using testing::StrictMock; 34 using testing::StrictMock;
36 using testing::WithArgs; 35 using testing::WithArgs;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 .WillOnce(Return(QuicConsumedData(kDataLen, true))); 176 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
178 stream_->WriteOrBufferData(kData1, false, nullptr); 177 stream_->WriteOrBufferData(kData1, false, nullptr);
179 EXPECT_FALSE(HasWriteBlockedStreams()); 178 EXPECT_FALSE(HasWriteBlockedStreams());
180 } 179 }
181 180
182 TEST_F(QuicStreamTest, NoBlockingIfNoDataOrFin) { 181 TEST_F(QuicStreamTest, NoBlockingIfNoDataOrFin) {
183 Initialize(kShouldProcessData); 182 Initialize(kShouldProcessData);
184 183
185 // Write no data and no fin. If we consume nothing we should not be write 184 // Write no data and no fin. If we consume nothing we should not be write
186 // blocked. 185 // blocked.
187 EXPECT_QUIC_BUG(stream_->WriteOrBufferData(StringPiece(), false, nullptr), 186 EXPECT_QUIC_BUG(stream_->WriteOrBufferData(QuicStringPiece(), false, nullptr),
188 ""); 187 "");
189 EXPECT_FALSE(HasWriteBlockedStreams()); 188 EXPECT_FALSE(HasWriteBlockedStreams());
190 } 189 }
191 190
192 TEST_F(QuicStreamTest, BlockIfOnlySomeDataConsumed) { 191 TEST_F(QuicStreamTest, BlockIfOnlySomeDataConsumed) {
193 Initialize(kShouldProcessData); 192 Initialize(kShouldProcessData);
194 193
195 // Write some data and no fin. If we consume some but not all of the data, 194 // Write some data and no fin. If we consume some but not all of the data,
196 // we should be write blocked a not all the data was consumed. 195 // we should be write blocked a not all the data was consumed.
197 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 196 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
198 .WillOnce(Return(QuicConsumedData(1, false))); 197 .WillOnce(Return(QuicConsumedData(1, false)));
199 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr); 198 stream_->WriteOrBufferData(QuicStringPiece(kData1, 2), false, nullptr);
200 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 199 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
201 EXPECT_EQ(1u, stream_->queued_data_bytes()); 200 EXPECT_EQ(1u, stream_->queued_data_bytes());
202 } 201 }
203 202
204 TEST_F(QuicStreamTest, BlockIfFinNotConsumedWithData) { 203 TEST_F(QuicStreamTest, BlockIfFinNotConsumedWithData) {
205 Initialize(kShouldProcessData); 204 Initialize(kShouldProcessData);
206 205
207 // Write some data and no fin. If we consume all the data but not the fin, 206 // Write some data and no fin. If we consume all the data but not the fin,
208 // we should be write blocked because the fin was not consumed. 207 // we should be write blocked because the fin was not consumed.
209 // (This should never actually happen as the fin should be sent out with the 208 // (This should never actually happen as the fin should be sent out with the
210 // last data) 209 // last data)
211 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 210 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
212 .WillOnce(Return(QuicConsumedData(2, false))); 211 .WillOnce(Return(QuicConsumedData(2, false)));
213 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 212 stream_->WriteOrBufferData(QuicStringPiece(kData1, 2), true, nullptr);
214 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 213 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
215 } 214 }
216 215
217 TEST_F(QuicStreamTest, BlockIfSoloFinNotConsumed) { 216 TEST_F(QuicStreamTest, BlockIfSoloFinNotConsumed) {
218 Initialize(kShouldProcessData); 217 Initialize(kShouldProcessData);
219 218
220 // Write no data and a fin. If we consume nothing we should be write blocked, 219 // Write no data and a fin. If we consume nothing we should be write blocked,
221 // as the fin was not consumed. 220 // as the fin was not consumed.
222 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 221 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
223 .WillOnce(Return(QuicConsumedData(0, false))); 222 .WillOnce(Return(QuicConsumedData(0, false)));
224 stream_->WriteOrBufferData(StringPiece(), true, nullptr); 223 stream_->WriteOrBufferData(QuicStringPiece(), true, nullptr);
225 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 224 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
226 } 225 }
227 226
228 TEST_F(QuicStreamTest, CloseOnPartialWrite) { 227 TEST_F(QuicStreamTest, CloseOnPartialWrite) {
229 Initialize(kShouldProcessData); 228 Initialize(kShouldProcessData);
230 229
231 // Write some data and no fin. However, while writing the data 230 // Write some data and no fin. However, while writing the data
232 // close the stream and verify that MarkConnectionLevelWriteBlocked does not 231 // close the stream and verify that MarkConnectionLevelWriteBlocked does not
233 // crash with an unknown stream. 232 // crash with an unknown stream.
234 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 233 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
235 .WillOnce(Invoke(this, &QuicStreamTest::CloseStreamOnWriteError)); 234 .WillOnce(Invoke(this, &QuicStreamTest::CloseStreamOnWriteError));
236 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr); 235 stream_->WriteOrBufferData(QuicStringPiece(kData1, 2), false, nullptr);
237 ASSERT_EQ(0u, write_blocked_list_->NumBlockedStreams()); 236 ASSERT_EQ(0u, write_blocked_list_->NumBlockedStreams());
238 } 237 }
239 238
240 TEST_F(QuicStreamTest, WriteOrBufferData) { 239 TEST_F(QuicStreamTest, WriteOrBufferData) {
241 Initialize(kShouldProcessData); 240 Initialize(kShouldProcessData);
242 241
243 EXPECT_FALSE(HasWriteBlockedStreams()); 242 EXPECT_FALSE(HasWriteBlockedStreams());
244 size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead( 243 size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead(
245 connection_->version(), PACKET_8BYTE_CONNECTION_ID, 244 connection_->version(), PACKET_8BYTE_CONNECTION_ID,
246 !kIncludeVersion, !kIncludeDiversificationNonce, 245 !kIncludeVersion, !kIncludeDiversificationNonce,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // before termination. 286 // before termination.
288 // Test that if no FIN has been sent, we send a RST. 287 // Test that if no FIN has been sent, we send a RST.
289 288
290 Initialize(kShouldProcessData); 289 Initialize(kShouldProcessData);
291 EXPECT_FALSE(fin_sent()); 290 EXPECT_FALSE(fin_sent());
292 EXPECT_FALSE(rst_sent()); 291 EXPECT_FALSE(rst_sent());
293 292
294 // Write some data, with no FIN. 293 // Write some data, with no FIN.
295 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 294 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
296 .WillOnce(Return(QuicConsumedData(1, false))); 295 .WillOnce(Return(QuicConsumedData(1, false)));
297 stream_->WriteOrBufferData(StringPiece(kData1, 1), false, nullptr); 296 stream_->WriteOrBufferData(QuicStringPiece(kData1, 1), false, nullptr);
298 EXPECT_FALSE(fin_sent()); 297 EXPECT_FALSE(fin_sent());
299 EXPECT_FALSE(rst_sent()); 298 EXPECT_FALSE(rst_sent());
300 299
301 // Now close the stream, and expect that we send a RST. 300 // Now close the stream, and expect that we send a RST.
302 EXPECT_CALL(*session_, SendRstStream(_, _, _)); 301 EXPECT_CALL(*session_, SendRstStream(_, _, _));
303 stream_->OnClose(); 302 stream_->OnClose();
304 EXPECT_FALSE(fin_sent()); 303 EXPECT_FALSE(fin_sent());
305 EXPECT_TRUE(rst_sent()); 304 EXPECT_TRUE(rst_sent());
306 } 305 }
307 306
308 TEST_F(QuicStreamTest, RstNotSentIfFinSent) { 307 TEST_F(QuicStreamTest, RstNotSentIfFinSent) {
309 // For flow control accounting, a stream must send either a FIN or a RST frame 308 // For flow control accounting, a stream must send either a FIN or a RST frame
310 // before termination. 309 // before termination.
311 // Test that if a FIN has been sent, we don't also send a RST. 310 // Test that if a FIN has been sent, we don't also send a RST.
312 311
313 Initialize(kShouldProcessData); 312 Initialize(kShouldProcessData);
314 EXPECT_FALSE(fin_sent()); 313 EXPECT_FALSE(fin_sent());
315 EXPECT_FALSE(rst_sent()); 314 EXPECT_FALSE(rst_sent());
316 315
317 // Write some data, with FIN. 316 // Write some data, with FIN.
318 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 317 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
319 .WillOnce(Return(QuicConsumedData(1, true))); 318 .WillOnce(Return(QuicConsumedData(1, true)));
320 stream_->WriteOrBufferData(StringPiece(kData1, 1), true, nullptr); 319 stream_->WriteOrBufferData(QuicStringPiece(kData1, 1), true, nullptr);
321 EXPECT_TRUE(fin_sent()); 320 EXPECT_TRUE(fin_sent());
322 EXPECT_FALSE(rst_sent()); 321 EXPECT_FALSE(rst_sent());
323 322
324 // Now close the stream, and expect that we do not send a RST. 323 // Now close the stream, and expect that we do not send a RST.
325 stream_->OnClose(); 324 stream_->OnClose();
326 EXPECT_TRUE(fin_sent()); 325 EXPECT_TRUE(fin_sent());
327 EXPECT_FALSE(rst_sent()); 326 EXPECT_FALSE(rst_sent());
328 } 327 }
329 328
330 TEST_F(QuicStreamTest, OnlySendOneRst) { 329 TEST_F(QuicStreamTest, OnlySendOneRst) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 // Verify that when we receive a packet which violates flow control (i.e. sends 532 // Verify that when we receive a packet which violates flow control (i.e. sends
534 // too much data on the stream) that the stream sequencer never sees this frame, 533 // too much data on the stream) that the stream sequencer never sees this frame,
535 // as we check for violation and close the connection early. 534 // as we check for violation and close the connection early.
536 TEST_F(QuicStreamTest, StreamSequencerNeverSeesPacketsViolatingFlowControl) { 535 TEST_F(QuicStreamTest, StreamSequencerNeverSeesPacketsViolatingFlowControl) {
537 Initialize(kShouldProcessData); 536 Initialize(kShouldProcessData);
538 537
539 // Receive a stream frame that violates flow control: the byte offset is 538 // Receive a stream frame that violates flow control: the byte offset is
540 // higher than the receive window offset. 539 // higher than the receive window offset.
541 QuicStreamFrame frame(stream_->id(), false, 540 QuicStreamFrame frame(stream_->id(), false,
542 kInitialSessionFlowControlWindowForTest + 1, 541 kInitialSessionFlowControlWindowForTest + 1,
543 StringPiece(".")); 542 QuicStringPiece("."));
544 EXPECT_GT(frame.offset, QuicFlowControllerPeer::ReceiveWindowOffset( 543 EXPECT_GT(frame.offset, QuicFlowControllerPeer::ReceiveWindowOffset(
545 stream_->flow_controller())); 544 stream_->flow_controller()));
546 545
547 // Stream should not accept the frame, and the connection should be closed. 546 // Stream should not accept the frame, and the connection should be closed.
548 EXPECT_CALL(*connection_, 547 EXPECT_CALL(*connection_,
549 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)); 548 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _));
550 stream_->OnStreamFrame(frame); 549 stream_->OnStreamFrame(frame);
551 } 550 }
552 551
553 // Verify that after the consumer calls StopReading(), the stream still sends 552 // Verify that after the consumer calls StopReading(), the stream still sends
(...skipping 20 matching lines...) Expand all
574 kInitialStreamFlowControlWindowForTest, 573 kInitialStreamFlowControlWindowForTest,
575 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller())); 574 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller()));
576 } 575 }
577 576
578 TEST_F(QuicStreamTest, FinalByteOffsetFromFin) { 577 TEST_F(QuicStreamTest, FinalByteOffsetFromFin) {
579 Initialize(kShouldProcessData); 578 Initialize(kShouldProcessData);
580 579
581 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); 580 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset());
582 581
583 QuicStreamFrame stream_frame_no_fin(stream_->id(), false, 1234, 582 QuicStreamFrame stream_frame_no_fin(stream_->id(), false, 1234,
584 StringPiece(".")); 583 QuicStringPiece("."));
585 stream_->OnStreamFrame(stream_frame_no_fin); 584 stream_->OnStreamFrame(stream_frame_no_fin);
586 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); 585 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset());
587 586
588 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, 587 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234,
589 StringPiece(".")); 588 QuicStringPiece("."));
590 stream_->OnStreamFrame(stream_frame_with_fin); 589 stream_->OnStreamFrame(stream_frame_with_fin);
591 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 590 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
592 } 591 }
593 592
594 TEST_F(QuicStreamTest, FinalByteOffsetFromRst) { 593 TEST_F(QuicStreamTest, FinalByteOffsetFromRst) {
595 Initialize(kShouldProcessData); 594 Initialize(kShouldProcessData);
596 595
597 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); 596 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset());
598 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234); 597 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234);
599 stream_->OnStreamReset(rst_frame); 598 stream_->OnStreamReset(rst_frame);
(...skipping 15 matching lines...) Expand all
615 const QuicStreamOffset current_stream_flow_control_offset = 614 const QuicStreamOffset current_stream_flow_control_offset =
616 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller()); 615 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller());
617 const QuicStreamOffset current_connection_flow_control_offset = 616 const QuicStreamOffset current_connection_flow_control_offset =
618 QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller()); 617 QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller());
619 ASSERT_GT(kByteOffsetExceedingFlowControlWindow, 618 ASSERT_GT(kByteOffsetExceedingFlowControlWindow,
620 current_stream_flow_control_offset); 619 current_stream_flow_control_offset);
621 ASSERT_GT(kByteOffsetExceedingFlowControlWindow, 620 ASSERT_GT(kByteOffsetExceedingFlowControlWindow,
622 current_connection_flow_control_offset); 621 current_connection_flow_control_offset);
623 QuicStreamFrame zero_length_stream_frame_with_fin( 622 QuicStreamFrame zero_length_stream_frame_with_fin(
624 stream_->id(), /*fin=*/true, kByteOffsetExceedingFlowControlWindow, 623 stream_->id(), /*fin=*/true, kByteOffsetExceedingFlowControlWindow,
625 StringPiece()); 624 QuicStringPiece());
626 EXPECT_EQ(0, zero_length_stream_frame_with_fin.data_length); 625 EXPECT_EQ(0, zero_length_stream_frame_with_fin.data_length);
627 626
628 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); 627 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
629 stream_->OnStreamFrame(zero_length_stream_frame_with_fin); 628 stream_->OnStreamFrame(zero_length_stream_frame_with_fin);
630 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 629 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
631 630
632 // The flow control receive offset values should not have changed. 631 // The flow control receive offset values should not have changed.
633 EXPECT_EQ( 632 EXPECT_EQ(
634 current_stream_flow_control_offset, 633 current_stream_flow_control_offset,
635 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller())); 634 QuicFlowControllerPeer::ReceiveWindowOffset(stream_->flow_controller()));
636 EXPECT_EQ( 635 EXPECT_EQ(
637 current_connection_flow_control_offset, 636 current_connection_flow_control_offset,
638 QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller())); 637 QuicFlowControllerPeer::ReceiveWindowOffset(session_->flow_controller()));
639 } 638 }
640 639
641 TEST_F(QuicStreamTest, SetDrainingIncomingOutgoing) { 640 TEST_F(QuicStreamTest, SetDrainingIncomingOutgoing) {
642 // Don't have incoming data consumed. 641 // Don't have incoming data consumed.
643 Initialize(kShouldNotProcessData); 642 Initialize(kShouldNotProcessData);
644 643
645 // Incoming data with FIN. 644 // Incoming data with FIN.
646 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, 645 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234,
647 StringPiece(".")); 646 QuicStringPiece("."));
648 stream_->OnStreamFrame(stream_frame_with_fin); 647 stream_->OnStreamFrame(stream_frame_with_fin);
649 // The FIN has been received but not consumed. 648 // The FIN has been received but not consumed.
650 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 649 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
651 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); 650 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
652 EXPECT_FALSE(stream_->reading_stopped()); 651 EXPECT_FALSE(stream_->reading_stopped());
653 652
654 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); 653 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams());
655 654
656 // Outgoing data with FIN. 655 // Outgoing data with FIN.
657 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 656 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
658 .WillOnce(Return(QuicConsumedData(2, true))); 657 .WillOnce(Return(QuicConsumedData(2, true)));
659 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 658 stream_->WriteOrBufferData(QuicStringPiece(kData1, 2), true, nullptr);
660 EXPECT_TRUE(stream_->write_side_closed()); 659 EXPECT_TRUE(stream_->write_side_closed());
661 660
662 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get()) 661 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get())
663 ->count(kTestStreamId)); 662 ->count(kTestStreamId));
664 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); 663 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
665 } 664 }
666 665
667 TEST_F(QuicStreamTest, SetDrainingOutgoingIncoming) { 666 TEST_F(QuicStreamTest, SetDrainingOutgoingIncoming) {
668 // Don't have incoming data consumed. 667 // Don't have incoming data consumed.
669 Initialize(kShouldNotProcessData); 668 Initialize(kShouldNotProcessData);
670 669
671 // Outgoing data with FIN. 670 // Outgoing data with FIN.
672 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _)) 671 EXPECT_CALL(*session_, WritevData(stream_, kTestStreamId, _, _, _, _))
673 .WillOnce(Return(QuicConsumedData(2, true))); 672 .WillOnce(Return(QuicConsumedData(2, true)));
674 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, nullptr); 673 stream_->WriteOrBufferData(QuicStringPiece(kData1, 2), true, nullptr);
675 EXPECT_TRUE(stream_->write_side_closed()); 674 EXPECT_TRUE(stream_->write_side_closed());
676 675
677 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); 676 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams());
678 677
679 // Incoming data with FIN. 678 // Incoming data with FIN.
680 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234, 679 QuicStreamFrame stream_frame_with_fin(stream_->id(), true, 1234,
681 StringPiece(".")); 680 QuicStringPiece("."));
682 stream_->OnStreamFrame(stream_frame_with_fin); 681 stream_->OnStreamFrame(stream_frame_with_fin);
683 // The FIN has been received but not consumed. 682 // The FIN has been received but not consumed.
684 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 683 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
685 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); 684 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_));
686 EXPECT_FALSE(stream_->reading_stopped()); 685 EXPECT_FALSE(stream_->reading_stopped());
687 686
688 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get()) 687 EXPECT_EQ(1u, QuicSessionPeer::GetDrainingStreams(session_.get())
689 ->count(kTestStreamId)); 688 ->count(kTestStreamId));
690 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); 689 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
691 } 690 }
692 691
693 TEST_F(QuicStreamTest, EarlyResponseFinHandling) { 692 TEST_F(QuicStreamTest, EarlyResponseFinHandling) {
694 // Verify that if the server completes the response before reading the end of 693 // Verify that if the server completes the response before reading the end of
695 // the request, the received FIN is recorded. 694 // the request, the received FIN is recorded.
696 695
697 Initialize(kShouldProcessData); 696 Initialize(kShouldProcessData);
698 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); 697 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
699 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) 698 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _))
700 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); 699 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData));
701 700
702 // Receive data for the request. 701 // Receive data for the request.
703 QuicStreamFrame frame1(stream_->id(), false, 0, StringPiece("Start")); 702 QuicStreamFrame frame1(stream_->id(), false, 0, QuicStringPiece("Start"));
704 stream_->OnStreamFrame(frame1); 703 stream_->OnStreamFrame(frame1);
705 // When QuicSimpleServerStream sends the response, it calls 704 // When QuicSimpleServerStream sends the response, it calls
706 // QuicStream::CloseReadSide() first. 705 // QuicStream::CloseReadSide() first.
707 QuicStreamPeer::CloseReadSide(stream_); 706 QuicStreamPeer::CloseReadSide(stream_);
708 // Send data and FIN for the response. 707 // Send data and FIN for the response.
709 stream_->WriteOrBufferData(kData1, false, nullptr); 708 stream_->WriteOrBufferData(kData1, false, nullptr);
710 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); 709 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_));
711 // Receive remaining data and FIN for the request. 710 // Receive remaining data and FIN for the request.
712 QuicStreamFrame frame2(stream_->id(), true, 0, StringPiece("End")); 711 QuicStreamFrame frame2(stream_->id(), true, 0, QuicStringPiece("End"));
713 stream_->OnStreamFrame(frame2); 712 stream_->OnStreamFrame(frame2);
714 EXPECT_TRUE(stream_->fin_received()); 713 EXPECT_TRUE(stream_->fin_received());
715 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 714 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
716 } 715 }
717 716
718 } // namespace 717 } // namespace
719 } // namespace test 718 } // namespace test
720 } // namespace net 719 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_stream_sequencer_test.cc ('k') | net/quic/core/quic_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698