1 // Copyright 2017 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 STORAGE_BROWSER_TEST_MOCK_BYTES_PROVIDER_H_
6 #define STORAGE_BROWSER_TEST_MOCK_BYTES_PROVIDER_H_
7 
8 #include "third_party/blink/public/mojom/blob/blob_registry.mojom.h"
9 #include "third_party/blink/public/mojom/blob/data_element.mojom.h"
10 
11 namespace storage {
12 
13 // Mock BytesProvider implementation. RequestAsStream blocks, so make sure to
14 // bind this implementation to a pipe on a separate sequence from where the
15 // bytes are consumed.
16 class MockBytesProvider : public blink::mojom::BytesProvider {
17  public:
18   explicit MockBytesProvider(
19       std::vector<uint8_t> data,
20       size_t* reply_request_count = nullptr,
21       size_t* stream_request_count = nullptr,
22       size_t* file_request_count = nullptr,
23       base::Optional<base::Time> file_modification_time = base::Time());
24   ~MockBytesProvider() override;
25 
26   // BytesProvider implementation:
27   void RequestAsReply(RequestAsReplyCallback callback) override;
28   void RequestAsStream(mojo::ScopedDataPipeProducerHandle pipe) override;
29   void RequestAsFile(uint64_t source_offset,
30                      uint64_t source_size,
31                      base::File file,
32                      uint64_t file_offset,
33                      RequestAsFileCallback callback) override;
34 
35  private:
36   std::vector<uint8_t> data_;
37   size_t* reply_request_count_;
38   size_t* stream_request_count_;
39   size_t* file_request_count_;
40   base::Optional<base::Time> file_modification_time_;
41 };
42 
43 }  // namespace storage
44 
45 #endif  // STORAGE_BROWSER_TEST_MOCK_BYTES_PROVIDER_H_
46