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/format_macros.h" |
7 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
8 #include "net/quic/quic_utils.h" | 9 #include "net/quic/quic_utils.h" |
9 #include "net/quic/test_tools/quic_connection_peer.h" | 10 #include "net/quic/test_tools/quic_connection_peer.h" |
10 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 11 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
11 #include "net/quic/test_tools/quic_test_utils.h" | 12 #include "net/quic/test_tools/quic_test_utils.h" |
12 #include "net/test/gtest_util.h" | 13 #include "net/test/gtest_util.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 | 15 |
15 using base::StringPrintf; | |
16 | |
17 namespace net { | 16 namespace net { |
18 namespace test { | 17 namespace test { |
19 | 18 |
20 using ::testing::_; | |
21 | |
22 class QuicFlowControllerTest : public ::testing::Test { | 19 class QuicFlowControllerTest : public ::testing::Test { |
23 public: | 20 public: |
24 QuicFlowControllerTest() | 21 QuicFlowControllerTest() |
25 : stream_id_(1234), | 22 : stream_id_(1234), |
26 send_window_(kInitialSessionFlowControlWindowForTest), | 23 send_window_(kInitialSessionFlowControlWindowForTest), |
27 receive_window_(kInitialSessionFlowControlWindowForTest), | 24 receive_window_(kInitialSessionFlowControlWindowForTest), |
28 max_receive_window_(kInitialSessionFlowControlWindowForTest), | 25 max_receive_window_(kInitialSessionFlowControlWindowForTest), |
29 connection_(false) { | 26 connection_(false) { |
30 } | 27 } |
31 | 28 |
32 void Initialize() { | 29 void Initialize() { |
33 flow_controller_.reset(new QuicFlowController( | 30 flow_controller_.reset(new QuicFlowController( |
34 &connection_, stream_id_, false, send_window_, | 31 &connection_, stream_id_, false, send_window_, |
35 receive_window_, max_receive_window_)); | 32 receive_window_, max_receive_window_)); |
36 } | 33 } |
37 | 34 |
38 protected: | 35 protected: |
39 QuicStreamId stream_id_; | 36 QuicStreamId stream_id_; |
40 uint64 send_window_; | 37 QuicByteCount send_window_; |
41 uint64 receive_window_; | 38 QuicByteCount receive_window_; |
42 uint64 max_receive_window_; | 39 QuicByteCount max_receive_window_; |
43 scoped_ptr<QuicFlowController> flow_controller_; | 40 scoped_ptr<QuicFlowController> flow_controller_; |
44 MockConnection connection_; | 41 MockConnection connection_; |
45 }; | 42 }; |
46 | 43 |
47 TEST_F(QuicFlowControllerTest, SendingBytes) { | 44 TEST_F(QuicFlowControllerTest, SendingBytes) { |
48 Initialize(); | 45 Initialize(); |
49 | 46 |
50 EXPECT_TRUE(flow_controller_->IsEnabled()); | 47 EXPECT_TRUE(flow_controller_->IsEnabled()); |
51 EXPECT_FALSE(flow_controller_->IsBlocked()); | 48 EXPECT_FALSE(flow_controller_->IsBlocked()); |
52 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 49 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
(...skipping 20 matching lines...) Expand all Loading... |
73 | 70 |
74 // Updating with a smaller offset doesn't change anything. | 71 // Updating with a smaller offset doesn't change anything. |
75 EXPECT_FALSE(flow_controller_->UpdateSendWindowOffset(send_window_ / 10)); | 72 EXPECT_FALSE(flow_controller_->UpdateSendWindowOffset(send_window_ / 10)); |
76 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); | 73 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize()); |
77 | 74 |
78 // Try to send more bytes, violating flow control. | 75 // Try to send more bytes, violating flow control. |
79 EXPECT_CALL(connection_, | 76 EXPECT_CALL(connection_, |
80 SendConnectionClose(QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA)); | 77 SendConnectionClose(QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA)); |
81 EXPECT_DFATAL( | 78 EXPECT_DFATAL( |
82 flow_controller_->AddBytesSent(send_window_ * 10), | 79 flow_controller_->AddBytesSent(send_window_ * 10), |
83 StringPrintf("Trying to send an extra %d bytes", | 80 base::StringPrintf("Trying to send an extra %" PRIu64 " bytes", |
84 static_cast<int>(send_window_ * 10))); | 81 send_window_ * 10)); |
85 EXPECT_TRUE(flow_controller_->IsBlocked()); | 82 EXPECT_TRUE(flow_controller_->IsBlocked()); |
86 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); | 83 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); |
87 } | 84 } |
88 | 85 |
89 TEST_F(QuicFlowControllerTest, ReceivingBytes) { | 86 TEST_F(QuicFlowControllerTest, ReceivingBytes) { |
90 Initialize(); | 87 Initialize(); |
91 | 88 |
92 EXPECT_TRUE(flow_controller_->IsEnabled()); | 89 EXPECT_TRUE(flow_controller_->IsEnabled()); |
93 EXPECT_FALSE(flow_controller_->IsBlocked()); | 90 EXPECT_FALSE(flow_controller_->IsBlocked()); |
94 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 91 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
95 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, | 92 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, |
96 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | 93 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
97 | 94 |
98 // Receive some bytes, updating highest received offset, but not enough to | 95 // Receive some bytes, updating highest received offset, but not enough to |
99 // fill flow control receive window. | 96 // fill flow control receive window. |
100 EXPECT_TRUE( | 97 EXPECT_TRUE( |
101 flow_controller_->UpdateHighestReceivedOffset(1 + receive_window_ / 2)); | 98 flow_controller_->UpdateHighestReceivedOffset(1 + receive_window_ / 2)); |
102 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 99 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
103 EXPECT_EQ((receive_window_ / 2) - 1, | 100 EXPECT_EQ((receive_window_ / 2) - 1, |
104 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | 101 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
105 | 102 |
106 // Consume enough bytes to send a WINDOW_UPDATE frame. | 103 // Consume enough bytes to send a WINDOW_UPDATE frame. |
107 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, _)).Times(1); | 104 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(1); |
108 | 105 |
109 flow_controller_->AddBytesConsumed(1 + receive_window_ / 2); | 106 flow_controller_->AddBytesConsumed(1 + receive_window_ / 2); |
110 | 107 |
111 // Result is that once again we have a fully open receive window. | 108 // Result is that once again we have a fully open receive window. |
112 EXPECT_FALSE(flow_controller_->FlowControlViolation()); | 109 EXPECT_FALSE(flow_controller_->FlowControlViolation()); |
113 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, | 110 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, |
114 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); | 111 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get())); |
115 } | 112 } |
116 | 113 |
117 TEST_F(QuicFlowControllerTest, OnlySendBlockedFrameOncePerOffset) { | 114 TEST_F(QuicFlowControllerTest, OnlySendBlockedFrameOncePerOffset) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 flow_controller_->AddBytesSent(send_window_); | 146 flow_controller_->AddBytesSent(send_window_); |
150 EXPECT_TRUE(flow_controller_->IsBlocked()); | 147 EXPECT_TRUE(flow_controller_->IsBlocked()); |
151 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); | 148 EXPECT_EQ(0u, flow_controller_->SendWindowSize()); |
152 | 149 |
153 // BLOCKED frame should get sent as send offset has changed. | 150 // BLOCKED frame should get sent as send offset has changed. |
154 flow_controller_->MaybeSendBlocked(); | 151 flow_controller_->MaybeSendBlocked(); |
155 } | 152 } |
156 | 153 |
157 } // namespace test | 154 } // namespace test |
158 } // namespace net | 155 } // namespace net |
OLD | NEW |