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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/quic_flow_controller.cc ('k') | net/quic/quic_headers_stream.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_flow_controller_test.cc
diff --git a/net/quic/quic_flow_controller_test.cc b/net/quic/quic_flow_controller_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b724ca42f9f4fe06b0e4eeb92fa1a6671050b4be
--- /dev/null
+++ b/net/quic/quic_flow_controller_test.cc
@@ -0,0 +1,101 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/quic/quic_flow_controller.h"
+
+#include "base/strings/stringprintf.h"
+#include "net/quic/quic_flags.h"
+#include "net/quic/quic_utils.h"
+#include "net/quic/test_tools/quic_flow_controller_peer.h"
+#include "net/quic/test_tools/quic_test_utils.h"
+#include "net/test/gtest_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+using base::StringPrintf;
+
+namespace net {
+namespace test {
+
+TEST(QuicFlowControllerTest, SendingBytes) {
+ ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control, true);
+
+ const QuicStreamId kStreamId = 1234;
+ const uint64 kSendWindow = 100;
+ const uint64 kReceiveWindow = 200;
+ const uint64 kMaxReceiveWindow = 200;
+
+ QuicFlowController fc(kStreamId, false, kSendWindow, kReceiveWindow,
+ kMaxReceiveWindow);
+
+ EXPECT_TRUE(fc.IsEnabled());
+ EXPECT_FALSE(fc.IsBlocked());
+ EXPECT_FALSE(fc.FlowControlViolation());
+ EXPECT_EQ(kSendWindow, fc.SendWindowSize());
+
+ // Send some bytes, but not enough to block.
+ fc.AddBytesSent(kSendWindow / 2);
+ EXPECT_FALSE(fc.IsBlocked());
+ EXPECT_EQ(kSendWindow / 2, fc.SendWindowSize());
+
+ // Send enough bytes to block.
+ fc.AddBytesSent(kSendWindow / 2);
+ EXPECT_TRUE(fc.IsBlocked());
+ EXPECT_EQ(0u, fc.SendWindowSize());
+
+ // BLOCKED frame should get sent.
+ MockConnection connection(false);
+ EXPECT_CALL(connection, SendBlocked(kStreamId)).Times(1);
+ fc.MaybeSendBlocked(&connection);
+
+ // Update the send window, and verify this has unblocked.
+ EXPECT_TRUE(fc.UpdateSendWindowOffset(2 * kSendWindow));
+ EXPECT_FALSE(fc.IsBlocked());
+ EXPECT_EQ(kSendWindow, fc.SendWindowSize());
+
+ // Updating with a smaller offset doesn't change anything.
+ EXPECT_FALSE(fc.UpdateSendWindowOffset(kSendWindow / 10));
+ EXPECT_EQ(kSendWindow, fc.SendWindowSize());
+
+ // Try to send more bytes, violating flow control.
+ EXPECT_DFATAL(fc.AddBytesSent(kSendWindow * 10),
+ StringPrintf("Trying to send an extra %d bytes",
+ static_cast<int>(kSendWindow * 10)));
+ EXPECT_TRUE(fc.IsBlocked());
+ EXPECT_EQ(0u, fc.SendWindowSize());
+}
+
+TEST(QuicFlowControllerTest, ReceivingBytes) {
+ ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control, true);
+
+ const QuicStreamId kStreamId = 1234;
+ const uint64 kSendWindow = 100;
+ const uint64 kReceiveWindow = 200;
+ const uint64 kMaxReceiveWindow = 200;
+
+ QuicFlowController fc(kStreamId, false, kSendWindow, kReceiveWindow,
+ kMaxReceiveWindow);
+
+ EXPECT_TRUE(fc.IsEnabled());
+ EXPECT_FALSE(fc.IsBlocked());
+ EXPECT_FALSE(fc.FlowControlViolation());
+
+ // Buffer some bytes, not enough to fill window.
+ fc.AddBytesBuffered(kReceiveWindow / 2);
+ EXPECT_FALSE(fc.FlowControlViolation());
+ EXPECT_EQ(kReceiveWindow / 2, QuicFlowControllerPeer::ReceiveWindowSize(&fc));
+
+ // Consume enough bytes to send a WINDOW_UPDATE frame.
+ fc.RemoveBytesBuffered(kReceiveWindow / 2);
+ fc.AddBytesConsumed(1 + kReceiveWindow / 2);
+ EXPECT_FALSE(fc.FlowControlViolation());
+ EXPECT_EQ((kReceiveWindow / 2) - 1,
+ QuicFlowControllerPeer::ReceiveWindowSize(&fc));
+
+ MockConnection connection(false);
+ EXPECT_CALL(connection, SendWindowUpdate(kStreamId, ::testing::_)).Times(1);
+ fc.MaybeSendWindowUpdate(&connection);
+}
+
+} // namespace test
+} // namespace net
« 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