Commit d95022e4 authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

[Blobs] Move MockBlob to its own file to allow reuse in different tests.

And rename from MockBlob to FakeBlob as that seems like a better name.

Bug: none
Change-Id: I560756e200a8712f7ba335130522158195633c5a
Reviewed-on: https://chromium-review.googlesource.com/1114126
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570204}
parent 1360c1e0
......@@ -320,6 +320,8 @@ static_library("test_support") {
sources = [
"test/async_file_test_helper.cc",
"test/async_file_test_helper.h",
"test/fake_blob.cc",
"test/fake_blob.h",
"test/fake_progress_client.cc",
"test/fake_progress_client.h",
"test/fileapi_test_file_set.cc",
......
......@@ -21,6 +21,7 @@
#include "storage/browser/blob/blob_data_builder.h"
#include "storage/browser/blob/blob_data_handle.h"
#include "storage/browser/blob/blob_storage_context.h"
#include "storage/browser/test/fake_blob.h"
#include "storage/browser/test/fake_progress_client.h"
#include "storage/browser/test/mock_blob_registry_delegate.h"
#include "storage/browser/test/mock_bytes_provider.h"
......@@ -40,42 +41,6 @@ const uint64_t kTestBlobStorageMaxDiskSpace = 4000;
const uint64_t kTestBlobStorageMinFileSizeBytes = 10;
const uint64_t kTestBlobStorageMaxFileSizeBytes = 100;
class MockBlob : public blink::mojom::Blob {
public:
explicit MockBlob(const std::string& uuid) : uuid_(uuid) {}
void Clone(blink::mojom::BlobRequest request) override {
mojo::MakeStrongBinding(std::make_unique<MockBlob>(uuid_),
std::move(request));
}
void AsDataPipeGetter(
network::mojom::DataPipeGetterRequest request) override {
NOTREACHED();
}
void ReadRange(uint64_t offset,
uint64_t size,
mojo::ScopedDataPipeProducerHandle,
blink::mojom::BlobReaderClientPtr) override {
NOTREACHED();
}
void ReadAll(mojo::ScopedDataPipeProducerHandle,
blink::mojom::BlobReaderClientPtr) override {
NOTREACHED();
}
void ReadSideData(ReadSideDataCallback) override { NOTREACHED(); }
void GetInternalUUID(GetInternalUUIDCallback callback) override {
std::move(callback).Run(uuid_);
}
private:
std::string uuid_;
};
void BindBytesProvider(std::unique_ptr<MockBytesProvider> impl,
blink::mojom::BytesProviderRequest request) {
mojo::MakeStrongBinding(std::move(impl), std::move(request));
......@@ -430,7 +395,7 @@ TEST_F(BlobRegistryImplTest, Register_NonExistentBlob) {
std::vector<blink::mojom::DataElementPtr> elements;
blink::mojom::BlobPtrInfo referenced_blob_info;
mojo::MakeStrongBinding(std::make_unique<MockBlob>("mock blob"),
mojo::MakeStrongBinding(std::make_unique<FakeBlob>("mock blob"),
MakeRequest(&referenced_blob_info));
elements.push_back(
blink::mojom::DataElement::NewBlob(blink::mojom::DataElementBlob::New(
......@@ -460,7 +425,7 @@ TEST_F(BlobRegistryImplTest, Register_ValidBlobReferences) {
std::unique_ptr<BlobDataHandle> handle =
CreateBlobFromString(kId1, "hello world");
blink::mojom::BlobPtrInfo blob1_info;
mojo::MakeStrongBinding(std::make_unique<MockBlob>(kId1),
mojo::MakeStrongBinding(std::make_unique<FakeBlob>(kId1),
MakeRequest(&blob1_info));
const std::string kId2 = "id2";
......@@ -930,7 +895,7 @@ TEST_F(BlobRegistryImplTest,
auto blob_handle = context_->AddFutureBlob(
kDepId, "", "", BlobStorageContext::BuildAbortedCallback());
blink::mojom::BlobPtrInfo referenced_blob_info;
mojo::MakeStrongBinding(std::make_unique<MockBlob>(kDepId),
mojo::MakeStrongBinding(std::make_unique<FakeBlob>(kDepId),
MakeRequest(&referenced_blob_info));
// Create mojo blob depending on future blob.
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "storage/browser/test/fake_blob.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
namespace storage {
FakeBlob::FakeBlob(const std::string& uuid) : uuid_(uuid) {}
blink::mojom::BlobPtr FakeBlob::Clone() {
blink::mojom::BlobPtr result;
Clone(MakeRequest(&result));
return result;
}
void FakeBlob::Clone(blink::mojom::BlobRequest request) {
mojo::MakeStrongBinding(std::make_unique<FakeBlob>(uuid_),
std::move(request));
}
void FakeBlob::AsDataPipeGetter(network::mojom::DataPipeGetterRequest) {
NOTREACHED();
}
void FakeBlob::ReadRange(uint64_t offset,
uint64_t size,
mojo::ScopedDataPipeProducerHandle,
blink::mojom::BlobReaderClientPtr) {
NOTREACHED();
}
void FakeBlob::ReadAll(mojo::ScopedDataPipeProducerHandle,
blink::mojom::BlobReaderClientPtr) {
NOTREACHED();
}
void FakeBlob::ReadSideData(ReadSideDataCallback) {
NOTREACHED();
}
void FakeBlob::GetInternalUUID(GetInternalUUIDCallback callback) {
std::move(callback).Run(uuid_);
}
} // namespace storage
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef STORAGE_BROWSER_TEST_FAKE_BLOB_H_
#define STORAGE_BROWSER_TEST_FAKE_BLOB_H_
#include "third_party/blink/public/mojom/blob/blob.mojom.h"
namespace storage {
// Implementation of the blink::mojom::Blob interface. Only supports the Clone
// and GetInternalUUID methods.
class FakeBlob : public blink::mojom::Blob {
public:
explicit FakeBlob(const std::string& uuid);
blink::mojom::BlobPtr Clone();
void Clone(blink::mojom::BlobRequest request) override;
void AsDataPipeGetter(network::mojom::DataPipeGetterRequest) override;
void ReadRange(uint64_t offset,
uint64_t size,
mojo::ScopedDataPipeProducerHandle,
blink::mojom::BlobReaderClientPtr) override;
void ReadAll(mojo::ScopedDataPipeProducerHandle,
blink::mojom::BlobReaderClientPtr) override;
void ReadSideData(ReadSideDataCallback) override;
void GetInternalUUID(GetInternalUUIDCallback callback) override;
private:
std::string uuid_;
};
} // namespace storage
#endif // STORAGE_BROWSER_TEST_FAKE_BLOB_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment