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