Land Recent QUIC Changes.
[chromium-blink-merge.git] / net / tools / quic / quic_client_session_test.cc
blob50f4c13ee7fb12396a0596242e997a7a87896625
1 // Copyright (c) 2012 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.
5 #include "net/tools/quic/quic_client_session.h"
7 #include <vector>
9 #include "net/base/ip_endpoint.h"
10 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
11 #include "net/quic/test_tools/crypto_test_utils.h"
12 #include "net/quic/test_tools/quic_test_utils.h"
13 #include "net/tools/quic/quic_spdy_client_stream.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 using net::test::CryptoTestUtils;
17 using net::test::DefaultQuicConfig;
18 using net::test::PacketSavingConnection;
19 using net::test::SupportedVersions;
20 using net::test::kInitialFlowControlWindowForTest;
21 using testing::_;
23 namespace net {
24 namespace tools {
25 namespace test {
26 namespace {
28 const char kServerHostname[] = "www.example.com";
29 const uint16 kPort = 80;
31 class ToolsQuicClientSessionTest
32 : public ::testing::TestWithParam<QuicVersion> {
33 protected:
34 ToolsQuicClientSessionTest()
35 : connection_(new PacketSavingConnection(false,
36 SupportedVersions(GetParam()))) {
37 crypto_config_.SetDefaults();
38 session_.reset(new QuicClientSession(
39 QuicServerId(kServerHostname, kPort, false, PRIVACY_MODE_DISABLED),
40 DefaultQuicConfig(),
41 connection_,
42 kInitialFlowControlWindowForTest,
43 &crypto_config_));
44 session_->config()->SetDefaults();
47 void CompleteCryptoHandshake() {
48 ASSERT_TRUE(session_->CryptoConnect());
49 CryptoTestUtils::HandshakeWithFakeServer(
50 connection_, session_->GetCryptoStream());
53 PacketSavingConnection* connection_;
54 scoped_ptr<QuicClientSession> session_;
55 QuicCryptoClientConfig crypto_config_;
58 INSTANTIATE_TEST_CASE_P(Tests, ToolsQuicClientSessionTest,
59 ::testing::ValuesIn(QuicSupportedVersions()));
61 TEST_P(ToolsQuicClientSessionTest, CryptoConnect) {
62 CompleteCryptoHandshake();
65 TEST_P(ToolsQuicClientSessionTest, MaxNumStreams) {
66 session_->config()->set_max_streams_per_connection(1, 1);
67 // FLAGS_max_streams_per_connection = 1;
68 // Initialize crypto before the client session will create a stream.
69 CompleteCryptoHandshake();
71 QuicSpdyClientStream* stream =
72 session_->CreateOutgoingDataStream();
73 ASSERT_TRUE(stream);
74 EXPECT_FALSE(session_->CreateOutgoingDataStream());
76 // Close a stream and ensure I can now open a new one.
77 session_->CloseStream(stream->id());
78 stream = session_->CreateOutgoingDataStream();
79 EXPECT_TRUE(stream);
82 TEST_P(ToolsQuicClientSessionTest, GoAwayReceived) {
83 CompleteCryptoHandshake();
85 // After receiving a GoAway, I should no longer be able to create outgoing
86 // streams.
87 session_->OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away."));
88 EXPECT_EQ(NULL, session_->CreateOutgoingDataStream());
91 } // namespace
92 } // namespace test
93 } // namespace tools
94 } // namespace net