| 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_flags.h" | 9 #include "net/quic/quic_flags.h" |
| 10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 session_.reset(new StrictMock<MockSession>(connection_)); | 114 session_.reset(new StrictMock<MockSession>(connection_)); |
| 115 | 115 |
| 116 // New streams rely on having the peer's flow control receive window | 116 // New streams rely on having the peer's flow control receive window |
| 117 // negotiated in the config. | 117 // negotiated in the config. |
| 118 QuicConfigPeer::SetReceivedInitialFlowControlWindow( | 118 QuicConfigPeer::SetReceivedInitialFlowControlWindow( |
| 119 session_->config(), initial_flow_control_window_bytes_); | 119 session_->config(), initial_flow_control_window_bytes_); |
| 120 | 120 |
| 121 stream_.reset(new TestStream(kHeadersStreamId, session_.get(), | 121 stream_.reset(new TestStream(kHeadersStreamId, session_.get(), |
| 122 stream_should_process_data)); | 122 stream_should_process_data)); |
| 123 write_blocked_list_ = | 123 write_blocked_list_ = |
| 124 QuicSessionPeer::GetWriteblockedStreams(session_.get()); | 124 QuicSessionPeer::GetWriteBlockedStreams(session_.get()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool fin_sent() { return ReliableQuicStreamPeer::FinSent(stream_.get()); } | 127 bool fin_sent() { return ReliableQuicStreamPeer::FinSent(stream_.get()); } |
| 128 bool rst_sent() { return ReliableQuicStreamPeer::RstSent(stream_.get()); } | 128 bool rst_sent() { return ReliableQuicStreamPeer::RstSent(stream_.get()); } |
| 129 | 129 |
| 130 void set_initial_flow_control_window_bytes(uint32 val) { | 130 void set_initial_flow_control_window_bytes(uint32 val) { |
| 131 initial_flow_control_window_bytes_ = val; | 131 initial_flow_control_window_bytes_ = val; |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool HasWriteBlockedStreams() { | 134 bool HasWriteBlockedStreams() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 146 QuicTime::Delta zero_; | 146 QuicTime::Delta zero_; |
| 147 QuicVersionVector supported_versions_; | 147 QuicVersionVector supported_versions_; |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 TEST_F(ReliableQuicStreamTest, WriteAllData) { | 150 TEST_F(ReliableQuicStreamTest, WriteAllData) { |
| 151 Initialize(kShouldProcessData); | 151 Initialize(kShouldProcessData); |
| 152 | 152 |
| 153 connection_->options()->max_packet_length = | 153 connection_->options()->max_packet_length = |
| 154 1 + QuicPacketCreator::StreamFramePacketOverhead( | 154 1 + QuicPacketCreator::StreamFramePacketOverhead( |
| 155 connection_->version(), PACKET_8BYTE_CONNECTION_ID, | 155 connection_->version(), PACKET_8BYTE_CONNECTION_ID, |
| 156 !kIncludeVersion, PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); | 156 !kIncludeVersion, PACKET_6BYTE_SEQUENCE_NUMBER, 0u, |
| 157 NOT_IN_FEC_GROUP); |
| 157 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 158 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) |
| 158 .WillOnce(Return(QuicConsumedData(kDataLen, true))); | 159 .WillOnce(Return(QuicConsumedData(kDataLen, true))); |
| 159 stream_->WriteOrBufferData(kData1, false, NULL); | 160 stream_->WriteOrBufferData(kData1, false, NULL); |
| 160 EXPECT_FALSE(HasWriteBlockedStreams()); | 161 EXPECT_FALSE(HasWriteBlockedStreams()); |
| 161 } | 162 } |
| 162 | 163 |
| 163 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) { | 164 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) { |
| 164 Initialize(kShouldProcessData); | 165 Initialize(kShouldProcessData); |
| 165 | 166 |
| 166 // Write no data and no fin. If we consume nothing we should not be write | 167 // Write no data and no fin. If we consume nothing we should not be write |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); | 205 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
| 205 } | 206 } |
| 206 | 207 |
| 207 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { | 208 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { |
| 208 Initialize(kShouldProcessData); | 209 Initialize(kShouldProcessData); |
| 209 | 210 |
| 210 EXPECT_FALSE(HasWriteBlockedStreams()); | 211 EXPECT_FALSE(HasWriteBlockedStreams()); |
| 211 connection_->options()->max_packet_length = | 212 connection_->options()->max_packet_length = |
| 212 1 + QuicPacketCreator::StreamFramePacketOverhead( | 213 1 + QuicPacketCreator::StreamFramePacketOverhead( |
| 213 connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 214 connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
| 214 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); | 215 PACKET_6BYTE_SEQUENCE_NUMBER, 0u, NOT_IN_FEC_GROUP); |
| 215 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)).WillOnce( | 216 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)).WillOnce( |
| 216 Return(QuicConsumedData(kDataLen - 1, false))); | 217 Return(QuicConsumedData(kDataLen - 1, false))); |
| 217 stream_->WriteOrBufferData(kData1, false, NULL); | 218 stream_->WriteOrBufferData(kData1, false, NULL); |
| 218 EXPECT_TRUE(HasWriteBlockedStreams()); | 219 EXPECT_TRUE(HasWriteBlockedStreams()); |
| 219 | 220 |
| 220 // Queue a bytes_consumed write. | 221 // Queue a bytes_consumed write. |
| 221 stream_->WriteOrBufferData(kData2, false, NULL); | 222 stream_->WriteOrBufferData(kData2, false, NULL); |
| 222 | 223 |
| 223 // Make sure we get the tail of the first write followed by the bytes_consumed | 224 // Make sure we get the tail of the first write followed by the bytes_consumed |
| 224 InSequence s; | 225 InSequence s; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 TEST_F(ReliableQuicStreamTest, StreamFlowControlMultipleWindowUpdates) { | 319 TEST_F(ReliableQuicStreamTest, StreamFlowControlMultipleWindowUpdates) { |
| 319 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); | 320 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); |
| 320 set_initial_flow_control_window_bytes(1000); | 321 set_initial_flow_control_window_bytes(1000); |
| 321 | 322 |
| 322 Initialize(kShouldProcessData); | 323 Initialize(kShouldProcessData); |
| 323 | 324 |
| 324 // If we receive multiple WINDOW_UPDATES (potentially out of order), then we | 325 // If we receive multiple WINDOW_UPDATES (potentially out of order), then we |
| 325 // want to make sure we latch the largest offset we see. | 326 // want to make sure we latch the largest offset we see. |
| 326 | 327 |
| 327 // Initially should be default. | 328 // Initially should be default. |
| 328 EXPECT_EQ(initial_flow_control_window_bytes_, | 329 EXPECT_EQ( |
| 329 QuicFlowControllerPeer::SendWindowOffset( | 330 initial_flow_control_window_bytes_, |
| 330 stream_.get()->flow_controller())); | 331 QuicFlowControllerPeer::SendWindowOffset(stream_->flow_controller())); |
| 331 | 332 |
| 332 // Check a single WINDOW_UPDATE results in correct offset. | 333 // Check a single WINDOW_UPDATE results in correct offset. |
| 333 QuicWindowUpdateFrame window_update_1(stream_->id(), 1234); | 334 QuicWindowUpdateFrame window_update_1(stream_->id(), 1234); |
| 334 stream_->OnWindowUpdateFrame(window_update_1); | 335 stream_->OnWindowUpdateFrame(window_update_1); |
| 335 EXPECT_EQ(window_update_1.byte_offset, | 336 EXPECT_EQ( |
| 336 QuicFlowControllerPeer::SendWindowOffset( | 337 window_update_1.byte_offset, |
| 337 stream_.get()->flow_controller())); | 338 QuicFlowControllerPeer::SendWindowOffset(stream_->flow_controller())); |
| 338 | 339 |
| 339 // Now send a few more WINDOW_UPDATES and make sure that only the largest is | 340 // Now send a few more WINDOW_UPDATES and make sure that only the largest is |
| 340 // remembered. | 341 // remembered. |
| 341 QuicWindowUpdateFrame window_update_2(stream_->id(), 1); | 342 QuicWindowUpdateFrame window_update_2(stream_->id(), 1); |
| 342 QuicWindowUpdateFrame window_update_3(stream_->id(), 9999); | 343 QuicWindowUpdateFrame window_update_3(stream_->id(), 9999); |
| 343 QuicWindowUpdateFrame window_update_4(stream_->id(), 5678); | 344 QuicWindowUpdateFrame window_update_4(stream_->id(), 5678); |
| 344 stream_->OnWindowUpdateFrame(window_update_2); | 345 stream_->OnWindowUpdateFrame(window_update_2); |
| 345 stream_->OnWindowUpdateFrame(window_update_3); | 346 stream_->OnWindowUpdateFrame(window_update_3); |
| 346 stream_->OnWindowUpdateFrame(window_update_4); | 347 stream_->OnWindowUpdateFrame(window_update_4); |
| 347 EXPECT_EQ(window_update_3.byte_offset, | 348 EXPECT_EQ( |
| 348 QuicFlowControllerPeer::SendWindowOffset( | 349 window_update_3.byte_offset, |
| 349 stream_.get()->flow_controller())); | 350 QuicFlowControllerPeer::SendWindowOffset(stream_->flow_controller())); |
| 350 } | 351 } |
| 351 | 352 |
| 352 TEST_F(ReliableQuicStreamTest, StreamFlowControlShouldNotBlockInLessThanQ017) { | 353 TEST_F(ReliableQuicStreamTest, StreamFlowControlShouldNotBlockInLessThanQ017) { |
| 353 // TODO(rjshade): Remove this test when we no longer have any versions < | 354 // TODO(rjshade): Remove this test when we no longer have any versions < |
| 354 // QUIC_VERSION_17. | 355 // QUIC_VERSION_17. |
| 355 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); | 356 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); |
| 356 | 357 |
| 357 // Make sure we are using a version which does not support flow control. | 358 // Make sure we are using a version which does not support flow control. |
| 358 QuicVersion kTestQuicVersions[] = {QUIC_VERSION_16}; | 359 QuicVersion kTestQuicVersions[] = {QUIC_VERSION_16}; |
| 359 QuicVersionVector versions; | 360 QuicVersionVector versions; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 | 549 |
| 549 // Handle the acks. | 550 // Handle the acks. |
| 550 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); | 551 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
| 551 EXPECT_CALL(*delegate, OnAckNotification(11, 22, 33, 44, zero_)); | 552 EXPECT_CALL(*delegate, OnAckNotification(11, 22, 33, 44, zero_)); |
| 552 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); | 553 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); |
| 553 } | 554 } |
| 554 | 555 |
| 555 } // namespace | 556 } // namespace |
| 556 } // namespace test | 557 } // namespace test |
| 557 } // namespace net | 558 } // namespace net |
| OLD | NEW |