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"
17 using net::test::CryptoTestUtils
;
18 using net::test::PacketSavingConnection
;
25 const char kServerHostname
[] = "www.example.com";
27 class ToolsQuicClientSessionTest
: public ::testing::Test
{
29 ToolsQuicClientSessionTest()
31 connection_(new PacketSavingConnection(guid_
, IPEndPoint(), false)) {
32 crypto_config_
.SetDefaults();
33 session_
.reset(new QuicClientSession(kServerHostname
, QuicConfig(),
34 connection_
, &crypto_config_
));
35 session_
->config()->SetDefaults();
38 void CompleteCryptoHandshake() {
39 ASSERT_TRUE(session_
->CryptoConnect());
40 CryptoTestUtils::HandshakeWithFakeServer(
41 connection_
, session_
->GetCryptoStream());
45 PacketSavingConnection
* connection_
;
46 scoped_ptr
<QuicClientSession
> session_
;
47 QuicCryptoClientConfig crypto_config_
;
50 TEST_F(ToolsQuicClientSessionTest
, CryptoConnect
) {
51 if (!Aes128Gcm12Encrypter::IsSupported()) {
52 LOG(INFO
) << "AES GCM not supported. Test skipped.";
55 CompleteCryptoHandshake();
58 TEST_F(ToolsQuicClientSessionTest
, MaxNumStreams
) {
59 session_
->config()->set_max_streams_per_connection(1, 1);
60 if (!Aes128Gcm12Encrypter::IsSupported()) {
61 LOG(INFO
) << "AES GCM not supported. Test skipped.";
64 // FLAGS_max_streams_per_connection = 1;
65 // Initialize crypto before the client session will create a stream.
66 CompleteCryptoHandshake();
68 QuicReliableClientStream
* stream
=
69 session_
->CreateOutgoingReliableStream();
71 EXPECT_FALSE(session_
->CreateOutgoingReliableStream());
73 // Close a stream and ensure I can now open a new one.
74 session_
->CloseStream(stream
->id());
75 stream
= session_
->CreateOutgoingReliableStream();
79 TEST_F(ToolsQuicClientSessionTest
, GoAwayReceived
) {
80 if (!Aes128Gcm12Encrypter::IsSupported()) {
81 LOG(INFO
) << "AES GCM not supported. Test skipped.";
85 CompleteCryptoHandshake();
87 // After receiving a GoAway, I should no longer be able to create outgoing
89 session_
->OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY
, 1u, "Going away."));
90 EXPECT_EQ(NULL
, session_
->CreateOutgoingReliableStream());