| Index: content/browser/blob_storage/blob_async_builder_host_unittest.cc
|
| diff --git a/content/browser/blob_storage/blob_async_builder_host_unittest.cc b/content/browser/blob_storage/blob_async_builder_host_unittest.cc
|
| index 31cdc6676c39d2e8d9d6f7cd0cd9bd567c804eb0..4c29109371d70620e484c3933326a4e937c97291 100644
|
| --- a/content/browser/blob_storage/blob_async_builder_host_unittest.cc
|
| +++ b/content/browser/blob_storage/blob_async_builder_host_unittest.cc
|
| @@ -29,6 +29,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) {
|
| @@ -67,49 +71,57 @@ void AddBlobItem(std::vector<DataElement>* out) {
|
| class BlobAsyncBuilderHostTest : public testing::Test {
|
| public:
|
| BlobAsyncBuilderHostTest()
|
| - : cancel_code_(IPCBlobCreationCancelCode::UNKNOWN),
|
| + : status_code_(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS),
|
| request_called_(false) {}
|
| ~BlobAsyncBuilderHostTest() 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_,
|
| + status_called_ = false;
|
| + host_.RegisterBlob(
|
| + uuid, kContentType, kContentDisposition, descriptions, &context_,
|
| base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
|
| + base::Unretained(this)),
|
| + base::Bind(&BlobAsyncBuilderHostTest::StatusCallback,
|
| base::Unretained(this)));
|
| + if (status_called_)
|
| + return status_code_;
|
| + else
|
| + return context_.GetBlobStatus(uuid);
|
| }
|
|
|
| void DecrementBlobRefCount(const std::string& uuid) {
|
| @@ -117,19 +129,18 @@ 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_;
|
| + 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_;
|
| };
|
|
|
| @@ -140,24 +151,23 @@ TEST_F(BlobAsyncBuilderHostTest, TestShortcut) {
|
|
|
| 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();
|
| @@ -172,8 +182,8 @@ TEST_F(BlobAsyncBuilderHostTest, TestShortcutNoRoom) {
|
| 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());
|
| @@ -184,9 +194,8 @@ TEST_F(BlobAsyncBuilderHostTest, TestSingleSharedMemRequest) {
|
| 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());
|
| @@ -213,9 +222,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 +247,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 +263,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());
|
| @@ -281,10 +289,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 +305,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 +318,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());
|
| @@ -327,25 +334,17 @@ TEST_F(BlobAsyncBuilderHostTest, TestBreakingAllBuilding) {
|
| 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 =
|
| @@ -377,13 +376,13 @@ TEST_F(BlobAsyncBuilderHostTest, TestBadIPCs) {
|
| // 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 +391,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,27 +404,27 @@ 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);
|
| @@ -437,44 +436,44 @@ TEST_F(BlobAsyncBuilderHostTest, WaitOnReferencedBlob) {
|
| 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 +482,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 +500,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
|
|
|