Home | History | Annotate | Download | only in test_tools
      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.
      4 
      5 #include "net/quic/test_tools/mock_crypto_client_stream.h"
      6 #include "testing/gtest/include/gtest/gtest.h"
      7 
      8 namespace net {
      9 
     10 MockCryptoClientStream::MockCryptoClientStream(
     11     const string& server_hostname,
     12     QuicSession* session,
     13     QuicCryptoClientConfig* crypto_config,
     14     HandshakeMode handshake_mode)
     15   : QuicCryptoClientStream(server_hostname, session, crypto_config),
     16     handshake_mode_(handshake_mode) {
     17 }
     18 
     19 MockCryptoClientStream::~MockCryptoClientStream() {
     20 }
     21 
     22 void MockCryptoClientStream::OnHandshakeMessage(
     23     const CryptoHandshakeMessage& message) {
     24   CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE);
     25 }
     26 
     27 bool MockCryptoClientStream::CryptoConnect() {
     28   switch (handshake_mode_) {
     29     case ZERO_RTT: {
     30       encryption_established_ = true;
     31       handshake_confirmed_ = false;
     32       session()->OnCryptoHandshakeEvent(
     33           QuicSession::ENCRYPTION_FIRST_ESTABLISHED);
     34       break;
     35     }
     36 
     37     case CONFIRM_HANDSHAKE: {
     38       encryption_established_ = true;
     39       handshake_confirmed_ = true;
     40       SetConfigNegotiated();
     41       session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED);
     42       break;
     43     }
     44 
     45     case COLD_START: {
     46       handshake_confirmed_ = false;
     47       encryption_established_ = false;
     48       break;
     49     }
     50   }
     51   return true;
     52 }
     53 
     54 void MockCryptoClientStream::SetConfigNegotiated() {
     55   ASSERT_FALSE(session()->config()->negotiated());
     56   QuicTagVector cgst;
     57   cgst.push_back(kINAR);
     58   cgst.push_back(kQBIC);
     59   session()->config()->set_congestion_control(cgst, kQBIC);
     60   session()->config()->set_idle_connection_state_lifetime(
     61       QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs),
     62       QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs));
     63   session()->config()->set_max_streams_per_connection(
     64       2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection);
     65 
     66   CryptoHandshakeMessage msg;
     67   session()->config()->ToHandshakeMessage(&msg);
     68   string error_details;
     69   const QuicErrorCode error =
     70       session()->config()->ProcessClientHello(msg, &error_details);
     71   ASSERT_EQ(QUIC_NO_ERROR, error);
     72   ASSERT_TRUE(session()->config()->negotiated());
     73 }
     74 
     75 }  // namespace net
     76