1 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_QUIC_MOCK_QUIC_DATA_H_ 6 #define NET_QUIC_MOCK_QUIC_DATA_H_ 7 8 #include "net/quic/quic_test_packet_printer.h" 9 #include "net/socket/socket_test_util.h" 10 #include "net/third_party/quiche/src/quic/core/quic_packets.h" 11 12 namespace net { 13 namespace test { 14 15 // Helper class to encapsulate MockReads and MockWrites for QUIC. 16 // Simplify ownership issues and the interaction with the MockSocketFactory. 17 class MockQuicData { 18 public: 19 explicit MockQuicData(quic::ParsedQuicVersion version); 20 ~MockQuicData(); 21 22 // Makes the Connect() call return |rv| either 23 // synchronusly or asynchronously based on |mode|. 24 void AddConnect(IoMode mode, int rv); 25 26 // Adds a read at the next sequence number which will read |packet| 27 // synchronously or asynchronously based on |mode|. 28 void AddRead(IoMode mode, std::unique_ptr<quic::QuicEncryptedPacket> packet); 29 30 // Adds a read at the next sequence number which will return |rv| either 31 // synchronously or asynchronously based on |mode|. 32 void AddRead(IoMode mode, int rv); 33 34 // Adds a write at the next sequence number which will write |packet| 35 // synchronously or asynchronously based on |mode|. 36 void AddWrite(IoMode mode, std::unique_ptr<quic::QuicEncryptedPacket> packet); 37 38 // Adds a write at the next sequence number which will return |rv| either 39 // synchronously or asynchronously based on |mode|. 40 void AddWrite(IoMode mode, int rv); 41 42 // Adds a write at the next sequence number which will write |packet| 43 // synchronously or asynchronously based on |mode| and return |rv|. 44 void AddWrite(IoMode mode, 45 int rv, 46 std::unique_ptr<quic::QuicEncryptedPacket> packet); 47 48 // Adds the reads and writes to |factory|. 49 void AddSocketDataToFactory(MockClientSocketFactory* factory); 50 51 // Returns true if all reads have been consumed. 52 bool AllReadDataConsumed(); 53 54 // Returns true if all writes have been consumed. 55 bool AllWriteDataConsumed(); 56 57 // Resumes I/O after it is paused. 58 void Resume(); 59 60 // Creates a new SequencedSocketData owned by this instance of MockQuicData. 61 // Returns a pointer to the newly created SequencedSocketData. 62 SequencedSocketData* InitializeAndGetSequencedSocketData(); 63 64 SequencedSocketData* GetSequencedSocketData(); 65 66 private: 67 std::vector<std::unique_ptr<quic::QuicEncryptedPacket>> packets_; 68 std::unique_ptr<MockConnect> connect_; 69 std::vector<MockWrite> writes_; 70 std::vector<MockRead> reads_; 71 size_t sequence_number_; 72 std::unique_ptr<SequencedSocketData> socket_data_; 73 QuicPacketPrinter printer_; 74 }; 75 76 } // namespace test 77 } // namespace net 78 79 #endif // NET_QUIC_MOCK_QUIC_DATA_H_ 80