| Index: content/browser/blob_storage/blob_transport_host_unittest.cc
|
| diff --git a/content/browser/blob_storage/blob_async_builder_host_unittest.cc b/content/browser/blob_storage/blob_transport_host_unittest.cc
|
| similarity index 53%
|
| rename from content/browser/blob_storage/blob_async_builder_host_unittest.cc
|
| rename to content/browser/blob_storage/blob_transport_host_unittest.cc
|
| index 31cdc6676c39d2e8d9d6f7cd0cd9bd567c804eb0..8888e20121af1088fb53a550ecb16aef3a285aa4 100644
|
| --- a/content/browser/blob_storage/blob_async_builder_host_unittest.cc
|
| +++ b/content/browser/blob_storage/blob_transport_host_unittest.cc
|
| @@ -2,8 +2,6 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "storage/browser/blob/blob_async_builder_host.h"
|
| -
|
| #include <stddef.h>
|
| #include <stdint.h>
|
| #include <string.h>
|
| @@ -16,6 +14,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/blob/blob_transport_host.h"
|
| #include "storage/common/blob_storage/blob_storage_constants.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -29,6 +28,10 @@ const std::string kCompletedBlobData = "completedBlobData";
|
|
|
| const size_t kTestBlobStorageIPCThresholdBytes = 5;
|
| const size_t kTestBlobStorageMaxSharedMemoryBytes = 20;
|
| +
|
| +const size_t kTestBlobStorageMaxBlobMemorySize = 400;
|
| +const uint64_t kTestBlobStorageMaxDiskSpace = 4000;
|
| +const uint64_t kTestBlobStorageMinFileSizeBytes = 10;
|
| const uint64_t kTestBlobStorageMaxFileSizeBytes = 100;
|
|
|
| void PopulateBytes(char* bytes, size_t length) {
|
| @@ -64,52 +67,60 @@ void AddBlobItem(std::vector<DataElement>* out) {
|
| }
|
| } // namespace
|
|
|
| -class BlobAsyncBuilderHostTest : public testing::Test {
|
| +class BlobTransportHostTest : public testing::Test {
|
| public:
|
| - BlobAsyncBuilderHostTest()
|
| - : cancel_code_(IPCBlobCreationCancelCode::UNKNOWN),
|
| + BlobTransportHostTest()
|
| + : status_code_(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS),
|
| request_called_(false) {}
|
| - ~BlobAsyncBuilderHostTest() override {}
|
| + ~BlobTransportHostTest() override {}
|
|
|
| void SetUp() override {
|
| - cancel_code_ = IPCBlobCreationCancelCode::UNKNOWN;
|
| + status_code_ = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS;
|
| request_called_ = false;
|
| requests_.clear();
|
| memory_handles_.clear();
|
| - host_.SetMemoryConstantsForTesting(kTestBlobStorageIPCThresholdBytes,
|
| - kTestBlobStorageMaxSharedMemoryBytes,
|
| - kTestBlobStorageMaxFileSizeBytes);
|
| + storage::BlobStorageLimits limits;
|
| + limits.max_ipc_memory_size = kTestBlobStorageIPCThresholdBytes;
|
| + limits.max_shared_memory_size = kTestBlobStorageMaxSharedMemoryBytes;
|
| + limits.max_blob_in_memory_space = kTestBlobStorageMaxBlobMemorySize;
|
| + limits.max_blob_disk_space = kTestBlobStorageMaxDiskSpace;
|
| + limits.min_page_file_size = kTestBlobStorageMinFileSizeBytes;
|
| + limits.max_file_size = kTestBlobStorageMaxFileSizeBytes;
|
| + context_.mutable_memory_controller()->set_limits_for_testing(limits);
|
| BlobDataBuilder builder(kCompletedBlobUUID);
|
| builder.AppendData(kCompletedBlobData);
|
| completed_blob_handle_ = context_.AddFinishedBlob(builder);
|
| - completed_blob_uuid_set_ = {kCompletedBlobUUID};
|
| + EXPECT_EQ(BlobStatus::DONE, completed_blob_handle_->GetBlobStatus());
|
| + }
|
| +
|
| + void StatusCallback(BlobStatus status) {
|
| + status_called_ = true;
|
| + status_code_ = status;
|
| }
|
|
|
| void RequestMemoryCallback(
|
| - std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests,
|
| - std::unique_ptr<std::vector<base::SharedMemoryHandle>>
|
| - shared_memory_handles,
|
| - std::unique_ptr<std::vector<base::File>> files) {
|
| - requests_ = std::move(*requests);
|
| - memory_handles_ = std::move(*shared_memory_handles);
|
| + std::vector<storage::BlobItemBytesRequest> requests,
|
| + std::vector<base::SharedMemoryHandle> shared_memory_handles,
|
| + std::vector<base::File> files) {
|
| + requests_ = std::move(requests);
|
| + memory_handles_ = std::move(shared_memory_handles);
|
| request_called_ = true;
|
| }
|
|
|
| - BlobTransportResult BuildBlobAsync(
|
| - const std::vector<DataElement>& descriptions,
|
| - const std::set<std::string>& referenced_blob_uuids,
|
| - size_t memory_available) {
|
| + BlobStatus BuildBlobAsync(const std::string& uuid,
|
| + const std::vector<DataElement>& descriptions) {
|
| request_called_ = false;
|
| - BlobTransportResult register_result =
|
| - host_.RegisterBlobUUID(kBlobUUID, kContentType, kContentDisposition,
|
| - referenced_blob_uuids, &context_);
|
| - if (register_result != BlobTransportResult::DONE) {
|
| - return register_result;
|
| - }
|
| - return host_.StartBuildingBlob(
|
| - kBlobUUID, descriptions, memory_available, &context_,
|
| - base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
|
| + status_called_ = false;
|
| + host_.StartBuildingBlob(
|
| + uuid, kContentType, kContentDisposition, descriptions, &context_,
|
| + base::Bind(&BlobTransportHostTest::RequestMemoryCallback,
|
| + base::Unretained(this)),
|
| + base::Bind(&BlobTransportHostTest::StatusCallback,
|
| base::Unretained(this)));
|
| + if (status_called_)
|
| + return status_code_;
|
| + else
|
| + return context_.GetBlobStatus(uuid);
|
| }
|
|
|
| void DecrementBlobRefCount(const std::string& uuid) {
|
| @@ -117,47 +128,45 @@ class BlobAsyncBuilderHostTest : public testing::Test {
|
| }
|
|
|
| bool IsBeingBuiltInContext(const std::string& uuid) {
|
| - return context_.IsBeingBuilt(uuid);
|
| + return BlobStatusIsPending(context_.GetBlobStatus(uuid));
|
| }
|
|
|
| content::TestBrowserThreadBundle browser_thread_bundle_;
|
| BlobStorageContext context_;
|
| - BlobAsyncBuilderHost host_;
|
| - IPCBlobCreationCancelCode cancel_code_;
|
| + BlobTransportHost host_;
|
| + bool status_called_;
|
| + BlobStatus status_code_;
|
|
|
| bool request_called_;
|
| std::vector<storage::BlobItemBytesRequest> requests_;
|
| std::vector<base::SharedMemoryHandle> memory_handles_;
|
| - std::set<std::string> completed_blob_uuid_set_;
|
| -
|
| std::unique_ptr<BlobDataHandle> completed_blob_handle_;
|
| };
|
|
|
| // The 'shortcut' method is when the data is included in the initial IPCs and
|
| // the browser uses that instead of requesting the memory.
|
| -TEST_F(BlobAsyncBuilderHostTest, TestShortcut) {
|
| +TEST_F(BlobTransportHostTest, TestShortcut) {
|
| std::vector<DataElement> descriptions;
|
|
|
| AddShortcutMemoryItem(10, &descriptions);
|
| AddBlobItem(&descriptions);
|
| - AddShortcutMemoryItem(5000, &descriptions);
|
| + AddShortcutMemoryItem(300, &descriptions);
|
|
|
| BlobDataBuilder expected(kBlobUUID);
|
| expected.set_content_type(kContentType);
|
| expected.set_content_disposition(kContentDisposition);
|
| AddShortcutMemoryItem(10, &expected);
|
| expected.AppendData(kCompletedBlobData);
|
| - AddShortcutMemoryItem(5000, &expected);
|
| + AddShortcutMemoryItem(300, &expected);
|
|
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
|
| + EXPECT_EQ(BlobStatus::DONE, BuildBlobAsync(kBlobUUID, descriptions));
|
|
|
| EXPECT_FALSE(request_called_);
|
| EXPECT_EQ(0u, host_.blob_building_count());
|
| std::unique_ptr<BlobDataHandle> handle =
|
| context_.GetBlobDataFromUUID(kBlobUUID);
|
| EXPECT_FALSE(handle->IsBeingBuilt());
|
| - EXPECT_FALSE(handle->IsBroken());
|
| + ASSERT_FALSE(handle->IsBroken());
|
| std::unique_ptr<BlobDataSnapshot> data = handle->CreateSnapshot();
|
| EXPECT_EQ(expected, *data);
|
| data.reset();
|
| @@ -165,28 +174,27 @@ TEST_F(BlobAsyncBuilderHostTest, TestShortcut) {
|
| base::RunLoop().RunUntilIdle();
|
| };
|
|
|
| -TEST_F(BlobAsyncBuilderHostTest, TestShortcutNoRoom) {
|
| +TEST_F(BlobTransportHostTest, TestShortcutNoRoom) {
|
| std::vector<DataElement> descriptions;
|
|
|
| AddShortcutMemoryItem(10, &descriptions);
|
| AddBlobItem(&descriptions);
|
| AddShortcutMemoryItem(5000, &descriptions);
|
|
|
| - EXPECT_EQ(BlobTransportResult::CANCEL_MEMORY_FULL,
|
| - BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5000));
|
| + EXPECT_EQ(BlobStatus::ERR_OUT_OF_MEMORY,
|
| + BuildBlobAsync(kBlobUUID, descriptions));
|
|
|
| EXPECT_FALSE(request_called_);
|
| EXPECT_EQ(0u, host_.blob_building_count());
|
| };
|
|
|
| -TEST_F(BlobAsyncBuilderHostTest, TestSingleSharedMemRequest) {
|
| +TEST_F(BlobTransportHostTest, TestSingleSharedMemRequest) {
|
| std::vector<DataElement> descriptions;
|
| const size_t kSize = kTestBlobStorageIPCThresholdBytes + 1;
|
| AddMemoryItem(kSize, &descriptions);
|
|
|
| - EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
|
| - BuildBlobAsync(descriptions, std::set<std::string>(),
|
| - kTestBlobStorageIPCThresholdBytes + 1));
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlobUUID, descriptions));
|
|
|
| EXPECT_TRUE(request_called_);
|
| EXPECT_EQ(1u, host_.blob_building_count());
|
| @@ -198,7 +206,7 @@ TEST_F(BlobAsyncBuilderHostTest, TestSingleSharedMemRequest) {
|
| requests_.at(0));
|
| };
|
|
|
| -TEST_F(BlobAsyncBuilderHostTest, TestMultipleSharedMemRequests) {
|
| +TEST_F(BlobTransportHostTest, TestMultipleSharedMemRequests) {
|
| std::vector<DataElement> descriptions;
|
| const size_t kSize = kTestBlobStorageMaxSharedMemoryBytes + 1;
|
| const char kFirstBlockByte = 7;
|
| @@ -213,9 +221,8 @@ TEST_F(BlobAsyncBuilderHostTest, TestMultipleSharedMemRequests) {
|
| expected.AppendData(data, kTestBlobStorageMaxSharedMemoryBytes);
|
| expected.AppendData(&kSecondBlockByte, 1);
|
|
|
| - EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
|
| - BuildBlobAsync(descriptions, std::set<std::string>(),
|
| - kTestBlobStorageMaxSharedMemoryBytes + 1));
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlobUUID, descriptions));
|
|
|
| EXPECT_TRUE(request_called_);
|
| EXPECT_EQ(1u, host_.blob_building_count());
|
| @@ -239,7 +246,7 @@ TEST_F(BlobAsyncBuilderHostTest, TestMultipleSharedMemRequests) {
|
|
|
| BlobItemBytesResponse response(0);
|
| std::vector<BlobItemBytesResponse> responses = {response};
|
| - EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| host_.OnMemoryResponses(kBlobUUID, responses, &context_));
|
|
|
| EXPECT_TRUE(request_called_);
|
| @@ -255,7 +262,7 @@ TEST_F(BlobAsyncBuilderHostTest, TestMultipleSharedMemRequests) {
|
|
|
| response.request_number = 1;
|
| responses[0] = response;
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| + EXPECT_EQ(BlobStatus::DONE,
|
| host_.OnMemoryResponses(kBlobUUID, responses, &context_));
|
| EXPECT_FALSE(request_called_);
|
| EXPECT_EQ(0u, host_.blob_building_count());
|
| @@ -267,7 +274,7 @@ TEST_F(BlobAsyncBuilderHostTest, TestMultipleSharedMemRequests) {
|
| EXPECT_EQ(expected, *blob_data);
|
| };
|
|
|
| -TEST_F(BlobAsyncBuilderHostTest, TestBasicIPCAndStopBuilding) {
|
| +TEST_F(BlobTransportHostTest, TestBasicIPCAndStopBuilding) {
|
| std::vector<DataElement> descriptions;
|
|
|
| AddMemoryItem(2, &descriptions);
|
| @@ -281,10 +288,9 @@ TEST_F(BlobAsyncBuilderHostTest, TestBasicIPCAndStopBuilding) {
|
| expected.AppendData(kCompletedBlobData);
|
| AddShortcutMemoryItem(2, &expected);
|
|
|
| - EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
|
| - BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
|
| - host_.CancelBuildingBlob(kBlobUUID, IPCBlobCreationCancelCode::UNKNOWN,
|
| - &context_);
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlobUUID, descriptions));
|
| + host_.CancelBuildingBlob(kBlobUUID, BlobStatus::ERR_OUT_OF_MEMORY, &context_);
|
|
|
| // Check that we're broken, and then remove the blob.
|
| std::unique_ptr<BlobDataHandle> blob_handle =
|
| @@ -298,8 +304,8 @@ TEST_F(BlobAsyncBuilderHostTest, TestBasicIPCAndStopBuilding) {
|
| EXPECT_FALSE(blob_handle.get());
|
|
|
| // This should succeed because we've removed all references to the blob.
|
| - EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
|
| - BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlobUUID, descriptions));
|
|
|
| EXPECT_TRUE(request_called_);
|
| EXPECT_EQ(1u, host_.blob_building_count());
|
| @@ -311,7 +317,7 @@ TEST_F(BlobAsyncBuilderHostTest, TestBasicIPCAndStopBuilding) {
|
| PopulateBytes(response2.allocate_mutable_data(2), 2);
|
| std::vector<BlobItemBytesResponse> responses = {response1, response2};
|
|
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| + EXPECT_EQ(BlobStatus::DONE,
|
| host_.OnMemoryResponses(kBlobUUID, responses, &context_));
|
| EXPECT_FALSE(request_called_);
|
| EXPECT_EQ(0u, host_.blob_building_count());
|
| @@ -322,30 +328,22 @@ TEST_F(BlobAsyncBuilderHostTest, TestBasicIPCAndStopBuilding) {
|
| EXPECT_EQ(expected, *blob_data);
|
| };
|
|
|
| -TEST_F(BlobAsyncBuilderHostTest, TestBreakingAllBuilding) {
|
| +TEST_F(BlobTransportHostTest, TestBreakingAllBuilding) {
|
| const std::string& kBlob1 = "blob1";
|
| const std::string& kBlob2 = "blob2";
|
| const std::string& kBlob3 = "blob3";
|
|
|
| - // Register blobs.
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition,
|
| - std::set<std::string>(), &context_));
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
|
| - std::set<std::string>(), &context_));
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kBlob3, kContentType, kContentDisposition,
|
| - std::set<std::string>(), &context_));
|
| -
|
| - // Start building one of them.
|
| std::vector<DataElement> descriptions;
|
| AddMemoryItem(2, &descriptions);
|
| - EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
|
| - host_.StartBuildingBlob(
|
| - kBlob1, descriptions, 2, &context_,
|
| - base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
|
| - base::Unretained(this))));
|
| +
|
| + // Register blobs.
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlob1, descriptions));
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlob2, descriptions));
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlob3, descriptions));
|
| +
|
| EXPECT_TRUE(request_called_);
|
|
|
| std::unique_ptr<BlobDataHandle> blob_handle1 =
|
| @@ -371,19 +369,19 @@ TEST_F(BlobAsyncBuilderHostTest, TestBreakingAllBuilding) {
|
| base::RunLoop().RunUntilIdle();
|
| };
|
|
|
| -TEST_F(BlobAsyncBuilderHostTest, TestBadIPCs) {
|
| +TEST_F(BlobTransportHostTest, TestBadIPCs) {
|
| std::vector<DataElement> descriptions;
|
|
|
| // Test reusing same blob uuid.
|
| AddMemoryItem(10, &descriptions);
|
| AddBlobItem(&descriptions);
|
| - AddMemoryItem(5000, &descriptions);
|
| - EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
|
| - BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
|
| - EXPECT_EQ(BlobTransportResult::BAD_IPC,
|
| - BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
|
| + AddMemoryItem(300, &descriptions);
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlobUUID, descriptions));
|
| + EXPECT_EQ(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS,
|
| + BuildBlobAsync(kBlobUUID, descriptions));
|
| EXPECT_FALSE(request_called_);
|
| - host_.CancelBuildingBlob(kBlobUUID, IPCBlobCreationCancelCode::UNKNOWN,
|
| + host_.CancelBuildingBlob(kBlobUUID, BlobStatus::ERR_REFERENCED_BLOB_BROKEN,
|
| &context_);
|
| base::RunLoop().RunUntilIdle();
|
| DecrementBlobRefCount(kBlobUUID);
|
| @@ -392,12 +390,12 @@ TEST_F(BlobAsyncBuilderHostTest, TestBadIPCs) {
|
| // Test we're an error if we get a bad uuid for responses.
|
| BlobItemBytesResponse response(0);
|
| std::vector<BlobItemBytesResponse> responses = {response};
|
| - EXPECT_EQ(BlobTransportResult::BAD_IPC,
|
| + EXPECT_EQ(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS,
|
| host_.OnMemoryResponses(kBlobUUID, responses, &context_));
|
|
|
| // Test empty responses.
|
| responses.clear();
|
| - EXPECT_EQ(BlobTransportResult::BAD_IPC,
|
| + EXPECT_EQ(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS,
|
| host_.OnMemoryResponses(kBlobUUID, responses, &context_));
|
|
|
| // Test response problems below here.
|
| @@ -405,76 +403,76 @@ TEST_F(BlobAsyncBuilderHostTest, TestBadIPCs) {
|
| AddMemoryItem(2, &descriptions);
|
| AddBlobItem(&descriptions);
|
| AddMemoryItem(2, &descriptions);
|
| - EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
|
| - BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlobUUID, descriptions));
|
|
|
| // Invalid request number.
|
| BlobItemBytesResponse response1(3);
|
| PopulateBytes(response1.allocate_mutable_data(2), 2);
|
| responses = {response1};
|
| - EXPECT_EQ(BlobTransportResult::BAD_IPC,
|
| + EXPECT_EQ(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS,
|
| host_.OnMemoryResponses(kBlobUUID, responses, &context_));
|
| EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlobUUID)->IsBroken());
|
| DecrementBlobRefCount(kBlobUUID);
|
| base::RunLoop().RunUntilIdle();
|
|
|
| // Duplicate request number responses.
|
| - EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
|
| - BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlobUUID, descriptions));
|
| response1.request_number = 0;
|
| BlobItemBytesResponse response2(0);
|
| PopulateBytes(response2.allocate_mutable_data(2), 2);
|
| responses = {response1, response2};
|
| - EXPECT_EQ(BlobTransportResult::BAD_IPC,
|
| + EXPECT_EQ(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS,
|
| host_.OnMemoryResponses(kBlobUUID, responses, &context_));
|
| EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlobUUID)->IsBroken());
|
| DecrementBlobRefCount(kBlobUUID);
|
| base::RunLoop().RunUntilIdle();
|
| };
|
|
|
| -TEST_F(BlobAsyncBuilderHostTest, WaitOnReferencedBlob) {
|
| +TEST_F(BlobTransportHostTest, WaitOnReferencedBlob) {
|
| const std::string& kBlob1 = "blob1";
|
| const std::string& kBlob2 = "blob2";
|
| const std::string& kBlob3 = "blob3";
|
|
|
| + std::vector<DataElement> descriptions;
|
| + AddMemoryItem(2, &descriptions);
|
| +
|
| // Register blobs.
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition,
|
| - std::set<std::string>(), &context_));
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
|
| - std::set<std::string>(), &context_));
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kBlob3, kContentType, kContentDisposition,
|
| - {kBlob1, kBlob2}, &context_));
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlob1, descriptions));
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlob2, descriptions));
|
| + EXPECT_TRUE(request_called_);
|
| + request_called_ = false;
|
|
|
| // Finish the third one, with a reference to the first and second blob.
|
| - std::vector<DataElement> descriptions;
|
| - AddShortcutMemoryItem(2, &descriptions);
|
| DataElement element;
|
| element.SetToBlob(kBlob1);
|
| descriptions.push_back(element);
|
| element.SetToBlob(kBlob2);
|
| descriptions.push_back(element);
|
|
|
| + EXPECT_EQ(BlobStatus::PENDING_TRANSPORT,
|
| + BuildBlobAsync(kBlob3, descriptions));
|
| + EXPECT_TRUE(request_called_);
|
| + request_called_ = false;
|
| +
|
| // Finish the third, but we should still be 'building' it.
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.StartBuildingBlob(
|
| - kBlob3, descriptions, 2, &context_,
|
| - base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
|
| - base::Unretained(this))));
|
| + BlobItemBytesResponse response1(0);
|
| + PopulateBytes(response1.allocate_mutable_data(2), 2);
|
| + std::vector<BlobItemBytesResponse> responses = {response1};
|
| + EXPECT_EQ(BlobStatus::DONE,
|
| + host_.OnMemoryResponses(kBlob3, responses, &context_));
|
| EXPECT_FALSE(request_called_);
|
| - EXPECT_TRUE(host_.IsBeingBuilt(kBlob3));
|
| + EXPECT_FALSE(host_.IsBeingBuilt(kBlob3));
|
| EXPECT_TRUE(IsBeingBuiltInContext(kBlob3));
|
|
|
| // Finish the first.
|
| descriptions.clear();
|
| AddShortcutMemoryItem(2, &descriptions);
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.StartBuildingBlob(
|
| - kBlob1, descriptions, 2, &context_,
|
| - base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
|
| - base::Unretained(this))));
|
| + EXPECT_EQ(BlobStatus::DONE,
|
| + host_.OnMemoryResponses(kBlob1, responses, &context_));
|
| EXPECT_FALSE(request_called_);
|
| EXPECT_FALSE(host_.IsBeingBuilt(kBlob1));
|
| EXPECT_FALSE(IsBeingBuiltInContext(kBlob1));
|
| @@ -483,15 +481,11 @@ TEST_F(BlobAsyncBuilderHostTest, WaitOnReferencedBlob) {
|
| // Run the message loop so we propogate the construction complete callbacks.
|
| base::RunLoop().RunUntilIdle();
|
| // Verify we're not done.
|
| - EXPECT_TRUE(host_.IsBeingBuilt(kBlob3));
|
| EXPECT_TRUE(IsBeingBuiltInContext(kBlob3));
|
|
|
| // Finish the second.
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.StartBuildingBlob(
|
| - kBlob2, descriptions, 2, &context_,
|
| - base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
|
| - base::Unretained(this))));
|
| + EXPECT_EQ(BlobStatus::DONE,
|
| + host_.OnMemoryResponses(kBlob2, responses, &context_));
|
| EXPECT_FALSE(request_called_);
|
| EXPECT_FALSE(host_.IsBeingBuilt(kBlob2));
|
| EXPECT_FALSE(IsBeingBuiltInContext(kBlob2));
|
| @@ -505,113 +499,4 @@ TEST_F(BlobAsyncBuilderHostTest, WaitOnReferencedBlob) {
|
| EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob3));
|
| };
|
|
|
| -TEST_F(BlobAsyncBuilderHostTest, IncorrectBlobDependencies) {
|
| - const std::string& kGoodBlob = "goodBlob";
|
| - const std::string& kBlob1 = "blob1";
|
| - const std::string& kBlob2 = "blob2";
|
| - const std::string& kBlob3 = "blob3";
|
| -
|
| - // Register blobs. Blob 1 has a reference to itself, Blob 2 has a reference
|
| - // but doesn't use it, and blob 3 doesn't list it's reference.
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kGoodBlob, kContentType, kContentDisposition,
|
| - std::set<std::string>(), &context_));
|
| - EXPECT_EQ(BlobTransportResult::BAD_IPC,
|
| - host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition,
|
| - {kBlob1}, &context_));
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
|
| - {kGoodBlob}, &context_));
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kBlob3, kContentType, kContentDisposition,
|
| - std::set<std::string>(), &context_));
|
| -
|
| - // The first blob shouldn't be building anymore.
|
| - EXPECT_FALSE(host_.IsBeingBuilt(kBlob1));
|
| -
|
| - // Try to finish the second one, without a reference to the first.
|
| - std::vector<DataElement> descriptions;
|
| - AddShortcutMemoryItem(2, &descriptions);
|
| - EXPECT_EQ(BlobTransportResult::BAD_IPC,
|
| - host_.StartBuildingBlob(
|
| - kBlob2, descriptions, 2, &context_,
|
| - base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
|
| - base::Unretained(this))));
|
| - EXPECT_FALSE(host_.IsBeingBuilt(kBlob2));
|
| -
|
| - // Try to finish the third one with the reference we didn't declare earlier.
|
| - descriptions.clear();
|
| - AddShortcutMemoryItem(2, &descriptions);
|
| - DataElement element;
|
| - element.SetToBlob(kGoodBlob);
|
| - descriptions.push_back(element);
|
| - EXPECT_EQ(BlobTransportResult::BAD_IPC,
|
| - host_.StartBuildingBlob(
|
| - kBlob3, descriptions, 2, &context_,
|
| - base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
|
| - base::Unretained(this))));
|
| - EXPECT_FALSE(host_.IsBeingBuilt(kBlob3));
|
| -};
|
| -
|
| -TEST_F(BlobAsyncBuilderHostTest, BlobBreaksWhenReferenceBreaks) {
|
| - const std::string& kBlob1 = "blob1";
|
| - const std::string& kBlob2 = "blob2";
|
| -
|
| - // Register blobs.
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition,
|
| - std::set<std::string>(), &context_));
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
|
| - {kBlob1}, &context_));
|
| -
|
| - // Finish the second one, with a reference to the first.
|
| - std::vector<DataElement> descriptions;
|
| - AddShortcutMemoryItem(2, &descriptions);
|
| - DataElement element;
|
| - element.SetToBlob(kBlob1);
|
| - descriptions.push_back(element);
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.StartBuildingBlob(
|
| - kBlob2, descriptions, 2, &context_,
|
| - base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
|
| - base::Unretained(this))));
|
| - EXPECT_FALSE(request_called_);
|
| - EXPECT_TRUE(host_.IsBeingBuilt(kBlob2));
|
| - EXPECT_TRUE(IsBeingBuiltInContext(kBlob2));
|
| -
|
| - // Break the first.
|
| - descriptions.clear();
|
| - host_.CancelBuildingBlob(kBlob1, IPCBlobCreationCancelCode::UNKNOWN,
|
| - &context_);
|
| - EXPECT_FALSE(host_.IsBeingBuilt(kBlob1));
|
| - EXPECT_FALSE(IsBeingBuiltInContext(kBlob1));
|
| - EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob1)->IsBroken());
|
| -
|
| - // Run the message loop so we propogate the construction complete callbacks.
|
| - base::RunLoop().RunUntilIdle();
|
| - // We should be finished with third blob, and it should be broken.
|
| - EXPECT_FALSE(host_.IsBeingBuilt(kBlob2));
|
| - EXPECT_FALSE(IsBeingBuiltInContext(kBlob2));
|
| - EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob2)->IsBroken());
|
| -};
|
| -
|
| -TEST_F(BlobAsyncBuilderHostTest, BlobBreaksWhenReferenceBroken) {
|
| - const std::string& kBlob1 = "blob1";
|
| - const std::string& kBlob2 = "blob2";
|
| -
|
| - // Register blobs.
|
| - EXPECT_EQ(BlobTransportResult::DONE,
|
| - host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition,
|
| - std::set<std::string>(), &context_));
|
| - host_.CancelBuildingBlob(kBlob1, IPCBlobCreationCancelCode::UNKNOWN,
|
| - &context_);
|
| - EXPECT_EQ(BlobTransportResult::CANCEL_REFERENCED_BLOB_BROKEN,
|
| - host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
|
| - {kBlob1}, &context_));
|
| - EXPECT_FALSE(host_.IsBeingBuilt(kBlob2));
|
| - EXPECT_FALSE(IsBeingBuiltInContext(kBlob2));
|
| - EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob2)->IsBroken());
|
| -};
|
| -
|
| } // namespace storage
|
|
|