OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_simple_server_session.h" | 5 #include "net/tools/quic/quic_simple_server_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 MockClock clock; | 200 MockClock clock; |
201 handshake_message_.reset(crypto_config_.AddDefaultConfig( | 201 handshake_message_.reset(crypto_config_.AddDefaultConfig( |
202 QuicRandom::GetInstance(), &clock, | 202 QuicRandom::GetInstance(), &clock, |
203 QuicCryptoServerConfig::ConfigOptions())); | 203 QuicCryptoServerConfig::ConfigOptions())); |
204 session_->Initialize(); | 204 session_->Initialize(); |
205 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 205 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
206 | 206 |
207 session_->OnConfigNegotiated(); | 207 session_->OnConfigNegotiated(); |
208 } | 208 } |
209 | 209 |
| 210 QuicStreamId GetNthClientInitiatedId(int n) { |
| 211 return QuicSpdySessionPeer::GetNthClientInitiatedStreamId(*session_, n); |
| 212 } |
| 213 |
| 214 QuicStreamId GetNthServerInitiatedId(int n) { |
| 215 return QuicSpdySessionPeer::GetNthServerInitiatedStreamId(*session_, n); |
| 216 } |
| 217 |
210 StrictMock<MockQuicSessionVisitor> owner_; | 218 StrictMock<MockQuicSessionVisitor> owner_; |
211 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_; | 219 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_; |
212 MockQuicConnectionHelper helper_; | 220 MockQuicConnectionHelper helper_; |
213 MockAlarmFactory alarm_factory_; | 221 MockAlarmFactory alarm_factory_; |
214 StrictMock<MockQuicConnectionWithSendStreamData>* connection_; | 222 StrictMock<MockQuicConnectionWithSendStreamData>* connection_; |
215 QuicConfig config_; | 223 QuicConfig config_; |
216 QuicCryptoServerConfig crypto_config_; | 224 QuicCryptoServerConfig crypto_config_; |
217 QuicCompressedCertsCache compressed_certs_cache_; | 225 QuicCompressedCertsCache compressed_certs_cache_; |
218 QuicHttpResponseCache response_cache_; | 226 QuicHttpResponseCache response_cache_; |
219 std::unique_ptr<MockQuicSimpleServerSession> session_; | 227 std::unique_ptr<MockQuicSimpleServerSession> session_; |
220 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; | 228 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; |
221 QuicConnectionVisitorInterface* visitor_; | 229 QuicConnectionVisitorInterface* visitor_; |
222 }; | 230 }; |
223 | 231 |
224 INSTANTIATE_TEST_CASE_P(Tests, | 232 INSTANTIATE_TEST_CASE_P(Tests, |
225 QuicSimpleServerSessionTest, | 233 QuicSimpleServerSessionTest, |
226 ::testing::ValuesIn(AllSupportedVersions())); | 234 ::testing::ValuesIn(AllSupportedVersions())); |
227 | 235 |
228 TEST_P(QuicSimpleServerSessionTest, CloseStreamDueToReset) { | 236 TEST_P(QuicSimpleServerSessionTest, CloseStreamDueToReset) { |
229 // Open a stream, then reset it. | 237 // Open a stream, then reset it. |
230 // Send two bytes of payload to open it. | 238 // Send two bytes of payload to open it. |
231 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT")); | 239 QuicStreamFrame data1(GetNthClientInitiatedId(0), false, 0, |
| 240 QuicStringPiece("HT")); |
232 session_->OnStreamFrame(data1); | 241 session_->OnStreamFrame(data1); |
233 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 242 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
234 | 243 |
235 // Receive a reset (and send a RST in response). | 244 // Receive a reset (and send a RST in response). |
236 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, | 245 QuicRstStreamFrame rst1(GetNthClientInitiatedId(0), |
237 0); | 246 QUIC_ERROR_PROCESSING_STREAM, 0); |
238 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); | 247 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
239 EXPECT_CALL(*connection_, | 248 EXPECT_CALL(*connection_, SendRstStream(GetNthClientInitiatedId(0), |
240 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 249 QUIC_RST_ACKNOWLEDGEMENT, 0)); |
241 visitor_->OnRstStream(rst1); | 250 visitor_->OnRstStream(rst1); |
242 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 251 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
243 | 252 |
244 // Send the same two bytes of payload in a new packet. | 253 // Send the same two bytes of payload in a new packet. |
245 visitor_->OnStreamFrame(data1); | 254 visitor_->OnStreamFrame(data1); |
246 | 255 |
247 // The stream should not be re-opened. | 256 // The stream should not be re-opened. |
248 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 257 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
249 EXPECT_TRUE(connection_->connected()); | 258 EXPECT_TRUE(connection_->connected()); |
250 } | 259 } |
251 | 260 |
252 TEST_P(QuicSimpleServerSessionTest, NeverOpenStreamDueToReset) { | 261 TEST_P(QuicSimpleServerSessionTest, NeverOpenStreamDueToReset) { |
253 // Send a reset (and expect the peer to send a RST in response). | 262 // Send a reset (and expect the peer to send a RST in response). |
254 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, | 263 QuicRstStreamFrame rst1(GetNthClientInitiatedId(0), |
255 0); | 264 QUIC_ERROR_PROCESSING_STREAM, 0); |
256 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); | 265 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
257 EXPECT_CALL(*connection_, | 266 EXPECT_CALL(*connection_, SendRstStream(GetNthClientInitiatedId(0), |
258 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 267 QUIC_RST_ACKNOWLEDGEMENT, 0)); |
259 visitor_->OnRstStream(rst1); | 268 visitor_->OnRstStream(rst1); |
260 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 269 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
261 | 270 |
262 // Send two bytes of payload. | 271 // Send two bytes of payload. |
263 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT")); | 272 QuicStreamFrame data1(GetNthClientInitiatedId(0), false, 0, |
| 273 QuicStringPiece("HT")); |
264 visitor_->OnStreamFrame(data1); | 274 visitor_->OnStreamFrame(data1); |
265 | 275 |
266 // The stream should never be opened, now that the reset is received. | 276 // The stream should never be opened, now that the reset is received. |
267 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); | 277 EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams()); |
268 EXPECT_TRUE(connection_->connected()); | 278 EXPECT_TRUE(connection_->connected()); |
269 } | 279 } |
270 | 280 |
271 TEST_P(QuicSimpleServerSessionTest, AcceptClosedStream) { | 281 TEST_P(QuicSimpleServerSessionTest, AcceptClosedStream) { |
272 // Send (empty) compressed headers followed by two bytes of data. | 282 // Send (empty) compressed headers followed by two bytes of data. |
273 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, | 283 QuicStreamFrame frame1(GetNthClientInitiatedId(0), false, 0, |
274 QuicStringPiece("\1\0\0\0\0\0\0\0HT")); | 284 QuicStringPiece("\1\0\0\0\0\0\0\0HT")); |
275 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, | 285 QuicStreamFrame frame2(GetNthClientInitiatedId(1), false, 0, |
276 QuicStringPiece("\2\0\0\0\0\0\0\0HT")); | 286 QuicStringPiece("\2\0\0\0\0\0\0\0HT")); |
277 visitor_->OnStreamFrame(frame1); | 287 visitor_->OnStreamFrame(frame1); |
278 visitor_->OnStreamFrame(frame2); | 288 visitor_->OnStreamFrame(frame2); |
279 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); | 289 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); |
280 | 290 |
281 // Send a reset (and expect the peer to send a RST in response). | 291 // Send a reset (and expect the peer to send a RST in response). |
282 QuicRstStreamFrame rst(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, 0); | 292 QuicRstStreamFrame rst(GetNthClientInitiatedId(0), |
| 293 QUIC_ERROR_PROCESSING_STREAM, 0); |
283 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); | 294 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
284 EXPECT_CALL(*connection_, | 295 EXPECT_CALL(*connection_, SendRstStream(GetNthClientInitiatedId(0), |
285 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 296 QUIC_RST_ACKNOWLEDGEMENT, 0)); |
286 visitor_->OnRstStream(rst); | 297 visitor_->OnRstStream(rst); |
287 | 298 |
288 // If we were tracking, we'd probably want to reject this because it's data | 299 // If we were tracking, we'd probably want to reject this because it's data |
289 // past the reset point of stream 3. As it's a closed stream we just drop the | 300 // past the reset point of stream 3. As it's a closed stream we just drop the |
290 // data on the floor, but accept the packet because it has data for stream 5. | 301 // data on the floor, but accept the packet because it has data for stream 5. |
291 QuicStreamFrame frame3(kClientDataStreamId1, false, 2, QuicStringPiece("TP")); | 302 QuicStreamFrame frame3(GetNthClientInitiatedId(0), false, 2, |
292 QuicStreamFrame frame4(kClientDataStreamId2, false, 2, QuicStringPiece("TP")); | 303 QuicStringPiece("TP")); |
| 304 QuicStreamFrame frame4(GetNthClientInitiatedId(1), false, 2, |
| 305 QuicStringPiece("TP")); |
293 visitor_->OnStreamFrame(frame3); | 306 visitor_->OnStreamFrame(frame3); |
294 visitor_->OnStreamFrame(frame4); | 307 visitor_->OnStreamFrame(frame4); |
295 // The stream should never be opened, now that the reset is received. | 308 // The stream should never be opened, now that the reset is received. |
296 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 309 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
297 EXPECT_TRUE(connection_->connected()); | 310 EXPECT_TRUE(connection_->connected()); |
298 } | 311 } |
299 | 312 |
300 TEST_P(QuicSimpleServerSessionTest, CreateIncomingDynamicStreamDisconnected) { | 313 TEST_P(QuicSimpleServerSessionTest, CreateIncomingDynamicStreamDisconnected) { |
301 // Tests that incoming stream creation fails when connection is not connected. | 314 // Tests that incoming stream creation fails when connection is not connected. |
302 size_t initial_num_open_stream = session_->GetNumOpenIncomingStreams(); | 315 size_t initial_num_open_stream = session_->GetNumOpenIncomingStreams(); |
303 QuicConnectionPeer::TearDownLocalConnectionState(connection_); | 316 QuicConnectionPeer::TearDownLocalConnectionState(connection_); |
304 EXPECT_QUIC_BUG(QuicSimpleServerSessionPeer::CreateIncomingDynamicStream( | 317 EXPECT_QUIC_BUG(QuicSimpleServerSessionPeer::CreateIncomingDynamicStream( |
305 session_.get(), kClientDataStreamId1), | 318 session_.get(), GetNthClientInitiatedId(0)), |
306 "ShouldCreateIncomingDynamicStream called when disconnected"); | 319 "ShouldCreateIncomingDynamicStream called when disconnected"); |
307 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenIncomingStreams()); | 320 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenIncomingStreams()); |
308 } | 321 } |
309 | 322 |
310 TEST_P(QuicSimpleServerSessionTest, CreateEvenIncomingDynamicStream) { | 323 TEST_P(QuicSimpleServerSessionTest, CreateEvenIncomingDynamicStream) { |
311 // Tests that incoming stream creation fails when given stream id is even. | 324 // Tests that incoming stream creation fails when given stream id is even. |
312 size_t initial_num_open_stream = session_->GetNumOpenIncomingStreams(); | 325 size_t initial_num_open_stream = session_->GetNumOpenIncomingStreams(); |
313 EXPECT_CALL(*connection_, | 326 EXPECT_CALL(*connection_, |
314 CloseConnection(QUIC_INVALID_STREAM_ID, | 327 CloseConnection(QUIC_INVALID_STREAM_ID, |
315 "Client created even numbered stream", _)); | 328 "Client created even numbered stream", _)); |
316 QuicSimpleServerSessionPeer::CreateIncomingDynamicStream(session_.get(), 2); | 329 QuicSimpleServerSessionPeer::CreateIncomingDynamicStream(session_.get(), 2); |
317 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenIncomingStreams()); | 330 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenIncomingStreams()); |
318 } | 331 } |
319 | 332 |
320 TEST_P(QuicSimpleServerSessionTest, CreateIncomingDynamicStream) { | 333 TEST_P(QuicSimpleServerSessionTest, CreateIncomingDynamicStream) { |
321 QuicSpdyStream* stream = | 334 QuicSpdyStream* stream = |
322 QuicSimpleServerSessionPeer::CreateIncomingDynamicStream( | 335 QuicSimpleServerSessionPeer::CreateIncomingDynamicStream( |
323 session_.get(), kClientDataStreamId1); | 336 session_.get(), GetNthClientInitiatedId(0)); |
324 EXPECT_NE(nullptr, stream); | 337 EXPECT_NE(nullptr, stream); |
325 EXPECT_EQ(kClientDataStreamId1, stream->id()); | 338 EXPECT_EQ(GetNthClientInitiatedId(0), stream->id()); |
326 } | 339 } |
327 | 340 |
328 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamDisconnected) { | 341 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamDisconnected) { |
329 // Tests that outgoing stream creation fails when connection is not connected. | 342 // Tests that outgoing stream creation fails when connection is not connected. |
330 size_t initial_num_open_stream = session_->GetNumOpenOutgoingStreams(); | 343 size_t initial_num_open_stream = session_->GetNumOpenOutgoingStreams(); |
331 QuicConnectionPeer::TearDownLocalConnectionState(connection_); | 344 QuicConnectionPeer::TearDownLocalConnectionState(connection_); |
332 EXPECT_QUIC_BUG(QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( | 345 EXPECT_QUIC_BUG(QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( |
333 session_.get(), kDefaultPriority), | 346 session_.get(), kDefaultPriority), |
334 "ShouldCreateOutgoingDynamicStream called when disconnected"); | 347 "ShouldCreateOutgoingDynamicStream called when disconnected"); |
335 | 348 |
(...skipping 10 matching lines...) Expand all Loading... |
346 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenOutgoingStreams()); | 359 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenOutgoingStreams()); |
347 } | 360 } |
348 | 361 |
349 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamUptoLimit) { | 362 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamUptoLimit) { |
350 // Tests that outgoing stream creation should not be affected by existing | 363 // Tests that outgoing stream creation should not be affected by existing |
351 // incoming stream and vice-versa. But when reaching the limit of max outgoing | 364 // incoming stream and vice-versa. But when reaching the limit of max outgoing |
352 // stream allowed, creation should fail. | 365 // stream allowed, creation should fail. |
353 | 366 |
354 // Receive some data to initiate a incoming stream which should not effect | 367 // Receive some data to initiate a incoming stream which should not effect |
355 // creating outgoing streams. | 368 // creating outgoing streams. |
356 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT")); | 369 QuicStreamFrame data1(GetNthClientInitiatedId(0), false, 0, |
| 370 QuicStringPiece("HT")); |
357 session_->OnStreamFrame(data1); | 371 session_->OnStreamFrame(data1); |
358 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 372 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
359 EXPECT_EQ(0u, session_->GetNumOpenOutgoingStreams()); | 373 EXPECT_EQ(0u, session_->GetNumOpenOutgoingStreams()); |
360 | 374 |
361 // Assume encryption already established. | 375 // Assume encryption already established. |
362 MockQuicCryptoServerStream* crypto_stream = | 376 MockQuicCryptoServerStream* crypto_stream = |
363 new MockQuicCryptoServerStream(&crypto_config_, &compressed_certs_cache_, | 377 new MockQuicCryptoServerStream(&crypto_config_, &compressed_certs_cache_, |
364 session_.get(), &stream_helper_); | 378 session_.get(), &stream_helper_); |
365 crypto_stream->set_encryption_established(true); | 379 crypto_stream->set_encryption_established(true); |
366 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); | 380 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); |
367 | 381 |
368 // Create push streams till reaching the upper limit of allowed open streams. | 382 // Create push streams till reaching the upper limit of allowed open streams. |
369 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { | 383 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { |
370 QuicSpdyStream* created_stream = | 384 QuicSpdyStream* created_stream = |
371 QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( | 385 QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( |
372 session_.get(), kDefaultPriority); | 386 session_.get(), kDefaultPriority); |
373 EXPECT_EQ(2 * (i + 1), created_stream->id()); | 387 EXPECT_EQ(GetNthServerInitiatedId(i), created_stream->id()); |
374 EXPECT_EQ(i + 1, session_->GetNumOpenOutgoingStreams()); | 388 EXPECT_EQ(i + 1, session_->GetNumOpenOutgoingStreams()); |
375 } | 389 } |
376 | 390 |
377 // Continuing creating push stream would fail. | 391 // Continuing creating push stream would fail. |
378 EXPECT_EQ(nullptr, QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( | 392 EXPECT_EQ(nullptr, QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( |
379 session_.get(), kDefaultPriority)); | 393 session_.get(), kDefaultPriority)); |
380 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); | 394 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); |
381 | 395 |
382 // Create peer initiated stream should have no problem. | 396 // Create peer initiated stream should have no problem. |
383 QuicStreamFrame data2(kClientDataStreamId2, false, 0, QuicStringPiece("HT")); | 397 QuicStreamFrame data2(GetNthClientInitiatedId(1), false, 0, |
| 398 QuicStringPiece("HT")); |
384 session_->OnStreamFrame(data2); | 399 session_->OnStreamFrame(data2); |
385 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); | 400 EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams()); |
386 } | 401 } |
387 | 402 |
388 TEST_P(QuicSimpleServerSessionTest, OnStreamFrameWithEvenStreamId) { | 403 TEST_P(QuicSimpleServerSessionTest, OnStreamFrameWithEvenStreamId) { |
389 QuicStreamFrame frame(2, false, 0, QuicStringPiece()); | 404 QuicStreamFrame frame(2, false, 0, QuicStringPiece()); |
390 EXPECT_CALL(*connection_, | 405 EXPECT_CALL(*connection_, |
391 CloseConnection(QUIC_INVALID_STREAM_ID, | 406 CloseConnection(QUIC_INVALID_STREAM_ID, |
392 "Client sent data on server push stream", _)); | 407 "Client sent data on server push stream", _)); |
393 session_->OnStreamFrame(frame); | 408 session_->OnStreamFrame(frame); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 | 478 |
464 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); | 479 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); |
465 | 480 |
466 string request_url = "mail.google.com/"; | 481 string request_url = "mail.google.com/"; |
467 SpdyHeaderBlock request_headers; | 482 SpdyHeaderBlock request_headers; |
468 string resource_host = "www.google.com"; | 483 string resource_host = "www.google.com"; |
469 string partial_push_resource_path = "/server_push_src"; | 484 string partial_push_resource_path = "/server_push_src"; |
470 std::list<QuicHttpResponseCache::ServerPushInfo> push_resources; | 485 std::list<QuicHttpResponseCache::ServerPushInfo> push_resources; |
471 string scheme = "http"; | 486 string scheme = "http"; |
472 for (unsigned int i = 1; i <= num_resources; ++i) { | 487 for (unsigned int i = 1; i <= num_resources; ++i) { |
473 QuicStreamId stream_id = i * 2; | 488 QuicStreamId stream_id = GetNthServerInitiatedId(i - 1); |
474 string path = | 489 string path = |
475 partial_push_resource_path + QuicTextUtils::Uint64ToString(i); | 490 partial_push_resource_path + QuicTextUtils::Uint64ToString(i); |
476 string url = scheme + "://" + resource_host + path; | 491 string url = scheme + "://" + resource_host + path; |
477 QuicUrl resource_url = QuicUrl(url); | 492 QuicUrl resource_url = QuicUrl(url); |
478 string body(body_size, 'a'); | 493 string body(body_size, 'a'); |
479 response_cache_.AddSimpleResponse(resource_host, path, 200, body); | 494 response_cache_.AddSimpleResponse(resource_host, path, 200, body); |
480 push_resources.push_back(QuicHttpResponseCache::ServerPushInfo( | 495 push_resources.push_back(QuicHttpResponseCache::ServerPushInfo( |
481 resource_url, SpdyHeaderBlock(), kDefaultPriority, body)); | 496 resource_url, SpdyHeaderBlock(), kDefaultPriority, body)); |
482 // PUSH_PROMISED are sent for all the resources. | 497 // PUSH_PROMISED are sent for all the resources. |
483 EXPECT_CALL(*session_, | 498 EXPECT_CALL(*session_, WritePushPromiseMock(GetNthClientInitiatedId(0), |
484 WritePushPromiseMock(kClientDataStreamId1, stream_id, _)); | 499 stream_id, _)); |
485 if (i <= kMaxStreamsForTest) { | 500 if (i <= kMaxStreamsForTest) { |
486 // |kMaxStreamsForTest| promised responses should be sent. | 501 // |kMaxStreamsForTest| promised responses should be sent. |
487 EXPECT_CALL(*session_, | 502 EXPECT_CALL(*session_, |
488 WriteHeadersMock(stream_id, _, false, kDefaultPriority, _)); | 503 WriteHeadersMock(stream_id, _, false, kDefaultPriority, _)); |
489 // Since flow control window is smaller than response body, not the | 504 // Since flow control window is smaller than response body, not the |
490 // whole body will be sent. | 505 // whole body will be sent. |
491 if (!session_->force_hol_blocking()) { | 506 if (!session_->force_hol_blocking()) { |
492 EXPECT_CALL(*connection_, SendStreamData(stream_id, _, 0, NO_FIN, _)) | 507 EXPECT_CALL(*connection_, SendStreamData(stream_id, _, 0, NO_FIN, _)) |
493 .WillOnce(Return( | 508 .WillOnce(Return( |
494 QuicConsumedData(kStreamFlowControlWindowSize, false))); | 509 QuicConsumedData(kStreamFlowControlWindowSize, false))); |
495 EXPECT_CALL(*connection_, SendBlocked(stream_id)); | 510 EXPECT_CALL(*connection_, SendBlocked(stream_id)); |
496 } else { | 511 } else { |
497 // The forced HOL blocking encapsulates the stream data into | 512 // The forced HOL blocking encapsulates the stream data into |
498 // HTTP/2 DATA frames within the headers stream. HTTP/2 | 513 // HTTP/2 DATA frames within the headers stream. HTTP/2 |
499 // DATA frames are limited to a max size of 16KB, so the | 514 // DATA frames are limited to a max size of 16KB, so the |
500 // 64KB body will be fragemented into four DATA frames. | 515 // 64KB body will be fragemented into four DATA frames. |
501 EXPECT_CALL(*connection_, SendStreamData(_, _, _, NO_FIN, _)) | 516 EXPECT_CALL(*connection_, SendStreamData(_, _, _, NO_FIN, _)) |
502 .Times(body_size / 16384) | 517 .Times(body_size / 16384) |
503 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) | 518 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) |
504 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) | 519 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) |
505 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) | 520 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) |
506 .WillOnce(Return(QuicConsumedData(9 + 16394, false))); | 521 .WillOnce(Return(QuicConsumedData(9 + 16394, false))); |
507 EXPECT_CALL(*connection_, SendBlocked(_)); | 522 EXPECT_CALL(*connection_, SendBlocked(_)); |
508 } | 523 } |
509 } | 524 } |
510 } | 525 } |
511 session_->PromisePushResources(request_url, push_resources, | 526 session_->PromisePushResources(request_url, push_resources, |
512 kClientDataStreamId1, request_headers); | 527 GetNthClientInitiatedId(0), request_headers); |
513 } | 528 } |
514 }; | 529 }; |
515 | 530 |
516 INSTANTIATE_TEST_CASE_P(Tests, | 531 INSTANTIATE_TEST_CASE_P(Tests, |
517 QuicSimpleServerSessionServerPushTest, | 532 QuicSimpleServerSessionServerPushTest, |
518 ::testing::ValuesIn(AllSupportedVersions())); | 533 ::testing::ValuesIn(AllSupportedVersions())); |
519 | 534 |
520 TEST_P(QuicSimpleServerSessionServerPushTest, TestPromisePushResources) { | 535 TEST_P(QuicSimpleServerSessionServerPushTest, TestPromisePushResources) { |
521 // Tests that given more than kMaxOpenStreamForTest resources, all their | 536 // Tests that given more than kMaxOpenStreamForTest resources, all their |
522 // PUSH_PROMISE's will be sent out and only |kMaxOpenStreamForTest| streams | 537 // PUSH_PROMISE's will be sent out and only |kMaxOpenStreamForTest| streams |
(...skipping 10 matching lines...) Expand all Loading... |
533 TEST_P(QuicSimpleServerSessionServerPushTest, | 548 TEST_P(QuicSimpleServerSessionServerPushTest, |
534 HandlePromisedPushRequestsAfterStreamDraining) { | 549 HandlePromisedPushRequestsAfterStreamDraining) { |
535 if (session_->force_hol_blocking()) { | 550 if (session_->force_hol_blocking()) { |
536 return; | 551 return; |
537 } | 552 } |
538 | 553 |
539 // Tests that after promised stream queued up, when an opened stream is marked | 554 // Tests that after promised stream queued up, when an opened stream is marked |
540 // draining, a queued promised stream will become open and send push response. | 555 // draining, a queued promised stream will become open and send push response. |
541 size_t num_resources = kMaxStreamsForTest + 1; | 556 size_t num_resources = kMaxStreamsForTest + 1; |
542 PromisePushResources(num_resources); | 557 PromisePushResources(num_resources); |
543 QuicStreamId next_out_going_stream_id = num_resources * 2; | 558 QuicStreamId next_out_going_stream_id = |
| 559 GetNthServerInitiatedId(kMaxStreamsForTest); |
544 | 560 |
545 // After an open stream is marked draining, a new stream is expected to be | 561 // After an open stream is marked draining, a new stream is expected to be |
546 // created and a response sent on the stream. | 562 // created and a response sent on the stream. |
547 EXPECT_CALL(*session_, WriteHeadersMock(next_out_going_stream_id, _, false, | 563 EXPECT_CALL(*session_, WriteHeadersMock(next_out_going_stream_id, _, false, |
548 kDefaultPriority, _)); | 564 kDefaultPriority, _)); |
549 EXPECT_CALL(*connection_, | 565 EXPECT_CALL(*connection_, |
550 SendStreamData(next_out_going_stream_id, _, 0, NO_FIN, _)) | 566 SendStreamData(next_out_going_stream_id, _, 0, NO_FIN, _)) |
551 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 567 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
552 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); | 568 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); |
553 session_->StreamDraining(2); | 569 session_->StreamDraining(2); |
554 // Number of open outgoing streams should still be the same, because a new | 570 // Number of open outgoing streams should still be the same, because a new |
555 // stream is opened. And the queue should be empty. | 571 // stream is opened. And the queue should be empty. |
556 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); | 572 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); |
557 } | 573 } |
558 | 574 |
559 TEST_P(QuicSimpleServerSessionServerPushTest, | 575 TEST_P(QuicSimpleServerSessionServerPushTest, |
560 ResetPromisedStreamToCancelServerPush) { | 576 ResetPromisedStreamToCancelServerPush) { |
561 if (session_->force_hol_blocking()) { | 577 if (session_->force_hol_blocking()) { |
562 return; | 578 return; |
563 } | 579 } |
564 // Tests that after all resources are promised, a RST frame from client can | 580 // Tests that after all resources are promised, a RST frame from client can |
565 // prevent a promised resource to be send out. | 581 // prevent a promised resource to be send out. |
566 | 582 |
567 // Having two extra resources to be send later. One of them will be reset, so | 583 // Having two extra resources to be send later. One of them will be reset, so |
568 // when opened stream become close, only one will become open. | 584 // when opened stream become close, only one will become open. |
569 size_t num_resources = kMaxStreamsForTest + 2; | 585 size_t num_resources = kMaxStreamsForTest + 2; |
570 PromisePushResources(num_resources); | 586 PromisePushResources(num_resources); |
571 | 587 |
572 // Reset the last stream in the queue. It should be marked cancelled. | 588 // Reset the last stream in the queue. It should be marked cancelled. |
573 QuicStreamId stream_got_reset = num_resources * 2; | 589 QuicStreamId stream_got_reset = |
| 590 GetNthServerInitiatedId(kMaxStreamsForTest + 1); |
574 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 591 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
575 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); | 592 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
576 EXPECT_CALL(*connection_, | 593 EXPECT_CALL(*connection_, |
577 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 594 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
578 visitor_->OnRstStream(rst); | 595 visitor_->OnRstStream(rst); |
579 | 596 |
580 // When the first 2 streams becomes draining, the two queued up stream could | 597 // When the first 2 streams becomes draining, the two queued up stream could |
581 // be created. But since one of them was marked cancelled due to RST frame, | 598 // be created. But since one of them was marked cancelled due to RST frame, |
582 // only one queued resource will be sent out. | 599 // only one queued resource will be sent out. |
583 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2; | 600 QuicStreamId stream_not_reset = GetNthServerInitiatedId(kMaxStreamsForTest); |
584 InSequence s; | 601 InSequence s; |
585 EXPECT_CALL(*session_, WriteHeadersMock(stream_not_reset, _, false, | 602 EXPECT_CALL(*session_, WriteHeadersMock(stream_not_reset, _, false, |
586 kDefaultPriority, _)); | 603 kDefaultPriority, _)); |
587 EXPECT_CALL(*connection_, SendStreamData(stream_not_reset, _, 0, NO_FIN, _)) | 604 EXPECT_CALL(*connection_, SendStreamData(stream_not_reset, _, 0, NO_FIN, _)) |
588 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 605 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
589 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset)); | 606 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset)); |
590 EXPECT_CALL(*session_, | 607 EXPECT_CALL(*session_, |
591 WriteHeadersMock(stream_got_reset, _, false, kDefaultPriority, _)) | 608 WriteHeadersMock(stream_got_reset, _, false, kDefaultPriority, _)) |
592 .Times(0); | 609 .Times(0); |
593 | 610 |
594 session_->StreamDraining(2); | 611 session_->StreamDraining(GetNthServerInitiatedId(0)); |
595 session_->StreamDraining(4); | 612 session_->StreamDraining(GetNthServerInitiatedId(1)); |
596 } | 613 } |
597 | 614 |
598 TEST_P(QuicSimpleServerSessionServerPushTest, | 615 TEST_P(QuicSimpleServerSessionServerPushTest, |
599 CloseStreamToHandleMorePromisedStream) { | 616 CloseStreamToHandleMorePromisedStream) { |
600 if (session_->force_hol_blocking()) { | 617 if (session_->force_hol_blocking()) { |
601 return; | 618 return; |
602 } | 619 } |
603 // Tests that closing a open outgoing stream can trigger a promised resource | 620 // Tests that closing a open outgoing stream can trigger a promised resource |
604 // in the queue to be send out. | 621 // in the queue to be send out. |
605 size_t num_resources = kMaxStreamsForTest + 1; | 622 size_t num_resources = kMaxStreamsForTest + 1; |
606 PromisePushResources(num_resources); | 623 PromisePushResources(num_resources); |
607 QuicStreamId stream_to_open = num_resources * 2; | 624 QuicStreamId stream_to_open = GetNthServerInitiatedId(kMaxStreamsForTest); |
608 | 625 |
609 // Resetting 1st open stream will close the stream and give space for extra | 626 // Resetting 1st open stream will close the stream and give space for extra |
610 // stream to be opened. | 627 // stream to be opened. |
611 QuicStreamId stream_got_reset = 2; | 628 QuicStreamId stream_got_reset = GetNthServerInitiatedId(0); |
612 EXPECT_CALL(*connection_, | 629 EXPECT_CALL(*connection_, |
613 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); | 630 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); |
614 EXPECT_CALL(*session_, | 631 EXPECT_CALL(*session_, |
615 WriteHeadersMock(stream_to_open, _, false, kDefaultPriority, _)); | 632 WriteHeadersMock(stream_to_open, _, false, kDefaultPriority, _)); |
616 EXPECT_CALL(*connection_, SendStreamData(stream_to_open, _, 0, NO_FIN, _)) | 633 EXPECT_CALL(*connection_, SendStreamData(stream_to_open, _, 0, NO_FIN, _)) |
617 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 634 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
618 | 635 |
619 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); | 636 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); |
620 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); | 637 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
621 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 638 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
622 visitor_->OnRstStream(rst); | 639 visitor_->OnRstStream(rst); |
623 } | 640 } |
624 | 641 |
625 } // namespace | 642 } // namespace |
626 } // namespace test | 643 } // namespace test |
627 } // namespace net | 644 } // namespace net |
OLD | NEW |