blob: 9c9dea776f93d659cba9a5447f49898a779b14e7 [file] [log] [blame]
Avi Drissman64595482022-09-14 20:52:291// Copyright 2015 The Chromium Authors
rchec765412016-08-25 20:14:412// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ryan Hamiltona3ee93a72018-08-01 22:03:085#ifndef NET_QUIC_MOCK_QUIC_DATA_H_
6#define NET_QUIC_MOCK_QUIC_DATA_H_
bnc3698b0a02016-12-09 23:36:507
Ryan Hamiltonabad59e2019-06-06 04:02:598#include "net/quic/quic_test_packet_printer.h"
rchec765412016-08-25 20:14:419#include "net/socket/socket_test_util.h"
Ryan Hamiltonea4fa192022-04-12 18:30:4910#include "net/third_party/quiche/src/quiche/quic/core/quic_packets.h"
rchec765412016-08-25 20:14:4111
Tsuyoshi Horo4f516be2022-06-14 11:53:1312namespace net::test {
rchec765412016-08-25 20:14:4113
14// Helper class to encapsulate MockReads and MockWrites for QUIC.
15// Simplify ownership issues and the interaction with the MockSocketFactory.
16class MockQuicData {
17 public:
Ryan Hamiltonabad59e2019-06-06 04:02:5918 explicit MockQuicData(quic::ParsedQuicVersion version);
rchec765412016-08-25 20:14:4119 ~MockQuicData();
20
rcha00569732016-08-27 11:09:3621 // Makes the Connect() call return |rv| either
22 // synchronusly or asynchronously based on |mode|.
23 void AddConnect(IoMode mode, int rv);
24
Zhongyi Shi32f2fd02018-04-16 18:23:4325 // Adds a read at the next sequence number which will read |packet|
26 // synchronously or asynchronously based on |mode|.
Ryan Hamilton8d9ee76e2018-05-29 23:52:5227 void AddRead(IoMode mode, std::unique_ptr<quic::QuicEncryptedPacket> packet);
rchec765412016-08-25 20:14:4128
29 // Adds a read at the next sequence number which will return |rv| either
rcha00569732016-08-27 11:09:3630 // synchronously or asynchronously based on |mode|.
rchec765412016-08-25 20:14:4131 void AddRead(IoMode mode, int rv);
32
Zhongyi Shi32f2fd02018-04-16 18:23:4333 // Adds a write at the next sequence number which will write |packet|
34 // synchronously or asynchronously based on |mode|.
Ryan Hamilton8d9ee76e2018-05-29 23:52:5235 void AddWrite(IoMode mode, std::unique_ptr<quic::QuicEncryptedPacket> packet);
rchbd089ab2017-05-26 23:05:0436
rcha00569732016-08-27 11:09:3637 // Adds a write at the next sequence number which will return |rv| either
38 // synchronously or asynchronously based on |mode|.
39 void AddWrite(IoMode mode, int rv);
40
Ryan Hamilton9f2eac32019-06-27 03:15:5441 // Adds a write at the next sequence number which will write |packet|
42 // synchronously or asynchronously based on |mode| and return |rv|.
43 void AddWrite(IoMode mode,
44 int rv,
45 std::unique_ptr<quic::QuicEncryptedPacket> packet);
46
rchec765412016-08-25 20:14:4147 // Adds the reads and writes to |factory|.
48 void AddSocketDataToFactory(MockClientSocketFactory* factory);
49
rcha00569732016-08-27 11:09:3650 // Returns true if all reads have been consumed.
51 bool AllReadDataConsumed();
52
53 // Returns true if all writes have been consumed.
54 bool AllWriteDataConsumed();
55
rchec765412016-08-25 20:14:4156 // Resumes I/O after it is paused.
57 void Resume();
58
Yixin Wang0d2c6b7e12017-08-16 21:12:5559 // Creates a new SequencedSocketData owned by this instance of MockQuicData.
60 // Returns a pointer to the newly created SequencedSocketData.
61 SequencedSocketData* InitializeAndGetSequencedSocketData();
62
63 SequencedSocketData* GetSequencedSocketData();
64
rchec765412016-08-25 20:14:4165 private:
Ryan Hamilton8d9ee76e2018-05-29 23:52:5266 std::vector<std::unique_ptr<quic::QuicEncryptedPacket>> packets_;
rcha00569732016-08-27 11:09:3667 std::unique_ptr<MockConnect> connect_;
rchec765412016-08-25 20:14:4168 std::vector<MockWrite> writes_;
69 std::vector<MockRead> reads_;
Tsuyoshi Horo4478fd32022-06-09 01:41:2570 size_t sequence_number_ = 0;
rchec765412016-08-25 20:14:4171 std::unique_ptr<SequencedSocketData> socket_data_;
Ryan Hamiltonabad59e2019-06-06 04:02:5972 QuicPacketPrinter printer_;
rchec765412016-08-25 20:14:4173};
74
Tsuyoshi Horo4f516be2022-06-14 11:53:1375} // namespace net::test
bnc3698b0a02016-12-09 23:36:5076
Ryan Hamiltona3ee93a72018-08-01 22:03:0877#endif // NET_QUIC_MOCK_QUIC_DATA_H_