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/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "net/base/capturing_net_log.h" | 10 #include "net/base/capturing_net_log.h" |
11 #include "net/base/test_completion_callback.h" | 11 #include "net/base/test_completion_callback.h" |
12 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 12 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
13 #include "net/quic/crypto/crypto_protocol.h" | 13 #include "net/quic/crypto/crypto_protocol.h" |
14 #include "net/quic/crypto/quic_decrypter.h" | 14 #include "net/quic/crypto/quic_decrypter.h" |
15 #include "net/quic/crypto/quic_encrypter.h" | 15 #include "net/quic/crypto/quic_encrypter.h" |
16 #include "net/quic/quic_default_packet_writer.h" | 16 #include "net/quic/quic_default_packet_writer.h" |
17 #include "net/quic/test_tools/crypto_test_utils.h" | 17 #include "net/quic/test_tools/crypto_test_utils.h" |
18 #include "net/quic/test_tools/quic_client_session_peer.h" | 18 #include "net/quic/test_tools/quic_client_session_peer.h" |
19 #include "net/quic/test_tools/quic_test_utils.h" | 19 #include "net/quic/test_tools/quic_test_utils.h" |
20 #include "net/socket/socket_test_util.h" | 20 #include "net/socket/socket_test_util.h" |
21 #include "net/udp/datagram_client_socket.h" | 21 #include "net/udp/datagram_client_socket.h" |
22 | 22 |
23 using testing::_; | 23 using testing::_; |
24 | 24 |
25 namespace net { | 25 namespace net { |
26 namespace test { | 26 namespace test { |
27 namespace { | 27 namespace { |
28 | 28 |
29 const char kServerHostname[] = "www.example.com"; | 29 const char kServerHostname[] = "www.example.com"; |
| 30 const uint16 kServerPort = 80; |
30 | 31 |
31 class TestPacketWriter : public QuicDefaultPacketWriter { | 32 class TestPacketWriter : public QuicDefaultPacketWriter { |
32 public: | 33 public: |
33 TestPacketWriter() { | 34 TestPacketWriter() { |
34 } | 35 } |
35 | 36 |
36 // QuicPacketWriter | 37 // QuicPacketWriter |
37 virtual WriteResult WritePacket( | 38 virtual WriteResult WritePacket( |
38 const char* buffer, size_t buf_len, | 39 const char* buffer, size_t buf_len, |
39 const IPAddressNumber& self_address, | 40 const IPAddressNumber& self_address, |
(...skipping 19 matching lines...) Expand all Loading... |
59 private: | 60 private: |
60 QuicPacketHeader header_; | 61 QuicPacketHeader header_; |
61 }; | 62 }; |
62 | 63 |
63 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { | 64 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { |
64 protected: | 65 protected: |
65 QuicClientSessionTest() | 66 QuicClientSessionTest() |
66 : writer_(new TestPacketWriter()), | 67 : writer_(new TestPacketWriter()), |
67 connection_( | 68 connection_( |
68 new PacketSavingConnection(false, SupportedVersions(GetParam()))), | 69 new PacketSavingConnection(false, SupportedVersions(GetParam()))), |
| 70 session_key_(kServerHostname, kServerPort, false), |
69 session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL, | 71 session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL, |
70 kServerHostname, DefaultQuicConfig(), &crypto_config_, | 72 session_key_, DefaultQuicConfig(), &crypto_config_, |
71 &net_log_) { | 73 &net_log_) { |
72 session_.config()->SetDefaults(); | 74 session_.config()->SetDefaults(); |
73 crypto_config_.SetDefaults(); | 75 crypto_config_.SetDefaults(); |
74 } | 76 } |
75 | 77 |
76 virtual void TearDown() OVERRIDE { | 78 virtual void TearDown() OVERRIDE { |
77 session_.CloseSessionOnError(ERR_ABORTED); | 79 session_.CloseSessionOnError(ERR_ABORTED); |
78 } | 80 } |
79 | 81 |
80 scoped_ptr<DatagramClientSocket> GetSocket() { | 82 scoped_ptr<DatagramClientSocket> GetSocket() { |
81 socket_factory_.AddSocketDataProvider(&socket_data_); | 83 socket_factory_.AddSocketDataProvider(&socket_data_); |
82 return socket_factory_.CreateDatagramClientSocket( | 84 return socket_factory_.CreateDatagramClientSocket( |
83 DatagramSocket::DEFAULT_BIND, base::Bind(&base::RandInt), | 85 DatagramSocket::DEFAULT_BIND, base::Bind(&base::RandInt), |
84 &net_log_, NetLog::Source()); | 86 &net_log_, NetLog::Source()); |
85 } | 87 } |
86 | 88 |
87 void CompleteCryptoHandshake() { | 89 void CompleteCryptoHandshake() { |
88 ASSERT_EQ(ERR_IO_PENDING, | 90 ASSERT_EQ(ERR_IO_PENDING, |
89 session_.CryptoConnect(false, callback_.callback())); | 91 session_.CryptoConnect(false, callback_.callback())); |
90 CryptoTestUtils::HandshakeWithFakeServer( | 92 CryptoTestUtils::HandshakeWithFakeServer( |
91 connection_, session_.GetCryptoStream()); | 93 connection_, session_.GetCryptoStream()); |
92 ASSERT_EQ(OK, callback_.WaitForResult()); | 94 ASSERT_EQ(OK, callback_.WaitForResult()); |
93 } | 95 } |
94 | 96 |
95 scoped_ptr<QuicDefaultPacketWriter> writer_; | 97 scoped_ptr<QuicDefaultPacketWriter> writer_; |
96 PacketSavingConnection* connection_; | 98 PacketSavingConnection* connection_; |
97 CapturingNetLog net_log_; | 99 CapturingNetLog net_log_; |
98 MockClientSocketFactory socket_factory_; | 100 MockClientSocketFactory socket_factory_; |
99 StaticSocketDataProvider socket_data_; | 101 StaticSocketDataProvider socket_data_; |
| 102 QuicSessionKey session_key_; |
100 QuicClientSession session_; | 103 QuicClientSession session_; |
101 MockClock clock_; | 104 MockClock clock_; |
102 MockRandom random_; | 105 MockRandom random_; |
103 QuicConnectionVisitorInterface* visitor_; | 106 QuicConnectionVisitorInterface* visitor_; |
104 TestCompletionCallback callback_; | 107 TestCompletionCallback callback_; |
105 QuicCryptoClientConfig crypto_config_; | 108 QuicCryptoClientConfig crypto_config_; |
106 }; | 109 }; |
107 | 110 |
108 INSTANTIATE_TEST_CASE_P(Tests, QuicClientSessionTest, | 111 INSTANTIATE_TEST_CASE_P(Tests, QuicClientSessionTest, |
109 ::testing::ValuesIn(QuicSupportedVersions())); | 112 ::testing::ValuesIn(QuicSupportedVersions())); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 160 |
158 // After receiving a GoAway, I should no longer be able to create outgoing | 161 // After receiving a GoAway, I should no longer be able to create outgoing |
159 // streams. | 162 // streams. |
160 session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); | 163 session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); |
161 EXPECT_EQ(NULL, session_.CreateOutgoingDataStream()); | 164 EXPECT_EQ(NULL, session_.CreateOutgoingDataStream()); |
162 } | 165 } |
163 | 166 |
164 } // namespace | 167 } // namespace |
165 } // namespace test | 168 } // namespace test |
166 } // namespace net | 169 } // namespace net |
OLD | NEW |