test_chunked_data_pipe_getter.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2018 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. #ifndef SERVICES_NETWORK_TEST_CHUNKED_DATA_PIPE_GETTER_H_
  5. #define SERVICES_NETWORK_TEST_CHUNKED_DATA_PIPE_GETTER_H_
  6. #include <memory>
  7. #include "base/run_loop.h"
  8. #include "mojo/public/cpp/bindings/pending_remote.h"
  9. #include "mojo/public/cpp/bindings/receiver.h"
  10. #include "mojo/public/cpp/system/data_pipe.h"
  11. #include "services/network/public/mojom/chunked_data_pipe_getter.mojom.h"
  12. namespace network {
  13. // Test implementation of mojom::DataPipeGetter that lets tests wait for
  14. // the mojo::ScopedDataPipeProducerHandle and ReadCallback to be received
  15. // and then manage them both directly.
  16. class TestChunkedDataPipeGetter : public mojom::ChunkedDataPipeGetter {
  17. public:
  18. TestChunkedDataPipeGetter();
  19. TestChunkedDataPipeGetter(const TestChunkedDataPipeGetter&) = delete;
  20. TestChunkedDataPipeGetter& operator=(const TestChunkedDataPipeGetter&) =
  21. delete;
  22. ~TestChunkedDataPipeGetter() override;
  23. // Returns the mojo::PendingRemote<mojom::ChunkedDataPipeGetter> corresponding
  24. // to |this|. May only be called once.
  25. mojo::PendingRemote<mojom::ChunkedDataPipeGetter> GetDataPipeGetterRemote();
  26. // Close the mojom::DataPipeGetter pipe.
  27. void ClosePipe();
  28. GetSizeCallback WaitForGetSize();
  29. mojo::ScopedDataPipeProducerHandle WaitForStartReading();
  30. private:
  31. // mojom::ChunkedDataPipeGetter implementation:
  32. void GetSize(GetSizeCallback get_size_callback) override;
  33. void StartReading(mojo::ScopedDataPipeProducerHandle pipe) override;
  34. std::unique_ptr<base::RunLoop> get_size_run_loop_;
  35. std::unique_ptr<base::RunLoop> start_reading_run_loop_;
  36. mojo::Receiver<mojom::ChunkedDataPipeGetter> receiver_{this};
  37. mojo::ScopedDataPipeProducerHandle write_pipe_;
  38. GetSizeCallback get_size_callback_;
  39. bool received_size_callback_ = false;
  40. };
  41. } // namespace network
  42. #endif // SERVICES_NETWORK_TEST_CHUNKED_DATA_PIPE_GETTER_H_