| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/quic_flow_controller.h" | 5 #include "net/quic/quic_flow_controller.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "net/quic/quic_flags.h" | 8 #include "net/quic/quic_flags.h" |
| 9 #include "net/quic/quic_utils.h" | 9 #include "net/quic/quic_utils.h" |
| 10 #include "net/quic/test_tools/quic_connection_peer.h" | 10 #include "net/quic/test_tools/quic_connection_peer.h" |
| 11 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 11 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
| 12 #include "net/quic/test_tools/quic_test_utils.h" | 12 #include "net/quic/test_tools/quic_test_utils.h" |
| 13 #include "net/test/gtest_util.h" | 13 #include "net/test/gtest_util.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 | 15 |
| 16 using base::StringPrintf; | 16 using base::StringPrintf; |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 namespace test { | 19 namespace test { |
| 20 | 20 |
| 21 using ::testing::_; | 21 using ::testing::_; |
| 22 | 22 |
| 23 class QuicFlowControllerTest : public ::testing::Test { | 23 class QuicFlowControllerTest : public ::testing::Test { |
| 24 public: | 24 public: |
| 25 QuicFlowControllerTest() | 25 QuicFlowControllerTest() |
| 26 : stream_id_(1234), | 26 : stream_id_(1234), |
| 27 send_window_(kInitialFlowControlWindowForTest), | 27 send_window_(kInitialSessionFlowControlWindowForTest), |
| 28 receive_window_(kInitialFlowControlWindowForTest), | 28 receive_window_(kInitialSessionFlowControlWindowForTest), |
| 29 max_receive_window_(kInitialFlowControlWindowForTest), | 29 max_receive_window_(kInitialSessionFlowControlWindowForTest), |
| 30 connection_(false), | 30 connection_(false), |
| 31 old_flag_(&FLAGS_enable_quic_stream_flow_control_2, true) { | 31 old_flag_(&FLAGS_enable_quic_stream_flow_control_2, true) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 void Initialize() { | 34 void Initialize() { |
| 35 flow_controller_.reset(new QuicFlowController( | 35 flow_controller_.reset(new QuicFlowController( |
| 36 &connection_, stream_id_, false, send_window_, | 36 &connection_, stream_id_, false, send_window_, |
| 37 receive_window_, max_receive_window_)); | 37 receive_window_, max_receive_window_)); |
| 38 } | 38 } |
| 39 | 39 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 EXPECT_TRUE(flow_controller_->IsBlocked()); | 88 EXPECT_TRUE(flow_controller_->IsBlocked()); |
| 89 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); | 89 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 TEST_F(QuicFlowControllerTest, ReceivingBytes) { | 92 TEST_F(QuicFlowControllerTest, ReceivingBytes) { |
| 93 Initialize(); | 93 Initialize(); |
| 94 | 94 |
| 95 EXPECT_TRUE(flow_controller_->IsEnabled()); | 95 EXPECT_TRUE(flow_controller_->IsEnabled()); |
| 96 EXPECT_FALSE(flow_controller_->IsBlocked()); | 96 EXPECT_FALSE(flow_controller_->IsBlocked()); |
| 97 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 97 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 98 EXPECT_EQ(kInitialFlowControlWindowForTest, | 98 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, |
| 99 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | 99 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
| 100 | 100 |
| 101 // Receive some bytes, updating highest received offset, but not enough to | 101 // Receive some bytes, updating highest received offset, but not enough to |
| 102 // fill flow control receive window. | 102 // fill flow control receive window. |
| 103 EXPECT_TRUE( | 103 EXPECT_TRUE( |
| 104 flow_controller_->UpdateHighestReceivedOffset(1 + receive_window_ / 2)); | 104 flow_controller_->UpdateHighestReceivedOffset(1 + receive_window_ / 2)); |
| 105 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 105 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 106 EXPECT_EQ((receive_window_ / 2) - 1, | 106 EXPECT_EQ((receive_window_ / 2) - 1, |
| 107 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | 107 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
| 108 | 108 |
| 109 // Consume enough bytes to send a WINDOW_UPDATE frame. | 109 // Consume enough bytes to send a WINDOW_UPDATE frame. |
| 110 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, _)).Times(1); | 110 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, _)).Times(1); |
| 111 | 111 |
| 112 flow_controller_->AddBytesConsumed(1 + receive_window_ / 2); | 112 flow_controller_->AddBytesConsumed(1 + receive_window_ / 2); |
| 113 | 113 |
| 114 // Result is that once again we have a fully open receive window. | 114 // Result is that once again we have a fully open receive window. |
| 115 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 115 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 116 EXPECT_EQ(kInitialFlowControlWindowForTest, | 116 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, |
| 117 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | 117 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
| 118 } | 118 } |
| 119 | 119 |
| 120 TEST_F(QuicFlowControllerTest, | 120 TEST_F(QuicFlowControllerTest, |
| 121 DisabledWhenQuicVersionDoesNotSupportFlowControl) { | 121 DisabledWhenQuicVersionDoesNotSupportFlowControl) { |
| 122 // Only support version 16: no flow control. | 122 // Only support version 16: no flow control. |
| 123 QuicConnectionPeer::SetSupportedVersions(&connection_, | 123 QuicConnectionPeer::SetSupportedVersions(&connection_, |
| 124 SupportedVersions(QUIC_VERSION_16)); | 124 SupportedVersions(QUIC_VERSION_16)); |
| 125 | 125 |
| 126 Initialize(); | 126 Initialize(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 flow_controller_->AddBytesSent(send_window_); | 215 flow_controller_->AddBytesSent(send_window_); |
| 216 EXPECT_TRUE(flow_controller_->IsBlocked()); | 216 EXPECT_TRUE(flow_controller_->IsBlocked()); |
| 217 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); | 217 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); |
| 218 | 218 |
| 219 // BLOCKED frame should get sent as send offset has changed. | 219 // BLOCKED frame should get sent as send offset has changed. |
| 220 flow_controller_->MaybeSendBlocked(); | 220 flow_controller_->MaybeSendBlocked(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 } // namespace test | 223 } // namespace test |
| 224 } // namespace net | 224 } // namespace net |
| OLD | NEW |