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"
6 #include "testing/gtest/include/gtest/gtest.h"
10 MockCryptoClientStream::MockCryptoClientStream(
11 const string& server_hostname,
13 QuicCryptoClientConfig* crypto_config,
14 HandshakeMode handshake_mode)
15 : QuicCryptoClientStream(server_hostname, session, crypto_config),
16 handshake_mode_(handshake_mode) {
19 MockCryptoClientStream::~MockCryptoClientStream() {
22 void MockCryptoClientStream::OnHandshakeMessage(
23 const CryptoHandshakeMessage& message) {
24 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE);
27 bool MockCryptoClientStream::CryptoConnect() {
28 switch (handshake_mode_) {
30 encryption_established_ = true;
31 handshake_confirmed_ = false;
32 session()->OnCryptoHandshakeEvent(
33 QuicSession::ENCRYPTION_FIRST_ESTABLISHED);
37 case CONFIRM_HANDSHAKE: {
38 encryption_established_ = true;
39 handshake_confirmed_ = true;
40 SetConfigNegotiated();
41 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED);
46 handshake_confirmed_ = false;
47 encryption_established_ = false;
54 void MockCryptoClientStream::SendOnCryptoHandshakeEvent(
55 QuicSession::CryptoHandshakeEvent event) {
56 encryption_established_ = true;
57 if (event == QuicSession::HANDSHAKE_CONFIRMED) {
58 handshake_confirmed_ = true;
59 SetConfigNegotiated();
61 session()->OnCryptoHandshakeEvent(event);
64 void MockCryptoClientStream::SetConfigNegotiated() {
65 ASSERT_FALSE(session()->config()->negotiated());
67 cgst.push_back(kINAR);
68 cgst.push_back(kQBIC);
69 session()->config()->set_congestion_control(cgst, kQBIC);
70 session()->config()->set_idle_connection_state_lifetime(
71 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs),
72 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs));
73 session()->config()->set_max_streams_per_connection(
74 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection);
76 CryptoHandshakeMessage msg;
77 session()->config()->ToHandshakeMessage(&msg);
79 const QuicErrorCode error =
80 session()->config()->ProcessClientHello(msg, &error_details);
81 ASSERT_EQ(QUIC_NO_ERROR, error);
82 ASSERT_TRUE(session()->config()->negotiated());