OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/tools/quic/quic_client_session.h" | 5 #include "net/tools/quic/quic_client_session.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
11 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 11 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
12 #include "net/quic/quic_flags.h" | 12 #include "net/quic/quic_flags.h" |
13 #include "net/quic/spdy_utils.h" | 13 #include "net/quic/spdy_utils.h" |
14 #include "net/quic/test_tools/crypto_test_utils.h" | 14 #include "net/quic/test_tools/crypto_test_utils.h" |
15 #include "net/quic/test_tools/mock_quic_spdy_client_stream.h" | 15 #include "net/quic/test_tools/mock_quic_spdy_client_stream.h" |
| 16 #include "net/quic/test_tools/quic_config_peer.h" |
16 #include "net/quic/test_tools/quic_connection_peer.h" | 17 #include "net/quic/test_tools/quic_connection_peer.h" |
17 #include "net/quic/test_tools/quic_packet_creator_peer.h" | 18 #include "net/quic/test_tools/quic_packet_creator_peer.h" |
18 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 19 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
19 #include "net/quic/test_tools/quic_test_utils.h" | 20 #include "net/quic/test_tools/quic_test_utils.h" |
20 #include "net/tools/quic/quic_spdy_client_stream.h" | 21 #include "net/tools/quic/quic_spdy_client_stream.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 using base::StringPrintf; | 24 using base::StringPrintf; |
24 using google::protobuf::implicit_cast; | 25 using google::protobuf::implicit_cast; |
25 using net::test::ConstructEncryptedPacket; | 26 using net::test::ConstructEncryptedPacket; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 session_->Initialize(); | 106 session_->Initialize(); |
106 push_promise_[":path"] = "/bar"; | 107 push_promise_[":path"] = "/bar"; |
107 push_promise_[":authority"] = "www.google.com"; | 108 push_promise_[":authority"] = "www.google.com"; |
108 push_promise_[":version"] = "HTTP/1.1"; | 109 push_promise_[":version"] = "HTTP/1.1"; |
109 push_promise_[":method"] = "GET"; | 110 push_promise_[":method"] = "GET"; |
110 push_promise_[":scheme"] = "https"; | 111 push_promise_[":scheme"] = "https"; |
111 promise_url_ = SpdyUtils::GetUrlFromHeaderBlock(push_promise_); | 112 promise_url_ = SpdyUtils::GetUrlFromHeaderBlock(push_promise_); |
112 } | 113 } |
113 | 114 |
114 void CompleteCryptoHandshake() { | 115 void CompleteCryptoHandshake() { |
| 116 CompleteCryptoHandshake(kDefaultMaxStreamsPerConnection); |
| 117 } |
| 118 |
| 119 void CompleteCryptoHandshake(uint32_t server_max_incoming_streams) { |
115 session_->CryptoConnect(); | 120 session_->CryptoConnect(); |
116 QuicCryptoClientStream* stream = | 121 QuicCryptoClientStream* stream = |
117 static_cast<QuicCryptoClientStream*>(session_->GetCryptoStream()); | 122 static_cast<QuicCryptoClientStream*>(session_->GetCryptoStream()); |
118 CryptoTestUtils::FakeServerOptions options; | 123 CryptoTestUtils::FakeServerOptions options; |
119 CryptoTestUtils::HandshakeWithFakeServer(&helper_, &alarm_factory_, | 124 QuicConfig config = DefaultQuicConfig(); |
| 125 config.SetMaxIncomingDynamicStreamsToSend(server_max_incoming_streams); |
| 126 CryptoTestUtils::HandshakeWithFakeServer(&config, &helper_, &alarm_factory_, |
120 connection_, stream, options); | 127 connection_, stream, options); |
121 } | 128 } |
122 | 129 |
123 QuicCryptoClientConfig crypto_config_; | 130 QuicCryptoClientConfig crypto_config_; |
124 MockQuicConnectionHelper helper_; | 131 MockQuicConnectionHelper helper_; |
125 MockAlarmFactory alarm_factory_; | 132 MockAlarmFactory alarm_factory_; |
126 PacketSavingConnection* connection_; | 133 PacketSavingConnection* connection_; |
127 std::unique_ptr<TestQuicClientSession> session_; | 134 std::unique_ptr<TestQuicClientSession> session_; |
128 QuicClientPushPromiseIndex push_promise_index_; | 135 QuicClientPushPromiseIndex push_promise_index_; |
129 SpdyHeaderBlock push_promise_; | 136 SpdyHeaderBlock push_promise_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 QuicIOVector iovector(&iov, 1, iov.iov_len); | 183 QuicIOVector iovector(&iov, 1, iov.iov_len); |
177 QuicConsumedData consumed = | 184 QuicConsumedData consumed = |
178 session_->WritevData(stream, stream->id(), iovector, 0, false, nullptr); | 185 session_->WritevData(stream, stream->id(), iovector, 0, false, nullptr); |
179 EXPECT_FALSE(consumed.fin_consumed); | 186 EXPECT_FALSE(consumed.fin_consumed); |
180 EXPECT_EQ(0u, consumed.bytes_consumed); | 187 EXPECT_EQ(0u, consumed.bytes_consumed); |
181 } | 188 } |
182 | 189 |
183 TEST_P(QuicClientSessionTest, MaxNumStreamsWithNoFinOrRst) { | 190 TEST_P(QuicClientSessionTest, MaxNumStreamsWithNoFinOrRst) { |
184 EXPECT_CALL(*connection_, SendRstStream(_, _, _)).Times(AnyNumber()); | 191 EXPECT_CALL(*connection_, SendRstStream(_, _, _)).Times(AnyNumber()); |
185 | 192 |
186 session_->config()->SetMaxStreamsPerConnection(1, 1); | 193 if (GetParam() <= QUIC_VERSION_34) { |
| 194 session_->config()->SetMaxStreamsPerConnection(1, 1); |
187 | 195 |
188 // Initialize crypto before the client session will create a stream. | 196 // Initialize crypto before the client session will create a stream. |
189 CompleteCryptoHandshake(); | 197 CompleteCryptoHandshake(); |
| 198 } else { |
| 199 const uint32_t kServerMaxIncomingStreams = 1; |
| 200 CompleteCryptoHandshake(kServerMaxIncomingStreams); |
| 201 } |
190 | 202 |
191 QuicSpdyClientStream* stream = | 203 QuicSpdyClientStream* stream = |
192 session_->CreateOutgoingDynamicStream(kDefaultPriority); | 204 session_->CreateOutgoingDynamicStream(kDefaultPriority); |
193 ASSERT_TRUE(stream); | 205 ASSERT_TRUE(stream); |
194 EXPECT_FALSE(session_->CreateOutgoingDynamicStream(kDefaultPriority)); | 206 EXPECT_FALSE(session_->CreateOutgoingDynamicStream(kDefaultPriority)); |
195 | 207 |
196 // Close the stream, but without having received a FIN or a RST_STREAM | 208 // Close the stream, but without having received a FIN or a RST_STREAM |
197 // and check that a new one can not be created. | 209 // and check that a new one can not be created. |
198 session_->CloseStream(stream->id()); | 210 session_->CloseStream(stream->id()); |
199 EXPECT_EQ(1u, session_->GetNumOpenOutgoingStreams()); | 211 EXPECT_EQ(1u, session_->GetNumOpenOutgoingStreams()); |
200 | 212 |
201 stream = session_->CreateOutgoingDynamicStream(kDefaultPriority); | 213 stream = session_->CreateOutgoingDynamicStream(kDefaultPriority); |
202 EXPECT_FALSE(stream); | 214 EXPECT_FALSE(stream); |
203 } | 215 } |
204 | 216 |
205 TEST_P(QuicClientSessionTest, MaxNumStreamsWithRst) { | 217 TEST_P(QuicClientSessionTest, MaxNumStreamsWithRst) { |
206 EXPECT_CALL(*connection_, SendRstStream(_, _, _)).Times(AnyNumber()); | 218 EXPECT_CALL(*connection_, SendRstStream(_, _, _)).Times(AnyNumber()); |
207 | 219 |
208 session_->config()->SetMaxStreamsPerConnection(1, 1); | 220 if (GetParam() <= QUIC_VERSION_34) { |
| 221 session_->config()->SetMaxStreamsPerConnection(1, 1); |
209 | 222 |
210 // Initialize crypto before the client session will create a stream. | 223 // Initialize crypto before the client session will create a stream. |
211 CompleteCryptoHandshake(); | 224 CompleteCryptoHandshake(); |
| 225 } else { |
| 226 const uint32_t kServerMaxIncomingStreams = 1; |
| 227 CompleteCryptoHandshake(kServerMaxIncomingStreams); |
| 228 } |
212 | 229 |
213 QuicSpdyClientStream* stream = | 230 QuicSpdyClientStream* stream = |
214 session_->CreateOutgoingDynamicStream(kDefaultPriority); | 231 session_->CreateOutgoingDynamicStream(kDefaultPriority); |
215 ASSERT_TRUE(stream); | 232 ASSERT_TRUE(stream); |
216 EXPECT_FALSE(session_->CreateOutgoingDynamicStream(kDefaultPriority)); | 233 EXPECT_FALSE(session_->CreateOutgoingDynamicStream(kDefaultPriority)); |
217 | 234 |
218 // Close the stream and receive an RST frame to remove the unfinished stream | 235 // Close the stream and receive an RST frame to remove the unfinished stream |
219 session_->CloseStream(stream->id()); | 236 session_->CloseStream(stream->id()); |
220 session_->OnRstStream(QuicRstStreamFrame( | 237 session_->OnRstStream(QuicRstStreamFrame( |
221 stream->id(), AdjustErrorForVersion(QUIC_RST_ACKNOWLEDGEMENT, GetParam()), | 238 stream->id(), AdjustErrorForVersion(QUIC_RST_ACKNOWLEDGEMENT, GetParam()), |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 QuicClientPromisedInfo* promised = | 527 QuicClientPromisedInfo* promised = |
511 session_->GetPromisedById(promised_stream_id_); | 528 session_->GetPromisedById(promised_stream_id_); |
512 EXPECT_NE(promised, nullptr); | 529 EXPECT_NE(promised, nullptr); |
513 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); | 530 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
514 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); | 531 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); |
515 } | 532 } |
516 | 533 |
517 } // namespace | 534 } // namespace |
518 } // namespace test | 535 } // namespace test |
519 } // namespace net | 536 } // namespace net |
OLD | NEW |