Land Recent QUIC Changes.
[chromium-blink-merge.git] / net / quic / test_tools / mock_crypto_client_stream.cc
blobb45d371713bfb432d732e0547f3a84b114303a83
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,
24 crypto_config),
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 bool MockCryptoClientStream::CryptoConnect() {
38 switch (handshake_mode_) {
39 case ZERO_RTT: {
40 encryption_established_ = true;
41 handshake_confirmed_ = false;
42 session()->connection()->SetDecrypter(QuicDecrypter::Create(kNULL),
43 ENCRYPTION_INITIAL);
44 session()->OnCryptoHandshakeEvent(
45 QuicSession::ENCRYPTION_FIRST_ESTABLISHED);
46 break;
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);
61 break;
64 case COLD_START: {
65 handshake_confirmed_ = false;
66 encryption_established_ = false;
67 break;
70 return true;
73 void MockCryptoClientStream::SendOnCryptoHandshakeEvent(
74 QuicSession::CryptoHandshakeEvent event) {
75 encryption_established_ = true;
76 if (event == QuicSession::HANDSHAKE_CONFIRMED) {
77 handshake_confirmed_ = true;
78 SetConfigNegotiated();
80 session()->OnCryptoHandshakeEvent(event);
83 void MockCryptoClientStream::SetConfigNegotiated() {
84 ASSERT_FALSE(session()->config()->negotiated());
85 QuicTagVector cgst;
86 // TODO(rtenneti): Enable the following code after BBR code is checked in.
87 #if 0
88 cgst.push_back(kTBBR);
89 #endif
90 cgst.push_back(kQBIC);
91 session()->config()->SetCongestionFeedback(cgst, kQBIC);
92 session()->config()->SetIdleConnectionStateLifetime(
93 QuicTime::Delta::FromSeconds(2 * kMaximumIdleTimeoutSecs),
94 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs));
95 session()->config()->SetMaxStreamsPerConnection(
96 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection);
98 CryptoHandshakeMessage msg;
99 session()->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());
112 } // namespace net