| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_spdy_stream.h" | 5 #include "net/quic/core/quic_spdy_stream.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 381 |
| 382 // Set a small flow control limit. | 382 // Set a small flow control limit. |
| 383 const uint64_t kWindow = 36; | 383 const uint64_t kWindow = 36; |
| 384 QuicFlowControllerPeer::SetSendWindowOffset(stream_->flow_controller(), | 384 QuicFlowControllerPeer::SetSendWindowOffset(stream_->flow_controller(), |
| 385 kWindow); | 385 kWindow); |
| 386 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset( | 386 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset( |
| 387 stream_->flow_controller())); | 387 stream_->flow_controller())); |
| 388 | 388 |
| 389 // Try to send more data than the flow control limit allows. | 389 // Try to send more data than the flow control limit allows. |
| 390 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 390 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 391 string body; | |
| 392 const uint64_t kOverflow = 15; | 391 const uint64_t kOverflow = 15; |
| 393 GenerateBody(&body, kWindow + kOverflow); | 392 string body(kWindow + kOverflow, 'a'); |
| 394 | 393 |
| 395 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)); | 394 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)); |
| 396 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) | 395 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 397 .WillOnce(Return(QuicConsumedData(kWindow, true))); | 396 .WillOnce(Return(QuicConsumedData(kWindow, true))); |
| 398 stream_->WriteOrBufferData(body, false, nullptr); | 397 stream_->WriteOrBufferData(body, false, nullptr); |
| 399 | 398 |
| 400 // Should have sent as much as possible, resulting in no send window left. | 399 // Should have sent as much as possible, resulting in no send window left. |
| 401 EXPECT_EQ(0u, | 400 EXPECT_EQ(0u, |
| 402 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller())); | 401 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller())); |
| 403 | 402 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 420 // Set a small flow control receive window. | 419 // Set a small flow control receive window. |
| 421 const uint64_t kWindow = 36; | 420 const uint64_t kWindow = 36; |
| 422 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 421 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
| 423 kWindow); | 422 kWindow); |
| 424 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), | 423 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), |
| 425 kWindow); | 424 kWindow); |
| 426 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset( | 425 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset( |
| 427 stream_->flow_controller())); | 426 stream_->flow_controller())); |
| 428 | 427 |
| 429 // Stream receives enough data to fill a fraction of the receive window. | 428 // Stream receives enough data to fill a fraction of the receive window. |
| 430 string body; | 429 string body(kWindow / 3, 'a'); |
| 431 GenerateBody(&body, kWindow / 3); | 430 auto headers = AsHeaderList(headers_); |
| 432 ProcessHeaders(false, headers_); | 431 ProcessHeaders(false, headers_); |
| 433 | 432 |
| 434 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body)); | 433 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body)); |
| 435 stream_->OnStreamFrame(frame1); | 434 stream_->OnStreamFrame(frame1); |
| 436 EXPECT_EQ(kWindow - (kWindow / 3), QuicFlowControllerPeer::ReceiveWindowSize( | 435 EXPECT_EQ(kWindow - (kWindow / 3), QuicFlowControllerPeer::ReceiveWindowSize( |
| 437 stream_->flow_controller())); | 436 stream_->flow_controller())); |
| 438 | 437 |
| 439 // Now receive another frame which results in the receive window being over | 438 // Now receive another frame which results in the receive window being over |
| 440 // half full. This should all be buffered, decreasing the receive window but | 439 // half full. This should all be buffered, decreasing the receive window but |
| 441 // not sending WINDOW_UPDATE. | 440 // not sending WINDOW_UPDATE. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 456 // Set a small flow control limit. | 455 // Set a small flow control limit. |
| 457 const uint64_t kWindow = 36; | 456 const uint64_t kWindow = 36; |
| 458 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 457 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
| 459 kWindow); | 458 kWindow); |
| 460 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), | 459 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), |
| 461 kWindow); | 460 kWindow); |
| 462 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset( | 461 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset( |
| 463 stream_->flow_controller())); | 462 stream_->flow_controller())); |
| 464 | 463 |
| 465 // Stream receives enough data to fill a fraction of the receive window. | 464 // Stream receives enough data to fill a fraction of the receive window. |
| 466 string body; | 465 string body(kWindow / 3, 'a'); |
| 467 GenerateBody(&body, kWindow / 3); | |
| 468 ProcessHeaders(false, headers_); | 466 ProcessHeaders(false, headers_); |
| 469 stream_->ConsumeHeaderList(); | 467 stream_->ConsumeHeaderList(); |
| 470 | 468 |
| 471 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body)); | 469 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body)); |
| 472 stream_->OnStreamFrame(frame1); | 470 stream_->OnStreamFrame(frame1); |
| 473 EXPECT_EQ(kWindow - (kWindow / 3), QuicFlowControllerPeer::ReceiveWindowSize( | 471 EXPECT_EQ(kWindow - (kWindow / 3), QuicFlowControllerPeer::ReceiveWindowSize( |
| 474 stream_->flow_controller())); | 472 stream_->flow_controller())); |
| 475 | 473 |
| 476 // Now receive another frame which results in the receive window being over | 474 // Now receive another frame which results in the receive window being over |
| 477 // half full. This will trigger the stream to increase its receive window | 475 // half full. This will trigger the stream to increase its receive window |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 auto headers = AsHeaderList(headers_); | 512 auto headers = AsHeaderList(headers_); |
| 515 stream_->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), | 513 stream_->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), |
| 516 headers); | 514 headers); |
| 517 stream_->ConsumeHeaderList(); | 515 stream_->ConsumeHeaderList(); |
| 518 stream2_->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), | 516 stream2_->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), |
| 519 headers); | 517 headers); |
| 520 stream2_->ConsumeHeaderList(); | 518 stream2_->ConsumeHeaderList(); |
| 521 | 519 |
| 522 // Each stream gets a quarter window of data. This should not trigger a | 520 // Each stream gets a quarter window of data. This should not trigger a |
| 523 // WINDOW_UPDATE for either stream, nor for the connection. | 521 // WINDOW_UPDATE for either stream, nor for the connection. |
| 524 string body; | 522 string body(kWindow / 4, 'a'); |
| 525 GenerateBody(&body, kWindow / 4); | |
| 526 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body)); | 523 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body)); |
| 527 stream_->OnStreamFrame(frame1); | 524 stream_->OnStreamFrame(frame1); |
| 528 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, StringPiece(body)); | 525 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, StringPiece(body)); |
| 529 stream2_->OnStreamFrame(frame2); | 526 stream2_->OnStreamFrame(frame2); |
| 530 | 527 |
| 531 // Now receive a further single byte on one stream - again this does not | 528 // Now receive a further single byte on one stream - again this does not |
| 532 // trigger a stream WINDOW_UPDATE, but now the connection flow control window | 529 // trigger a stream WINDOW_UPDATE, but now the connection flow control window |
| 533 // is over half full and thus a connection WINDOW_UPDATE is sent. | 530 // is over half full and thus a connection WINDOW_UPDATE is sent. |
| 534 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId1, _)).Times(0); | 531 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId1, _)).Times(0); |
| 535 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId2, _)).Times(0); | 532 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId2, _)).Times(0); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 551 Initialize(!kShouldProcessData); | 548 Initialize(!kShouldProcessData); |
| 552 | 549 |
| 553 // Set a small flow control limit. | 550 // Set a small flow control limit. |
| 554 const uint64_t kWindow = 50; | 551 const uint64_t kWindow = 50; |
| 555 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 552 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
| 556 kWindow); | 553 kWindow); |
| 557 | 554 |
| 558 ProcessHeaders(false, headers_); | 555 ProcessHeaders(false, headers_); |
| 559 | 556 |
| 560 // Receive data to overflow the window, violating flow control. | 557 // Receive data to overflow the window, violating flow control. |
| 561 string body; | 558 string body(kWindow + 1, 'a'); |
| 562 GenerateBody(&body, kWindow + 1); | |
| 563 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body)); | 559 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body)); |
| 564 EXPECT_CALL(*connection_, | 560 EXPECT_CALL(*connection_, |
| 565 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)); | 561 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)); |
| 566 stream_->OnStreamFrame(frame); | 562 stream_->OnStreamFrame(frame); |
| 567 } | 563 } |
| 568 | 564 |
| 569 TEST_P(QuicSpdyStreamTest, TestHandlingQuicRstStreamNoError) { | 565 TEST_P(QuicSpdyStreamTest, TestHandlingQuicRstStreamNoError) { |
| 570 Initialize(kShouldProcessData); | 566 Initialize(kShouldProcessData); |
| 571 ProcessHeaders(false, headers_); | 567 ProcessHeaders(false, headers_); |
| 572 | 568 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 589 const uint64_t kStreamWindow = 50; | 585 const uint64_t kStreamWindow = 50; |
| 590 const uint64_t kConnectionWindow = 10; | 586 const uint64_t kConnectionWindow = 10; |
| 591 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 587 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
| 592 kStreamWindow); | 588 kStreamWindow); |
| 593 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(), | 589 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(), |
| 594 kConnectionWindow); | 590 kConnectionWindow); |
| 595 | 591 |
| 596 ProcessHeaders(false, headers_); | 592 ProcessHeaders(false, headers_); |
| 597 | 593 |
| 598 // Send enough data to overflow the connection level flow control window. | 594 // Send enough data to overflow the connection level flow control window. |
| 599 string body; | 595 string body(kConnectionWindow + 1, 'a'); |
| 600 GenerateBody(&body, kConnectionWindow + 1); | |
| 601 EXPECT_LT(body.size(), kStreamWindow); | 596 EXPECT_LT(body.size(), kStreamWindow); |
| 602 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body)); | 597 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body)); |
| 603 | 598 |
| 604 EXPECT_CALL(*connection_, | 599 EXPECT_CALL(*connection_, |
| 605 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)); | 600 CloseConnection(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _, _)); |
| 606 stream_->OnStreamFrame(frame); | 601 stream_->OnStreamFrame(frame); |
| 607 } | 602 } |
| 608 | 603 |
| 609 TEST_P(QuicSpdyStreamTest, StreamFlowControlFinNotBlocked) { | 604 TEST_P(QuicSpdyStreamTest, StreamFlowControlFinNotBlocked) { |
| 610 // An attempt to write a FIN with no data should not be flow control blocked, | 605 // An attempt to write a FIN with no data should not be flow control blocked, |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 | 926 |
| 932 // Writing Trailers should fail, as the FIN has already been sent. | 927 // Writing Trailers should fail, as the FIN has already been sent. |
| 933 // populated with the number of body bytes written. | 928 // populated with the number of body bytes written. |
| 934 EXPECT_QUIC_BUG(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), | 929 EXPECT_QUIC_BUG(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), |
| 935 "Trailers cannot be sent after a FIN"); | 930 "Trailers cannot be sent after a FIN"); |
| 936 } | 931 } |
| 937 | 932 |
| 938 } // namespace | 933 } // namespace |
| 939 } // namespace test | 934 } // namespace test |
| 940 } // namespace net | 935 } // namespace net |
| OLD | NEW |