Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / net / tools / quic / quic_client_session_test.cc
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 net::test::SupportedVersions;
20 using testing::_;
21
22 namespace net {
23 namespace tools {
24 namespace test {
25 namespace {
26
27 const char kServerHostname[] = "www.example.com";
28
29 class ToolsQuicClientSessionTest
30     : public ::testing::TestWithParam<QuicVersion> {
31  protected:
32   ToolsQuicClientSessionTest()
33       : connection_(new PacketSavingConnection(false,
34                                                SupportedVersions(GetParam()))) {
35     crypto_config_.SetDefaults();
36     session_.reset(new QuicClientSession(kServerHostname, DefaultQuicConfig(),
37                                          connection_, &crypto_config_));
38     session_->config()->SetDefaults();
39   }
40
41   void CompleteCryptoHandshake() {
42     ASSERT_TRUE(session_->CryptoConnect());
43     CryptoTestUtils::HandshakeWithFakeServer(
44         connection_, session_->GetCryptoStream());
45   }
46
47   PacketSavingConnection* connection_;
48   scoped_ptr<QuicClientSession> session_;
49   QuicCryptoClientConfig crypto_config_;
50 };
51
52 INSTANTIATE_TEST_CASE_P(Tests, ToolsQuicClientSessionTest,
53                         ::testing::ValuesIn(QuicSupportedVersions()));
54
55 TEST_P(ToolsQuicClientSessionTest, CryptoConnect) {
56   CompleteCryptoHandshake();
57 }
58
59 TEST_P(ToolsQuicClientSessionTest, MaxNumStreams) {
60   session_->config()->set_max_streams_per_connection(1, 1);
61   // FLAGS_max_streams_per_connection = 1;
62   // Initialize crypto before the client session will create a stream.
63   CompleteCryptoHandshake();
64
65   QuicSpdyClientStream* stream =
66       session_->CreateOutgoingDataStream();
67   ASSERT_TRUE(stream);
68   EXPECT_FALSE(session_->CreateOutgoingDataStream());
69
70   // Close a stream and ensure I can now open a new one.
71   session_->CloseStream(stream->id());
72   stream = session_->CreateOutgoingDataStream();
73   EXPECT_TRUE(stream);
74 }
75
76 TEST_P(ToolsQuicClientSessionTest, GoAwayReceived) {
77   CompleteCryptoHandshake();
78
79   // After receiving a GoAway, I should no longer be able to create outgoing
80   // streams.
81   session_->OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away."));
82   EXPECT_EQ(NULL, session_->CreateOutgoingDataStream());
83 }
84
85 }  // namespace
86 }  // namespace test
87 }  // namespace tools
88 }  // namespace net