- add sources.
[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_reliable_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       : guid_(1),
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();
37   }
38
39   void CompleteCryptoHandshake() {
40     ASSERT_TRUE(session_->CryptoConnect());
41     CryptoTestUtils::HandshakeWithFakeServer(
42         connection_, session_->GetCryptoStream());
43   }
44
45   QuicGuid guid_;
46   PacketSavingConnection* connection_;
47   scoped_ptr<QuicClientSession> session_;
48   QuicCryptoClientConfig crypto_config_;
49 };
50
51 TEST_F(ToolsQuicClientSessionTest, CryptoConnect) {
52   CompleteCryptoHandshake();
53 }
54
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();
60
61   QuicReliableClientStream* stream =
62       session_->CreateOutgoingReliableStream();
63   ASSERT_TRUE(stream);
64   EXPECT_FALSE(session_->CreateOutgoingReliableStream());
65
66   // Close a stream and ensure I can now open a new one.
67   session_->CloseStream(stream->id());
68   stream = session_->CreateOutgoingReliableStream();
69   EXPECT_TRUE(stream);
70 }
71
72 TEST_F(ToolsQuicClientSessionTest, GoAwayReceived) {
73   CompleteCryptoHandshake();
74
75   // After receiving a GoAway, I should no longer be able to create outgoing
76   // streams.
77   session_->OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away."));
78   EXPECT_EQ(NULL, session_->CreateOutgoingReliableStream());
79 }
80
81 }  // namespace
82 }  // namespace test
83 }  // namespace tools
84 }  // namespace net