#include "base/basictypes.h"
#include "base/containers/hash_tables.h"
+#include "base/rand_util.h"
+#include "base/strings/string_number_conversions.h"
#include "net/quic/crypto/crypto_protocol.h"
#include "net/quic/quic_crypto_stream.h"
#include "net/quic/quic_flags.h"
}
TEST_P(QuicSessionTest, IncreasedTimeoutAfterCryptoHandshake) {
- EXPECT_EQ(kDefaultInitialTimeoutSecs,
+ // Add 1 to the connection timeout on the server side.
+ EXPECT_EQ(kDefaultInitialTimeoutSecs + 1,
QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
CryptoHandshakeMessage msg;
session_.GetCryptoStream()->OnHandshakeMessage(msg);
- EXPECT_EQ(kDefaultTimeoutSecs,
+ EXPECT_EQ(kMaximumIdleTimeoutSecs + 1,
QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
}
stream2->SendBody(body, false);
EXPECT_TRUE(stream2->flow_controller()->IsBlocked());
+ // The handshake message will call OnCanWrite, so the stream can resume
+ // writing.
+ EXPECT_CALL(*stream2, OnCanWrite());
// Now complete the crypto handshake, resulting in an increased flow control
// send window.
CryptoHandshakeMessage msg;
EXPECT_FALSE(stream2->flow_controller()->IsBlocked());
}
+TEST_P(QuicSessionTest, HandshakeUnblocksFlowControlBlockedCryptoStream) {
+ if (version() <= QUIC_VERSION_19) {
+ return;
+ }
+ // Test that if the crypto stream is flow control blocked, then if the SHLO
+ // contains a larger send window offset, the stream becomes unblocked.
+ session_.set_writev_consumes_all_data(true);
+ TestCryptoStream* crypto_stream = session_.GetCryptoStream();
+ EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
+ QuicHeadersStream* headers_stream =
+ QuicSessionPeer::GetHeadersStream(&session_);
+ EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
+ // Write until the crypto stream is flow control blocked.
+ int i = 0;
+ while (!crypto_stream->flow_controller()->IsBlocked() && i < 1000) {
+ QuicConfig config;
+ CryptoHandshakeMessage crypto_message;
+ config.ToHandshakeMessage(&crypto_message);
+ crypto_stream->SendHandshakeMessage(crypto_message);
+ ++i;
+ }
+ EXPECT_TRUE(crypto_stream->flow_controller()->IsBlocked());
+ EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
+ EXPECT_FALSE(session_.HasDataToWrite());
+ EXPECT_TRUE(crypto_stream->HasBufferedData());
+
+ // The handshake message will call OnCanWrite, so the stream can
+ // resume writing.
+ EXPECT_CALL(*crypto_stream, OnCanWrite());
+ // Now complete the crypto handshake, resulting in an increased flow control
+ // send window.
+ CryptoHandshakeMessage msg;
+ session_.GetCryptoStream()->OnHandshakeMessage(msg);
+
+ // Stream is now unblocked and will no longer have buffered data.
+ EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
+}
+
+TEST_P(QuicSessionTest, HandshakeUnblocksFlowControlBlockedHeadersStream) {
+ if (version() <= QUIC_VERSION_19) {
+ return;
+ }
+ // Test that if the header stream is flow control blocked, then if the SHLO
+ // contains a larger send window offset, the stream becomes unblocked.
+ session_.set_writev_consumes_all_data(true);
+ TestCryptoStream* crypto_stream = session_.GetCryptoStream();
+ EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
+ QuicHeadersStream* headers_stream =
+ QuicSessionPeer::GetHeadersStream(&session_);
+ EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
+ QuicStreamId stream_id = 5;
+ // Write until the header stream is flow control blocked.
+ while (!headers_stream->flow_controller()->IsBlocked() && stream_id < 2000) {
+ SpdyHeaderBlock headers;
+ headers["header"] = base::Uint64ToString(base::RandUint64()) +
+ base::Uint64ToString(base::RandUint64()) +
+ base::Uint64ToString(base::RandUint64());
+ headers_stream->WriteHeaders(stream_id, headers, true, nullptr);
+ stream_id += 2;
+ }
+ EXPECT_TRUE(headers_stream->flow_controller()->IsBlocked());
+ EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
+ EXPECT_FALSE(session_.HasDataToWrite());
+ EXPECT_TRUE(headers_stream->HasBufferedData());
+
+ // Now complete the crypto handshake, resulting in an increased flow control
+ // send window.
+ CryptoHandshakeMessage msg;
+ session_.GetCryptoStream()->OnHandshakeMessage(msg);
+
+ // Stream is now unblocked and will no longer have buffered data.
+ EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
+ EXPECT_FALSE(headers_stream->HasBufferedData());
+}
+
TEST_P(QuicSessionTest, InvalidFlowControlWindowInHandshake) {
// TODO(rjshade): Remove this test when removing QUIC_VERSION_19.
// Test that receipt of an invalid (< default) flow control window from
EXPECT_FALSE(stream->flow_controller()->IsEnabled());
}
+TEST_P(QuicSessionTest, WindowUpdateUnblocksHeadersStream) {
+ // Test that a flow control blocked headers stream gets unblocked on recipt of
+ // a WINDOW_UPDATE frame. Regression test for b/17413860.
+ if (version() < QUIC_VERSION_21) {
+ return;
+ }
+
+ // Set the headers stream to be flow control blocked.
+ QuicHeadersStream* headers_stream =
+ QuicSessionPeer::GetHeadersStream(&session_);
+ QuicFlowControllerPeer::SetSendWindowOffset(headers_stream->flow_controller(),
+ 0);
+ EXPECT_TRUE(headers_stream->flow_controller()->IsBlocked());
+
+ // Unblock the headers stream by supplying a WINDOW_UPDATE.
+ QuicWindowUpdateFrame window_update_frame(headers_stream->id(),
+ 2 * kDefaultFlowControlSendWindow);
+ vector<QuicWindowUpdateFrame> frames;
+ frames.push_back(window_update_frame);
+ session_.OnWindowUpdateFrames(frames);
+ EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
+}
+
TEST_P(QuicSessionTest, TooManyUnfinishedStreamsCauseConnectionClose) {
if (version() < QUIC_VERSION_18) {
return;
}
// If a buggy/malicious peer creates too many streams that are not ended with
// a FIN or RST then we send a connection close.
- ValueRestore<bool> old_flag(&FLAGS_close_quic_connection_unfinished_streams,
+ ValueRestore<bool> old_flag(&FLAGS_close_quic_connection_unfinished_streams_2,
true);
EXPECT_CALL(*connection_,
EXPECT_EQ(1u, session_.GetNumOpenStreams());
session_.CloseStream(i);
}
+
+ // Called after any new data is received by the session, and triggers the call
+ // to close the connection.
+ session_.PostProcessAfterData();
}
} // namespace