| 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 // Common utilities for Quic tests | 5 // Common utilities for Quic tests |
| 6 | 6 |
| 7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 15 #include "net/quic/congestion_control/loss_detection_interface.h" | 15 #include "net/quic/congestion_control/loss_detection_interface.h" |
| 16 #include "net/quic/congestion_control/send_algorithm_interface.h" | 16 #include "net/quic/congestion_control/send_algorithm_interface.h" |
| 17 #include "net/quic/quic_ack_notifier.h" | 17 #include "net/quic/quic_ack_notifier.h" |
| 18 #include "net/quic/quic_client_session_base.h" | 18 #include "net/quic/quic_client_session_base.h" |
| 19 #include "net/quic/quic_connection.h" | 19 #include "net/quic/quic_connection.h" |
| 20 #include "net/quic/quic_dispatcher.h" | |
| 21 #include "net/quic/quic_framer.h" | 20 #include "net/quic/quic_framer.h" |
| 22 #include "net/quic/quic_per_connection_packet_writer.h" | |
| 23 #include "net/quic/quic_protocol.h" | 21 #include "net/quic/quic_protocol.h" |
| 24 #include "net/quic/quic_sent_packet_manager.h" | 22 #include "net/quic/quic_sent_packet_manager.h" |
| 25 #include "net/quic/quic_session.h" | 23 #include "net/quic/quic_session.h" |
| 26 #include "net/quic/test_tools/mock_clock.h" | 24 #include "net/quic/test_tools/mock_clock.h" |
| 27 #include "net/quic/test_tools/mock_random.h" | 25 #include "net/quic/test_tools/mock_random.h" |
| 28 #include "net/spdy/spdy_framer.h" | 26 #include "net/spdy/spdy_framer.h" |
| 27 #include "net/tools/quic/quic_dispatcher.h" |
| 28 #include "net/tools/quic/quic_per_connection_packet_writer.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 30 | 30 |
| 31 namespace net { | 31 namespace net { |
| 32 | 32 |
| 33 namespace test { | 33 namespace test { |
| 34 | 34 |
| 35 static const QuicConnectionId kTestConnectionId = 42; | 35 static const QuicConnectionId kTestConnectionId = 42; |
| 36 static const uint16 kTestPort = 123; | 36 static const uint16 kTestPort = 123; |
| 37 static const uint32 kInitialStreamFlowControlWindowForTest = | 37 static const uint32 kInitialStreamFlowControlWindowForTest = |
| 38 1024 * 1024; // 1 MB | 38 1024 * 1024; // 1 MB |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 MOCK_METHOD0(OnCongestionWindowChange, void()); | 579 MOCK_METHOD0(OnCongestionWindowChange, void()); |
| 580 MOCK_METHOD0(OnRttChange, void()); | 580 MOCK_METHOD0(OnRttChange, void()); |
| 581 | 581 |
| 582 private: | 582 private: |
| 583 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor); | 583 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor); |
| 584 }; | 584 }; |
| 585 | 585 |
| 586 // Creates per-connection packet writers that register themselves with the | 586 // Creates per-connection packet writers that register themselves with the |
| 587 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can | 587 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can |
| 588 // be routed to the appropriate QuicConnection. | 588 // be routed to the appropriate QuicConnection. |
| 589 class TestWriterFactory : public QuicDispatcher::PacketWriterFactory { | 589 class TestWriterFactory : public tools::QuicDispatcher::PacketWriterFactory { |
| 590 public: | 590 public: |
| 591 TestWriterFactory(); | 591 TestWriterFactory(); |
| 592 ~TestWriterFactory() override; | 592 ~TestWriterFactory() override; |
| 593 | 593 |
| 594 QuicPacketWriter* Create(QuicServerPacketWriter* writer, | 594 QuicPacketWriter* Create(QuicPacketWriter* writer, |
| 595 QuicConnection* connection) override; | 595 QuicConnection* connection) override; |
| 596 | 596 |
| 597 // Calls OnPacketSent on the last QuicConnection to write through one of the | 597 // Calls OnPacketSent on the last QuicConnection to write through one of the |
| 598 // packet writers created by this factory. | 598 // packet writers created by this factory. |
| 599 void OnPacketSent(WriteResult result); | 599 void OnPacketSent(WriteResult result); |
| 600 | 600 |
| 601 private: | 601 private: |
| 602 class PerConnectionPacketWriter : public QuicPerConnectionPacketWriter { | 602 class PerConnectionPacketWriter |
| 603 : public tools::QuicPerConnectionPacketWriter { |
| 603 public: | 604 public: |
| 604 PerConnectionPacketWriter(TestWriterFactory* factory, | 605 PerConnectionPacketWriter(TestWriterFactory* factory, |
| 605 QuicServerPacketWriter* writer, | 606 QuicPacketWriter* writer, |
| 606 QuicConnection* connection); | 607 QuicConnection* connection); |
| 607 ~PerConnectionPacketWriter() override; | 608 ~PerConnectionPacketWriter() override; |
| 608 | 609 |
| 609 WriteResult WritePacket(const char* buffer, | 610 WriteResult WritePacket(const char* buffer, |
| 610 size_t buf_len, | 611 size_t buf_len, |
| 611 const IPAddressNumber& self_address, | 612 const IPAddressNumber& self_address, |
| 612 const IPEndPoint& peer_address) override; | 613 const IPEndPoint& peer_address) override; |
| 613 | 614 |
| 614 private: | 615 private: |
| 615 TestWriterFactory* factory_; | 616 TestWriterFactory* factory_; |
| 616 }; | 617 }; |
| 617 | 618 |
| 618 // If an asynchronous write is happening and |writer| gets deleted, this | 619 // If an asynchronous write is happening and |writer| gets deleted, this |
| 619 // clears the pointer to it to prevent use-after-free. | 620 // clears the pointer to it to prevent use-after-free. |
| 620 void Unregister(PerConnectionPacketWriter* writer); | 621 void Unregister(PerConnectionPacketWriter* writer); |
| 621 | 622 |
| 622 PerConnectionPacketWriter* current_writer_; | 623 PerConnectionPacketWriter* current_writer_; |
| 623 }; | 624 }; |
| 624 | 625 |
| 625 } // namespace test | 626 } // namespace test |
| 626 } // namespace net | 627 } // namespace net |
| 627 | 628 |
| 628 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 629 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| OLD | NEW |