| 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" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "net/quic/core/quic_connection.h" | 12 #include "net/quic/core/quic_connection.h" |
| 13 #include "net/quic/core/quic_utils.h" | 13 #include "net/quic/core/quic_utils.h" |
| 14 #include "net/quic/core/quic_write_blocked_list.h" | 14 #include "net/quic/core/quic_write_blocked_list.h" |
| 15 #include "net/quic/core/spdy_utils.h" | 15 #include "net/quic/core/spdy_utils.h" |
| 16 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 16 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
| 17 #include "net/quic/test_tools/quic_session_peer.h" | 17 #include "net/quic/test_tools/quic_session_peer.h" |
| 18 #include "net/quic/test_tools/quic_stream_peer.h" |
| 18 #include "net/quic/test_tools/quic_test_utils.h" | 19 #include "net/quic/test_tools/quic_test_utils.h" |
| 19 #include "net/quic/test_tools/reliable_quic_stream_peer.h" | |
| 20 #include "net/test/gtest_util.h" | 20 #include "net/test/gtest_util.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 | 22 |
| 23 using base::StringPiece; | 23 using base::StringPiece; |
| 24 using std::min; | 24 using std::min; |
| 25 using std::string; | 25 using std::string; |
| 26 using testing::AnyNumber; | 26 using testing::AnyNumber; |
| 27 using testing::Invoke; | 27 using testing::Invoke; |
| 28 using testing::Return; | 28 using testing::Return; |
| 29 using testing::StrictMock; | 29 using testing::StrictMock; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 char buffer[2048]; | 50 char buffer[2048]; |
| 51 struct iovec vec; | 51 struct iovec vec; |
| 52 vec.iov_base = buffer; | 52 vec.iov_base = buffer; |
| 53 vec.iov_len = arraysize(buffer); | 53 vec.iov_len = arraysize(buffer); |
| 54 size_t bytes_read = Readv(&vec, 1); | 54 size_t bytes_read = Readv(&vec, 1); |
| 55 data_ += string(buffer, bytes_read); | 55 data_ += string(buffer, bytes_read); |
| 56 } | 56 } |
| 57 | 57 |
| 58 using ReliableQuicStream::WriteOrBufferData; | 58 using QuicStream::WriteOrBufferData; |
| 59 using ReliableQuicStream::CloseWriteSide; | 59 using QuicStream::CloseWriteSide; |
| 60 | 60 |
| 61 const string& data() const { return data_; } | 61 const string& data() const { return data_; } |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 bool should_process_data_; | 64 bool should_process_data_; |
| 65 string data_; | 65 string data_; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 class QuicSpdyStreamTest : public ::testing::TestWithParam<QuicVersion> { | 68 class QuicSpdyStreamTest : public ::testing::TestWithParam<QuicVersion> { |
| 69 public: | 69 public: |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)); | 395 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)); |
| 396 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) | 396 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 397 .WillOnce(Return(QuicConsumedData(kWindow, true))); | 397 .WillOnce(Return(QuicConsumedData(kWindow, true))); |
| 398 stream_->WriteOrBufferData(body, false, nullptr); | 398 stream_->WriteOrBufferData(body, false, nullptr); |
| 399 | 399 |
| 400 // Should have sent as much as possible, resulting in no send window left. | 400 // Should have sent as much as possible, resulting in no send window left. |
| 401 EXPECT_EQ(0u, | 401 EXPECT_EQ(0u, |
| 402 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller())); | 402 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller())); |
| 403 | 403 |
| 404 // And we should have queued the overflowed data. | 404 // And we should have queued the overflowed data. |
| 405 EXPECT_EQ(kOverflow, ReliableQuicStreamPeer::SizeOfQueuedData(stream_)); | 405 EXPECT_EQ(kOverflow, QuicStreamPeer::SizeOfQueuedData(stream_)); |
| 406 } | 406 } |
| 407 | 407 |
| 408 TEST_P(QuicSpdyStreamTest, StreamFlowControlNoWindowUpdateIfNotConsumed) { | 408 TEST_P(QuicSpdyStreamTest, StreamFlowControlNoWindowUpdateIfNotConsumed) { |
| 409 // The flow control receive window decreases whenever we add new bytes to the | 409 // The flow control receive window decreases whenever we add new bytes to the |
| 410 // sequencer, whether they are consumed immediately or buffered. However we | 410 // sequencer, whether they are consumed immediately or buffered. However we |
| 411 // only send WINDOW_UPDATE frames based on increasing number of bytes | 411 // only send WINDOW_UPDATE frames based on increasing number of bytes |
| 412 // consumed. | 412 // consumed. |
| 413 | 413 |
| 414 // Don't process data - it will be buffered instead. | 414 // Don't process data - it will be buffered instead. |
| 415 Initialize(!kShouldProcessData); | 415 Initialize(!kShouldProcessData); |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 | 931 |
| 932 // Writing Trailers should fail, as the FIN has already been sent. | 932 // Writing Trailers should fail, as the FIN has already been sent. |
| 933 // populated with the number of body bytes written. | 933 // populated with the number of body bytes written. |
| 934 EXPECT_QUIC_BUG(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), | 934 EXPECT_QUIC_BUG(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), |
| 935 "Trailers cannot be sent after a FIN"); | 935 "Trailers cannot be sent after a FIN"); |
| 936 } | 936 } |
| 937 | 937 |
| 938 } // namespace | 938 } // namespace |
| 939 } // namespace test | 939 } // namespace test |
| 940 } // namespace net | 940 } // namespace net |
| OLD | NEW |