Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / quic / test_tools / mock_crypto_client_stream.cc
blob290693933fd3202e7658e1167e4b220906d2a64e
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"
12 using std::string;
14 namespace net {
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, crypto_config),
24 handshake_mode_(handshake_mode),
25 proof_verify_details_(proof_verify_details) {
28 MockCryptoClientStream::~MockCryptoClientStream() {
31 void MockCryptoClientStream::OnHandshakeMessage(
32 const CryptoHandshakeMessage& message) {
33 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE);
36 void MockCryptoClientStream::CryptoConnect() {
37 switch (handshake_mode_) {
38 case ZERO_RTT: {
39 encryption_established_ = true;
40 handshake_confirmed_ = false;
41 session()->connection()->SetDecrypter(ENCRYPTION_INITIAL,
42 QuicDecrypter::Create(kNULL));
43 session()->OnCryptoHandshakeEvent(
44 QuicSession::ENCRYPTION_FIRST_ESTABLISHED);
45 break;
48 case CONFIRM_HANDSHAKE: {
49 encryption_established_ = true;
50 handshake_confirmed_ = true;
51 crypto_negotiated_params_.key_exchange = kC255;
52 crypto_negotiated_params_.aead = kAESG;
53 if (proof_verify_details_) {
54 client_session()->OnProofVerifyDetailsAvailable(*proof_verify_details_);
56 SetConfigNegotiated();
57 session()->connection()->SetDecrypter(ENCRYPTION_FORWARD_SECURE,
58 QuicDecrypter::Create(kNULL));
59 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED);
60 break;
63 case COLD_START: {
64 handshake_confirmed_ = false;
65 encryption_established_ = false;
66 break;
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());
83 QuicTagVector cgst;
84 // TODO(rtenneti): Enable the following code after BBR code is checked in.
85 #if 0
86 cgst.push_back(kTBBR);
87 #endif
88 cgst.push_back(kQBIC);
89 QuicConfig config;
90 config.SetIdleConnectionStateLifetime(
91 QuicTime::Delta::FromSeconds(2 * kMaximumIdleTimeoutSecs),
92 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs));
93 config.SetMaxStreamsPerConnection(kDefaultMaxStreamsPerConnection / 2,
94 kDefaultMaxStreamsPerConnection / 2);
95 config.SetBytesForConnectionIdToSend(PACKET_8BYTE_CONNECTION_ID);
97 CryptoHandshakeMessage msg;
98 config.ToHandshakeMessage(&msg);
99 string error_details;
100 const QuicErrorCode error =
101 session()->config()->ProcessPeerHello(msg, CLIENT, &error_details);
102 ASSERT_EQ(QUIC_NO_ERROR, error);
103 ASSERT_TRUE(session()->config()->negotiated());
104 session()->OnConfigNegotiated();
107 QuicClientSessionBase* MockCryptoClientStream::client_session() {
108 return reinterpret_cast<QuicClientSessionBase*>(session());
111 } // namespace net