| 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/core/quic_flow_controller.h" | 5 #include "net/quic/core/quic_flow_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "net/quic/platform/api/quic_str_cat.h" | 9 #include "net/quic/platform/api/quic_str_cat.h" |
| 10 #include "net/quic/platform/api/quic_test.h" |
| 10 #include "net/quic/test_tools/quic_connection_peer.h" | 11 #include "net/quic/test_tools/quic_connection_peer.h" |
| 11 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 12 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
| 12 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 13 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
| 13 #include "net/quic/test_tools/quic_test_utils.h" | 14 #include "net/quic/test_tools/quic_test_utils.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | 15 |
| 16 using testing::_; | 16 using testing::_; |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 namespace test { | 19 namespace test { |
| 20 | 20 |
| 21 // Receive window auto-tuning uses RTT in its logic. | 21 // Receive window auto-tuning uses RTT in its logic. |
| 22 const int64_t kRtt = 100; | 22 const int64_t kRtt = 100; |
| 23 | 23 |
| 24 class MockFlowController : public QuicFlowControllerInterface { | 24 class MockFlowController : public QuicFlowControllerInterface { |
| 25 public: | 25 public: |
| 26 MockFlowController() {} | 26 MockFlowController() {} |
| 27 ~MockFlowController() override {} | 27 ~MockFlowController() override {} |
| 28 | 28 |
| 29 MOCK_METHOD1(EnsureWindowAtLeast, void(QuicByteCount)); | 29 MOCK_METHOD1(EnsureWindowAtLeast, void(QuicByteCount)); |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(MockFlowController); | 32 DISALLOW_COPY_AND_ASSIGN(MockFlowController); |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class QuicFlowControllerTest : public ::testing::Test { | 35 class QuicFlowControllerTest : public QuicTest { |
| 36 public: | 36 public: |
| 37 QuicFlowControllerTest() | 37 QuicFlowControllerTest() |
| 38 : stream_id_(1234), | 38 : stream_id_(1234), |
| 39 send_window_(kInitialSessionFlowControlWindowForTest), | 39 send_window_(kInitialSessionFlowControlWindowForTest), |
| 40 receive_window_(kInitialSessionFlowControlWindowForTest), | 40 receive_window_(kInitialSessionFlowControlWindowForTest), |
| 41 connection_(&helper_, &alarm_factory_, Perspective::IS_CLIENT) { | 41 connection_(&helper_, &alarm_factory_, Perspective::IS_CLIENT) { |
| 42 FLAGS_quic_reloadable_flag_quic_flow_control_faster_autotune = true; | 42 FLAGS_quic_reloadable_flag_quic_flow_control_faster_autotune = true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void Initialize() { | 45 void Initialize() { |
| 46 flow_controller_.reset(new QuicFlowController( | 46 flow_controller_.reset(new QuicFlowController( |
| 47 &connection_, stream_id_, Perspective::IS_CLIENT, send_window_, | 47 &connection_, stream_id_, Perspective::IS_CLIENT, send_window_, |
| 48 receive_window_, false, &session_flow_controller_)); | 48 receive_window_, false, &session_flow_controller_)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 protected: | 51 protected: |
| 52 QuicStreamId stream_id_; | 52 QuicStreamId stream_id_; |
| 53 QuicByteCount send_window_; | 53 QuicByteCount send_window_; |
| 54 QuicByteCount receive_window_; | 54 QuicByteCount receive_window_; |
| 55 std::unique_ptr<QuicFlowController> flow_controller_; | 55 std::unique_ptr<QuicFlowController> flow_controller_; |
| 56 MockQuicConnectionHelper helper_; | 56 MockQuicConnectionHelper helper_; |
| 57 MockAlarmFactory alarm_factory_; | 57 MockAlarmFactory alarm_factory_; |
| 58 MockQuicConnection connection_; | 58 MockQuicConnection connection_; |
| 59 MockFlowController session_flow_controller_; | 59 MockFlowController session_flow_controller_; |
| 60 QuicFlagSaver flag_saver_; | |
| 61 }; | 60 }; |
| 62 | 61 |
| 63 TEST_F(QuicFlowControllerTest, SendingBytes) { | 62 TEST_F(QuicFlowControllerTest, SendingBytes) { |
| 64 Initialize(); | 63 Initialize(); |
| 65 | 64 |
| 66 EXPECT_FALSE(flow_controller_->IsBlocked()); | 65 EXPECT_FALSE(flow_controller_->IsBlocked()); |
| 67 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 66 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 68 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); | 67 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); |
| 69 | 68 |
| 70 // Send some bytes, but not enough to block. | 69 // Send some bytes, but not enough to block. |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 418 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
| 420 | 419 |
| 421 QuicByteCount new_threshold = | 420 QuicByteCount new_threshold = |
| 422 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); | 421 QuicFlowControllerPeer::WindowUpdateThreshold(flow_controller_.get()); |
| 423 | 422 |
| 424 EXPECT_EQ(new_threshold, threshold); | 423 EXPECT_EQ(new_threshold, threshold); |
| 425 } | 424 } |
| 426 | 425 |
| 427 } // namespace test | 426 } // namespace test |
| 428 } // namespace net | 427 } // namespace net |
| OLD | NEW |