Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / tools / quic / quic_client_session_test.cc
blob6f8136f3aed9cf9be917df15fc7120996c1a57dc
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"
7 #include <vector>
9 #include "net/base/ip_endpoint.h"
10 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
11 #include "net/quic/quic_flags.h"
12 #include "net/quic/test_tools/crypto_test_utils.h"
13 #include "net/quic/test_tools/quic_session_peer.h"
14 #include "net/quic/test_tools/quic_test_utils.h"
15 #include "net/tools/quic/quic_spdy_client_stream.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 using net::test::CryptoTestUtils;
19 using net::test::DefaultQuicConfig;
20 using net::test::PacketSavingConnection;
21 using net::test::QuicSessionPeer;
22 using net::test::SupportedVersions;
23 using net::test::ValueRestore;
24 using testing::_;
26 namespace net {
27 namespace tools {
28 namespace test {
29 namespace {
31 const char kServerHostname[] = "www.example.com";
32 const uint16 kPort = 80;
34 class ToolsQuicClientSessionTest
35 : public ::testing::TestWithParam<QuicVersion> {
36 protected:
37 ToolsQuicClientSessionTest()
38 : connection_(new PacketSavingConnection(false,
39 SupportedVersions(GetParam()))) {
40 crypto_config_.SetDefaults();
41 session_.reset(new QuicClientSession(DefaultQuicConfig(), connection_));
42 session_->InitializeSession(
43 QuicServerId(kServerHostname, kPort, false, PRIVACY_MODE_DISABLED),
44 &crypto_config_);
45 session_->config()->SetDefaults();
48 void CompleteCryptoHandshake() {
49 ASSERT_TRUE(session_->CryptoConnect());
50 CryptoTestUtils::HandshakeWithFakeServer(
51 connection_, session_->GetCryptoStream());
54 PacketSavingConnection* connection_;
55 scoped_ptr<QuicClientSession> session_;
56 QuicCryptoClientConfig crypto_config_;
59 INSTANTIATE_TEST_CASE_P(Tests, ToolsQuicClientSessionTest,
60 ::testing::ValuesIn(QuicSupportedVersions()));
62 TEST_P(ToolsQuicClientSessionTest, CryptoConnect) {
63 CompleteCryptoHandshake();
66 TEST_P(ToolsQuicClientSessionTest, MaxNumStreams) {
67 session_->config()->set_max_streams_per_connection(1, 1);
68 // FLAGS_max_streams_per_connection = 1;
69 // Initialize crypto before the client session will create a stream.
70 CompleteCryptoHandshake();
72 QuicSpdyClientStream* stream =
73 session_->CreateOutgoingDataStream();
74 ASSERT_TRUE(stream);
75 EXPECT_FALSE(session_->CreateOutgoingDataStream());
77 // Close a stream and ensure I can now open a new one.
78 session_->CloseStream(stream->id());
79 stream = session_->CreateOutgoingDataStream();
80 EXPECT_TRUE(stream);
83 TEST_P(ToolsQuicClientSessionTest, GoAwayReceived) {
84 CompleteCryptoHandshake();
86 // After receiving a GoAway, I should no longer be able to create outgoing
87 // streams.
88 session_->OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away."));
89 EXPECT_EQ(NULL, session_->CreateOutgoingDataStream());
92 TEST_P(ToolsQuicClientSessionTest, SetFecProtectionFromConfig) {
93 ValueRestore<bool> old_flag(&FLAGS_enable_quic_fec, true);
95 // Set FEC config in client's connection options.
96 QuicTagVector copt;
97 copt.push_back(kFHDR);
98 session_->config()->SetConnectionOptionsToSend(copt);
100 // Doing the handshake should set up FEC config correctly.
101 CompleteCryptoHandshake();
103 // Verify that headers stream is always protected and data streams are
104 // optionally protected.
105 EXPECT_EQ(FEC_PROTECT_ALWAYS,
106 QuicSessionPeer::GetHeadersStream(session_.get())->fec_policy());
107 QuicSpdyClientStream* stream = session_->CreateOutgoingDataStream();
108 ASSERT_TRUE(stream);
109 EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream->fec_policy());
112 } // namespace
113 } // namespace test
114 } // namespace tools
115 } // namespace net