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/test_tools/mock_clock.h" | 17 #include "net/quic/test_tools/mock_clock.h" |
17 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" | 18 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" |
18 #include "net/quic/test_tools/quic_test_utils.h" | 19 #include "net/quic/test_tools/quic_test_utils.h" |
19 #include "net/test/gtest_util.h" | 20 #include "net/test/gtest_util.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gmock_mutant.h" | 22 #include "testing/gmock_mutant.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 using base::StringPiece; | |
25 using std::string; | 25 using std::string; |
26 using testing::_; | 26 using testing::_; |
27 using testing::AnyNumber; | 27 using testing::AnyNumber; |
28 using testing::CreateFunctor; | 28 using testing::CreateFunctor; |
29 using testing::InSequence; | 29 using testing::InSequence; |
30 using testing::Return; | 30 using testing::Return; |
31 using testing::StrEq; | 31 using testing::StrEq; |
32 | 32 |
33 namespace net { | 33 namespace net { |
34 namespace test { | 34 namespace test { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 for (size_t i = 0; i < num_iovecs; ++i) { | 105 for (size_t i = 0; i < num_iovecs; ++i) { |
106 if (!VerifyIovec(iovecs[i], | 106 if (!VerifyIovec(iovecs[i], |
107 expected[0].substr(start_position, iovecs[i].iov_len))) { | 107 expected[0].substr(start_position, iovecs[i].iov_len))) { |
108 return false; | 108 return false; |
109 } | 109 } |
110 start_position += iovecs[i].iov_len; | 110 start_position += iovecs[i].iov_len; |
111 } | 111 } |
112 return true; | 112 return true; |
113 } | 113 } |
114 | 114 |
115 bool VerifyIovec(const iovec& iovec, StringPiece expected) { | 115 bool VerifyIovec(const iovec& iovec, QuicStringPiece expected) { |
116 if (iovec.iov_len != expected.length()) { | 116 if (iovec.iov_len != expected.length()) { |
117 QUIC_LOG(ERROR) << "Invalid length: " << iovec.iov_len << " vs " | 117 QUIC_LOG(ERROR) << "Invalid length: " << iovec.iov_len << " vs " |
118 << expected.length(); | 118 << expected.length(); |
119 return false; | 119 return false; |
120 } | 120 } |
121 if (memcmp(iovec.iov_base, expected.data(), expected.length()) != 0) { | 121 if (memcmp(iovec.iov_base, expected.data(), expected.length()) != 0) { |
122 QUIC_LOG(ERROR) << "Invalid data: " << static_cast<char*>(iovec.iov_base) | 122 QUIC_LOG(ERROR) << "Invalid data: " << static_cast<char*>(iovec.iov_base) |
123 << " vs " << expected; | 123 << " vs " << expected; |
124 return false; | 124 return false; |
125 } | 125 } |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 std::vector<string> expected = {"abcdef"}; | 564 std::vector<string> expected = {"abcdef"}; |
565 ASSERT_TRUE(VerifyReadableRegions(expected)); | 565 ASSERT_TRUE(VerifyReadableRegions(expected)); |
566 | 566 |
567 sequencer_->MarkConsumed(6); | 567 sequencer_->MarkConsumed(6); |
568 } | 568 } |
569 | 569 |
570 TEST_F(QuicStreamSequencerTest, DontAcceptOverlappingFrames) { | 570 TEST_F(QuicStreamSequencerTest, DontAcceptOverlappingFrames) { |
571 // 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 |
572 // overlapping byte ranges - if they do, we close the connection. | 572 // overlapping byte ranges - if they do, we close the connection. |
573 | 573 |
574 QuicStreamFrame frame1(kClientDataStreamId1, false, 1, StringPiece("hello")); | 574 QuicStreamFrame frame1(kClientDataStreamId1, false, 1, |
| 575 QuicStringPiece("hello")); |
575 sequencer_->OnStreamFrame(frame1); | 576 sequencer_->OnStreamFrame(frame1); |
576 | 577 |
577 QuicStreamFrame frame2(kClientDataStreamId1, false, 2, StringPiece("hello")); | 578 QuicStreamFrame frame2(kClientDataStreamId1, false, 2, |
| 579 QuicStringPiece("hello")); |
578 EXPECT_CALL(stream_, | 580 EXPECT_CALL(stream_, |
579 CloseConnectionWithDetails(QUIC_OVERLAPPING_STREAM_DATA, _)) | 581 CloseConnectionWithDetails(QUIC_OVERLAPPING_STREAM_DATA, _)) |
580 .Times(1); | 582 .Times(1); |
581 sequencer_->OnStreamFrame(frame2); | 583 sequencer_->OnStreamFrame(frame2); |
582 } | 584 } |
583 | 585 |
584 TEST_F(QuicStreamSequencerTest, InOrderTimestamps) { | 586 TEST_F(QuicStreamSequencerTest, InOrderTimestamps) { |
585 // This test verifies that timestamps returned by | 587 // This test verifies that timestamps returned by |
586 // GetReadableRegion() are in the correct sequence when frames | 588 // GetReadableRegion() are in the correct sequence when frames |
587 // arrive at the sequencer in order. | 589 // arrive at the sequencer in order. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 EXPECT_EQ(timestamp, t1); | 661 EXPECT_EQ(timestamp, t1); |
660 QuicStreamSequencerTest::ConsumeData(3); | 662 QuicStreamSequencerTest::ConsumeData(3); |
661 EXPECT_EQ(0u, NumBufferedBytes()); | 663 EXPECT_EQ(0u, NumBufferedBytes()); |
662 EXPECT_EQ(6u, sequencer_->NumBytesConsumed()); | 664 EXPECT_EQ(6u, sequencer_->NumBytesConsumed()); |
663 EXPECT_EQ(0u, sequencer_->NumBytesBuffered()); | 665 EXPECT_EQ(0u, sequencer_->NumBytesBuffered()); |
664 } | 666 } |
665 | 667 |
666 TEST_F(QuicStreamSequencerTest, OnStreamFrameWithNullSource) { | 668 TEST_F(QuicStreamSequencerTest, OnStreamFrameWithNullSource) { |
667 // 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 |
668 // connection with error. | 670 // connection with error. |
669 StringPiece source; | 671 QuicStringPiece source; |
670 source.set(nullptr, 5u); | 672 source.set(nullptr, 5u); |
671 QuicStreamFrame frame(kClientDataStreamId1, false, 1, source); | 673 QuicStreamFrame frame(kClientDataStreamId1, false, 1, source); |
672 EXPECT_CALL(stream_, CloseConnectionWithDetails( | 674 EXPECT_CALL(stream_, CloseConnectionWithDetails( |
673 QUIC_STREAM_SEQUENCER_INVALID_STATE, _)); | 675 QUIC_STREAM_SEQUENCER_INVALID_STATE, _)); |
674 sequencer_->OnStreamFrame(frame); | 676 sequencer_->OnStreamFrame(frame); |
675 } | 677 } |
676 | 678 |
677 } // namespace | 679 } // namespace |
678 } // namespace test | 680 } // namespace test |
679 } // namespace net | 681 } // namespace net |
OLD | NEW |