Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / net / quic / quic_config_test.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/quic_config.h"
6
7 #include "net/quic/crypto/crypto_handshake_message.h"
8 #include "net/quic/crypto/crypto_protocol.h"
9 #include "net/quic/quic_protocol.h"
10 #include "net/quic/quic_sent_packet_manager.h"
11 #include "net/quic/quic_time.h"
12 #include "net/quic/quic_utils.h"
13 #include "net/quic/test_tools/quic_test_utils.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using std::string;
17
18 namespace net {
19 namespace test {
20 namespace {
21
22 class QuicConfigTest : public ::testing::Test {
23  protected:
24   QuicConfigTest() {
25     config_.SetDefaults();
26     config_.set_initial_round_trip_time_us(kMaxInitialRoundTripTimeUs, 0);
27   }
28
29   QuicConfig config_;
30 };
31
32 TEST_F(QuicConfigTest, ToHandshakeMessage) {
33   FLAGS_enable_quic_pacing = false;
34   config_.SetDefaults();
35   config_.set_idle_connection_state_lifetime(QuicTime::Delta::FromSeconds(5),
36                                              QuicTime::Delta::FromSeconds(2));
37   config_.set_max_streams_per_connection(4, 2);
38   CryptoHandshakeMessage msg;
39   config_.ToHandshakeMessage(&msg);
40
41   uint32 value;
42   QuicErrorCode error = msg.GetUint32(kICSL, &value);
43   EXPECT_EQ(QUIC_NO_ERROR, error);
44   EXPECT_EQ(5u, value);
45
46   error = msg.GetUint32(kMSPC, &value);
47   EXPECT_EQ(QUIC_NO_ERROR, error);
48   EXPECT_EQ(4u, value);
49
50   const QuicTag* out;
51   size_t out_len;
52   error = msg.GetTaglist(kCGST, &out, &out_len);
53   EXPECT_EQ(1u, out_len);
54   EXPECT_EQ(kQBIC, *out);
55 }
56
57 TEST_F(QuicConfigTest, ToHandshakeMessageWithPacing) {
58   ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true);
59
60   config_.SetDefaults();
61   CryptoHandshakeMessage msg;
62   config_.ToHandshakeMessage(&msg);
63
64   const QuicTag* out;
65   size_t out_len;
66   EXPECT_EQ(QUIC_NO_ERROR, msg.GetTaglist(kCGST, &out, &out_len));
67   EXPECT_EQ(2u, out_len);
68   EXPECT_EQ(kPACE, out[0]);
69   EXPECT_EQ(kQBIC, out[1]);
70 }
71
72 TEST_F(QuicConfigTest, ProcessClientHello) {
73   QuicConfig client_config;
74   QuicTagVector cgst;
75   cgst.push_back(kINAR);
76   cgst.push_back(kQBIC);
77   client_config.set_congestion_control(cgst, kQBIC);
78   client_config.set_idle_connection_state_lifetime(
79       QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs),
80       QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs));
81   client_config.set_max_streams_per_connection(
82       2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection);
83   client_config.set_initial_round_trip_time_us(
84       10 * base::Time::kMicrosecondsPerMillisecond,
85       10 * base::Time::kMicrosecondsPerMillisecond);
86
87   CryptoHandshakeMessage msg;
88   client_config.ToHandshakeMessage(&msg);
89   string error_details;
90   const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details);
91   EXPECT_EQ(QUIC_NO_ERROR, error);
92   EXPECT_TRUE(config_.negotiated());
93   EXPECT_EQ(kQBIC, config_.congestion_control());
94   EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs),
95             config_.idle_connection_state_lifetime());
96   EXPECT_EQ(kDefaultMaxStreamsPerConnection,
97             config_.max_streams_per_connection());
98   EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout());
99   EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond,
100             config_.initial_round_trip_time_us());
101 }
102
103 TEST_F(QuicConfigTest, ProcessServerHello) {
104   QuicConfig server_config;
105   QuicTagVector cgst;
106   cgst.push_back(kQBIC);
107   server_config.set_congestion_control(cgst, kQBIC);
108   server_config.set_idle_connection_state_lifetime(
109       QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2),
110       QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2));
111   server_config.set_max_streams_per_connection(
112       kDefaultMaxStreamsPerConnection / 2,
113       kDefaultMaxStreamsPerConnection / 2);
114   server_config.set_server_initial_congestion_window(kDefaultInitialWindow / 2,
115                                                      kDefaultInitialWindow / 2);
116   server_config.set_initial_round_trip_time_us(
117       10 * base::Time::kMicrosecondsPerMillisecond,
118       10 * base::Time::kMicrosecondsPerMillisecond);
119
120   CryptoHandshakeMessage msg;
121   server_config.ToHandshakeMessage(&msg);
122   string error_details;
123   const QuicErrorCode error = config_.ProcessServerHello(msg, &error_details);
124   EXPECT_EQ(QUIC_NO_ERROR, error);
125   EXPECT_TRUE(config_.negotiated());
126   EXPECT_EQ(kQBIC, config_.congestion_control());
127   EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2),
128             config_.idle_connection_state_lifetime());
129   EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2,
130             config_.max_streams_per_connection());
131   EXPECT_EQ(kDefaultInitialWindow / 2,
132             config_.server_initial_congestion_window());
133   EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout());
134   EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond,
135             config_.initial_round_trip_time_us());
136 }
137
138 TEST_F(QuicConfigTest, MissingValueInCHLO) {
139   CryptoHandshakeMessage msg;
140   msg.SetValue(kICSL, 1);
141   msg.SetVector(kCGST, QuicTagVector(1, kQBIC));
142   // Missing kMSPC. KATO is optional.
143   string error_details;
144   const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details);
145   EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error);
146 }
147
148 TEST_F(QuicConfigTest, MissingValueInSHLO) {
149   CryptoHandshakeMessage msg;
150   msg.SetValue(kICSL, 1);
151   msg.SetValue(kMSPC, 3);
152   // Missing CGST. KATO is optional.
153   string error_details;
154   const QuicErrorCode error = config_.ProcessServerHello(msg, &error_details);
155   EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error);
156 }
157
158 TEST_F(QuicConfigTest, OutOfBoundSHLO) {
159   QuicConfig server_config;
160   server_config.set_idle_connection_state_lifetime(
161       QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs),
162       QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs));
163
164   CryptoHandshakeMessage msg;
165   server_config.ToHandshakeMessage(&msg);
166   string error_details;
167   const QuicErrorCode error = config_.ProcessServerHello(msg, &error_details);
168   EXPECT_EQ(QUIC_INVALID_NEGOTIATED_VALUE, error);
169 }
170
171 TEST_F(QuicConfigTest, MultipleNegotiatedValuesInVectorTag) {
172   QuicConfig server_config;
173   QuicTagVector cgst;
174   cgst.push_back(kQBIC);
175   cgst.push_back(kINAR);
176   server_config.set_congestion_control(cgst, kQBIC);
177
178   CryptoHandshakeMessage msg;
179   server_config.ToHandshakeMessage(&msg);
180   string error_details;
181   const QuicErrorCode error = config_.ProcessServerHello(msg, &error_details);
182   EXPECT_EQ(QUIC_INVALID_NEGOTIATED_VALUE, error);
183 }
184
185 TEST_F(QuicConfigTest, NoOverLapInCGST) {
186   QuicConfig server_config;
187   server_config.SetDefaults();
188   QuicTagVector cgst;
189   cgst.push_back(kINAR);
190   server_config.set_congestion_control(cgst, kINAR);
191
192   CryptoHandshakeMessage msg;
193   string error_details;
194   server_config.ToHandshakeMessage(&msg);
195   const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details);
196   LOG(INFO) << QuicUtils::ErrorToString(error);
197   EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP, error);
198 }
199
200 }  // namespace
201 }  // namespace test
202 }  // namespace net