| 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/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 11 #include "net/base/capturing_net_log.h" | 11 #include "net/base/capturing_net_log.h" |
| 12 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
| 13 #include "net/base/test_data_directory.h" | 13 #include "net/base/test_data_directory.h" |
| 14 #include "net/cert/cert_verify_result.h" | 14 #include "net/cert/cert_verify_result.h" |
| 15 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 15 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| 16 #include "net/quic/crypto/crypto_protocol.h" | 16 #include "net/quic/crypto/crypto_protocol.h" |
| 17 #include "net/quic/crypto/proof_verifier_chromium.h" | 17 #include "net/quic/crypto/proof_verifier_chromium.h" |
| 18 #include "net/quic/crypto/quic_decrypter.h" | 18 #include "net/quic/crypto/quic_decrypter.h" |
| 19 #include "net/quic/crypto/quic_encrypter.h" | 19 #include "net/quic/crypto/quic_encrypter.h" |
| 20 #include "net/quic/crypto/quic_server_info.h" | 20 #include "net/quic/crypto/quic_server_info.h" |
| 21 #include "net/quic/quic_default_packet_writer.h" | |
| 22 #include "net/quic/test_tools/crypto_test_utils.h" | 21 #include "net/quic/test_tools/crypto_test_utils.h" |
| 23 #include "net/quic/test_tools/quic_client_session_peer.h" | 22 #include "net/quic/test_tools/quic_client_session_peer.h" |
| 24 #include "net/quic/test_tools/quic_test_utils.h" | 23 #include "net/quic/test_tools/quic_test_utils.h" |
| 25 #include "net/quic/test_tools/simple_quic_framer.h" | 24 #include "net/quic/test_tools/simple_quic_framer.h" |
| 26 #include "net/socket/socket_test_util.h" | 25 #include "net/socket/socket_test_util.h" |
| 27 #include "net/test/cert_test_util.h" | 26 #include "net/test/cert_test_util.h" |
| 28 #include "net/udp/datagram_client_socket.h" | 27 #include "net/udp/datagram_client_socket.h" |
| 29 | 28 |
| 30 using testing::_; | 29 using testing::_; |
| 31 | 30 |
| 32 namespace net { | 31 namespace net { |
| 33 namespace test { | 32 namespace test { |
| 34 namespace { | 33 namespace { |
| 35 | 34 |
| 36 const char kServerHostname[] = "www.example.org"; | 35 const char kServerHostname[] = "www.example.org"; |
| 37 const uint16 kServerPort = 80; | 36 const uint16 kServerPort = 80; |
| 38 | 37 |
| 39 class TestPacketWriter : public QuicDefaultPacketWriter { | |
| 40 public: | |
| 41 TestPacketWriter(QuicVersion version) : version_(version) {} | |
| 42 | |
| 43 // QuicPacketWriter | |
| 44 virtual WriteResult WritePacket( | |
| 45 const char* buffer, size_t buf_len, | |
| 46 const IPAddressNumber& self_address, | |
| 47 const IPEndPoint& peer_address) OVERRIDE { | |
| 48 SimpleQuicFramer framer(SupportedVersions(version_)); | |
| 49 QuicEncryptedPacket packet(buffer, buf_len); | |
| 50 EXPECT_TRUE(framer.ProcessPacket(packet)); | |
| 51 header_ = framer.header(); | |
| 52 return WriteResult(WRITE_STATUS_OK, packet.length()); | |
| 53 } | |
| 54 | |
| 55 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { | |
| 56 // Chrome sockets' Write() methods buffer the data until the Write is | |
| 57 // permitted. | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 // Returns the header from the last packet written. | |
| 62 const QuicPacketHeader& header() { return header_; } | |
| 63 | |
| 64 private: | |
| 65 QuicVersion version_; | |
| 66 QuicPacketHeader header_; | |
| 67 }; | |
| 68 | |
| 69 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { | 38 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { |
| 70 protected: | 39 protected: |
| 71 QuicClientSessionTest() | 40 QuicClientSessionTest() |
| 72 : writer_(new TestPacketWriter(GetParam())), | 41 : connection_( |
| 73 connection_( | |
| 74 new PacketSavingConnection(false, SupportedVersions(GetParam()))), | 42 new PacketSavingConnection(false, SupportedVersions(GetParam()))), |
| 75 session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL, | 43 session_(connection_, GetSocket().Pass(), NULL, NULL, |
| 76 make_scoped_ptr((QuicServerInfo*)NULL), | 44 make_scoped_ptr((QuicServerInfo*)NULL), |
| 77 QuicServerId(kServerHostname, kServerPort, false, | 45 QuicServerId(kServerHostname, kServerPort, false, |
| 78 PRIVACY_MODE_DISABLED), | 46 PRIVACY_MODE_DISABLED), |
| 79 DefaultQuicConfig(), &crypto_config_, | 47 DefaultQuicConfig(), &crypto_config_, |
| 80 base::MessageLoop::current()->message_loop_proxy().get(), | 48 base::MessageLoop::current()->message_loop_proxy().get(), |
| 81 &net_log_) { | 49 &net_log_) { |
| 82 session_.InitializeSession(); | 50 session_.InitializeSession(); |
| 83 session_.config()->SetDefaults(); | 51 session_.config()->SetDefaults(); |
| 84 crypto_config_.SetDefaults(); | 52 crypto_config_.SetDefaults(); |
| 85 } | 53 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 96 } | 64 } |
| 97 | 65 |
| 98 void CompleteCryptoHandshake() { | 66 void CompleteCryptoHandshake() { |
| 99 ASSERT_EQ(ERR_IO_PENDING, | 67 ASSERT_EQ(ERR_IO_PENDING, |
| 100 session_.CryptoConnect(false, callback_.callback())); | 68 session_.CryptoConnect(false, callback_.callback())); |
| 101 CryptoTestUtils::HandshakeWithFakeServer( | 69 CryptoTestUtils::HandshakeWithFakeServer( |
| 102 connection_, session_.GetCryptoStream()); | 70 connection_, session_.GetCryptoStream()); |
| 103 ASSERT_EQ(OK, callback_.WaitForResult()); | 71 ASSERT_EQ(OK, callback_.WaitForResult()); |
| 104 } | 72 } |
| 105 | 73 |
| 106 scoped_ptr<QuicDefaultPacketWriter> writer_; | |
| 107 PacketSavingConnection* connection_; | 74 PacketSavingConnection* connection_; |
| 108 CapturingNetLog net_log_; | 75 CapturingNetLog net_log_; |
| 109 MockClientSocketFactory socket_factory_; | 76 MockClientSocketFactory socket_factory_; |
| 110 StaticSocketDataProvider socket_data_; | 77 StaticSocketDataProvider socket_data_; |
| 111 QuicClientSession session_; | 78 QuicClientSession session_; |
| 112 MockClock clock_; | 79 MockClock clock_; |
| 113 MockRandom random_; | 80 MockRandom random_; |
| 114 QuicConnectionVisitorInterface* visitor_; | 81 QuicConnectionVisitorInterface* visitor_; |
| 115 TestCompletionCallback callback_; | 82 TestCompletionCallback callback_; |
| 116 QuicCryptoClientConfig crypto_config_; | 83 QuicCryptoClientConfig crypto_config_; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 183 |
| 217 EXPECT_TRUE(session_.CanPool("www.example.org")); | 184 EXPECT_TRUE(session_.CanPool("www.example.org")); |
| 218 EXPECT_TRUE(session_.CanPool("mail.example.org")); | 185 EXPECT_TRUE(session_.CanPool("mail.example.org")); |
| 219 EXPECT_FALSE(session_.CanPool("mail.example.com")); | 186 EXPECT_FALSE(session_.CanPool("mail.example.com")); |
| 220 EXPECT_FALSE(session_.CanPool("mail.google.com")); | 187 EXPECT_FALSE(session_.CanPool("mail.google.com")); |
| 221 } | 188 } |
| 222 | 189 |
| 223 } // namespace | 190 } // namespace |
| 224 } // namespace test | 191 } // namespace test |
| 225 } // namespace net | 192 } // namespace net |
| OLD | NEW |