1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/quic/test_tools/mock_crypto_client_stream.h"
7 #include "net/quic/crypto/quic_decrypter.h"
8 #include "net/quic/quic_client_session_base.h"
9 #include "net/quic/quic_server_id.h"
10 #include "testing/gtest/include/gtest/gtest.h"
16 MockCryptoClientStream::MockCryptoClientStream(
17 const QuicServerId
& server_id
,
18 QuicClientSessionBase
* session
,
19 ProofVerifyContext
* verify_context
,
20 QuicCryptoClientConfig
* crypto_config
,
21 HandshakeMode handshake_mode
,
22 const ProofVerifyDetails
* proof_verify_details
)
23 : QuicCryptoClientStream(server_id
, session
, verify_context
,
25 handshake_mode_(handshake_mode
),
26 proof_verify_details_(proof_verify_details
) {
29 MockCryptoClientStream::~MockCryptoClientStream() {
32 void MockCryptoClientStream::OnHandshakeMessage(
33 const CryptoHandshakeMessage
& message
) {
34 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE
);
37 void MockCryptoClientStream::CryptoConnect() {
38 switch (handshake_mode_
) {
40 encryption_established_
= true;
41 handshake_confirmed_
= false;
42 session()->connection()->SetDecrypter(QuicDecrypter::Create(kNULL
),
44 session()->OnCryptoHandshakeEvent(
45 QuicSession::ENCRYPTION_FIRST_ESTABLISHED
);
49 case CONFIRM_HANDSHAKE
: {
50 encryption_established_
= true;
51 handshake_confirmed_
= true;
52 crypto_negotiated_params_
.key_exchange
= kC255
;
53 crypto_negotiated_params_
.aead
= kAESG
;
54 if (proof_verify_details_
) {
55 client_session()->OnProofVerifyDetailsAvailable(*proof_verify_details_
);
57 SetConfigNegotiated();
58 session()->connection()->SetDecrypter(QuicDecrypter::Create(kNULL
),
59 ENCRYPTION_FORWARD_SECURE
);
60 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED
);
65 handshake_confirmed_
= false;
66 encryption_established_
= false;
72 void MockCryptoClientStream::SendOnCryptoHandshakeEvent(
73 QuicSession::CryptoHandshakeEvent event
) {
74 encryption_established_
= true;
75 if (event
== QuicSession::HANDSHAKE_CONFIRMED
) {
76 handshake_confirmed_
= true;
77 SetConfigNegotiated();
79 session()->OnCryptoHandshakeEvent(event
);
82 void MockCryptoClientStream::SetConfigNegotiated() {
83 ASSERT_FALSE(session()->config()->negotiated());
85 // TODO(rtenneti): Enable the following code after BBR code is checked in.
87 cgst
.push_back(kTBBR
);
89 cgst
.push_back(kQBIC
);
91 config
.SetIdleConnectionStateLifetime(
92 QuicTime::Delta::FromSeconds(2 * kMaximumIdleTimeoutSecs
),
93 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs
));
94 config
.SetMaxStreamsPerConnection(kDefaultMaxStreamsPerConnection
/ 2,
95 kDefaultMaxStreamsPerConnection
/ 2);
96 config
.SetBytesForConnectionIdToSend(PACKET_8BYTE_CONNECTION_ID
);
98 CryptoHandshakeMessage msg
;
99 config
.ToHandshakeMessage(&msg
);
100 string error_details
;
101 const QuicErrorCode error
=
102 session()->config()->ProcessPeerHello(msg
, CLIENT
, &error_details
);
103 ASSERT_EQ(QUIC_NO_ERROR
, error
);
104 ASSERT_TRUE(session()->config()->negotiated());
105 session()->OnConfigNegotiated();
108 QuicClientSessionBase
* MockCryptoClientStream::client_session() {
109 return reinterpret_cast<QuicClientSessionBase
*>(session());