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"
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_reliable_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;
26 const char kServerHostname[] = "www.example.com";
28 class ToolsQuicClientSessionTest : public ::testing::Test {
30 ToolsQuicClientSessionTest()
32 connection_(new PacketSavingConnection(guid_, IPEndPoint(), false)) {
33 crypto_config_.SetDefaults();
34 session_.reset(new QuicClientSession(kServerHostname, DefaultQuicConfig(),
35 connection_, &crypto_config_));
36 session_->config()->SetDefaults();
39 void CompleteCryptoHandshake() {
40 ASSERT_TRUE(session_->CryptoConnect());
41 CryptoTestUtils::HandshakeWithFakeServer(
42 connection_, session_->GetCryptoStream());
46 PacketSavingConnection* connection_;
47 scoped_ptr<QuicClientSession> session_;
48 QuicCryptoClientConfig crypto_config_;
51 TEST_F(ToolsQuicClientSessionTest, CryptoConnect) {
52 CompleteCryptoHandshake();
55 TEST_F(ToolsQuicClientSessionTest, MaxNumStreams) {
56 session_->config()->set_max_streams_per_connection(1, 1);
57 // FLAGS_max_streams_per_connection = 1;
58 // Initialize crypto before the client session will create a stream.
59 CompleteCryptoHandshake();
61 QuicReliableClientStream* stream =
62 session_->CreateOutgoingReliableStream();
64 EXPECT_FALSE(session_->CreateOutgoingReliableStream());
66 // Close a stream and ensure I can now open a new one.
67 session_->CloseStream(stream->id());
68 stream = session_->CreateOutgoingReliableStream();
72 TEST_F(ToolsQuicClientSessionTest, GoAwayReceived) {
73 CompleteCryptoHandshake();
75 // After receiving a GoAway, I should no longer be able to create outgoing
77 session_->OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away."));
78 EXPECT_EQ(NULL, session_->CreateOutgoingReliableStream());