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/quic_client_session_base.h"
8 #include "net/quic/quic_session_key.h"
9 #include "testing/gtest/include/gtest/gtest.h"
13 MockCryptoClientStream::MockCryptoClientStream(
14 const QuicSessionKey& server_key,
15 QuicClientSessionBase* session,
16 ProofVerifyContext* verify_context,
17 QuicCryptoClientConfig* crypto_config,
18 HandshakeMode handshake_mode,
19 const ProofVerifyDetails* proof_verify_details)
20 : QuicCryptoClientStream(server_key, session, verify_context,
22 handshake_mode_(handshake_mode),
23 proof_verify_details_(proof_verify_details) {
26 MockCryptoClientStream::~MockCryptoClientStream() {
29 void MockCryptoClientStream::OnHandshakeMessage(
30 const CryptoHandshakeMessage& message) {
31 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE);
34 bool MockCryptoClientStream::CryptoConnect() {
35 switch (handshake_mode_) {
37 encryption_established_ = true;
38 handshake_confirmed_ = false;
39 session()->OnCryptoHandshakeEvent(
40 QuicSession::ENCRYPTION_FIRST_ESTABLISHED);
44 case CONFIRM_HANDSHAKE: {
45 encryption_established_ = true;
46 handshake_confirmed_ = true;
47 if (proof_verify_details_) {
48 client_session()->OnProofVerifyDetailsAvailable(*proof_verify_details_);
50 SetConfigNegotiated();
51 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED);
56 handshake_confirmed_ = false;
57 encryption_established_ = false;
64 void MockCryptoClientStream::SendOnCryptoHandshakeEvent(
65 QuicSession::CryptoHandshakeEvent event) {
66 encryption_established_ = true;
67 if (event == QuicSession::HANDSHAKE_CONFIRMED) {
68 handshake_confirmed_ = true;
69 SetConfigNegotiated();
71 session()->OnCryptoHandshakeEvent(event);
74 void MockCryptoClientStream::SetConfigNegotiated() {
75 ASSERT_FALSE(session()->config()->negotiated());
77 cgst.push_back(kINAR);
78 cgst.push_back(kQBIC);
79 session()->config()->set_congestion_control(cgst, kQBIC);
80 session()->config()->set_idle_connection_state_lifetime(
81 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs),
82 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs));
83 session()->config()->set_max_streams_per_connection(
84 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection);
86 CryptoHandshakeMessage msg;
87 session()->config()->ToHandshakeMessage(&msg);
89 const QuicErrorCode error =
90 session()->config()->ProcessClientHello(msg, &error_details);
91 ASSERT_EQ(QUIC_NO_ERROR, error);
92 ASSERT_TRUE(session()->config()->negotiated());
95 QuicClientSessionBase* MockCryptoClientStream::client_session() {
96 return reinterpret_cast<QuicClientSessionBase*>(session());