- add sources.
[platform/framework/web/crosswalk.git] / src / net / quic / test_tools / mock_crypto_client_stream.cc
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::SendOnCryptoHandshakeEvent(
55     QuicSession::CryptoHandshakeEvent event) {
56   encryption_established_ = true;
57   if (event == QuicSession::HANDSHAKE_CONFIRMED) {
58     handshake_confirmed_ = true;
59     SetConfigNegotiated();
60   }
61   session()->OnCryptoHandshakeEvent(event);
62 }
63
64 void MockCryptoClientStream::SetConfigNegotiated() {
65   ASSERT_FALSE(session()->config()->negotiated());
66   QuicTagVector cgst;
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);
75
76   CryptoHandshakeMessage msg;
77   session()->config()->ToHandshakeMessage(&msg);
78   string error_details;
79   const QuicErrorCode error =
80       session()->config()->ProcessClientHello(msg, &error_details);
81   ASSERT_EQ(QUIC_NO_ERROR, error);
82   ASSERT_TRUE(session()->config()->negotiated());
83 }
84
85 }  // namespace net