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"
14 MockCryptoClientStream::MockCryptoClientStream(
15 const QuicServerId
& server_id
,
16 QuicClientSessionBase
* session
,
17 ProofVerifyContext
* verify_context
,
18 QuicCryptoClientConfig
* crypto_config
,
19 HandshakeMode handshake_mode
,
20 const ProofVerifyDetails
* proof_verify_details
)
21 : QuicCryptoClientStream(server_id
, session
, verify_context
,
23 handshake_mode_(handshake_mode
),
24 proof_verify_details_(proof_verify_details
) {
27 MockCryptoClientStream::~MockCryptoClientStream() {
30 void MockCryptoClientStream::OnHandshakeMessage(
31 const CryptoHandshakeMessage
& message
) {
32 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE
);
35 bool MockCryptoClientStream::CryptoConnect() {
36 switch (handshake_mode_
) {
38 encryption_established_
= true;
39 handshake_confirmed_
= false;
40 session()->connection()->SetDecrypter(QuicDecrypter::Create(kNULL
),
42 session()->OnCryptoHandshakeEvent(
43 QuicSession::ENCRYPTION_FIRST_ESTABLISHED
);
47 case CONFIRM_HANDSHAKE
: {
48 encryption_established_
= true;
49 handshake_confirmed_
= true;
50 crypto_negotiated_params_
.key_exchange
= kC255
;
51 crypto_negotiated_params_
.aead
= kAESG
;
52 if (proof_verify_details_
) {
53 client_session()->OnProofVerifyDetailsAvailable(*proof_verify_details_
);
55 SetConfigNegotiated();
56 session()->connection()->SetDecrypter(QuicDecrypter::Create(kNULL
),
57 ENCRYPTION_FORWARD_SECURE
);
58 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED
);
63 handshake_confirmed_
= false;
64 encryption_established_
= false;
71 void MockCryptoClientStream::SendOnCryptoHandshakeEvent(
72 QuicSession::CryptoHandshakeEvent event
) {
73 encryption_established_
= true;
74 if (event
== QuicSession::HANDSHAKE_CONFIRMED
) {
75 handshake_confirmed_
= true;
76 SetConfigNegotiated();
78 session()->OnCryptoHandshakeEvent(event
);
81 void MockCryptoClientStream::SetConfigNegotiated() {
82 ASSERT_FALSE(session()->config()->negotiated());
84 // TODO(rtenneti): Enable the following code after BBR code is checked in.
86 cgst
.push_back(kTBBR
);
88 cgst
.push_back(kQBIC
);
89 session()->config()->set_congestion_feedback(cgst
, kQBIC
);
90 session()->config()->set_idle_connection_state_lifetime(
91 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs
),
92 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs
));
93 session()->config()->set_max_streams_per_connection(
94 2 * kDefaultMaxStreamsPerConnection
, kDefaultMaxStreamsPerConnection
);
96 CryptoHandshakeMessage msg
;
97 session()->config()->ToHandshakeMessage(&msg
);
99 const QuicErrorCode error
=
100 session()->config()->ProcessPeerHello(msg
, CLIENT
, &error_details
);
101 ASSERT_EQ(QUIC_NO_ERROR
, error
);
102 ASSERT_TRUE(session()->config()->negotiated());
105 QuicClientSessionBase
* MockCryptoClientStream::client_session() {
106 return reinterpret_cast<QuicClientSessionBase
*>(session());