910e62b5创建于 1月15日历史提交
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef STORAGE_BROWSER_TEST_MOCK_BYTES_PROVIDER_H_
#define STORAGE_BROWSER_TEST_MOCK_BYTES_PROVIDER_H_

#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "third_party/blink/public/mojom/blob/blob_registry.mojom.h"
#include "third_party/blink/public/mojom/blob/data_element.mojom.h"

namespace storage {

// Mock BytesProvider implementation. RequestAsStream blocks, so make sure to
// bind this implementation to a pipe on a separate sequence from where the
// bytes are consumed.
class MockBytesProvider : public blink::mojom::BytesProvider {
 public:
  explicit MockBytesProvider(
      std::vector<uint8_t> data,
      size_t* reply_request_count = nullptr,
      size_t* stream_request_count = nullptr,
      size_t* file_request_count = nullptr,
      std::optional<base::Time> file_modification_time = base::Time());
  ~MockBytesProvider() override;

  // BytesProvider implementation:
  void RequestAsReply(RequestAsReplyCallback callback) override;
  void RequestAsStream(mojo::ScopedDataPipeProducerHandle pipe) override;
  void RequestAsFile(uint64_t source_offset,
                     uint64_t source_size,
                     base::File file,
                     uint64_t file_offset,
                     RequestAsFileCallback callback) override;

 private:
  std::vector<uint8_t> data_;
  raw_ptr<size_t> reply_request_count_;
  raw_ptr<size_t> stream_request_count_;
  raw_ptr<size_t> file_request_count_;
  std::optional<base::Time> file_modification_time_;
};

}  // namespace storage

#endif  // STORAGE_BROWSER_TEST_MOCK_BYTES_PROVIDER_H_