// Copyright 2024 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef NET_QUIC_QUIC_SOCKET_DATA_PROVIDER_H_ #define NET_QUIC_QUIC_SOCKET_DATA_PROVIDER_H_ #include <map> #include <memory> #include <optional> #include <set> #include <string> #include "base/memory/weak_ptr.h" #include "base/run_loop.h" #include "net/quic/quic_test_packet_printer.h" #include "net/socket/socket_test_util.h" #include "net/third_party/quiche/src/quiche/quic/core/quic_packets.h" namespace net::test { // A `SocketDataProvider` specifically designed to handle QUIC's packet-based // nature, and to give useful errors when things do not go as planned. This // fills the same purpose as `MockQuicData` and it should be straightforward to // "upgrade" a use of `MockQuicData` to this class when adding or modifying // tests. // // To use: create a new `QuicSocketDataProvider`, then add expected reads and // writes to it using the `AddRead` and `AddWrite` methods. Each read or write // must have a short, unique name that will appear in logs and error messages. // Once the provider is populated, add it to a `MockClientSocketFactory` with // `AddSocketDataProvider`. // // Each `Add` method creates an "expectation" that some event will occur on the // socket. A write expectation signals that the system under test will call // `Write` with a packet matching the given data. A read expectation signals // that the SUT will call `Read`, and the data in the expectation will be // returned. // // Expectations can be adjusted when they are created by chaining method calls, // such as setting the mode. Expectations are consumed in a partial order: each // expectation specifies the expectations which must be consumed before it can // be consumed. By default, each expectation must come after the previously // added expectation, but the `After` method can be used to adjust this ordering // for cases where the order is unimportant or might vary. For example, an ACK // might be written before or after a read of stream data. // // When a Write expectation is not met, such as write data not matching the // expected packet, the Write call will result in `ERR_UNEXPECTED`. // // Use `--vmodule=quic_socket_data_provider*=1` in the test command-line to see // additional logging from this module. class QuicSocketDataProvider : public SocketDataProvider { … }; } // namespace net::test #endif // NET_QUIC_QUIC_SOCKET_DATA_PROVIDER_H_