| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/quic/quic_client_session.h" | 5 #include "net/tools/quic/quic_client_session.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
| 10 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 10 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 namespace test { | 24 namespace test { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const char kServerHostname[] = "www.example.com"; | 27 const char kServerHostname[] = "www.example.com"; |
| 28 const uint16 kPort = 80; | 28 const uint16 kPort = 80; |
| 29 | 29 |
| 30 class ToolsQuicClientSessionTest | 30 class ToolsQuicClientSessionTest |
| 31 : public ::testing::TestWithParam<QuicVersion> { | 31 : public ::testing::TestWithParam<QuicVersion> { |
| 32 protected: | 32 protected: |
| 33 ToolsQuicClientSessionTest() | 33 ToolsQuicClientSessionTest() |
| 34 : connection_(new PacketSavingConnection(false, | 34 : connection_( |
| 35 SupportedVersions(GetParam()))) { | 35 new PacketSavingConnection(false, SupportedVersions(GetParam()))) { |
| 36 crypto_config_.SetDefaults(); | 36 crypto_config_.SetDefaults(); |
| 37 session_.reset(new QuicClientSession( | 37 session_.reset(new QuicClientSession( |
| 38 QuicServerId(kServerHostname, kPort, false, PRIVACY_MODE_DISABLED), | 38 QuicServerId(kServerHostname, kPort, false, PRIVACY_MODE_DISABLED), |
| 39 DefaultQuicConfig(), | 39 DefaultQuicConfig(), |
| 40 connection_, | 40 connection_, |
| 41 &crypto_config_)); | 41 &crypto_config_)); |
| 42 session_->config()->SetDefaults(); | 42 session_->config()->SetDefaults(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void CompleteCryptoHandshake() { | 45 void CompleteCryptoHandshake() { |
| 46 ASSERT_TRUE(session_->CryptoConnect()); | 46 ASSERT_TRUE(session_->CryptoConnect()); |
| 47 CryptoTestUtils::HandshakeWithFakeServer( | 47 CryptoTestUtils::HandshakeWithFakeServer(connection_, |
| 48 connection_, session_->GetCryptoStream()); | 48 session_->GetCryptoStream()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 PacketSavingConnection* connection_; | 51 PacketSavingConnection* connection_; |
| 52 scoped_ptr<QuicClientSession> session_; | 52 scoped_ptr<QuicClientSession> session_; |
| 53 QuicCryptoClientConfig crypto_config_; | 53 QuicCryptoClientConfig crypto_config_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 INSTANTIATE_TEST_CASE_P(Tests, ToolsQuicClientSessionTest, | 56 INSTANTIATE_TEST_CASE_P(Tests, |
| 57 ToolsQuicClientSessionTest, |
| 57 ::testing::ValuesIn(QuicSupportedVersions())); | 58 ::testing::ValuesIn(QuicSupportedVersions())); |
| 58 | 59 |
| 59 TEST_P(ToolsQuicClientSessionTest, CryptoConnect) { | 60 TEST_P(ToolsQuicClientSessionTest, CryptoConnect) { |
| 60 CompleteCryptoHandshake(); | 61 CompleteCryptoHandshake(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 TEST_P(ToolsQuicClientSessionTest, MaxNumStreams) { | 64 TEST_P(ToolsQuicClientSessionTest, MaxNumStreams) { |
| 64 session_->config()->set_max_streams_per_connection(1, 1); | 65 session_->config()->set_max_streams_per_connection(1, 1); |
| 65 // FLAGS_max_streams_per_connection = 1; | 66 // FLAGS_max_streams_per_connection = 1; |
| 66 // Initialize crypto before the client session will create a stream. | 67 // Initialize crypto before the client session will create a stream. |
| 67 CompleteCryptoHandshake(); | 68 CompleteCryptoHandshake(); |
| 68 | 69 |
| 69 QuicSpdyClientStream* stream = | 70 QuicSpdyClientStream* stream = session_->CreateOutgoingDataStream(); |
| 70 session_->CreateOutgoingDataStream(); | |
| 71 ASSERT_TRUE(stream); | 71 ASSERT_TRUE(stream); |
| 72 EXPECT_FALSE(session_->CreateOutgoingDataStream()); | 72 EXPECT_FALSE(session_->CreateOutgoingDataStream()); |
| 73 | 73 |
| 74 // Close a stream and ensure I can now open a new one. | 74 // Close a stream and ensure I can now open a new one. |
| 75 session_->CloseStream(stream->id()); | 75 session_->CloseStream(stream->id()); |
| 76 stream = session_->CreateOutgoingDataStream(); | 76 stream = session_->CreateOutgoingDataStream(); |
| 77 EXPECT_TRUE(stream); | 77 EXPECT_TRUE(stream); |
| 78 } | 78 } |
| 79 | 79 |
| 80 TEST_P(ToolsQuicClientSessionTest, GoAwayReceived) { | 80 TEST_P(ToolsQuicClientSessionTest, GoAwayReceived) { |
| 81 CompleteCryptoHandshake(); | 81 CompleteCryptoHandshake(); |
| 82 | 82 |
| 83 // After receiving a GoAway, I should no longer be able to create outgoing | 83 // After receiving a GoAway, I should no longer be able to create outgoing |
| 84 // streams. | 84 // streams. |
| 85 session_->OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); | 85 session_->OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); |
| 86 EXPECT_EQ(NULL, session_->CreateOutgoingDataStream()); | 86 EXPECT_EQ(NULL, session_->CreateOutgoingDataStream()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace | 89 } // namespace |
| 90 } // namespace test | 90 } // namespace test |
| 91 } // namespace tools | 91 } // namespace tools |
| 92 } // namespace net | 92 } // namespace net |
| OLD | NEW |