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_flow_controller_peer.h" | 10 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
11 #include "net/quic/test_tools/quic_test_utils.h" | 11 #include "net/quic/test_tools/quic_test_utils.h" |
12 #include "net/test/gtest_util.h" | 12 #include "net/test/gtest_util.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 | 14 |
15 using base::StringPrintf; | 15 using base::StringPrintf; |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 namespace test { | 18 namespace test { |
19 | 19 |
20 using ::testing::_; | 20 using ::testing::_; |
21 | 21 |
22 class QuicFlowControllerTest : public ::testing::Test { | 22 class QuicFlowControllerTest : public ::testing::Test { |
23 public: | 23 public: |
24 QuicFlowControllerTest() | 24 QuicFlowControllerTest() |
25 : stream_id_(1234), | 25 : stream_id_(1234), |
26 send_window_(100), | 26 send_window_(100), |
27 receive_window_(200), | 27 receive_window_(200), |
28 max_receive_window_(200), | 28 max_receive_window_(200), |
29 version_(QuicVersionMax()), | 29 version_(QuicVersionMax()), |
30 old_flag_(&FLAGS_enable_quic_stream_flow_control_2, true) { | 30 old_flag_(&FLAGS_enable_quic_stream_flow_control_2, true) {} |
31 } | |
32 | 31 |
33 void Initialize() { | 32 void Initialize() { |
34 flow_controller_.reset(new QuicFlowController(version_, stream_id_, false, | 33 flow_controller_.reset(new QuicFlowController(version_, |
35 send_window_, receive_window_, | 34 stream_id_, |
| 35 false, |
| 36 send_window_, |
| 37 receive_window_, |
36 max_receive_window_)); | 38 max_receive_window_)); |
37 } | 39 } |
38 | 40 |
39 void set_version(QuicVersion version) { version_ = version; } | 41 void set_version(QuicVersion version) { version_ = version; } |
40 | 42 |
41 protected: | 43 protected: |
42 QuicStreamId stream_id_; | 44 QuicStreamId stream_id_; |
43 uint64 send_window_; | 45 uint64 send_window_; |
44 uint64 receive_window_; | 46 uint64 receive_window_; |
45 uint64 max_receive_window_; | 47 uint64 max_receive_window_; |
(...skipping 28 matching lines...) Expand all Loading... |
74 // Update the send window, and verify this has unblocked. | 76 // Update the send window, and verify this has unblocked. |
75 EXPECT_TRUE(flow_controller_->UpdateSendWindowOffset(2 * send_window_)); | 77 EXPECT_TRUE(flow_controller_->UpdateSendWindowOffset(2 * send_window_)); |
76 EXPECT_FALSE(flow_controller_->IsBlocked()); | 78 EXPECT_FALSE(flow_controller_->IsBlocked()); |
77 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); | 79 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); |
78 | 80 |
79 // Updating with a smaller offset doesn't change anything. | 81 // Updating with a smaller offset doesn't change anything. |
80 EXPECT_FALSE(flow_controller_->UpdateSendWindowOffset(send_window_ / 10)); | 82 EXPECT_FALSE(flow_controller_->UpdateSendWindowOffset(send_window_ / 10)); |
81 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); | 83 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); |
82 | 84 |
83 // Try to send more bytes, violating flow control. | 85 // Try to send more bytes, violating flow control. |
84 EXPECT_DFATAL( | 86 EXPECT_DFATAL(flow_controller_->AddBytesSent(send_window_ * 10), |
85 flow_controller_->AddBytesSent(send_window_ * 10), | 87 StringPrintf("Trying to send an extra %d bytes", |
86 StringPrintf("Trying to send an extra %d bytes", | 88 static_cast<int>(send_window_ * 10))); |
87 static_cast<int>(send_window_ * 10))); | |
88 EXPECT_TRUE(flow_controller_->IsBlocked()); | 89 EXPECT_TRUE(flow_controller_->IsBlocked()); |
89 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); | 90 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); |
90 } | 91 } |
91 | 92 |
92 TEST_F(QuicFlowControllerTest, ReceivingBytes) { | 93 TEST_F(QuicFlowControllerTest, ReceivingBytes) { |
93 Initialize(); | 94 Initialize(); |
94 | 95 |
95 EXPECT_TRUE(flow_controller_->IsEnabled()); | 96 EXPECT_TRUE(flow_controller_->IsEnabled()); |
96 EXPECT_FALSE(flow_controller_->IsBlocked()); | 97 EXPECT_FALSE(flow_controller_->IsBlocked()); |
97 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 98 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
(...skipping 23 matching lines...) Expand all Loading... |
121 | 122 |
122 // Should not be enabled, and should not report as blocked. | 123 // Should not be enabled, and should not report as blocked. |
123 EXPECT_FALSE(flow_controller_->IsEnabled()); | 124 EXPECT_FALSE(flow_controller_->IsEnabled()); |
124 EXPECT_FALSE(flow_controller_->IsBlocked()); | 125 EXPECT_FALSE(flow_controller_->IsBlocked()); |
125 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 126 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
126 | 127 |
127 // Any attempts to add/remove bytes should have no effect. | 128 // Any attempts to add/remove bytes should have no effect. |
128 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); | 129 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); |
129 EXPECT_EQ(send_window_, | 130 EXPECT_EQ(send_window_, |
130 QuicFlowControllerPeer::SendWindowOffset(flow_controller_.get())); | 131 QuicFlowControllerPeer::SendWindowOffset(flow_controller_.get())); |
131 EXPECT_EQ(receive_window_, QuicFlowControllerPeer::ReceiveWindowOffset( | 132 EXPECT_EQ( |
132 flow_controller_.get())); | 133 receive_window_, |
| 134 QuicFlowControllerPeer::ReceiveWindowOffset(flow_controller_.get())); |
133 flow_controller_->AddBytesSent(123); | 135 flow_controller_->AddBytesSent(123); |
134 flow_controller_->AddBytesConsumed(456); | 136 flow_controller_->AddBytesConsumed(456); |
135 flow_controller_->AddBytesBuffered(789); | 137 flow_controller_->AddBytesBuffered(789); |
136 flow_controller_->RemoveBytesBuffered(321); | 138 flow_controller_->RemoveBytesBuffered(321); |
137 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); | 139 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); |
138 EXPECT_EQ(send_window_, | 140 EXPECT_EQ(send_window_, |
139 QuicFlowControllerPeer::SendWindowOffset(flow_controller_.get())); | 141 QuicFlowControllerPeer::SendWindowOffset(flow_controller_.get())); |
140 EXPECT_EQ(receive_window_, QuicFlowControllerPeer::ReceiveWindowOffset( | 142 EXPECT_EQ( |
141 flow_controller_.get())); | 143 receive_window_, |
| 144 QuicFlowControllerPeer::ReceiveWindowOffset(flow_controller_.get())); |
142 | 145 |
143 // Any attempt to change offset should have no effect. | 146 // Any attempt to change offset should have no effect. |
144 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); | 147 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); |
145 EXPECT_EQ(send_window_, | 148 EXPECT_EQ(send_window_, |
146 QuicFlowControllerPeer::SendWindowOffset(flow_controller_.get())); | 149 QuicFlowControllerPeer::SendWindowOffset(flow_controller_.get())); |
147 flow_controller_->UpdateSendWindowOffset(send_window_ + 12345); | 150 flow_controller_->UpdateSendWindowOffset(send_window_ + 12345); |
148 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); | 151 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); |
149 EXPECT_EQ(send_window_, | 152 EXPECT_EQ(send_window_, |
150 QuicFlowControllerPeer::SendWindowOffset(flow_controller_.get())); | 153 QuicFlowControllerPeer::SendWindowOffset(flow_controller_.get())); |
151 | 154 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 flow_controller_->AddBytesSent(send_window_); | 213 flow_controller_->AddBytesSent(send_window_); |
211 EXPECT_TRUE(flow_controller_->IsBlocked()); | 214 EXPECT_TRUE(flow_controller_->IsBlocked()); |
212 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); | 215 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); |
213 | 216 |
214 // BLOCKED frame should get sent as send offset has changed. | 217 // BLOCKED frame should get sent as send offset has changed. |
215 flow_controller_->MaybeSendBlocked(&connection); | 218 flow_controller_->MaybeSendBlocked(&connection); |
216 } | 219 } |
217 | 220 |
218 } // namespace test | 221 } // namespace test |
219 } // namespace net | 222 } // namespace net |
OLD | NEW |