| 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/quic/quic_client_session.h" | 5 #include "net/quic/quic_client_session.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "net/base/test_completion_callback.h" |
| 10 #include "net/quic/crypto/crypto_protocol.h" | 11 #include "net/quic/crypto/crypto_protocol.h" |
| 11 #include "net/quic/test_tools/quic_test_utils.h" | 12 #include "net/quic/test_tools/quic_test_utils.h" |
| 12 | 13 |
| 13 using testing::_; | 14 using testing::_; |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 namespace test { | 17 namespace test { |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 class QuicClientSessionTest : public ::testing::Test { | 20 class QuicClientSessionTest : public ::testing::Test { |
| 20 protected: | 21 protected: |
| 21 QuicClientSessionTest() | 22 QuicClientSessionTest() |
| 22 : guid_(1), | 23 : guid_(1), |
| 23 connection_(new PacketSavingConnection(guid_, IPEndPoint())), | 24 connection_(new PacketSavingConnection(guid_, IPEndPoint())), |
| 24 session_(connection_) { | 25 session_(connection_) { |
| 25 } | 26 } |
| 26 | 27 |
| 27 protected: | 28 protected: |
| 28 QuicGuid guid_; | 29 QuicGuid guid_; |
| 29 PacketSavingConnection* connection_; | 30 PacketSavingConnection* connection_; |
| 30 QuicClientSession session_; | 31 QuicClientSession session_; |
| 31 QuicConnectionVisitorInterface* visitor_; | 32 QuicConnectionVisitorInterface* visitor_; |
| 33 TestCompletionCallback callback_; |
| 32 }; | 34 }; |
| 33 | 35 |
| 34 TEST_F(QuicClientSessionTest, CryptoConnect) { | 36 TEST_F(QuicClientSessionTest, CryptoConnectSendsCorrectData) { |
| 35 session_.CryptoConnect(); | 37 EXPECT_EQ(ERR_IO_PENDING, session_.CryptoConnect(callback_.callback())); |
| 36 ASSERT_EQ(1u, connection_->packets_.size()); | 38 ASSERT_EQ(1u, connection_->packets_.size()); |
| 37 scoped_ptr<QuicPacket> chlo(ConstructHandshakePacket(guid_, kCHLO)); | 39 scoped_ptr<QuicPacket> chlo(ConstructHandshakePacket(guid_, kCHLO)); |
| 38 CompareQuicDataWithHexError("CHLO", connection_->packets_[0], chlo.get()); | 40 CompareQuicDataWithHexError("CHLO", connection_->packets_[0], chlo.get()); |
| 39 } | 41 } |
| 40 | 42 |
| 41 TEST_F(QuicClientSessionTest, MaxNumConnections) { | 43 TEST_F(QuicClientSessionTest, CryptoConnectSendsCompletesAfterSHLO) { |
| 42 // Initialize crypto before the client session will create a stream. | 44 session_.CryptoConnect(callback_.callback()); |
| 43 session_.CryptoConnect(); | 45 // Send the SHLO message. |
| 44 ASSERT_EQ(1u, connection_->packets_.size()); | |
| 45 scoped_ptr<QuicPacket> chlo(ConstructHandshakePacket(guid_, kCHLO)); | |
| 46 CompareQuicDataWithHexError("CHLO", connection_->packets_[0], chlo.get()); | |
| 47 // Simulate the server crypto handshake. | |
| 48 CryptoHandshakeMessage server_message; | 46 CryptoHandshakeMessage server_message; |
| 49 server_message.tag = kSHLO; | 47 server_message.tag = kSHLO; |
| 50 session_.GetCryptoStream()->OnHandshakeMessage(server_message); | 48 session_.GetCryptoStream()->OnHandshakeMessage(server_message); |
| 49 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 50 } |
| 51 |
| 52 TEST_F(QuicClientSessionTest, MaxNumConnections) { |
| 53 // Initialize crypto before the client session will create a stream. |
| 54 session_.CryptoConnect(callback_.callback()); |
| 55 CryptoHandshakeMessage server_message; |
| 56 server_message.tag = kSHLO; |
| 57 session_.GetCryptoStream()->OnHandshakeMessage(server_message); |
| 58 callback_.WaitForResult(); |
| 51 | 59 |
| 52 std::vector<QuicReliableClientStream*> streams; | 60 std::vector<QuicReliableClientStream*> streams; |
| 53 for (size_t i = 0; i < kDefaultMaxStreamsPerConnection; i++) { | 61 for (size_t i = 0; i < kDefaultMaxStreamsPerConnection; i++) { |
| 54 QuicReliableClientStream* stream = session_.CreateOutgoingReliableStream(); | 62 QuicReliableClientStream* stream = session_.CreateOutgoingReliableStream(); |
| 63 EXPECT_TRUE(stream); |
| 55 streams.push_back(stream); | 64 streams.push_back(stream); |
| 56 EXPECT_TRUE(stream); | |
| 57 } | 65 } |
| 58 EXPECT_FALSE(session_.CreateOutgoingReliableStream()); | 66 EXPECT_FALSE(session_.CreateOutgoingReliableStream()); |
| 59 | 67 |
| 60 // Close a stream and ensure I can now open a new one. | 68 // Close a stream and ensure I can now open a new one. |
| 61 session_.CloseStream(streams[0]->id()); | 69 session_.CloseStream(streams[0]->id()); |
| 62 scoped_ptr<QuicReliableClientStream> stream( | 70 EXPECT_TRUE(session_.CreateOutgoingReliableStream()); |
| 63 session_.CreateOutgoingReliableStream()); | |
| 64 EXPECT_TRUE(stream.get()); | |
| 65 STLDeleteElements(&streams); | |
| 66 } | 71 } |
| 67 | 72 |
| 68 } // namespace | 73 } // namespace |
| 69 } // namespace test | 74 } // namespace test |
| 70 } // namespace net | 75 } // namespace net |
| OLD | NEW |