| 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/quic/core/quic_stream_sequencer.h" | 5 #include "net/quic/core/quic_stream_sequencer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstdint> | 8 #include <cstdint> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "net/quic/core/quic_stream.h" | 13 #include "net/quic/core/quic_stream.h" |
| 14 #include "net/quic/core/quic_utils.h" | 14 #include "net/quic/core/quic_utils.h" |
| 15 #include "net/quic/platform/api/quic_logging.h" | 15 #include "net/quic/platform/api/quic_logging.h" |
| 16 #include "net/quic/platform/api/quic_string_piece.h" | 16 #include "net/quic/platform/api/quic_string_piece.h" |
| 17 #include "net/quic/platform/api/quic_test.h" | 17 #include "net/quic/platform/api/quic_test.h" |
| 18 #include "net/quic/test_tools/mock_clock.h" | 18 #include "net/quic/test_tools/mock_clock.h" |
| 19 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
| 19 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" | 20 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" |
| 20 #include "net/quic/test_tools/quic_test_utils.h" | 21 #include "net/quic/test_tools/quic_test_utils.h" |
| 21 #include "net/test/gtest_util.h" | 22 #include "net/test/gtest_util.h" |
| 22 #include "testing/gmock_mutant.h" | 23 #include "testing/gmock_mutant.h" |
| 23 | 24 |
| 24 using std::string; | 25 using std::string; |
| 25 using testing::_; | 26 using testing::_; |
| 26 using testing::AnyNumber; | 27 using testing::AnyNumber; |
| 27 using testing::CreateFunctor; | 28 using testing::CreateFunctor; |
| 28 using testing::InSequence; | 29 using testing::InSequence; |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 | 563 |
| 563 std::vector<string> expected = {"abcdef"}; | 564 std::vector<string> expected = {"abcdef"}; |
| 564 ASSERT_TRUE(VerifyReadableRegions(expected)); | 565 ASSERT_TRUE(VerifyReadableRegions(expected)); |
| 565 | 566 |
| 566 sequencer_->MarkConsumed(6); | 567 sequencer_->MarkConsumed(6); |
| 567 } | 568 } |
| 568 | 569 |
| 569 TEST_F(QuicStreamSequencerTest, DontAcceptOverlappingFrames) { | 570 TEST_F(QuicStreamSequencerTest, DontAcceptOverlappingFrames) { |
| 570 // The peer should never send us non-identical stream frames which contain | 571 // The peer should never send us non-identical stream frames which contain |
| 571 // overlapping byte ranges - if they do, we close the connection. | 572 // overlapping byte ranges - if they do, we close the connection. |
| 573 QuicStreamId id = |
| 574 QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, 0); |
| 572 | 575 |
| 573 QuicStreamFrame frame1(kClientDataStreamId1, false, 1, | 576 QuicStreamFrame frame1(id, false, 1, QuicStringPiece("hello")); |
| 574 QuicStringPiece("hello")); | |
| 575 sequencer_->OnStreamFrame(frame1); | 577 sequencer_->OnStreamFrame(frame1); |
| 576 | 578 |
| 577 QuicStreamFrame frame2(kClientDataStreamId1, false, 2, | 579 QuicStreamFrame frame2(id, false, 2, QuicStringPiece("hello")); |
| 578 QuicStringPiece("hello")); | |
| 579 EXPECT_CALL(stream_, | 580 EXPECT_CALL(stream_, |
| 580 CloseConnectionWithDetails(QUIC_OVERLAPPING_STREAM_DATA, _)) | 581 CloseConnectionWithDetails(QUIC_OVERLAPPING_STREAM_DATA, _)) |
| 581 .Times(1); | 582 .Times(1); |
| 582 sequencer_->OnStreamFrame(frame2); | 583 sequencer_->OnStreamFrame(frame2); |
| 583 } | 584 } |
| 584 | 585 |
| 585 TEST_F(QuicStreamSequencerTest, InOrderTimestamps) { | 586 TEST_F(QuicStreamSequencerTest, InOrderTimestamps) { |
| 586 // This test verifies that timestamps returned by | 587 // This test verifies that timestamps returned by |
| 587 // GetReadableRegion() are in the correct sequence when frames | 588 // GetReadableRegion() are in the correct sequence when frames |
| 588 // arrive at the sequencer in order. | 589 // arrive at the sequencer in order. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 EXPECT_EQ(0u, NumBufferedBytes()); | 663 EXPECT_EQ(0u, NumBufferedBytes()); |
| 663 EXPECT_EQ(6u, sequencer_->NumBytesConsumed()); | 664 EXPECT_EQ(6u, sequencer_->NumBytesConsumed()); |
| 664 EXPECT_EQ(0u, sequencer_->NumBytesBuffered()); | 665 EXPECT_EQ(0u, sequencer_->NumBytesBuffered()); |
| 665 } | 666 } |
| 666 | 667 |
| 667 TEST_F(QuicStreamSequencerTest, OnStreamFrameWithNullSource) { | 668 TEST_F(QuicStreamSequencerTest, OnStreamFrameWithNullSource) { |
| 668 // Pass in a frame with data pointing to null address, expect to close | 669 // Pass in a frame with data pointing to null address, expect to close |
| 669 // connection with error. | 670 // connection with error. |
| 670 QuicStringPiece source; | 671 QuicStringPiece source; |
| 671 source.set(nullptr, 5u); | 672 source.set(nullptr, 5u); |
| 672 QuicStreamFrame frame(kClientDataStreamId1, false, 1, source); | 673 QuicStreamFrame frame( |
| 674 QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, 0), false, 1, |
| 675 source); |
| 673 EXPECT_CALL(stream_, CloseConnectionWithDetails( | 676 EXPECT_CALL(stream_, CloseConnectionWithDetails( |
| 674 QUIC_STREAM_SEQUENCER_INVALID_STATE, _)); | 677 QUIC_STREAM_SEQUENCER_INVALID_STATE, _)); |
| 675 sequencer_->OnStreamFrame(frame); | 678 sequencer_->OnStreamFrame(frame); |
| 676 } | 679 } |
| 677 | 680 |
| 678 } // namespace | 681 } // namespace |
| 679 } // namespace test | 682 } // namespace test |
| 680 } // namespace net | 683 } // namespace net |
| OLD | NEW |