| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 class QuicSimpleServerSessionPeer { | 49 class QuicSimpleServerSessionPeer { |
| 50 public: | 50 public: |
| 51 static void SetCryptoStream(QuicSimpleServerSession* s, | 51 static void SetCryptoStream(QuicSimpleServerSession* s, |
| 52 QuicCryptoServerStream* crypto_stream) { | 52 QuicCryptoServerStream* crypto_stream) { |
| 53 s->crypto_stream_.reset(crypto_stream); | 53 s->crypto_stream_.reset(crypto_stream); |
| 54 s->static_streams()[kCryptoStreamId] = crypto_stream; | 54 s->static_streams()[kCryptoStreamId] = crypto_stream; |
| 55 } | 55 } |
| 56 | 56 |
| 57 static QuicSpdyStream* CreateIncomingDynamicStream(QuicSimpleServerSession* s, | 57 static QuicSpdyStream* CreateIncomingDynamicStream(QuicSimpleServerSession* s, |
| 58 QuicStreamId id) { | 58 QuicStreamId id) { |
| 59 return s->CreateIncomingDynamicStream(id); | 59 return FLAGS_quic_reloadable_flag_quic_refactor_stream_creation |
| 60 ? s->MaybeCreateIncomingDynamicStream(id) |
| 61 : s->CreateIncomingDynamicStream(id); |
| 60 } | 62 } |
| 61 | 63 |
| 62 static QuicSimpleServerStream* CreateOutgoingDynamicStream( | 64 static QuicSimpleServerStream* CreateOutgoingDynamicStream( |
| 63 QuicSimpleServerSession* s, | 65 QuicSimpleServerSession* s, |
| 64 SpdyPriority priority) { | 66 SpdyPriority priority) { |
| 65 return s->CreateOutgoingDynamicStream(priority); | 67 return FLAGS_quic_reloadable_flag_quic_refactor_stream_creation |
| 68 ? static_cast<QuicSimpleServerStream*>( |
| 69 s->MaybeCreateOutgoingDynamicStream(priority)) |
| 70 : s->CreateOutgoingDynamicStream(priority); |
| 66 } | 71 } |
| 67 | 72 |
| 68 static std::deque<PromisedStreamInfo>* promised_streams( | 73 static std::deque<PromisedStreamInfo>* promised_streams( |
| 69 QuicSimpleServerSession* s) { | 74 QuicSimpleServerSession* s) { |
| 70 return &(s->promised_streams_); | 75 return &(s->promised_streams_); |
| 71 } | 76 } |
| 72 | 77 |
| 73 static QuicStreamId hightest_promised_stream_id(QuicSimpleServerSession* s) { | 78 static QuicStreamId hightest_promised_stream_id(QuicSimpleServerSession* s) { |
| 74 return s->highest_promised_stream_id_; | 79 return s->highest_promised_stream_id_; |
| 75 } | 80 } |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 visitor_->OnStreamFrame(frame4); | 312 visitor_->OnStreamFrame(frame4); |
| 308 // The stream should never be opened, now that the reset is received. | 313 // The stream should never be opened, now that the reset is received. |
| 309 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 314 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
| 310 EXPECT_TRUE(connection_->connected()); | 315 EXPECT_TRUE(connection_->connected()); |
| 311 } | 316 } |
| 312 | 317 |
| 313 TEST_P(QuicSimpleServerSessionTest, CreateIncomingDynamicStreamDisconnected) { | 318 TEST_P(QuicSimpleServerSessionTest, CreateIncomingDynamicStreamDisconnected) { |
| 314 // Tests that incoming stream creation fails when connection is not connected. | 319 // Tests that incoming stream creation fails when connection is not connected. |
| 315 size_t initial_num_open_stream = session_->GetNumOpenIncomingStreams(); | 320 size_t initial_num_open_stream = session_->GetNumOpenIncomingStreams(); |
| 316 QuicConnectionPeer::TearDownLocalConnectionState(connection_); | 321 QuicConnectionPeer::TearDownLocalConnectionState(connection_); |
| 317 EXPECT_QUIC_BUG(QuicSimpleServerSessionPeer::CreateIncomingDynamicStream( | 322 if (FLAGS_quic_reloadable_flag_quic_refactor_stream_creation) { |
| 318 session_.get(), GetNthClientInitiatedId(0)), | 323 EXPECT_EQ(nullptr, QuicSimpleServerSessionPeer::CreateIncomingDynamicStream( |
| 319 "ShouldCreateIncomingDynamicStream called when disconnected"); | 324 session_.get(), GetNthClientInitiatedId(0))); |
| 325 } else { |
| 326 EXPECT_QUIC_BUG(QuicSimpleServerSessionPeer::CreateIncomingDynamicStream( |
| 327 session_.get(), GetNthClientInitiatedId(0)), |
| 328 "ShouldCreateIncomingDynamicStream called when " |
| 329 "disconnected"); |
| 330 } |
| 320 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenIncomingStreams()); | 331 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenIncomingStreams()); |
| 321 } | 332 } |
| 322 | 333 |
| 323 TEST_P(QuicSimpleServerSessionTest, CreateEvenIncomingDynamicStream) { | 334 TEST_P(QuicSimpleServerSessionTest, CreateEvenIncomingDynamicStream) { |
| 335 if (FLAGS_quic_reloadable_flag_quic_refactor_stream_creation) { |
| 336 EXPECT_EQ(nullptr, QuicSimpleServerSessionPeer::CreateIncomingDynamicStream( |
| 337 session_.get(), 2)); |
| 338 return; |
| 339 } |
| 324 // Tests that incoming stream creation fails when given stream id is even. | 340 // Tests that incoming stream creation fails when given stream id is even. |
| 325 size_t initial_num_open_stream = session_->GetNumOpenIncomingStreams(); | 341 size_t initial_num_open_stream = session_->GetNumOpenIncomingStreams(); |
| 326 EXPECT_CALL(*connection_, | 342 EXPECT_CALL(*connection_, |
| 327 CloseConnection(QUIC_INVALID_STREAM_ID, | 343 CloseConnection(QUIC_INVALID_STREAM_ID, |
| 328 "Client created even numbered stream", _)); | 344 "Client created even numbered stream", _)); |
| 329 QuicSimpleServerSessionPeer::CreateIncomingDynamicStream(session_.get(), 2); | 345 QuicSimpleServerSessionPeer::CreateIncomingDynamicStream(session_.get(), 2); |
| 330 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenIncomingStreams()); | 346 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenIncomingStreams()); |
| 331 } | 347 } |
| 332 | 348 |
| 333 TEST_P(QuicSimpleServerSessionTest, CreateIncomingDynamicStream) { | 349 TEST_P(QuicSimpleServerSessionTest, CreateIncomingDynamicStream) { |
| 334 QuicSpdyStream* stream = | 350 QuicSpdyStream* stream = |
| 335 QuicSimpleServerSessionPeer::CreateIncomingDynamicStream( | 351 QuicSimpleServerSessionPeer::CreateIncomingDynamicStream( |
| 336 session_.get(), GetNthClientInitiatedId(0)); | 352 session_.get(), GetNthClientInitiatedId(0)); |
| 337 EXPECT_NE(nullptr, stream); | 353 EXPECT_NE(nullptr, stream); |
| 338 EXPECT_EQ(GetNthClientInitiatedId(0), stream->id()); | 354 EXPECT_EQ(GetNthClientInitiatedId(0), stream->id()); |
| 339 } | 355 } |
| 340 | 356 |
| 341 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamDisconnected) { | 357 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamDisconnected) { |
| 342 // Tests that outgoing stream creation fails when connection is not connected. | 358 // Tests that outgoing stream creation fails when connection is not connected. |
| 343 size_t initial_num_open_stream = session_->GetNumOpenOutgoingStreams(); | 359 size_t initial_num_open_stream = session_->GetNumOpenOutgoingStreams(); |
| 344 QuicConnectionPeer::TearDownLocalConnectionState(connection_); | 360 QuicConnectionPeer::TearDownLocalConnectionState(connection_); |
| 345 EXPECT_QUIC_BUG(QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( | 361 if (FLAGS_quic_reloadable_flag_quic_refactor_stream_creation) { |
| 346 session_.get(), kDefaultPriority), | 362 EXPECT_EQ(nullptr, QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( |
| 347 "ShouldCreateOutgoingDynamicStream called when disconnected"); | 363 session_.get(), kDefaultPriority)); |
| 364 } else { |
| 365 EXPECT_QUIC_BUG(QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( |
| 366 session_.get(), kDefaultPriority), |
| 367 "ShouldCreateOutgoingDynamicStream called when " |
| 368 "disconnected"); |
| 369 } |
| 348 | 370 |
| 349 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenOutgoingStreams()); | 371 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenOutgoingStreams()); |
| 350 } | 372 } |
| 351 | 373 |
| 352 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamUnencrypted) { | 374 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamUnencrypted) { |
| 353 // Tests that outgoing stream creation fails when encryption has not yet been | 375 // Tests that outgoing stream creation fails when encryption has not yet been |
| 354 // established. | 376 // established. |
| 355 size_t initial_num_open_stream = session_->GetNumOpenOutgoingStreams(); | 377 size_t initial_num_open_stream = session_->GetNumOpenOutgoingStreams(); |
| 356 EXPECT_QUIC_BUG(QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( | 378 if (FLAGS_quic_reloadable_flag_quic_refactor_stream_creation) { |
| 357 session_.get(), kDefaultPriority), | 379 EXPECT_EQ(nullptr, QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( |
| 358 "Encryption not established so no outgoing stream created."); | 380 session_.get(), kDefaultPriority)); |
| 381 } else { |
| 382 EXPECT_QUIC_BUG(QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( |
| 383 session_.get(), kDefaultPriority), |
| 384 "Encryption not established so no outgoing stream " |
| 385 "created."); |
| 386 } |
| 359 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenOutgoingStreams()); | 387 EXPECT_EQ(initial_num_open_stream, session_->GetNumOpenOutgoingStreams()); |
| 360 } | 388 } |
| 361 | 389 |
| 362 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamUptoLimit) { | 390 TEST_P(QuicSimpleServerSessionTest, CreateOutgoingDynamicStreamUptoLimit) { |
| 363 // Tests that outgoing stream creation should not be affected by existing | 391 // Tests that outgoing stream creation should not be affected by existing |
| 364 // incoming stream and vice-versa. But when reaching the limit of max outgoing | 392 // incoming stream and vice-versa. But when reaching the limit of max outgoing |
| 365 // stream allowed, creation should fail. | 393 // stream allowed, creation should fail. |
| 366 | 394 |
| 367 // Receive some data to initiate a incoming stream which should not effect | 395 // Receive some data to initiate a incoming stream which should not effect |
| 368 // creating outgoing streams. | 396 // creating outgoing streams. |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 | 663 |
| 636 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); | 664 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); |
| 637 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); | 665 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
| 638 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 666 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
| 639 visitor_->OnRstStream(rst); | 667 visitor_->OnRstStream(rst); |
| 640 } | 668 } |
| 641 | 669 |
| 642 } // namespace | 670 } // namespace |
| 643 } // namespace test | 671 } // namespace test |
| 644 } // namespace net | 672 } // namespace net |
| OLD | NEW |