| 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/tools/quic/quic_dispatcher.h" | 5 #include "net/tools/quic/quic_dispatcher.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 ProcessUdpPacket(_, _, _)) | 622 ProcessUdpPacket(_, _, _)) |
| 623 .Times(1) | 623 .Times(1) |
| 624 .WillOnce(testing::WithArgs<2>( | 624 .WillOnce(testing::WithArgs<2>( |
| 625 Invoke(this, &QuicDispatcherTest::ValidatePacket))); | 625 Invoke(this, &QuicDispatcherTest::ValidatePacket))); |
| 626 } | 626 } |
| 627 ProcessPacket(client_address, connection_id, true, false, "foo"); | 627 ProcessPacket(client_address, connection_id, true, false, "foo"); |
| 628 } | 628 } |
| 629 | 629 |
| 630 // Verify the stopgap test: Packets with truncated connection IDs should be | 630 // Verify the stopgap test: Packets with truncated connection IDs should be |
| 631 // dropped. | 631 // dropped. |
| 632 class QuicDispatcherTestStrayPacketConnectionId | 632 class QuicDispatcherTestStrayPacketConnectionId : public QuicDispatcherTest {}; |
| 633 : public QuicDispatcherTest, | |
| 634 public ::testing::WithParamInterface<QuicConnectionIdLength> {}; | |
| 635 | 633 |
| 636 // Packets with truncated connection IDs should be dropped. | 634 // Packets with truncated connection IDs should be dropped. |
| 637 TEST_P(QuicDispatcherTestStrayPacketConnectionId, | 635 TEST_F(QuicDispatcherTestStrayPacketConnectionId, |
| 638 StrayPacketTruncatedConnectionId) { | 636 StrayPacketTruncatedConnectionId) { |
| 639 const QuicConnectionIdLength connection_id_length = GetParam(); | |
| 640 | |
| 641 CreateTimeWaitListManager(); | 637 CreateTimeWaitListManager(); |
| 642 | 638 |
| 643 IPEndPoint client_address(net::test::Loopback4(), 1); | 639 IPEndPoint client_address(net::test::Loopback4(), 1); |
| 644 QuicConnectionId connection_id = 1; | 640 QuicConnectionId connection_id = 1; |
| 645 // Dispatcher drops this packet. | 641 // Dispatcher drops this packet. |
| 646 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0); | 642 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0); |
| 647 EXPECT_CALL(*time_wait_list_manager_, | 643 EXPECT_CALL(*time_wait_list_manager_, |
| 648 ProcessPacket(_, _, connection_id, _, _)) | 644 ProcessPacket(_, _, connection_id, _, _)) |
| 649 .Times(0); | 645 .Times(0); |
| 650 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) | 646 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) |
| 651 .Times(0); | 647 .Times(0); |
| 652 ProcessPacket(client_address, connection_id, true, false, "data", | 648 ProcessPacket(client_address, connection_id, true, false, "data", |
| 653 connection_id_length, PACKET_6BYTE_PACKET_NUMBER); | 649 PACKET_0BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER); |
| 654 } | 650 } |
| 655 | 651 |
| 656 INSTANTIATE_TEST_CASE_P(ConnectionIdLength, | |
| 657 QuicDispatcherTestStrayPacketConnectionId, | |
| 658 ::testing::Values(PACKET_0BYTE_CONNECTION_ID, | |
| 659 PACKET_1BYTE_CONNECTION_ID, | |
| 660 PACKET_4BYTE_CONNECTION_ID)); | |
| 661 | |
| 662 class BlockingWriter : public QuicPacketWriterWrapper { | 652 class BlockingWriter : public QuicPacketWriterWrapper { |
| 663 public: | 653 public: |
| 664 BlockingWriter() : write_blocked_(false) {} | 654 BlockingWriter() : write_blocked_(false) {} |
| 665 | 655 |
| 666 bool IsWriteBlocked() const override { return write_blocked_; } | 656 bool IsWriteBlocked() const override { return write_blocked_; } |
| 667 void SetWritable() override { write_blocked_ = false; } | 657 void SetWritable() override { write_blocked_ = false; } |
| 668 | 658 |
| 669 WriteResult WritePacket(const char* buffer, | 659 WriteResult WritePacket(const char* buffer, |
| 670 size_t buf_len, | 660 size_t buf_len, |
| 671 const IPAddress& self_client_address, | 661 const IPAddress& self_client_address, |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 | 843 |
| 854 // And we'll resume where we left off when we get another call. | 844 // And we'll resume where we left off when we get another call. |
| 855 EXPECT_CALL(*connection2(), OnCanWrite()); | 845 EXPECT_CALL(*connection2(), OnCanWrite()); |
| 856 dispatcher_.OnCanWrite(); | 846 dispatcher_.OnCanWrite(); |
| 857 EXPECT_FALSE(dispatcher_.HasPendingWrites()); | 847 EXPECT_FALSE(dispatcher_.HasPendingWrites()); |
| 858 } | 848 } |
| 859 | 849 |
| 860 } // namespace | 850 } // namespace |
| 861 } // namespace test | 851 } // namespace test |
| 862 } // namespace net | 852 } // namespace net |
| OLD | NEW |