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/test_tools/crypto_test_utils.h" | 10 #include "net/quic/test_tools/crypto_test_utils.h" |
11 #include "net/quic/test_tools/quic_test_utils.h" | 11 #include "net/quic/test_tools/quic_test_utils.h" |
12 #include "net/tools/quic/quic_reliable_client_stream.h" | 12 #include "net/tools/quic/quic_reliable_client_stream.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 using testing::_; | 15 using testing::_; |
16 using net::test::CryptoTestUtils; | 16 using net::test::CryptoTestUtils; |
17 using net::test::PacketSavingConnection; | 17 using net::test::PacketSavingConnection; |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 namespace tools { | 20 namespace tools { |
21 namespace test { | 21 namespace test { |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kServerHostname[] = "www.example.com"; | 24 const char kServerHostname[] = "www.example.com"; |
25 | 25 |
26 class QuicClientSessionTest : public ::testing::Test { | 26 class QuicClientSessionTest : public ::testing::Test { |
27 protected: | 27 protected: |
28 QuicClientSessionTest() | 28 QuicClientSessionTest() |
29 : guid_(1), | 29 : guid_(1), |
30 connection_(new PacketSavingConnection(guid_, IPEndPoint(), false)), | 30 connection_(new PacketSavingConnection(guid_, IPEndPoint(), false)) { |
31 session_(kServerHostname, config_, connection_, &crypto_config_) { | |
32 config_.SetDefaults(); | |
33 crypto_config_.SetDefaults(); | 31 crypto_config_.SetDefaults(); |
| 32 session_.reset(new QuicClientSession(kServerHostname, QuicConfig(), |
| 33 connection_, &crypto_config_)); |
| 34 session_->config()->SetDefaults(); |
| 35 session_->config()->set_max_streams_per_connection(1, 1); |
34 } | 36 } |
35 | 37 |
36 void CompleteCryptoHandshake() { | 38 void CompleteCryptoHandshake() { |
37 ASSERT_TRUE(session_.CryptoConnect()); | 39 ASSERT_TRUE(session_->CryptoConnect()); |
38 CryptoTestUtils::HandshakeWithFakeServer( | 40 CryptoTestUtils::HandshakeWithFakeServer( |
39 connection_, session_.GetCryptoStream()); | 41 connection_, session_->GetCryptoStream()); |
40 } | 42 } |
41 | 43 |
42 QuicGuid guid_; | 44 QuicGuid guid_; |
43 PacketSavingConnection* connection_; | 45 PacketSavingConnection* connection_; |
44 QuicClientSession session_; | 46 scoped_ptr<QuicClientSession> session_; |
45 QuicConfig config_; | |
46 QuicCryptoClientConfig crypto_config_; | 47 QuicCryptoClientConfig crypto_config_; |
47 }; | 48 }; |
48 | 49 |
49 TEST_F(QuicClientSessionTest, CryptoConnect) { | 50 TEST_F(QuicClientSessionTest, CryptoConnect) { |
50 CompleteCryptoHandshake(); | 51 CompleteCryptoHandshake(); |
51 } | 52 } |
52 | 53 |
53 TEST_F(QuicClientSessionTest, DISABLED_MaxNumConnections) { | 54 TEST_F(QuicClientSessionTest, DISABLED_MaxNumConnections) { |
54 // FLAGS_max_streams_per_connection = 1; | 55 // FLAGS_max_streams_per_connection = 1; |
55 // Initialize crypto before the client session will create a stream. | 56 // Initialize crypto before the client session will create a stream. |
56 CompleteCryptoHandshake(); | 57 CompleteCryptoHandshake(); |
57 | 58 |
58 QuicReliableClientStream* stream = | 59 QuicReliableClientStream* stream = |
59 session_.CreateOutgoingReliableStream(); | 60 session_->CreateOutgoingReliableStream(); |
60 ASSERT_TRUE(stream); | 61 ASSERT_TRUE(stream); |
61 EXPECT_FALSE(session_.CreateOutgoingReliableStream()); | 62 EXPECT_FALSE(session_->CreateOutgoingReliableStream()); |
62 | 63 |
63 // Close a stream and ensure I can now open a new one. | 64 // Close a stream and ensure I can now open a new one. |
64 session_.CloseStream(stream->id()); | 65 session_->CloseStream(stream->id()); |
65 stream = session_.CreateOutgoingReliableStream(); | 66 stream = session_->CreateOutgoingReliableStream(); |
66 EXPECT_TRUE(stream); | 67 EXPECT_TRUE(stream); |
67 } | 68 } |
68 | 69 |
69 TEST_F(QuicClientSessionTest, GoAwayReceived) { | 70 TEST_F(QuicClientSessionTest, GoAwayReceived) { |
70 // Initialize crypto before the client session will create a stream. | 71 // Initialize crypto before the client session will create a stream. |
71 ASSERT_TRUE(session_.CryptoConnect()); | 72 ASSERT_TRUE(session_->CryptoConnect()); |
72 // Simulate the server crypto handshake. | 73 // Simulate the server crypto handshake. |
73 CryptoHandshakeMessage server_message; | 74 CryptoHandshakeMessage server_message; |
74 server_message.set_tag(kSHLO); | 75 server_message.set_tag(kSHLO); |
75 session_.GetCryptoStream()->OnHandshakeMessage(server_message); | 76 session_->GetCryptoStream()->OnHandshakeMessage(server_message); |
76 | 77 |
77 // After receiving a GoAway, I should no longer be able to create outgoing | 78 // After receiving a GoAway, I should no longer be able to create outgoing |
78 // streams. | 79 // streams. |
79 session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); | 80 session_->OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); |
80 EXPECT_EQ(NULL, session_.CreateOutgoingReliableStream()); | 81 EXPECT_EQ(NULL, session_->CreateOutgoingReliableStream()); |
81 } | 82 } |
82 | 83 |
83 } // namespace | 84 } // namespace |
84 } // namespace test | 85 } // namespace test |
85 } // namespace tools | 86 } // namespace tools |
86 } // namespace net | 87 } // namespace net |
OLD | NEW |