Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Side by Side Diff: net/quic/quic_client_session_test.cc

Issue 11633030: Send the ClientHello handshake message. Fix a bug in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Remove an extraneous test:: before TestCryptoVisitor Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_client_session.cc ('k') | net/quic/quic_crypto_client_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base/test_completion_callback.h"
11 #include "net/quic/crypto/crypto_protocol.h" 11 #include "net/quic/crypto/crypto_protocol.h"
12 #include "net/quic/test_tools/quic_test_utils.h" 12 #include "net/quic/test_tools/quic_test_utils.h"
13 13
14 using testing::_; 14 using testing::_;
15 15
16 namespace net { 16 namespace net {
17 namespace test { 17 namespace test {
18 namespace { 18 namespace {
19 19
20 class QuicClientSessionTest : public ::testing::Test { 20 class QuicClientSessionTest : public ::testing::Test {
21 protected: 21 protected:
22 QuicClientSessionTest() 22 QuicClientSessionTest()
23 : guid_(1), 23 : guid_(1),
24 connection_(new PacketSavingConnection(guid_, IPEndPoint())), 24 connection_(new PacketSavingConnection(guid_, IPEndPoint())),
25 session_(connection_, NULL, NULL) { 25 session_(connection_, NULL, NULL) {
26 } 26 }
27 27
28 protected:
29 QuicGuid guid_; 28 QuicGuid guid_;
30 PacketSavingConnection* connection_; 29 PacketSavingConnection* connection_;
31 QuicClientSession session_; 30 QuicClientSession session_;
32 QuicConnectionVisitorInterface* visitor_; 31 QuicConnectionVisitorInterface* visitor_;
33 TestCompletionCallback callback_; 32 TestCompletionCallback callback_;
34 }; 33 };
35 34
36 TEST_F(QuicClientSessionTest, CryptoConnectSendsCorrectData) { 35 TEST_F(QuicClientSessionTest, CryptoConnectSendsCorrectData) {
37 EXPECT_EQ(ERR_IO_PENDING, session_.CryptoConnect(callback_.callback())); 36 EXPECT_EQ(ERR_IO_PENDING, session_.CryptoConnect(callback_.callback()));
38 ASSERT_EQ(1u, connection_->packets_.size()); 37 ASSERT_EQ(1u, connection_->packets_.size());
39 scoped_ptr<QuicPacket> chlo(ConstructHandshakePacket(guid_, kCHLO)); 38 scoped_ptr<QuicPacket> chlo(ConstructClientHelloPacket(
39 guid_, connection_->clock(), connection_->random_generator()));
40 CompareQuicDataWithHexError("CHLO", connection_->packets_[0], chlo.get()); 40 CompareQuicDataWithHexError("CHLO", connection_->packets_[0], chlo.get());
41 } 41 }
42 42
43 TEST_F(QuicClientSessionTest, CryptoConnectSendsCompletesAfterSHLO) { 43 TEST_F(QuicClientSessionTest, CryptoConnectSendsCompletesAfterSHLO) {
44 ASSERT_EQ(ERR_IO_PENDING, session_.CryptoConnect(callback_.callback())); 44 ASSERT_EQ(ERR_IO_PENDING, session_.CryptoConnect(callback_.callback()));
45 // Send the SHLO message. 45 // Send the SHLO message.
46 CryptoHandshakeMessage server_message; 46 CryptoHandshakeMessage server_message;
47 server_message.tag = kSHLO; 47 server_message.tag = kSHLO;
48 session_.GetCryptoStream()->OnHandshakeMessage(server_message); 48 session_.GetCryptoStream()->OnHandshakeMessage(server_message);
49 EXPECT_EQ(OK, callback_.WaitForResult()); 49 EXPECT_EQ(OK, callback_.WaitForResult());
50 } 50 }
51 51
52 TEST_F(QuicClientSessionTest, MaxNumConnections) { 52 TEST_F(QuicClientSessionTest, MaxNumConnections) {
53 // Initialize crypto before the client session will create a stream. 53 // Initialize crypto before the client session will create a stream.
54 ASSERT_EQ(ERR_IO_PENDING, session_.CryptoConnect(callback_.callback())); 54 ASSERT_EQ(ERR_IO_PENDING, session_.CryptoConnect(callback_.callback()));
55 // Simulate the server crypto handshake.
55 CryptoHandshakeMessage server_message; 56 CryptoHandshakeMessage server_message;
56 server_message.tag = kSHLO; 57 server_message.tag = kSHLO;
57 session_.GetCryptoStream()->OnHandshakeMessage(server_message); 58 session_.GetCryptoStream()->OnHandshakeMessage(server_message);
58 callback_.WaitForResult(); 59 callback_.WaitForResult();
59 60
60 std::vector<QuicReliableClientStream*> streams; 61 std::vector<QuicReliableClientStream*> streams;
61 for (size_t i = 0; i < kDefaultMaxStreamsPerConnection; i++) { 62 for (size_t i = 0; i < kDefaultMaxStreamsPerConnection; i++) {
62 QuicReliableClientStream* stream = session_.CreateOutgoingReliableStream(); 63 QuicReliableClientStream* stream = session_.CreateOutgoingReliableStream();
63 EXPECT_TRUE(stream); 64 EXPECT_TRUE(stream);
64 streams.push_back(stream); 65 streams.push_back(stream);
65 } 66 }
66 EXPECT_FALSE(session_.CreateOutgoingReliableStream()); 67 EXPECT_FALSE(session_.CreateOutgoingReliableStream());
67 68
68 // Close a stream and ensure I can now open a new one. 69 // Close a stream and ensure I can now open a new one.
69 session_.CloseStream(streams[0]->id()); 70 session_.CloseStream(streams[0]->id());
70 EXPECT_TRUE(session_.CreateOutgoingReliableStream()); 71 EXPECT_TRUE(session_.CreateOutgoingReliableStream());
71 } 72 }
72 73
73 } // namespace 74 } // namespace
74 } // namespace test 75 } // namespace test
75 } // namespace net 76 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_client_session.cc ('k') | net/quic/quic_crypto_client_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698