Complete SyncMessageFilter initialization after SyncChannel initialization
[chromium-blink-merge.git] / net / quic / quic_config_test.cc
blobdcf19a5805780d03becec78cdd6be3acd1916f7b
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_time.h"
12 #include "net/quic/quic_utils.h"
13 #include "net/quic/test_tools/quic_config_peer.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 QuicConfig config_;
29 TEST_F(QuicConfigTest, ToHandshakeMessage) {
30 config_.SetInitialStreamFlowControlWindowToSend(
31 kInitialStreamFlowControlWindowForTest);
32 config_.SetInitialSessionFlowControlWindowToSend(
33 kInitialSessionFlowControlWindowForTest);
34 config_.SetIdleConnectionStateLifetime(QuicTime::Delta::FromSeconds(5),
35 QuicTime::Delta::FromSeconds(2));
36 config_.SetMaxStreamsPerConnection(4, 2);
37 config_.SetSocketReceiveBufferToSend(kDefaultSocketReceiveBuffer);
38 CryptoHandshakeMessage msg;
39 config_.ToHandshakeMessage(&msg);
41 uint32 value;
42 QuicErrorCode error = msg.GetUint32(kICSL, &value);
43 EXPECT_EQ(QUIC_NO_ERROR, error);
44 EXPECT_EQ(5u, value);
46 error = msg.GetUint32(kMSPC, &value);
47 EXPECT_EQ(QUIC_NO_ERROR, error);
48 EXPECT_EQ(4u, value);
50 error = msg.GetUint32(kSFCW, &value);
51 EXPECT_EQ(QUIC_NO_ERROR, error);
52 EXPECT_EQ(kInitialStreamFlowControlWindowForTest, value);
54 error = msg.GetUint32(kCFCW, &value);
55 EXPECT_EQ(QUIC_NO_ERROR, error);
56 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, value);
58 error = msg.GetUint32(kSRBF, &value);
59 EXPECT_EQ(QUIC_NO_ERROR, error);
60 EXPECT_EQ(kDefaultSocketReceiveBuffer, value);
63 TEST_F(QuicConfigTest, ProcessClientHello) {
64 QuicConfig client_config;
65 QuicTagVector cgst;
66 cgst.push_back(kQBIC);
67 client_config.SetIdleConnectionStateLifetime(
68 QuicTime::Delta::FromSeconds(2 * kMaximumIdleTimeoutSecs),
69 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs));
70 client_config.SetMaxStreamsPerConnection(
71 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection);
72 client_config.SetInitialRoundTripTimeUsToSend(10 * kNumMicrosPerMilli);
73 client_config.SetInitialStreamFlowControlWindowToSend(
74 2 * kInitialStreamFlowControlWindowForTest);
75 client_config.SetInitialSessionFlowControlWindowToSend(
76 2 * kInitialSessionFlowControlWindowForTest);
77 client_config.SetSocketReceiveBufferToSend(kDefaultSocketReceiveBuffer);
78 QuicTagVector copt;
79 copt.push_back(kTBBR);
80 copt.push_back(kFHDR);
81 client_config.SetConnectionOptionsToSend(copt);
82 CryptoHandshakeMessage msg;
83 client_config.ToHandshakeMessage(&msg);
85 string error_details;
86 const QuicErrorCode error =
87 config_.ProcessPeerHello(msg, CLIENT, &error_details);
88 EXPECT_EQ(QUIC_NO_ERROR, error);
89 EXPECT_TRUE(config_.negotiated());
90 EXPECT_EQ(QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs),
91 config_.IdleConnectionStateLifetime());
92 EXPECT_EQ(kDefaultMaxStreamsPerConnection,
93 config_.MaxStreamsPerConnection());
94 EXPECT_EQ(10 * kNumMicrosPerMilli, config_.ReceivedInitialRoundTripTimeUs());
95 EXPECT_TRUE(config_.HasReceivedConnectionOptions());
96 EXPECT_EQ(2u, config_.ReceivedConnectionOptions().size());
97 EXPECT_EQ(config_.ReceivedConnectionOptions()[0], kTBBR);
98 EXPECT_EQ(config_.ReceivedConnectionOptions()[1], kFHDR);
99 EXPECT_EQ(config_.ReceivedInitialStreamFlowControlWindowBytes(),
100 2 * kInitialStreamFlowControlWindowForTest);
101 EXPECT_EQ(config_.ReceivedInitialSessionFlowControlWindowBytes(),
102 2 * kInitialSessionFlowControlWindowForTest);
103 EXPECT_EQ(config_.ReceivedSocketReceiveBuffer(),
104 kDefaultSocketReceiveBuffer);
107 TEST_F(QuicConfigTest, ProcessServerHello) {
108 QuicConfig server_config;
109 QuicTagVector cgst;
110 cgst.push_back(kQBIC);
111 server_config.SetIdleConnectionStateLifetime(
112 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2),
113 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2));
114 server_config.SetMaxStreamsPerConnection(
115 kDefaultMaxStreamsPerConnection / 2,
116 kDefaultMaxStreamsPerConnection / 2);
117 server_config.SetInitialRoundTripTimeUsToSend(10 * kNumMicrosPerMilli);
118 server_config.SetInitialStreamFlowControlWindowToSend(
119 2 * kInitialStreamFlowControlWindowForTest);
120 server_config.SetInitialSessionFlowControlWindowToSend(
121 2 * kInitialSessionFlowControlWindowForTest);
122 server_config.SetSocketReceiveBufferToSend(kDefaultSocketReceiveBuffer);
123 CryptoHandshakeMessage msg;
124 server_config.ToHandshakeMessage(&msg);
125 string error_details;
126 const QuicErrorCode error =
127 config_.ProcessPeerHello(msg, SERVER, &error_details);
128 EXPECT_EQ(QUIC_NO_ERROR, error);
129 EXPECT_TRUE(config_.negotiated());
130 EXPECT_EQ(QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2),
131 config_.IdleConnectionStateLifetime());
132 EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2,
133 config_.MaxStreamsPerConnection());
134 EXPECT_EQ(10 * kNumMicrosPerMilli, config_.ReceivedInitialRoundTripTimeUs());
135 EXPECT_EQ(config_.ReceivedInitialStreamFlowControlWindowBytes(),
136 2 * kInitialStreamFlowControlWindowForTest);
137 EXPECT_EQ(config_.ReceivedInitialSessionFlowControlWindowBytes(),
138 2 * kInitialSessionFlowControlWindowForTest);
139 EXPECT_EQ(config_.ReceivedSocketReceiveBuffer(),
140 kDefaultSocketReceiveBuffer);
143 TEST_F(QuicConfigTest, MissingOptionalValuesInCHLO) {
144 CryptoHandshakeMessage msg;
145 msg.SetValue(kICSL, 1);
147 // Set all REQUIRED tags.
148 msg.SetValue(kICSL, 1);
149 msg.SetValue(kMSPC, 1);
151 // No error, as rest are optional.
152 string error_details;
153 const QuicErrorCode error =
154 config_.ProcessPeerHello(msg, CLIENT, &error_details);
155 EXPECT_EQ(QUIC_NO_ERROR, error);
156 EXPECT_TRUE(config_.negotiated());
159 TEST_F(QuicConfigTest, MissingOptionalValuesInSHLO) {
160 CryptoHandshakeMessage msg;
162 // Set all REQUIRED tags.
163 msg.SetValue(kICSL, 1);
164 msg.SetValue(kMSPC, 1);
166 // No error, as rest are optional.
167 string error_details;
168 const QuicErrorCode error =
169 config_.ProcessPeerHello(msg, SERVER, &error_details);
170 EXPECT_EQ(QUIC_NO_ERROR, error);
171 EXPECT_TRUE(config_.negotiated());
174 TEST_F(QuicConfigTest, MissingValueInCHLO) {
175 CryptoHandshakeMessage msg;
176 msg.SetValue(kICSL, 1);
177 // Missing kMSPC. KATO is optional.
178 string error_details;
179 const QuicErrorCode error =
180 config_.ProcessPeerHello(msg, CLIENT, &error_details);
181 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error);
184 TEST_F(QuicConfigTest, MissingValueInSHLO) {
185 CryptoHandshakeMessage msg;
186 msg.SetValue(kMSPC, 3);
187 // Missing ICSL. KATO is optional.
188 string error_details;
189 const QuicErrorCode error =
190 config_.ProcessPeerHello(msg, SERVER, &error_details);
191 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error);
194 TEST_F(QuicConfigTest, OutOfBoundSHLO) {
195 QuicConfig server_config;
196 server_config.SetIdleConnectionStateLifetime(
197 QuicTime::Delta::FromSeconds(2 * kMaximumIdleTimeoutSecs),
198 QuicTime::Delta::FromSeconds(2 * kMaximumIdleTimeoutSecs));
200 CryptoHandshakeMessage msg;
201 server_config.ToHandshakeMessage(&msg);
202 string error_details;
203 const QuicErrorCode error =
204 config_.ProcessPeerHello(msg, SERVER, &error_details);
205 EXPECT_EQ(QUIC_INVALID_NEGOTIATED_VALUE, error);
208 TEST_F(QuicConfigTest, InvalidFlowControlWindow) {
209 // QuicConfig should not accept an invalid flow control window to send to the
210 // peer: the receive window must be at least the default of 16 Kb.
211 QuicConfig config;
212 const uint64 kInvalidWindow = kMinimumFlowControlSendWindow - 1;
213 EXPECT_DFATAL(config.SetInitialStreamFlowControlWindowToSend(kInvalidWindow),
214 "Initial stream flow control receive window");
216 EXPECT_EQ(kMinimumFlowControlSendWindow,
217 config.GetInitialStreamFlowControlWindowToSend());
220 TEST_F(QuicConfigTest, HasClientSentConnectionOption) {
221 QuicConfig client_config;
222 QuicTagVector copt;
223 copt.push_back(kTBBR);
224 copt.push_back(kFHDR);
225 client_config.SetConnectionOptionsToSend(copt);
226 EXPECT_TRUE(client_config.HasClientSentConnectionOption(
227 kTBBR, Perspective::IS_CLIENT));
228 EXPECT_TRUE(client_config.HasClientSentConnectionOption(
229 kFHDR, Perspective::IS_CLIENT));
231 CryptoHandshakeMessage msg;
232 client_config.ToHandshakeMessage(&msg);
234 string error_details;
235 const QuicErrorCode error =
236 config_.ProcessPeerHello(msg, CLIENT, &error_details);
237 EXPECT_EQ(QUIC_NO_ERROR, error);
238 EXPECT_TRUE(config_.negotiated());
240 EXPECT_TRUE(config_.HasReceivedConnectionOptions());
241 EXPECT_EQ(2u, config_.ReceivedConnectionOptions().size());
242 EXPECT_TRUE(
243 config_.HasClientSentConnectionOption(kTBBR, Perspective::IS_SERVER));
244 EXPECT_TRUE(
245 config_.HasClientSentConnectionOption(kFHDR, Perspective::IS_SERVER));
248 } // namespace
249 } // namespace test
250 } // namespace net