Home | History | Annotate | Download | only in quic
      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.
      4 
      5 #include "net/tools/quic/quic_client_session.h"
      6 
      7 #include <vector>
      8 
      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"
     15 
     16 using net::test::CryptoTestUtils;
     17 using net::test::DefaultQuicConfig;
     18 using net::test::PacketSavingConnection;
     19 using testing::_;
     20 
     21 namespace net {
     22 namespace tools {
     23 namespace test {
     24 namespace {
     25 
     26 const char kServerHostname[] = "www.example.com";
     27 
     28 class ToolsQuicClientSessionTest : public ::testing::Test {
     29  protected:
     30   ToolsQuicClientSessionTest()
     31       : connection_(new PacketSavingConnection(false)) {
     32     crypto_config_.SetDefaults();
     33     session_.reset(new QuicClientSession(kServerHostname, DefaultQuicConfig(),
     34                                          connection_, &crypto_config_));
     35     session_->config()->SetDefaults();
     36   }
     37 
     38   void CompleteCryptoHandshake() {
     39     ASSERT_TRUE(session_->CryptoConnect());
     40     CryptoTestUtils::HandshakeWithFakeServer(
     41         connection_, session_->GetCryptoStream());
     42   }
     43 
     44   PacketSavingConnection* connection_;
     45   scoped_ptr<QuicClientSession> session_;
     46   QuicCryptoClientConfig crypto_config_;
     47 };
     48 
     49 TEST_F(ToolsQuicClientSessionTest, CryptoConnect) {
     50   CompleteCryptoHandshake();
     51 }
     52 
     53 TEST_F(ToolsQuicClientSessionTest, MaxNumStreams) {
     54   session_->config()->set_max_streams_per_connection(1, 1);
     55   // FLAGS_max_streams_per_connection = 1;
     56   // Initialize crypto before the client session will create a stream.
     57   CompleteCryptoHandshake();
     58 
     59   QuicSpdyClientStream* stream =
     60       session_->CreateOutgoingDataStream();
     61   ASSERT_TRUE(stream);
     62   EXPECT_FALSE(session_->CreateOutgoingDataStream());
     63 
     64   // Close a stream and ensure I can now open a new one.
     65   session_->CloseStream(stream->id());
     66   stream = session_->CreateOutgoingDataStream();
     67   EXPECT_TRUE(stream);
     68 }
     69 
     70 TEST_F(ToolsQuicClientSessionTest, GoAwayReceived) {
     71   CompleteCryptoHandshake();
     72 
     73   // After receiving a GoAway, I should no longer be able to create outgoing
     74   // streams.
     75   session_->OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away."));
     76   EXPECT_EQ(NULL, session_->CreateOutgoingDataStream());
     77 }
     78 
     79 }  // namespace
     80 }  // namespace test
     81 }  // namespace tools
     82 }  // namespace net
     83