Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / net / quic / quic_config_test.cc
blob5241fed7e6f25269bd9a42cd24796c9e66b7aad1
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/quic_config.h"
7 #include "net/quic/crypto/crypto_handshake_message.h"
8 #include "net/quic/crypto/crypto_protocol.h"
9 #include "net/quic/quic_flags.h"
10 #include "net/quic/quic_protocol.h"
11 #include "net/quic/quic_sent_packet_manager.h"
12 #include "net/quic/quic_time.h"
13 #include "net/quic/quic_utils.h"
14 #include "net/quic/test_tools/quic_test_utils.h"
15 #include "net/test/gtest_util.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 using std::string;
20 namespace net {
21 namespace test {
22 namespace {
24 class QuicConfigTest : public ::testing::Test {
25 protected:
26 QuicConfigTest() {
27 config_.SetDefaults();
30 QuicConfig config_;
33 TEST_F(QuicConfigTest, ToHandshakeMessage) {
34 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, false);
35 config_.SetDefaults();
36 config_.SetInitialFlowControlWindowToSend(
37 kInitialSessionFlowControlWindowForTest);
38 config_.SetInitialStreamFlowControlWindowToSend(
39 kInitialStreamFlowControlWindowForTest);
40 config_.SetInitialSessionFlowControlWindowToSend(
41 kInitialSessionFlowControlWindowForTest);
42 config_.set_idle_connection_state_lifetime(QuicTime::Delta::FromSeconds(5),
43 QuicTime::Delta::FromSeconds(2));
44 config_.set_max_streams_per_connection(4, 2);
45 CryptoHandshakeMessage msg;
46 config_.ToHandshakeMessage(&msg);
48 uint32 value;
49 QuicErrorCode error = msg.GetUint32(kICSL, &value);
50 EXPECT_EQ(QUIC_NO_ERROR, error);
51 EXPECT_EQ(5u, value);
53 error = msg.GetUint32(kMSPC, &value);
54 EXPECT_EQ(QUIC_NO_ERROR, error);
55 EXPECT_EQ(4u, value);
57 error = msg.GetUint32(kIFCW, &value);
58 EXPECT_EQ(QUIC_NO_ERROR, error);
59 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, value);
61 error = msg.GetUint32(kSFCW, &value);
62 EXPECT_EQ(QUIC_NO_ERROR, error);
63 EXPECT_EQ(kInitialStreamFlowControlWindowForTest, value);
65 error = msg.GetUint32(kCFCW, &value);
66 EXPECT_EQ(QUIC_NO_ERROR, error);
67 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, value);
69 const QuicTag* out;
70 size_t out_len;
71 error = msg.GetTaglist(kCGST, &out, &out_len);
72 EXPECT_EQ(1u, out_len);
73 EXPECT_EQ(kQBIC, *out);
76 TEST_F(QuicConfigTest, ToHandshakeMessageWithPacing) {
77 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true);
79 config_.SetDefaults();
80 CryptoHandshakeMessage msg;
81 config_.ToHandshakeMessage(&msg);
83 const QuicTag* out;
84 size_t out_len;
85 EXPECT_EQ(QUIC_NO_ERROR, msg.GetTaglist(kCGST, &out, &out_len));
86 EXPECT_EQ(2u, out_len);
87 EXPECT_EQ(kPACE, out[0]);
88 EXPECT_EQ(kQBIC, out[1]);
91 TEST_F(QuicConfigTest, ProcessClientHello) {
92 QuicConfig client_config;
93 QuicTagVector cgst;
94 cgst.push_back(kINAR);
95 cgst.push_back(kQBIC);
96 client_config.set_congestion_feedback(cgst, kQBIC);
97 client_config.set_idle_connection_state_lifetime(
98 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs),
99 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs));
100 client_config.set_max_streams_per_connection(
101 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection);
102 client_config.SetInitialRoundTripTimeUsToSend(
103 10 * base::Time::kMicrosecondsPerMillisecond);
104 client_config.SetInitialFlowControlWindowToSend(
105 2 * kInitialSessionFlowControlWindowForTest);
106 client_config.SetInitialStreamFlowControlWindowToSend(
107 2 * kInitialStreamFlowControlWindowForTest);
108 client_config.SetInitialSessionFlowControlWindowToSend(
109 2 * kInitialSessionFlowControlWindowForTest);
110 QuicTagVector copt;
111 copt.push_back(kTBBR);
112 copt.push_back(kFHDR);
113 client_config.SetConnectionOptionsToSend(copt);
114 CryptoHandshakeMessage msg;
115 client_config.ToHandshakeMessage(&msg);
116 string error_details;
117 const QuicErrorCode error =
118 config_.ProcessPeerHello(msg, CLIENT, &error_details);
119 EXPECT_EQ(QUIC_NO_ERROR, error);
120 EXPECT_TRUE(config_.negotiated());
121 EXPECT_EQ(kQBIC, config_.congestion_feedback());
122 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs),
123 config_.idle_connection_state_lifetime());
124 EXPECT_EQ(kDefaultMaxStreamsPerConnection,
125 config_.max_streams_per_connection());
126 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout());
127 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond,
128 config_.ReceivedInitialRoundTripTimeUs());
129 EXPECT_FALSE(config_.HasReceivedLossDetection());
130 EXPECT_TRUE(config_.HasReceivedConnectionOptions());
131 EXPECT_EQ(2u, config_.ReceivedConnectionOptions().size());
132 EXPECT_EQ(config_.ReceivedConnectionOptions()[0], kTBBR);
133 EXPECT_EQ(config_.ReceivedConnectionOptions()[1], kFHDR);
134 EXPECT_EQ(config_.ReceivedInitialFlowControlWindowBytes(),
135 2 * kInitialSessionFlowControlWindowForTest);
136 EXPECT_EQ(config_.ReceivedInitialStreamFlowControlWindowBytes(),
137 2 * kInitialStreamFlowControlWindowForTest);
138 EXPECT_EQ(config_.ReceivedInitialSessionFlowControlWindowBytes(),
139 2 * kInitialSessionFlowControlWindowForTest);
142 TEST_F(QuicConfigTest, ProcessServerHello) {
143 QuicConfig server_config;
144 QuicTagVector cgst;
145 cgst.push_back(kQBIC);
146 server_config.set_congestion_feedback(cgst, kQBIC);
147 server_config.set_idle_connection_state_lifetime(
148 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2),
149 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2));
150 server_config.set_max_streams_per_connection(
151 kDefaultMaxStreamsPerConnection / 2,
152 kDefaultMaxStreamsPerConnection / 2);
153 server_config.SetInitialCongestionWindowToSend(kDefaultInitialWindow / 2);
154 server_config.SetInitialRoundTripTimeUsToSend(
155 10 * base::Time::kMicrosecondsPerMillisecond);
156 server_config.SetInitialFlowControlWindowToSend(
157 2 * kInitialSessionFlowControlWindowForTest);
158 server_config.SetInitialStreamFlowControlWindowToSend(
159 2 * kInitialStreamFlowControlWindowForTest);
160 server_config.SetInitialSessionFlowControlWindowToSend(
161 2 * kInitialSessionFlowControlWindowForTest);
162 CryptoHandshakeMessage msg;
163 server_config.ToHandshakeMessage(&msg);
164 string error_details;
165 const QuicErrorCode error =
166 config_.ProcessPeerHello(msg, SERVER, &error_details);
167 EXPECT_EQ(QUIC_NO_ERROR, error);
168 EXPECT_TRUE(config_.negotiated());
169 EXPECT_EQ(kQBIC, config_.congestion_feedback());
170 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2),
171 config_.idle_connection_state_lifetime());
172 EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2,
173 config_.max_streams_per_connection());
174 EXPECT_EQ(kDefaultInitialWindow / 2,
175 config_.ReceivedInitialCongestionWindow());
176 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout());
177 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond,
178 config_.ReceivedInitialRoundTripTimeUs());
179 EXPECT_FALSE(config_.HasReceivedLossDetection());
180 EXPECT_EQ(config_.ReceivedInitialFlowControlWindowBytes(),
181 2 * kInitialSessionFlowControlWindowForTest);
182 EXPECT_EQ(config_.ReceivedInitialStreamFlowControlWindowBytes(),
183 2 * kInitialStreamFlowControlWindowForTest);
184 EXPECT_EQ(config_.ReceivedInitialSessionFlowControlWindowBytes(),
185 2 * kInitialSessionFlowControlWindowForTest);
188 TEST_F(QuicConfigTest, MissingOptionalValuesInCHLO) {
189 CryptoHandshakeMessage msg;
190 msg.SetValue(kICSL, 1);
191 msg.SetVector(kCGST, QuicTagVector(1, kQBIC));
193 // Set all REQUIRED tags.
194 msg.SetValue(kICSL, 1);
195 msg.SetVector(kCGST, QuicTagVector(1, kQBIC));
196 msg.SetValue(kMSPC, 1);
198 // No error, as rest are optional.
199 string error_details;
200 const QuicErrorCode error =
201 config_.ProcessPeerHello(msg, CLIENT, &error_details);
202 EXPECT_EQ(QUIC_NO_ERROR, error);
204 EXPECT_FALSE(config_.HasReceivedInitialFlowControlWindowBytes());
207 TEST_F(QuicConfigTest, MissingOptionalValuesInSHLO) {
208 CryptoHandshakeMessage msg;
210 // Set all REQUIRED tags.
211 msg.SetValue(kICSL, 1);
212 msg.SetVector(kCGST, QuicTagVector(1, kQBIC));
213 msg.SetValue(kMSPC, 1);
215 // No error, as rest are optional.
216 string error_details;
217 const QuicErrorCode error =
218 config_.ProcessPeerHello(msg, SERVER, &error_details);
219 EXPECT_EQ(QUIC_NO_ERROR, error);
221 EXPECT_FALSE(config_.HasReceivedInitialFlowControlWindowBytes());
224 TEST_F(QuicConfigTest, MissingValueInCHLO) {
225 CryptoHandshakeMessage msg;
226 msg.SetValue(kICSL, 1);
227 msg.SetVector(kCGST, QuicTagVector(1, kQBIC));
228 // Missing kMSPC. KATO is optional.
229 string error_details;
230 const QuicErrorCode error =
231 config_.ProcessPeerHello(msg, CLIENT, &error_details);
232 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error);
235 TEST_F(QuicConfigTest, MissingValueInSHLO) {
236 CryptoHandshakeMessage msg;
237 msg.SetValue(kICSL, 1);
238 msg.SetValue(kMSPC, 3);
239 // Missing CGST. KATO is optional.
240 string error_details;
241 const QuicErrorCode error =
242 config_.ProcessPeerHello(msg, SERVER, &error_details);
243 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error);
246 TEST_F(QuicConfigTest, OutOfBoundSHLO) {
247 QuicConfig server_config;
248 server_config.set_idle_connection_state_lifetime(
249 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs),
250 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs));
252 CryptoHandshakeMessage msg;
253 server_config.ToHandshakeMessage(&msg);
254 string error_details;
255 const QuicErrorCode error =
256 config_.ProcessPeerHello(msg, SERVER, &error_details);
257 EXPECT_EQ(QUIC_INVALID_NEGOTIATED_VALUE, error);
260 TEST_F(QuicConfigTest, MultipleNegotiatedValuesInVectorTag) {
261 QuicConfig server_config;
262 QuicTagVector cgst;
263 cgst.push_back(kQBIC);
264 cgst.push_back(kINAR);
265 server_config.set_congestion_feedback(cgst, kQBIC);
267 CryptoHandshakeMessage msg;
268 server_config.ToHandshakeMessage(&msg);
269 string error_details;
270 const QuicErrorCode error =
271 config_.ProcessPeerHello(msg, SERVER, &error_details);
272 EXPECT_EQ(QUIC_INVALID_NEGOTIATED_VALUE, error);
275 TEST_F(QuicConfigTest, NoOverLapInCGST) {
276 QuicConfig server_config;
277 server_config.SetDefaults();
278 QuicTagVector cgst;
279 cgst.push_back(kINAR);
280 server_config.set_congestion_feedback(cgst, kINAR);
282 CryptoHandshakeMessage msg;
283 string error_details;
284 server_config.ToHandshakeMessage(&msg);
285 const QuicErrorCode error =
286 config_.ProcessPeerHello(msg, CLIENT, &error_details);
287 DVLOG(1) << QuicUtils::ErrorToString(error);
288 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP, error);
291 TEST_F(QuicConfigTest, InvalidFlowControlWindow) {
292 // QuicConfig should not accept an invalid flow control window to send to the
293 // peer: the receive window must be at least the default of 16 Kb.
294 QuicConfig config;
295 const uint64 kInvalidWindow = kDefaultFlowControlSendWindow - 1;
296 EXPECT_DFATAL(config.SetInitialFlowControlWindowToSend(kInvalidWindow),
297 "Initial flow control receive window");
299 EXPECT_EQ(kDefaultFlowControlSendWindow,
300 config.GetInitialFlowControlWindowToSend());
303 } // namespace
304 } // namespace test
305 } // namespace net