| Index: content/browser/fileapi/blob_storage_context_unittest.cc
|
| diff --git a/content/browser/fileapi/blob_storage_context_unittest.cc b/content/browser/fileapi/blob_storage_context_unittest.cc
|
| index 5ae280e444e13e0ed2038812b27e0c1ea7d9f4f8..dd853014402dd196f15dbb0a072286a076243e35 100644
|
| --- a/content/browser/fileapi/blob_storage_context_unittest.cc
|
| +++ b/content/browser/fileapi/blob_storage_context_unittest.cc
|
| @@ -72,25 +72,104 @@ disk_cache::ScopedEntryPtr CreateDiskCacheEntry(disk_cache::Backend* cache,
|
| return entry.Pass();
|
| }
|
|
|
| -void SetupBasicBlob(BlobStorageHost* host, const std::string& id) {
|
| - EXPECT_TRUE(host->StartBuildingBlob(id));
|
| - DataElement item;
|
| - item.SetToBytes("1", 1);
|
| - EXPECT_TRUE(host->AppendBlobDataItem(id, item));
|
| - EXPECT_TRUE(host->FinishBuildingBlob(id, "text/plain"));
|
| - EXPECT_FALSE(host->StartBuildingBlob(id));
|
| -}
|
|
|
| } // namespace
|
|
|
| -TEST(BlobStorageContextTest, IncrementDecrementRef) {
|
| +class BlobStorageContextTest : public testing::Test {
|
| + protected:
|
| + BlobStorageContextTest()
|
| + : done_called_(false),
|
| + cancel_called_(false),
|
| + cancel_code_(storage::IPCBlobCreationCancelCode::UNKNOWN),
|
| + request_called_(false) {}
|
| + ~BlobStorageContextTest() override {}
|
| +
|
| + // Callback Methods and Getters
|
| + base::Callback<void(storage::IPCBlobCreationCancelCode)> GetCancelCallback() {
|
| + cancel_called_ = false;
|
| + return base::Bind(&BlobStorageContextTest::CancelCallback,
|
| + base::Unretained(this));
|
| + }
|
| +
|
| + void CancelCallback(storage::IPCBlobCreationCancelCode code) {
|
| + cancel_called_ = true;
|
| + cancel_code_ = code;
|
| + }
|
| +
|
| + base::Closure GetDoneCallback() {
|
| + done_called_ = false;
|
| + return base::Bind(&BlobStorageContextTest::DoneCallback,
|
| + base::Unretained(this));
|
| + }
|
| +
|
| + void DoneCallback() { done_called_ = true; }
|
| +
|
| + base::Callback<void(const std::vector<storage::BlobItemBytesRequest>&,
|
| + const std::vector<base::SharedMemoryHandle>&,
|
| + const std::vector<IPC::PlatformFileForTransit>&)>
|
| + GetRequestCallback() {
|
| + request_called_ = false;
|
| + return base::Bind(&BlobStorageContextTest::RequestMemoryCallback,
|
| + base::Unretained(this));
|
| + }
|
| +
|
| + void RequestMemoryCallback(const std::vector<storage::BlobItemBytesRequest>&,
|
| + const std::vector<base::SharedMemoryHandle>&,
|
| + const std::vector<IPC::PlatformFileForTransit>&) {
|
| + request_called_ = true;
|
| + }
|
| +
|
| + // Helper call to create basic blob.
|
| + void SetupBasicBlob(BlobStorageHost* host,
|
| + BlobStorageContext* context,
|
| + const std::string& id) {
|
| + EXPECT_FALSE(context->MaybeStartAsyncBlobTransfer(id));
|
| + EXPECT_TRUE(host->RegisterBlobUUID(id));
|
| + EXPECT_TRUE(context->MaybeStartAsyncBlobTransfer(id));
|
| + BlobDataBuilder builder(id);
|
| + builder.AppendData("1", 1);
|
| + builder.set_content_type("text/plain");
|
| + context->FinishAsyncBlobTransfer(GetDoneCallback(), GetCancelCallback(),
|
| + builder);
|
| + EXPECT_TRUE(done_called_);
|
| + EXPECT_FALSE(cancel_called_);
|
| + EXPECT_FALSE(host->RegisterBlobUUID(id));
|
| + }
|
| +
|
| + // Delegating methods
|
| + bool MaybeStartAsyncBlobTransfer(BlobStorageContext* context,
|
| + const std::string& uuid) {
|
| + return context->MaybeStartAsyncBlobTransfer(uuid);
|
| + }
|
| +
|
| + void FinishAsyncBlobTransfer(BlobStorageContext* context,
|
| + const storage::BlobDataBuilder& builder) {
|
| + context->FinishAsyncBlobTransfer(GetDoneCallback(), GetCancelCallback(),
|
| + builder);
|
| + }
|
| +
|
| + void AsyncBlobTransfer(BlobStorageHost* host, const std::string& uuid) {
|
| + DataElement e;
|
| + e.SetToBytes("1", 1);
|
| + std::vector<storage::DataElement> elements = {e};
|
| + host->StartBuildingBlob(uuid, "text/plain", elements, GetRequestCallback(),
|
| + GetDoneCallback(), GetCancelCallback());
|
| + }
|
| +
|
| + bool done_called_;
|
| + bool cancel_called_;
|
| + storage::IPCBlobCreationCancelCode cancel_code_;
|
| + bool request_called_;
|
| +};
|
| +
|
| +TEST_F(BlobStorageContextTest, IncrementDecrementRef) {
|
| BlobStorageContext context;
|
| BlobStorageHost host(&context);
|
| base::MessageLoop fake_io_message_loop;
|
|
|
| // Build up a basic blob.
|
| const std::string kId("id");
|
| - SetupBasicBlob(&host, kId);
|
| + SetupBasicBlob(&host, &context, kId);
|
|
|
| // Make sure it's there, finish building implies a ref of one.
|
| scoped_ptr<BlobDataHandle> blob_data_handle;
|
| @@ -115,30 +194,36 @@ TEST(BlobStorageContextTest, IncrementDecrementRef) {
|
| EXPECT_FALSE(host.IncrementBlobRefCount(kId));
|
| }
|
|
|
| -TEST(BlobStorageContextTest, CancelBuildingBlob) {
|
| +TEST_F(BlobStorageContextTest, CancelBuildingBlob) {
|
| BlobStorageContext context;
|
| BlobStorageHost host(&context);
|
| base::MessageLoop fake_io_message_loop;
|
|
|
| // Build up a basic blob.
|
| const std::string kId("id");
|
| - EXPECT_TRUE(host.StartBuildingBlob(kId));
|
| - DataElement item;
|
| - item.SetToBytes("1", 1);
|
| - EXPECT_TRUE(host.AppendBlobDataItem(kId, item));
|
| + EXPECT_FALSE(host.CancelBuildingBlob(kId));
|
| + EXPECT_TRUE(host.RegisterBlobUUID(kId));
|
| + EXPECT_TRUE(MaybeStartAsyncBlobTransfer(&context, kId));
|
| EXPECT_TRUE(host.CancelBuildingBlob(kId));
|
| - EXPECT_FALSE(host.FinishBuildingBlob(kId, "text/plain"));
|
| - EXPECT_TRUE(host.StartBuildingBlob(kId));
|
| +
|
| + BlobDataBuilder builder(kId);
|
| + builder.AppendData("1", 1);
|
| + builder.set_content_type("text/plain");
|
| + FinishAsyncBlobTransfer(&context, builder);
|
| + EXPECT_FALSE(done_called_);
|
| + EXPECT_TRUE(cancel_called_);
|
| +
|
| + EXPECT_TRUE(host.RegisterBlobUUID(kId));
|
| }
|
|
|
| -TEST(BlobStorageContextTest, BlobDataHandle) {
|
| +TEST_F(BlobStorageContextTest, BlobDataHandle) {
|
| BlobStorageContext context;
|
| BlobStorageHost host(&context);
|
| base::MessageLoop fake_io_message_loop;
|
|
|
| // Build up a basic blob.
|
| const std::string kId("id");
|
| - SetupBasicBlob(&host, kId);
|
| + SetupBasicBlob(&host, &context, kId);
|
|
|
| // Get a handle to it.
|
| scoped_ptr<BlobDataHandle> blob_data_handle =
|
| @@ -162,7 +247,7 @@ TEST(BlobStorageContextTest, BlobDataHandle) {
|
| EXPECT_FALSE(blob_data_handle);
|
| }
|
|
|
| -TEST(BlobStorageContextTest, MemoryUsage) {
|
| +TEST_F(BlobStorageContextTest, MemoryUsage) {
|
| const std::string kId1("id1");
|
| const std::string kId2("id2");
|
|
|
| @@ -189,17 +274,42 @@ TEST(BlobStorageContextTest, MemoryUsage) {
|
| context.AddFinishedBlob(&builder2);
|
| EXPECT_EQ(10lu, context.memory_usage());
|
|
|
| + EXPECT_EQ(2u, context.registry().blob_count());
|
| +
|
| blob_data_handle.reset();
|
| base::RunLoop().RunUntilIdle();
|
|
|
| EXPECT_EQ(10lu, context.memory_usage());
|
| + EXPECT_EQ(1u, context.registry().blob_count());
|
| blob_data_handle2.reset();
|
| base::RunLoop().RunUntilIdle();
|
|
|
| EXPECT_EQ(0lu, context.memory_usage());
|
| + EXPECT_EQ(0u, context.registry().blob_count());
|
| +}
|
| +
|
| +TEST_F(BlobStorageContextTest, AsyncPipeline) {
|
| + BlobStorageContext context;
|
| + BlobStorageHost host(&context);
|
| +
|
| + // Build up a basic blob.
|
| + const std::string kId("id");
|
| + EXPECT_FALSE(MaybeStartAsyncBlobTransfer(&context, kId));
|
| + AsyncBlobTransfer(&host, kId);
|
| + EXPECT_TRUE(cancel_called_);
|
| + EXPECT_FALSE(done_called_);
|
| +
|
| + EXPECT_TRUE(host.RegisterBlobUUID(kId));
|
| + AsyncBlobTransfer(&host, kId);
|
| + EXPECT_TRUE(done_called_);
|
| + EXPECT_FALSE(cancel_called_);
|
| + // We assume that it uses the shortcut method, and immediately returns.
|
| + EXPECT_FALSE(request_called_);
|
| +
|
| + EXPECT_EQ(1u, context.registry().blob_count());
|
| }
|
|
|
| -TEST(BlobStorageContextTest, AddFinishedBlob) {
|
| +TEST_F(BlobStorageContextTest, AddFinishedBlob) {
|
| const std::string kId1("id1");
|
| const std::string kId2("id12");
|
| const std::string kId2Prime("id2.prime");
|
| @@ -268,7 +378,7 @@ TEST(BlobStorageContextTest, AddFinishedBlob) {
|
| base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| -TEST(BlobStorageContextTest, AddFinishedBlob_LargeOffset) {
|
| +TEST_F(BlobStorageContextTest, AddFinishedBlob_LargeOffset) {
|
| // A value which does not fit in a 4-byte data type. Used to confirm that
|
| // large values are supported on 32-bit Chromium builds. Regression test for:
|
| // crbug.com/458122.
|
| @@ -304,7 +414,7 @@ TEST(BlobStorageContextTest, AddFinishedBlob_LargeOffset) {
|
| base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| -TEST(BlobStorageContextTest, BuildDiskCacheBlob) {
|
| +TEST_F(BlobStorageContextTest, BuildDiskCacheBlob) {
|
| base::MessageLoop fake_io_message_loop;
|
| scoped_refptr<BlobDataBuilder::DataHandle>
|
| data_handle = new EmptyDataHandle();
|
| @@ -342,7 +452,7 @@ TEST(BlobStorageContextTest, BuildDiskCacheBlob) {
|
| base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| -TEST(BlobStorageContextTest, CompoundBlobs) {
|
| +TEST_F(BlobStorageContextTest, CompoundBlobs) {
|
| const std::string kId1("id1");
|
| const std::string kId2("id2");
|
| const std::string kId3("id3");
|
| @@ -412,14 +522,14 @@ TEST(BlobStorageContextTest, CompoundBlobs) {
|
| base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| -TEST(BlobStorageContextTest, PublicBlobUrls) {
|
| +TEST_F(BlobStorageContextTest, PublicBlobUrls) {
|
| BlobStorageContext context;
|
| BlobStorageHost host(&context);
|
| base::MessageLoop fake_io_message_loop;
|
|
|
| // Build up a basic blob.
|
| const std::string kId("id");
|
| - SetupBasicBlob(&host, kId);
|
| + SetupBasicBlob(&host, &context, kId);
|
|
|
| // Now register a url for that blob.
|
| GURL kUrl("blob:id");
|
| @@ -447,7 +557,7 @@ TEST(BlobStorageContextTest, PublicBlobUrls) {
|
| EXPECT_FALSE(host.RevokePublicBlobURL(kUrl));
|
| }
|
|
|
| -TEST(BlobStorageContextTest, HostCleanup) {
|
| +TEST_F(BlobStorageContextTest, HostCleanup) {
|
| BlobStorageContext context;
|
| scoped_ptr<BlobStorageHost> host(new BlobStorageHost(&context));
|
| base::MessageLoop fake_io_message_loop;
|
| @@ -455,7 +565,7 @@ TEST(BlobStorageContextTest, HostCleanup) {
|
| // Build up a basic blob and register a url
|
| const std::string kId("id");
|
| GURL kUrl("blob:id");
|
| - SetupBasicBlob(host.get(), kId);
|
| + SetupBasicBlob(host.get(), &context, kId);
|
| EXPECT_TRUE(host->RegisterPublicBlobURL(kUrl, kId));
|
|
|
| // All should disappear upon host deletion.
|
| @@ -466,7 +576,7 @@ TEST(BlobStorageContextTest, HostCleanup) {
|
| EXPECT_TRUE(!handle.get());
|
| }
|
|
|
| -TEST(BlobStorageContextTest, EarlyContextDeletion) {
|
| +TEST_F(BlobStorageContextTest, EarlyContextDeletion) {
|
| scoped_ptr<BlobStorageContext> context(new BlobStorageContext);
|
| BlobStorageHost host(context.get());
|
| base::MessageLoop fake_io_message_loop;
|
| @@ -476,11 +586,14 @@ TEST(BlobStorageContextTest, EarlyContextDeletion) {
|
|
|
| const std::string kId("id");
|
| GURL kUrl("blob:id");
|
| - EXPECT_FALSE(host.StartBuildingBlob(kId));
|
| + EXPECT_FALSE(host.RegisterBlobUUID(kId));
|
| DataElement item;
|
| item.SetToBytes("1", 1);
|
| - EXPECT_FALSE(host.AppendBlobDataItem(kId, item));
|
| - EXPECT_FALSE(host.FinishBuildingBlob(kId, "text/plain"));
|
| + EXPECT_FALSE(host.CancelBuildingBlob(kId));
|
| + AsyncBlobTransfer(&host, kId);
|
| + EXPECT_FALSE(request_called_);
|
| + EXPECT_FALSE(done_called_);
|
| + EXPECT_TRUE(cancel_called_);
|
| EXPECT_FALSE(host.RegisterPublicBlobURL(kUrl, kId));
|
| EXPECT_FALSE(host.IncrementBlobRefCount(kId));
|
| EXPECT_FALSE(host.DecrementBlobRefCount(kId));
|
|
|