Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: net/quic/quic_flow_controller_test.cc

Issue 242593002: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Build fix. Use uint32 instead of int Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_flow_controller.cc ('k') | net/quic/quic_headers_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/quic/quic_flow_controller.h"
6
7 #include "base/strings/stringprintf.h"
8 #include "net/quic/quic_flags.h"
9 #include "net/quic/quic_utils.h"
10 #include "net/quic/test_tools/quic_flow_controller_peer.h"
11 #include "net/quic/test_tools/quic_test_utils.h"
12 #include "net/test/gtest_util.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14
15 using base::StringPrintf;
16
17 namespace net {
18 namespace test {
19
20 TEST(QuicFlowControllerTest, SendingBytes) {
21 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control, true);
22
23 const QuicStreamId kStreamId = 1234;
24 const uint64 kSendWindow = 100;
25 const uint64 kReceiveWindow = 200;
26 const uint64 kMaxReceiveWindow = 200;
27
28 QuicFlowController fc(kStreamId, false, kSendWindow, kReceiveWindow,
29 kMaxReceiveWindow);
30
31 EXPECT_TRUE(fc.IsEnabled());
32 EXPECT_FALSE(fc.IsBlocked());
33 EXPECT_FALSE(fc.FlowControlViolation());
34 EXPECT_EQ(kSendWindow, fc.SendWindowSize());
35
36 // Send some bytes, but not enough to block.
37 fc.AddBytesSent(kSendWindow / 2);
38 EXPECT_FALSE(fc.IsBlocked());
39 EXPECT_EQ(kSendWindow / 2, fc.SendWindowSize());
40
41 // Send enough bytes to block.
42 fc.AddBytesSent(kSendWindow / 2);
43 EXPECT_TRUE(fc.IsBlocked());
44 EXPECT_EQ(0u, fc.SendWindowSize());
45
46 // BLOCKED frame should get sent.
47 MockConnection connection(false);
48 EXPECT_CALL(connection, SendBlocked(kStreamId)).Times(1);
49 fc.MaybeSendBlocked(&connection);
50
51 // Update the send window, and verify this has unblocked.
52 EXPECT_TRUE(fc.UpdateSendWindowOffset(2 * kSendWindow));
53 EXPECT_FALSE(fc.IsBlocked());
54 EXPECT_EQ(kSendWindow, fc.SendWindowSize());
55
56 // Updating with a smaller offset doesn't change anything.
57 EXPECT_FALSE(fc.UpdateSendWindowOffset(kSendWindow / 10));
58 EXPECT_EQ(kSendWindow, fc.SendWindowSize());
59
60 // Try to send more bytes, violating flow control.
61 EXPECT_DFATAL(fc.AddBytesSent(kSendWindow * 10),
62 StringPrintf("Trying to send an extra %d bytes",
63 static_cast<int>(kSendWindow * 10)));
64 EXPECT_TRUE(fc.IsBlocked());
65 EXPECT_EQ(0u, fc.SendWindowSize());
66 }
67
68 TEST(QuicFlowControllerTest, ReceivingBytes) {
69 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control, true);
70
71 const QuicStreamId kStreamId = 1234;
72 const uint64 kSendWindow = 100;
73 const uint64 kReceiveWindow = 200;
74 const uint64 kMaxReceiveWindow = 200;
75
76 QuicFlowController fc(kStreamId, false, kSendWindow, kReceiveWindow,
77 kMaxReceiveWindow);
78
79 EXPECT_TRUE(fc.IsEnabled());
80 EXPECT_FALSE(fc.IsBlocked());
81 EXPECT_FALSE(fc.FlowControlViolation());
82
83 // Buffer some bytes, not enough to fill window.
84 fc.AddBytesBuffered(kReceiveWindow / 2);
85 EXPECT_FALSE(fc.FlowControlViolation());
86 EXPECT_EQ(kReceiveWindow / 2, QuicFlowControllerPeer::ReceiveWindowSize(&fc));
87
88 // Consume enough bytes to send a WINDOW_UPDATE frame.
89 fc.RemoveBytesBuffered(kReceiveWindow / 2);
90 fc.AddBytesConsumed(1 + kReceiveWindow / 2);
91 EXPECT_FALSE(fc.FlowControlViolation());
92 EXPECT_EQ((kReceiveWindow / 2) - 1,
93 QuicFlowControllerPeer::ReceiveWindowSize(&fc));
94
95 MockConnection connection(false);
96 EXPECT_CALL(connection, SendWindowUpdate(kStreamId, ::testing::_)).Times(1);
97 fc.MaybeSendWindowUpdate(&connection);
98 }
99
100 } // namespace test
101 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_flow_controller.cc ('k') | net/quic/quic_headers_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698