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/quic_stream_sequencer.h" | 5 #include "net/quic/quic_stream_sequencer.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "net/base/ip_endpoint.h" | 12 #include "net/base/ip_endpoint.h" |
13 #include "net/quic/quic_utils.h" | 13 #include "net/quic/quic_utils.h" |
14 #include "net/quic/reliable_quic_stream.h" | 14 #include "net/quic/reliable_quic_stream.h" |
15 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" | 15 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" |
16 #include "net/quic/test_tools/quic_test_utils.h" | 16 #include "net/quic/test_tools/quic_test_utils.h" |
17 #include "net/test/gtest_util.h" | 17 #include "net/test/gtest_util.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 using base::StringPiece; | 21 using base::StringPiece; |
| 22 using std::map; |
22 using std::min; | 23 using std::min; |
23 using std::pair; | 24 using std::pair; |
24 using std::vector; | 25 using std::vector; |
25 using testing::_; | 26 using testing::_; |
26 using testing::AnyNumber; | 27 using testing::AnyNumber; |
27 using testing::InSequence; | 28 using testing::InSequence; |
28 using testing::Return; | 29 using testing::Return; |
29 using testing::StrEq; | 30 using testing::StrEq; |
30 | 31 |
31 namespace net { | 32 namespace net { |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 373 |
373 while (!list_.empty()) { | 374 while (!list_.empty()) { |
374 int index = OneToN(list_.size()) - 1; | 375 int index = OneToN(list_.size()) - 1; |
375 LOG(ERROR) << "Sending index " << index << " " << list_[index].second; | 376 LOG(ERROR) << "Sending index " << index << " " << list_[index].second; |
376 EXPECT_TRUE(OnFrame(list_[index].first, list_[index].second.data())); | 377 EXPECT_TRUE(OnFrame(list_[index].first, list_[index].second.data())); |
377 | 378 |
378 list_.erase(list_.begin() + index); | 379 list_.erase(list_.begin() + index); |
379 } | 380 } |
380 } | 381 } |
381 | 382 |
| 383 TEST_F(QuicStreamSequencerTest, FrameOverlapsBufferedData) { |
| 384 // Ensure that FrameOverlapsBufferedData returns appropriate responses when |
| 385 // there is existing data buffered. |
| 386 |
| 387 map<QuicStreamOffset, string>* buffered_frames = |
| 388 QuicStreamSequencerPeer::GetBufferedFrames(sequencer_.get()); |
| 389 |
| 390 const int kBufferedOffset = 10; |
| 391 const int kBufferedDataLength = 3; |
| 392 const int kNewDataLength = 3; |
| 393 IOVector data = MakeIOVector(string(kNewDataLength, '.')); |
| 394 |
| 395 // No overlap if no buffered frames. |
| 396 EXPECT_TRUE(buffered_frames_->empty()); |
| 397 EXPECT_FALSE(sequencer_->FrameOverlapsBufferedData( |
| 398 QuicStreamFrame(1, false, kBufferedOffset - 1, data))); |
| 399 |
| 400 // Add a buffered frame. |
| 401 buffered_frames->insert( |
| 402 make_pair(kBufferedOffset, string(kBufferedDataLength, '.'))); |
| 403 |
| 404 // New byte range partially overlaps with buffered frame, start offset |
| 405 // preceeding buffered frame. |
| 406 EXPECT_TRUE(sequencer_->FrameOverlapsBufferedData( |
| 407 QuicStreamFrame(1, false, kBufferedOffset - 1, data))); |
| 408 EXPECT_TRUE(sequencer_->FrameOverlapsBufferedData( |
| 409 QuicStreamFrame(1, false, kBufferedOffset - kNewDataLength + 1, data))); |
| 410 |
| 411 // New byte range partially overlaps with buffered frame, start offset |
| 412 // inside existing buffered frame. |
| 413 EXPECT_TRUE(sequencer_->FrameOverlapsBufferedData( |
| 414 QuicStreamFrame(1, false, kBufferedOffset + 1, data))); |
| 415 EXPECT_TRUE(sequencer_->FrameOverlapsBufferedData(QuicStreamFrame( |
| 416 1, false, kBufferedOffset + kBufferedDataLength - 1, data))); |
| 417 |
| 418 // New byte range entirely outside of buffered frames, start offset preceeding |
| 419 // buffered frame. |
| 420 EXPECT_FALSE(sequencer_->FrameOverlapsBufferedData( |
| 421 QuicStreamFrame(1, false, kBufferedOffset - kNewDataLength, data))); |
| 422 |
| 423 // New byte range entirely outside of buffered frames, start offset later than |
| 424 // buffered frame. |
| 425 EXPECT_FALSE(sequencer_->FrameOverlapsBufferedData(QuicStreamFrame( |
| 426 1, false, kBufferedOffset + kBufferedDataLength, data))); |
| 427 } |
| 428 |
| 429 TEST_F(QuicStreamSequencerTest, DontAcceptOverlappingFrames) { |
| 430 // The peer should never send us non-identical stream frames which contain |
| 431 // overlapping byte ranges - if they do, we close the connection. |
| 432 |
| 433 QuicStreamFrame frame1(kClientDataStreamId1, false, 1, MakeIOVector("hello")); |
| 434 sequencer_->OnStreamFrame(frame1); |
| 435 |
| 436 QuicStreamFrame frame2(kClientDataStreamId1, false, 2, MakeIOVector("hello")); |
| 437 EXPECT_TRUE(sequencer_->FrameOverlapsBufferedData(frame2)); |
| 438 EXPECT_CALL(stream_, CloseConnectionWithDetails(QUIC_INVALID_STREAM_FRAME, _)) |
| 439 .Times(1); |
| 440 sequencer_->OnStreamFrame(frame2); |
| 441 } |
| 442 |
382 } // namespace | 443 } // namespace |
383 } // namespace test | 444 } // namespace test |
384 } // namespace net | 445 } // namespace net |
OLD | NEW |