Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: net/quic/quic_config_test.cc

Issue 2193073003: Move shared files in net/quic/ into net/quic/core/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: io_thread_unittest.cc Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_config.cc ('k') | net/quic/quic_connection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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_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"
17
18 using std::string;
19
20 namespace net {
21 namespace test {
22 namespace {
23
24 class QuicConfigTest : public ::testing::Test {
25 protected:
26 QuicConfig config_;
27 };
28
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);
40
41 uint32_t 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 error = msg.GetUint32(kSFCW, &value);
51 EXPECT_EQ(QUIC_NO_ERROR, error);
52 EXPECT_EQ(kInitialStreamFlowControlWindowForTest, value);
53
54 error = msg.GetUint32(kCFCW, &value);
55 EXPECT_EQ(QUIC_NO_ERROR, error);
56 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, value);
57
58 error = msg.GetUint32(kSRBF, &value);
59 EXPECT_EQ(QUIC_NO_ERROR, error);
60 EXPECT_EQ(kDefaultSocketReceiveBuffer, value);
61 }
62
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(2 * kDefaultMaxStreamsPerConnection,
71 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 client_config.SetConnectionOptionsToSend(copt);
81 CryptoHandshakeMessage msg;
82 client_config.ToHandshakeMessage(&msg);
83
84 string error_details;
85 QuicTagVector initial_received_options;
86 initial_received_options.push_back(kIW50);
87 EXPECT_TRUE(
88 config_.SetInitialReceivedConnectionOptions(initial_received_options));
89 EXPECT_FALSE(
90 config_.SetInitialReceivedConnectionOptions(initial_received_options))
91 << "You can only set initial options once.";
92 const QuicErrorCode error =
93 config_.ProcessPeerHello(msg, CLIENT, &error_details);
94 EXPECT_FALSE(
95 config_.SetInitialReceivedConnectionOptions(initial_received_options))
96 << "You cannot set initial options after the hello.";
97 EXPECT_EQ(QUIC_NO_ERROR, error);
98 EXPECT_TRUE(config_.negotiated());
99 EXPECT_EQ(QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs),
100 config_.IdleConnectionStateLifetime());
101 EXPECT_EQ(kDefaultMaxStreamsPerConnection, config_.MaxStreamsPerConnection());
102 EXPECT_EQ(10 * kNumMicrosPerMilli, config_.ReceivedInitialRoundTripTimeUs());
103 EXPECT_TRUE(config_.HasReceivedConnectionOptions());
104 EXPECT_EQ(2u, config_.ReceivedConnectionOptions().size());
105 EXPECT_EQ(config_.ReceivedConnectionOptions()[0], kIW50);
106 EXPECT_EQ(config_.ReceivedConnectionOptions()[1], kTBBR);
107 EXPECT_EQ(config_.ReceivedInitialStreamFlowControlWindowBytes(),
108 2 * kInitialStreamFlowControlWindowForTest);
109 EXPECT_EQ(config_.ReceivedInitialSessionFlowControlWindowBytes(),
110 2 * kInitialSessionFlowControlWindowForTest);
111 EXPECT_EQ(config_.ReceivedSocketReceiveBuffer(), kDefaultSocketReceiveBuffer);
112 }
113
114 TEST_F(QuicConfigTest, ProcessServerHello) {
115 const IPEndPoint kTestServerAddress(IPAddress(127, 0, 3, 1), 1234);
116 QuicConfig server_config;
117 QuicTagVector cgst;
118 cgst.push_back(kQBIC);
119 server_config.SetIdleConnectionStateLifetime(
120 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2),
121 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2));
122 server_config.SetMaxStreamsPerConnection(kDefaultMaxStreamsPerConnection / 2,
123 kDefaultMaxStreamsPerConnection / 2);
124 server_config.SetInitialRoundTripTimeUsToSend(10 * kNumMicrosPerMilli);
125 server_config.SetInitialStreamFlowControlWindowToSend(
126 2 * kInitialStreamFlowControlWindowForTest);
127 server_config.SetInitialSessionFlowControlWindowToSend(
128 2 * kInitialSessionFlowControlWindowForTest);
129 server_config.SetSocketReceiveBufferToSend(kDefaultSocketReceiveBuffer);
130 server_config.SetAlternateServerAddressToSend(kTestServerAddress);
131 CryptoHandshakeMessage msg;
132 server_config.ToHandshakeMessage(&msg);
133 string error_details;
134 const QuicErrorCode error =
135 config_.ProcessPeerHello(msg, SERVER, &error_details);
136 EXPECT_EQ(QUIC_NO_ERROR, error);
137 EXPECT_TRUE(config_.negotiated());
138 EXPECT_EQ(QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2),
139 config_.IdleConnectionStateLifetime());
140 EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2,
141 config_.MaxStreamsPerConnection());
142 EXPECT_EQ(10 * kNumMicrosPerMilli, config_.ReceivedInitialRoundTripTimeUs());
143 EXPECT_EQ(config_.ReceivedInitialStreamFlowControlWindowBytes(),
144 2 * kInitialStreamFlowControlWindowForTest);
145 EXPECT_EQ(config_.ReceivedInitialSessionFlowControlWindowBytes(),
146 2 * kInitialSessionFlowControlWindowForTest);
147 EXPECT_EQ(config_.ReceivedSocketReceiveBuffer(), kDefaultSocketReceiveBuffer);
148 EXPECT_TRUE(config_.HasReceivedAlternateServerAddress());
149 EXPECT_EQ(kTestServerAddress, config_.ReceivedAlternateServerAddress());
150 }
151
152 TEST_F(QuicConfigTest, MissingOptionalValuesInCHLO) {
153 CryptoHandshakeMessage msg;
154 msg.SetValue(kICSL, 1);
155
156 // Set all REQUIRED tags.
157 msg.SetValue(kICSL, 1);
158 msg.SetValue(kMSPC, 1);
159
160 // No error, as rest are optional.
161 string error_details;
162 const QuicErrorCode error =
163 config_.ProcessPeerHello(msg, CLIENT, &error_details);
164 EXPECT_EQ(QUIC_NO_ERROR, error);
165 EXPECT_TRUE(config_.negotiated());
166 }
167
168 TEST_F(QuicConfigTest, MissingOptionalValuesInSHLO) {
169 CryptoHandshakeMessage msg;
170
171 // Set all REQUIRED tags.
172 msg.SetValue(kICSL, 1);
173 msg.SetValue(kMSPC, 1);
174
175 // No error, as rest are optional.
176 string error_details;
177 const QuicErrorCode error =
178 config_.ProcessPeerHello(msg, SERVER, &error_details);
179 EXPECT_EQ(QUIC_NO_ERROR, error);
180 EXPECT_TRUE(config_.negotiated());
181 }
182
183 TEST_F(QuicConfigTest, MissingValueInCHLO) {
184 // Server receives CHLO with missing kICSL.
185 CryptoHandshakeMessage msg;
186 string error_details;
187 const QuicErrorCode error =
188 config_.ProcessPeerHello(msg, CLIENT, &error_details);
189 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error);
190 }
191
192 TEST_F(QuicConfigTest, MissingValueInSHLO) {
193 // Client receives SHLO with missing kICSL.
194 CryptoHandshakeMessage msg;
195 string error_details;
196 const QuicErrorCode error =
197 config_.ProcessPeerHello(msg, SERVER, &error_details);
198 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error);
199 }
200
201 TEST_F(QuicConfigTest, OutOfBoundSHLO) {
202 QuicConfig server_config;
203 server_config.SetIdleConnectionStateLifetime(
204 QuicTime::Delta::FromSeconds(2 * kMaximumIdleTimeoutSecs),
205 QuicTime::Delta::FromSeconds(2 * kMaximumIdleTimeoutSecs));
206
207 CryptoHandshakeMessage msg;
208 server_config.ToHandshakeMessage(&msg);
209 string error_details;
210 const QuicErrorCode error =
211 config_.ProcessPeerHello(msg, SERVER, &error_details);
212 EXPECT_EQ(QUIC_INVALID_NEGOTIATED_VALUE, error);
213 }
214
215 TEST_F(QuicConfigTest, InvalidFlowControlWindow) {
216 // QuicConfig should not accept an invalid flow control window to send to the
217 // peer: the receive window must be at least the default of 16 Kb.
218 QuicConfig config;
219 const uint64_t kInvalidWindow = kMinimumFlowControlSendWindow - 1;
220 EXPECT_DFATAL(config.SetInitialStreamFlowControlWindowToSend(kInvalidWindow),
221 "Initial stream flow control receive window");
222
223 EXPECT_EQ(kMinimumFlowControlSendWindow,
224 config.GetInitialStreamFlowControlWindowToSend());
225 }
226
227 TEST_F(QuicConfigTest, HasClientSentConnectionOption) {
228 QuicConfig client_config;
229 QuicTagVector copt;
230 copt.push_back(kTBBR);
231 client_config.SetConnectionOptionsToSend(copt);
232 EXPECT_TRUE(client_config.HasClientSentConnectionOption(
233 kTBBR, Perspective::IS_CLIENT));
234
235 CryptoHandshakeMessage msg;
236 client_config.ToHandshakeMessage(&msg);
237
238 string error_details;
239 const QuicErrorCode error =
240 config_.ProcessPeerHello(msg, CLIENT, &error_details);
241 EXPECT_EQ(QUIC_NO_ERROR, error);
242 EXPECT_TRUE(config_.negotiated());
243
244 EXPECT_TRUE(config_.HasReceivedConnectionOptions());
245 EXPECT_EQ(1u, config_.ReceivedConnectionOptions().size());
246 EXPECT_TRUE(
247 config_.HasClientSentConnectionOption(kTBBR, Perspective::IS_SERVER));
248 }
249
250 } // namespace
251 } // namespace test
252 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_config.cc ('k') | net/quic/quic_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698