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

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

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « net/quic/quic_flow_controller.cc ('k') | net/quic/quic_framer.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 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/format_macros.h"
8 #include "base/strings/stringprintf.h"
9 #include "net/quic/quic_utils.h"
10 #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_test_utils.h"
13 #include "net/test/gtest_util.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15
16 namespace net {
17 namespace test {
18
19 class QuicFlowControllerTest : public ::testing::Test {
20 public:
21 QuicFlowControllerTest()
22 : stream_id_(1234),
23 send_window_(kInitialSessionFlowControlWindowForTest),
24 receive_window_(kInitialSessionFlowControlWindowForTest),
25 max_receive_window_(kInitialSessionFlowControlWindowForTest),
26 connection_(false) {
27 }
28
29 void Initialize() {
30 flow_controller_.reset(new QuicFlowController(
31 &connection_, stream_id_, false, send_window_,
32 receive_window_, max_receive_window_));
33 }
34
35 protected:
36 QuicStreamId stream_id_;
37 QuicByteCount send_window_;
38 QuicByteCount receive_window_;
39 QuicByteCount max_receive_window_;
40 scoped_ptr<QuicFlowController> flow_controller_;
41 MockConnection connection_;
42 };
43
44 TEST_F(QuicFlowControllerTest, SendingBytes) {
45 Initialize();
46
47 EXPECT_TRUE(flow_controller_->IsEnabled());
48 EXPECT_FALSE(flow_controller_->IsBlocked());
49 EXPECT_FALSE(flow_controller_->FlowControlViolation());
50 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize());
51
52 // Send some bytes, but not enough to block.
53 flow_controller_->AddBytesSent(send_window_ / 2);
54 EXPECT_FALSE(flow_controller_->IsBlocked());
55 EXPECT_EQ(send_window_ / 2, flow_controller_->SendWindowSize());
56
57 // Send enough bytes to block.
58 flow_controller_->AddBytesSent(send_window_ / 2);
59 EXPECT_TRUE(flow_controller_->IsBlocked());
60 EXPECT_EQ(0u, flow_controller_->SendWindowSize());
61
62 // BLOCKED frame should get sent.
63 EXPECT_CALL(connection_, SendBlocked(stream_id_)).Times(1);
64 flow_controller_->MaybeSendBlocked();
65
66 // Update the send window, and verify this has unblocked.
67 EXPECT_TRUE(flow_controller_->UpdateSendWindowOffset(2 * send_window_));
68 EXPECT_FALSE(flow_controller_->IsBlocked());
69 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize());
70
71 // Updating with a smaller offset doesn't change anything.
72 EXPECT_FALSE(flow_controller_->UpdateSendWindowOffset(send_window_ / 10));
73 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize());
74
75 // Try to send more bytes, violating flow control.
76 EXPECT_CALL(connection_,
77 SendConnectionClose(QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA));
78 EXPECT_DFATAL(
79 flow_controller_->AddBytesSent(send_window_ * 10),
80 base::StringPrintf("Trying to send an extra %" PRIu64 " bytes",
81 send_window_ * 10));
82 EXPECT_TRUE(flow_controller_->IsBlocked());
83 EXPECT_EQ(0u, flow_controller_->SendWindowSize());
84 }
85
86 TEST_F(QuicFlowControllerTest, ReceivingBytes) {
87 Initialize();
88
89 EXPECT_TRUE(flow_controller_->IsEnabled());
90 EXPECT_FALSE(flow_controller_->IsBlocked());
91 EXPECT_FALSE(flow_controller_->FlowControlViolation());
92 EXPECT_EQ(kInitialSessionFlowControlWindowForTest,
93 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get()));
94
95 // Receive some bytes, updating highest received offset, but not enough to
96 // fill flow control receive window.
97 EXPECT_TRUE(
98 flow_controller_->UpdateHighestReceivedOffset(1 + receive_window_ / 2));
99 EXPECT_FALSE(flow_controller_->FlowControlViolation());
100 EXPECT_EQ((receive_window_ / 2) - 1,
101 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get()));
102
103 // Consume enough bytes to send a WINDOW_UPDATE frame.
104 EXPECT_CALL(connection_, SendWindowUpdate(stream_id_, ::testing::_)).Times(1);
105
106 flow_controller_->AddBytesConsumed(1 + receive_window_ / 2);
107
108 // Result is that once again we have a fully open receive window.
109 EXPECT_FALSE(flow_controller_->FlowControlViolation());
110 EXPECT_EQ(kInitialSessionFlowControlWindowForTest,
111 QuicFlowControllerPeer::ReceiveWindowSize(flow_controller_.get()));
112 }
113
114 TEST_F(QuicFlowControllerTest, OnlySendBlockedFrameOncePerOffset) {
115 Initialize();
116
117 // Test that we don't send duplicate BLOCKED frames. We should only send one
118 // BLOCKED frame at a given send window offset.
119 EXPECT_TRUE(flow_controller_->IsEnabled());
120 EXPECT_FALSE(flow_controller_->IsBlocked());
121 EXPECT_FALSE(flow_controller_->FlowControlViolation());
122 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize());
123
124 // Send enough bytes to block.
125 flow_controller_->AddBytesSent(send_window_);
126 EXPECT_TRUE(flow_controller_->IsBlocked());
127 EXPECT_EQ(0u, flow_controller_->SendWindowSize());
128
129 // Expect that 2 BLOCKED frames should get sent in total.
130 EXPECT_CALL(connection_, SendBlocked(stream_id_)).Times(2);
131
132 // BLOCKED frame should get sent.
133 flow_controller_->MaybeSendBlocked();
134
135 // BLOCKED frame should not get sent again until our send offset changes.
136 flow_controller_->MaybeSendBlocked();
137 flow_controller_->MaybeSendBlocked();
138 flow_controller_->MaybeSendBlocked();
139 flow_controller_->MaybeSendBlocked();
140 flow_controller_->MaybeSendBlocked();
141
142 // Update the send window, then send enough bytes to block again.
143 EXPECT_TRUE(flow_controller_->UpdateSendWindowOffset(2 * send_window_));
144 EXPECT_FALSE(flow_controller_->IsBlocked());
145 EXPECT_EQ(send_window_, flow_controller_->SendWindowSize());
146 flow_controller_->AddBytesSent(send_window_);
147 EXPECT_TRUE(flow_controller_->IsBlocked());
148 EXPECT_EQ(0u, flow_controller_->SendWindowSize());
149
150 // BLOCKED frame should get sent as send offset has changed.
151 flow_controller_->MaybeSendBlocked();
152 }
153
154 } // namespace test
155 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_flow_controller.cc ('k') | net/quic/quic_framer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698