#ifndef SERVICES_NETWORK_TEST_TEST_DATA_PIPE_GETTER_H_
#define SERVICES_NETWORK_TEST_TEST_DATA_PIPE_GETTER_H_
#include <memory>
#include <string>
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/network/public/mojom/data_pipe_getter.mojom.h"
namespace network {
class TestDataPipeGetter : public mojom::DataPipeGetter {
public:
TestDataPipeGetter(const std::string& string_to_write,
mojo::PendingReceiver<mojom::DataPipeGetter> receiver);
TestDataPipeGetter(const TestDataPipeGetter&) = delete;
TestDataPipeGetter& operator=(const TestDataPipeGetter&) = delete;
~TestDataPipeGetter() override;
void set_start_error(int32_t start_error);
void set_pipe_closed_early(bool pipe_closed_early);
void Read(mojo::ScopedDataPipeProducerHandle pipe,
ReadCallback callback) override;
void Clone(mojo::PendingReceiver<mojom::DataPipeGetter> receiver) override;
private:
void MojoReadyCallback(MojoResult result,
const mojo::HandleSignalsState& state);
void WriteData();
const std::string string_to_write_;
int32_t start_error_ = 0;
bool pipe_closed_early_ = false;
mojo::ReceiverSet<mojom::DataPipeGetter> receivers_;
mojo::ScopedDataPipeProducerHandle pipe_;
std::unique_ptr<mojo::SimpleWatcher> handle_watcher_;
size_t write_position_ = 0;
};
}
#endif