| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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_stream.h" | 5 #include "net/tools/quic/quic_simple_server_stream.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 319 |
| 320 InSequence s; | 320 InSequence s; |
| 321 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, _)); | 321 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, _)); |
| 322 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 322 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
| 323 .Times(1) | 323 .Times(1) |
| 324 .WillOnce(Return(QuicConsumedData( | 324 .WillOnce(Return(QuicConsumedData( |
| 325 strlen(QuicSimpleServerStream::kErrorResponseBody), true))); | 325 strlen(QuicSimpleServerStream::kErrorResponseBody), true))); |
| 326 | 326 |
| 327 QuicSimpleServerStreamPeer::SendResponse(stream_); | 327 QuicSimpleServerStreamPeer::SendResponse(stream_); |
| 328 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); | 328 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); |
| 329 EXPECT_TRUE(stream_->reading_stopped()); | 329 if (!FLAGS_quic_reloadable_flag_quic_always_enable_bidi_streaming) { |
| 330 EXPECT_TRUE(stream_->reading_stopped()); |
| 331 } |
| 330 EXPECT_TRUE(stream_->write_side_closed()); | 332 EXPECT_TRUE(stream_->write_side_closed()); |
| 331 } | 333 } |
| 332 | 334 |
| 333 TEST_P(QuicSimpleServerStreamTest, SendResponseWithIllegalResponseStatus2) { | 335 TEST_P(QuicSimpleServerStreamTest, SendResponseWithIllegalResponseStatus2) { |
| 334 // Send an illegal response with response status not supported by HTTP/2. | 336 // Send an illegal response with response status not supported by HTTP/2. |
| 335 SpdyHeaderBlock* request_headers = stream_->mutable_headers(); | 337 SpdyHeaderBlock* request_headers = stream_->mutable_headers(); |
| 336 (*request_headers)[":path"] = "/bar"; | 338 (*request_headers)[":path"] = "/bar"; |
| 337 (*request_headers)[":authority"] = "www.google.com"; | 339 (*request_headers)[":authority"] = "www.google.com"; |
| 338 (*request_headers)[":version"] = "HTTP/1.1"; | 340 (*request_headers)[":version"] = "HTTP/1.1"; |
| 339 (*request_headers)[":method"] = "GET"; | 341 (*request_headers)[":method"] = "GET"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 350 | 352 |
| 351 InSequence s; | 353 InSequence s; |
| 352 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, _)); | 354 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, _)); |
| 353 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 355 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
| 354 .Times(1) | 356 .Times(1) |
| 355 .WillOnce(Return(QuicConsumedData( | 357 .WillOnce(Return(QuicConsumedData( |
| 356 strlen(QuicSimpleServerStream::kErrorResponseBody), true))); | 358 strlen(QuicSimpleServerStream::kErrorResponseBody), true))); |
| 357 | 359 |
| 358 QuicSimpleServerStreamPeer::SendResponse(stream_); | 360 QuicSimpleServerStreamPeer::SendResponse(stream_); |
| 359 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); | 361 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); |
| 360 EXPECT_TRUE(stream_->reading_stopped()); | 362 if (!FLAGS_quic_reloadable_flag_quic_always_enable_bidi_streaming) { |
| 363 EXPECT_TRUE(stream_->reading_stopped()); |
| 364 } |
| 361 EXPECT_TRUE(stream_->write_side_closed()); | 365 EXPECT_TRUE(stream_->write_side_closed()); |
| 362 } | 366 } |
| 363 | 367 |
| 364 TEST_P(QuicSimpleServerStreamTest, SendPushResponseWith404Response) { | 368 TEST_P(QuicSimpleServerStreamTest, SendPushResponseWith404Response) { |
| 365 // Create a new promised stream with even id(). | 369 // Create a new promised stream with even id(). |
| 366 QuicSimpleServerStreamPeer* promised_stream = | 370 QuicSimpleServerStreamPeer* promised_stream = |
| 367 new QuicSimpleServerStreamPeer(2, &session_, &response_cache_); | 371 new QuicSimpleServerStreamPeer(2, &session_, &response_cache_); |
| 368 session_.ActivateStream(QuicWrapUnique(promised_stream)); | 372 session_.ActivateStream(QuicWrapUnique(promised_stream)); |
| 369 | 373 |
| 370 // Send a push response with response status 404, which will be regarded as | 374 // Send a push response with response status 404, which will be regarded as |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 stream_->set_fin_received(true); | 410 stream_->set_fin_received(true); |
| 407 | 411 |
| 408 InSequence s; | 412 InSequence s; |
| 409 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, _)); | 413 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, _)); |
| 410 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 414 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
| 411 .Times(1) | 415 .Times(1) |
| 412 .WillOnce(Return(QuicConsumedData(body.length(), true))); | 416 .WillOnce(Return(QuicConsumedData(body.length(), true))); |
| 413 | 417 |
| 414 QuicSimpleServerStreamPeer::SendResponse(stream_); | 418 QuicSimpleServerStreamPeer::SendResponse(stream_); |
| 415 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); | 419 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); |
| 416 EXPECT_TRUE(stream_->reading_stopped()); | 420 if (!FLAGS_quic_reloadable_flag_quic_always_enable_bidi_streaming) { |
| 421 EXPECT_TRUE(stream_->reading_stopped()); |
| 422 } |
| 417 EXPECT_TRUE(stream_->write_side_closed()); | 423 EXPECT_TRUE(stream_->write_side_closed()); |
| 418 } | 424 } |
| 419 | 425 |
| 420 TEST_P(QuicSimpleServerStreamTest, SendReponseWithPushResources) { | 426 TEST_P(QuicSimpleServerStreamTest, SendReponseWithPushResources) { |
| 421 // Tests that if a reponse has push resources to be send, SendResponse() will | 427 // Tests that if a reponse has push resources to be send, SendResponse() will |
| 422 // call PromisePushResources() to handle these resources. | 428 // call PromisePushResources() to handle these resources. |
| 423 | 429 |
| 424 // Add a request and response with valid headers into cache. | 430 // Add a request and response with valid headers into cache. |
| 425 string host = "www.google.com"; | 431 string host = "www.google.com"; |
| 426 string request_path = "/foo"; | 432 string request_path = "/foo"; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 stream_->set_fin_received(true); | 516 stream_->set_fin_received(true); |
| 511 | 517 |
| 512 InSequence s; | 518 InSequence s; |
| 513 EXPECT_CALL(session_, WriteHeadersMock(_, _, _, _, _)); | 519 EXPECT_CALL(session_, WriteHeadersMock(_, _, _, _, _)); |
| 514 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 520 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
| 515 .Times(1) | 521 .Times(1) |
| 516 .WillOnce(Return(QuicConsumedData(3, true))); | 522 .WillOnce(Return(QuicConsumedData(3, true))); |
| 517 | 523 |
| 518 QuicSimpleServerStreamPeer::SendErrorResponse(stream_); | 524 QuicSimpleServerStreamPeer::SendErrorResponse(stream_); |
| 519 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); | 525 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); |
| 520 EXPECT_TRUE(stream_->reading_stopped()); | 526 if (!FLAGS_quic_reloadable_flag_quic_always_enable_bidi_streaming) { |
| 527 EXPECT_TRUE(stream_->reading_stopped()); |
| 528 } |
| 521 EXPECT_TRUE(stream_->write_side_closed()); | 529 EXPECT_TRUE(stream_->write_side_closed()); |
| 522 } | 530 } |
| 523 | 531 |
| 524 TEST_P(QuicSimpleServerStreamTest, InvalidMultipleContentLength) { | 532 TEST_P(QuicSimpleServerStreamTest, InvalidMultipleContentLength) { |
| 525 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(0); | 533 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(0); |
| 526 | 534 |
| 527 SpdyHeaderBlock request_headers; | 535 SpdyHeaderBlock request_headers; |
| 528 // \000 is a way to write the null byte when followed by a literal digit. | 536 // \000 is a way to write the null byte when followed by a literal digit. |
| 529 header_list_.OnHeader("content-length", StringPiece("11\00012", 5)); | 537 header_list_.OnHeader("content-length", StringPiece("11\00012", 5)); |
| 530 | 538 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 | 578 |
| 571 stream_->OnStreamHeaderList(false, kFakeFrameLen, header_list_); | 579 stream_->OnStreamHeaderList(false, kFakeFrameLen, header_list_); |
| 572 | 580 |
| 573 EXPECT_EQ(11, QuicSimpleServerStreamPeer::content_length(stream_)); | 581 EXPECT_EQ(11, QuicSimpleServerStreamPeer::content_length(stream_)); |
| 574 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); | 582 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); |
| 575 EXPECT_FALSE(stream_->reading_stopped()); | 583 EXPECT_FALSE(stream_->reading_stopped()); |
| 576 EXPECT_FALSE(stream_->write_side_closed()); | 584 EXPECT_FALSE(stream_->write_side_closed()); |
| 577 } | 585 } |
| 578 | 586 |
| 579 TEST_P(QuicSimpleServerStreamTest, SendQuicRstStreamNoErrorWithEarlyResponse) { | 587 TEST_P(QuicSimpleServerStreamTest, SendQuicRstStreamNoErrorWithEarlyResponse) { |
| 588 if (FLAGS_quic_reloadable_flag_quic_always_enable_bidi_streaming) { |
| 589 return; |
| 590 } |
| 580 InSequence s; | 591 InSequence s; |
| 581 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, _)); | 592 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, _)); |
| 582 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 593 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
| 583 .Times(1) | 594 .Times(1) |
| 584 .WillOnce(Return(QuicConsumedData(3, true))); | 595 .WillOnce(Return(QuicConsumedData(3, true))); |
| 585 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(1); | 596 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(1); |
| 586 EXPECT_FALSE(stream_->fin_received()); | 597 EXPECT_FALSE(stream_->fin_received()); |
| 587 QuicSimpleServerStreamPeer::SendErrorResponse(stream_); | 598 QuicSimpleServerStreamPeer::SendErrorResponse(stream_); |
| 588 EXPECT_TRUE(stream_->reading_stopped()); | 599 EXPECT_TRUE(stream_->reading_stopped()); |
| 589 EXPECT_TRUE(stream_->write_side_closed()); | 600 EXPECT_TRUE(stream_->write_side_closed()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 }; | 640 }; |
| 630 StringPiece data(arr, arraysize(arr)); | 641 StringPiece data(arr, arraysize(arr)); |
| 631 QuicStreamFrame frame(stream_->id(), true, 0, data); | 642 QuicStreamFrame frame(stream_->id(), true, 0, data); |
| 632 // Verify that we don't crash when we get a invalid headers in stream frame. | 643 // Verify that we don't crash when we get a invalid headers in stream frame. |
| 633 stream_->OnStreamFrame(frame); | 644 stream_->OnStreamFrame(frame); |
| 634 } | 645 } |
| 635 | 646 |
| 636 } // namespace | 647 } // namespace |
| 637 } // namespace test | 648 } // namespace test |
| 638 } // namespace net | 649 } // namespace net |
| OLD | NEW |