| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/blob_storage/blob_dispatcher_host.h" | 5 #include "content/browser/blob_storage/blob_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 15 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 15 #include "content/common/fileapi/webblob_messages.h" | 16 #include "content/common/fileapi/webblob_messages.h" |
| 16 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/test/test_browser_context.h" | 18 #include "content/public/test/test_browser_context.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 19 #include "content/public/test/test_file_system_context.h" | 20 #include "content/public/test/test_file_system_context.h" |
| 20 #include "ipc/ipc_sender.h" | 21 #include "ipc/ipc_sender.h" |
| 21 #include "ipc/ipc_test_sink.h" | 22 #include "ipc/ipc_test_sink.h" |
| 22 #include "ipc/message_filter.h" | 23 #include "ipc/message_filter.h" |
| 23 #include "storage/browser/blob/blob_data_builder.h" | 24 #include "storage/browser/blob/blob_data_builder.h" |
| 24 #include "storage/browser/blob/blob_data_handle.h" | 25 #include "storage/browser/blob/blob_data_handle.h" |
| 25 #include "storage/browser/blob/blob_storage_context.h" | 26 #include "storage/browser/blob/blob_storage_context.h" |
| 26 #include "storage/common/blob_storage/blob_item_bytes_request.h" | 27 #include "storage/common/blob_storage/blob_item_bytes_request.h" |
| 27 #include "storage/common/blob_storage/blob_item_bytes_response.h" | 28 #include "storage/common/blob_storage/blob_item_bytes_response.h" |
| 28 #include "storage/common/data_element.h" | 29 #include "storage/common/data_element.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 32 |
| 32 using storage::BlobDataBuilder; | 33 using storage::BlobDataBuilder; |
| 33 using storage::BlobDataHandle; | 34 using storage::BlobDataHandle; |
| 34 using storage::BlobItemBytesRequest; | 35 using storage::BlobItemBytesRequest; |
| 35 using storage::BlobItemBytesResponse; | 36 using storage::BlobItemBytesResponse; |
| 37 using storage::BlobStatus; |
| 36 using storage::BlobStorageContext; | 38 using storage::BlobStorageContext; |
| 37 using storage::BlobTransportResult; | |
| 38 using storage::DataElement; | 39 using storage::DataElement; |
| 39 using storage::IPCBlobCreationCancelCode; | |
| 40 using RequestMemoryCallback = | 40 using RequestMemoryCallback = |
| 41 storage::BlobAsyncBuilderHost::RequestMemoryCallback; | 41 storage::BlobTransportHost::RequestMemoryCallback; |
| 42 | 42 |
| 43 namespace content { | 43 namespace content { |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 const char kContentType[] = "text/plain"; | 46 const char kContentType[] = "text/plain"; |
| 47 const char kContentDisposition[] = "content_disposition"; | 47 const char kContentDisposition[] = "content_disposition"; |
| 48 const char kData[] = "data!!"; | 48 const char kData[] = "data!!"; |
| 49 const size_t kDataSize = 6; | 49 const size_t kDataSize = 6; |
| 50 | 50 |
| 51 const size_t kTestBlobStorageIPCThresholdBytes = 20; | 51 const size_t kTestBlobStorageIPCThresholdBytes = 20; |
| 52 const size_t kTestBlobStorageMaxSharedMemoryBytes = 50; | 52 const size_t kTestBlobStorageMaxSharedMemoryBytes = 50; |
| 53 const size_t kTestBlobStorageMaxBlobMemorySize = 400; |
| 54 const uint64_t kTestBlobStorageMaxDiskSpace = 1000; |
| 55 const uint64_t kTestBlobStorageMinFileSizeBytes = 10; |
| 53 const uint64_t kTestBlobStorageMaxFileSizeBytes = 100; | 56 const uint64_t kTestBlobStorageMaxFileSizeBytes = 100; |
| 54 | 57 |
| 55 void ConstructionCompletePopulator(bool* succeeded_pointer, | 58 void ConstructionCompletePopulator(bool* success_pointer, |
| 56 IPCBlobCreationCancelCode* reason_pointer, | 59 BlobStatus* reason_pointer, |
| 57 bool succeeded, | 60 BlobStatus reason) { |
| 58 IPCBlobCreationCancelCode reason) { | |
| 59 *succeeded_pointer = succeeded; | |
| 60 *reason_pointer = reason; | 61 *reason_pointer = reason; |
| 62 *success_pointer = reason == BlobStatus::DONE; |
| 61 } | 63 } |
| 62 | 64 |
| 63 // TODO(dmurph): Create file test that verifies security policy. | 65 // TODO(dmurph): Create file test that verifies security policy. |
| 64 class TestableBlobDispatcherHost : public BlobDispatcherHost { | 66 class TestableBlobDispatcherHost : public BlobDispatcherHost { |
| 65 public: | 67 public: |
| 66 TestableBlobDispatcherHost(ChromeBlobStorageContext* blob_storage_context, | 68 TestableBlobDispatcherHost(ChromeBlobStorageContext* blob_storage_context, |
| 67 storage::FileSystemContext* file_system_context, | 69 storage::FileSystemContext* file_system_context, |
| 68 IPC::TestSink* sink) | 70 IPC::TestSink* sink) |
| 69 : BlobDispatcherHost(0 /* process_id */, | 71 : BlobDispatcherHost(0 /* process_id */, |
| 70 make_scoped_refptr(blob_storage_context), | 72 make_scoped_refptr(blob_storage_context), |
| 71 make_scoped_refptr(file_system_context)), | 73 make_scoped_refptr(file_system_context)), |
| 72 sink_(sink) { | 74 sink_(sink) {} |
| 73 this->SetMemoryConstantsForTesting(kTestBlobStorageIPCThresholdBytes, | |
| 74 kTestBlobStorageMaxSharedMemoryBytes, | |
| 75 kTestBlobStorageMaxFileSizeBytes); | |
| 76 } | |
| 77 | 75 |
| 78 bool Send(IPC::Message* message) override { return sink_->Send(message); } | 76 bool Send(IPC::Message* message) override { return sink_->Send(message); } |
| 79 | 77 |
| 80 void ShutdownForBadMessage() override { shutdown_for_bad_message_ = true; } | 78 void ShutdownForBadMessage() override { shutdown_for_bad_message_ = true; } |
| 81 | 79 |
| 82 bool shutdown_for_bad_message_ = false; | 80 bool shutdown_for_bad_message_ = false; |
| 83 | 81 |
| 84 protected: | 82 protected: |
| 85 ~TestableBlobDispatcherHost() override {} | 83 ~TestableBlobDispatcherHost() override {} |
| 86 | 84 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 105 ~BlobDispatcherHostTest() override {} | 103 ~BlobDispatcherHostTest() override {} |
| 106 | 104 |
| 107 void SetUp() override { | 105 void SetUp() override { |
| 108 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 106 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 109 if (!command_line->HasSwitch(switches::kDisableKillAfterBadIPC)) { | 107 if (!command_line->HasSwitch(switches::kDisableKillAfterBadIPC)) { |
| 110 command_line->AppendSwitch(switches::kDisableKillAfterBadIPC); | 108 command_line->AppendSwitch(switches::kDisableKillAfterBadIPC); |
| 111 } | 109 } |
| 112 // We run the run loop to initialize the chrome blob storage context. | 110 // We run the run loop to initialize the chrome blob storage context. |
| 113 base::RunLoop().RunUntilIdle(); | 111 base::RunLoop().RunUntilIdle(); |
| 114 context_ = chrome_blob_storage_context_->context(); | 112 context_ = chrome_blob_storage_context_->context(); |
| 115 DCHECK(context_); | 113 ASSERT_TRUE(context_); |
| 114 |
| 115 storage::BlobStorageLimits limits; |
| 116 limits.max_ipc_memory_size = kTestBlobStorageIPCThresholdBytes; |
| 117 limits.max_shared_memory_size = kTestBlobStorageMaxSharedMemoryBytes; |
| 118 limits.max_blob_in_memory_space = kTestBlobStorageMaxBlobMemorySize; |
| 119 limits.max_blob_disk_space = kTestBlobStorageMaxDiskSpace; |
| 120 limits.min_page_file_size = kTestBlobStorageMinFileSizeBytes; |
| 121 limits.max_file_size = kTestBlobStorageMaxFileSizeBytes; |
| 122 context_->mutable_memory_controller()->set_limits_for_testing(limits); |
| 116 } | 123 } |
| 117 | 124 |
| 118 void ExpectBlobNotExist(const std::string& id) { | 125 void ExpectBlobNotExist(const std::string& id) { |
| 119 EXPECT_FALSE(context_->registry().HasEntry(id)); | 126 EXPECT_FALSE(context_->registry().HasEntry(id)); |
| 120 EXPECT_FALSE(host_->IsInUseInHost(id)); | 127 EXPECT_FALSE(host_->IsInUseInHost(id)); |
| 121 EXPECT_FALSE(IsBeingBuiltInHost(id)); | 128 EXPECT_FALSE(IsBeingBuiltInHost(id)); |
| 122 } | 129 } |
| 123 | 130 |
| 124 void AsyncShortcutBlobTransfer(const std::string& id) { | 131 void AsyncShortcutBlobTransfer(const std::string& id) { |
| 125 sink_.ClearMessages(); | 132 sink_.ClearMessages(); |
| 126 ExpectBlobNotExist(id); | 133 ExpectBlobNotExist(id); |
| 127 host_->OnRegisterBlobUUID(id, std::string(kContentType), | |
| 128 std::string(kContentDisposition), | |
| 129 std::set<std::string>()); | |
| 130 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 131 DataElement element; | 134 DataElement element; |
| 132 element.SetToBytes(kData, kDataSize); | 135 element.SetToBytes(kData, kDataSize); |
| 133 std::vector<DataElement> elements = {element}; | 136 std::vector<DataElement> elements = {element}; |
| 134 host_->OnStartBuildingBlob(id, elements); | 137 host_->OnRegisterBlob(id, std::string(kContentType), |
| 138 std::string(kContentDisposition), elements); |
| 135 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 139 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 136 ExpectDone(id); | 140 ExpectDone(id); |
| 137 sink_.ClearMessages(); | 141 sink_.ClearMessages(); |
| 138 } | 142 } |
| 139 | 143 |
| 140 void AsyncBlobTransfer(const std::string& id) { | 144 void AsyncBlobTransfer(const std::string& id) { |
| 141 sink_.ClearMessages(); | 145 sink_.ClearMessages(); |
| 142 ExpectBlobNotExist(id); | 146 ExpectBlobNotExist(id); |
| 143 host_->OnRegisterBlobUUID(id, std::string(kContentType), | |
| 144 std::string(kContentDisposition), | |
| 145 std::set<std::string>()); | |
| 146 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 147 DataElement element; | 147 DataElement element; |
| 148 element.SetToBytesDescription(kDataSize); | 148 element.SetToBytesDescription(kDataSize); |
| 149 std::vector<DataElement> elements = {element}; | 149 std::vector<DataElement> elements = {element}; |
| 150 host_->OnStartBuildingBlob(id, elements); | 150 host_->OnRegisterBlob(id, std::string(kContentType), |
| 151 std::string(kContentDisposition), elements); |
| 151 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 152 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 152 | 153 |
| 153 // Expect our request. | 154 // Expect our request. |
| 154 std::vector<BlobItemBytesRequest> expected_requests = { | 155 std::vector<BlobItemBytesRequest> expected_requests = { |
| 155 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; | 156 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; |
| 156 ExpectRequest(id, expected_requests); | 157 ExpectRequest(id, expected_requests); |
| 157 sink_.ClearMessages(); | 158 sink_.ClearMessages(); |
| 158 | 159 |
| 159 // Send results; | 160 // Send results; |
| 160 BlobItemBytesResponse response(0); | 161 BlobItemBytesResponse response(0); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 180 const DataElement& actual = snapshot->items()[i]->data_element(); | 181 const DataElement& actual = snapshot->items()[i]->data_element(); |
| 181 EXPECT_EQ(expected, actual); | 182 EXPECT_EQ(expected, actual); |
| 182 } | 183 } |
| 183 EXPECT_EQ(data.size(), snapshot->items().size()); | 184 EXPECT_EQ(data.size(), snapshot->items().size()); |
| 184 } | 185 } |
| 185 | 186 |
| 186 void ExpectRequest( | 187 void ExpectRequest( |
| 187 const std::string& expected_uuid, | 188 const std::string& expected_uuid, |
| 188 const std::vector<BlobItemBytesRequest>& expected_requests) { | 189 const std::vector<BlobItemBytesRequest>& expected_requests) { |
| 189 EXPECT_FALSE( | 190 EXPECT_FALSE( |
| 190 sink_.GetFirstMessageMatching(BlobStorageMsg_DoneBuildingBlob::ID)); | 191 sink_.GetFirstMessageMatching(BlobStorageMsg_SendBlobStatus::ID)); |
| 191 EXPECT_FALSE( | |
| 192 sink_.GetFirstMessageMatching(BlobStorageMsg_CancelBuildingBlob::ID)); | |
| 193 const IPC::Message* message = | 192 const IPC::Message* message = |
| 194 sink_.GetUniqueMessageMatching(BlobStorageMsg_RequestMemoryItem::ID); | 193 sink_.GetUniqueMessageMatching(BlobStorageMsg_RequestMemoryItem::ID); |
| 195 ASSERT_TRUE(message); | 194 ASSERT_TRUE(message); |
| 196 std::tuple<std::string, std::vector<storage::BlobItemBytesRequest>, | 195 std::tuple<std::string, std::vector<storage::BlobItemBytesRequest>, |
| 197 std::vector<base::SharedMemoryHandle>, | 196 std::vector<base::SharedMemoryHandle>, |
| 198 std::vector<IPC::PlatformFileForTransit>> | 197 std::vector<IPC::PlatformFileForTransit>> |
| 199 args; | 198 args; |
| 200 BlobStorageMsg_RequestMemoryItem::Read(message, &args); | 199 BlobStorageMsg_RequestMemoryItem::Read(message, &args); |
| 201 EXPECT_EQ(expected_uuid, std::get<0>(args)); | 200 EXPECT_EQ(expected_uuid, std::get<0>(args)); |
| 202 std::vector<BlobItemBytesRequest> requests = std::get<1>(args); | 201 std::vector<BlobItemBytesRequest> requests = std::get<1>(args); |
| 203 ASSERT_EQ(requests.size(), expected_requests.size()); | 202 ASSERT_EQ(requests.size(), expected_requests.size()); |
| 204 for (size_t i = 0; i < expected_requests.size(); ++i) { | 203 for (size_t i = 0; i < expected_requests.size(); ++i) { |
| 205 EXPECT_EQ(expected_requests[i], requests[i]); | 204 EXPECT_EQ(expected_requests[i], requests[i]); |
| 206 } | 205 } |
| 207 } | 206 } |
| 208 | 207 |
| 209 void ExpectRequestWithSharedMemoryHandles( | 208 void ExpectRequestWithSharedMemoryHandles( |
| 210 const std::string& expected_uuid, | 209 const std::string& expected_uuid, |
| 211 const std::vector<BlobItemBytesRequest>& expected_requests, | 210 const std::vector<BlobItemBytesRequest>& expected_requests, |
| 212 std::vector<base::SharedMemoryHandle>* shared_memory_handles) { | 211 std::vector<base::SharedMemoryHandle>* shared_memory_handles) { |
| 213 EXPECT_FALSE( | 212 EXPECT_FALSE( |
| 214 sink_.GetFirstMessageMatching(BlobStorageMsg_DoneBuildingBlob::ID)); | 213 sink_.GetFirstMessageMatching(BlobStorageMsg_SendBlobStatus::ID)); |
| 215 EXPECT_FALSE( | |
| 216 sink_.GetFirstMessageMatching(BlobStorageMsg_CancelBuildingBlob::ID)); | |
| 217 const IPC::Message* message = | 214 const IPC::Message* message = |
| 218 sink_.GetUniqueMessageMatching(BlobStorageMsg_RequestMemoryItem::ID); | 215 sink_.GetUniqueMessageMatching(BlobStorageMsg_RequestMemoryItem::ID); |
| 219 ASSERT_TRUE(message); | 216 ASSERT_TRUE(message); |
| 220 std::tuple<std::string, std::vector<storage::BlobItemBytesRequest>, | 217 std::tuple<std::string, std::vector<storage::BlobItemBytesRequest>, |
| 221 std::vector<base::SharedMemoryHandle>, | 218 std::vector<base::SharedMemoryHandle>, |
| 222 std::vector<IPC::PlatformFileForTransit>> | 219 std::vector<IPC::PlatformFileForTransit>> |
| 223 args; | 220 args; |
| 224 BlobStorageMsg_RequestMemoryItem::Read(message, &args); | 221 BlobStorageMsg_RequestMemoryItem::Read(message, &args); |
| 225 EXPECT_EQ(expected_uuid, std::get<0>(args)); | 222 EXPECT_EQ(expected_uuid, std::get<0>(args)); |
| 226 std::vector<BlobItemBytesRequest> requests = std::get<1>(args); | 223 std::vector<BlobItemBytesRequest> requests = std::get<1>(args); |
| 227 ASSERT_EQ(requests.size(), expected_requests.size()); | 224 ASSERT_EQ(requests.size(), expected_requests.size()); |
| 228 for (size_t i = 0; i < expected_requests.size(); ++i) { | 225 for (size_t i = 0; i < expected_requests.size(); ++i) { |
| 229 EXPECT_EQ(expected_requests[i], requests[i]); | 226 EXPECT_EQ(expected_requests[i], requests[i]); |
| 230 } | 227 } |
| 231 *shared_memory_handles = std::move(std::get<2>(args)); | 228 *shared_memory_handles = std::move(std::get<2>(args)); |
| 232 } | 229 } |
| 233 | 230 |
| 234 void ExpectCancel(const std::string& expected_uuid, | 231 void ExpectCancel(const std::string& expected_uuid, BlobStatus code) { |
| 235 IPCBlobCreationCancelCode code) { | |
| 236 EXPECT_FALSE( | 232 EXPECT_FALSE( |
| 237 sink_.GetFirstMessageMatching(BlobStorageMsg_RequestMemoryItem::ID)); | 233 sink_.GetFirstMessageMatching(BlobStorageMsg_RequestMemoryItem::ID)); |
| 238 EXPECT_FALSE( | |
| 239 sink_.GetFirstMessageMatching(BlobStorageMsg_DoneBuildingBlob::ID)); | |
| 240 const IPC::Message* message = | 234 const IPC::Message* message = |
| 241 sink_.GetUniqueMessageMatching(BlobStorageMsg_CancelBuildingBlob::ID); | 235 sink_.GetUniqueMessageMatching(BlobStorageMsg_SendBlobStatus::ID); |
| 242 ASSERT_TRUE(message); | 236 ASSERT_TRUE(message); |
| 243 std::tuple<std::string, IPCBlobCreationCancelCode> args; | 237 std::tuple<std::string, BlobStatus> args; |
| 244 BlobStorageMsg_CancelBuildingBlob::Read(message, &args); | 238 BlobStorageMsg_SendBlobStatus::Read(message, &args); |
| 245 EXPECT_EQ(expected_uuid, std::get<0>(args)); | 239 EXPECT_EQ(expected_uuid, std::get<0>(args)); |
| 246 EXPECT_EQ(code, std::get<1>(args)); | 240 EXPECT_EQ(code, std::get<1>(args)); |
| 247 } | 241 } |
| 248 | 242 |
| 249 void ExpectDone(const std::string& expected_uuid) { | 243 void ExpectDone(const std::string& expected_uuid) { |
| 250 EXPECT_FALSE( | 244 EXPECT_FALSE( |
| 251 sink_.GetFirstMessageMatching(BlobStorageMsg_RequestMemoryItem::ID)); | 245 sink_.GetFirstMessageMatching(BlobStorageMsg_RequestMemoryItem::ID)); |
| 252 EXPECT_FALSE( | |
| 253 sink_.GetFirstMessageMatching(BlobStorageMsg_CancelBuildingBlob::ID)); | |
| 254 const IPC::Message* message = | 246 const IPC::Message* message = |
| 255 sink_.GetUniqueMessageMatching(BlobStorageMsg_DoneBuildingBlob::ID); | 247 sink_.GetUniqueMessageMatching(BlobStorageMsg_SendBlobStatus::ID); |
| 256 std::tuple<std::string> args; | 248 ASSERT_TRUE(message); |
| 257 BlobStorageMsg_DoneBuildingBlob::Read(message, &args); | 249 std::tuple<std::string, BlobStatus> args; |
| 250 BlobStorageMsg_SendBlobStatus::Read(message, &args); |
| 258 EXPECT_EQ(expected_uuid, std::get<0>(args)); | 251 EXPECT_EQ(expected_uuid, std::get<0>(args)); |
| 252 EXPECT_EQ(BlobStatus::DONE, std::get<1>(args)); |
| 259 } | 253 } |
| 260 | 254 |
| 261 bool IsBeingBuiltInHost(const std::string& uuid) { | 255 bool IsBeingBuiltInHost(const std::string& uuid) { |
| 262 return host_->async_builder_.IsBeingBuilt(uuid); | 256 return host_->async_builder_.IsBeingBuilt(uuid); |
| 263 } | 257 } |
| 264 | 258 |
| 259 bool IsBeingBuiltInContext(const std::string& uuid) { |
| 260 return BlobStatusIsPending(context_->GetBlobStatus(uuid)); |
| 261 } |
| 262 |
| 265 IPC::TestSink sink_; | 263 IPC::TestSink sink_; |
| 266 TestBrowserThreadBundle browser_thread_bundle_; | 264 TestBrowserThreadBundle browser_thread_bundle_; |
| 267 TestBrowserContext browser_context_; | 265 TestBrowserContext browser_context_; |
| 268 ChromeBlobStorageContext* chrome_blob_storage_context_; | 266 ChromeBlobStorageContext* chrome_blob_storage_context_; |
| 269 BlobStorageContext* context_ = nullptr; | 267 BlobStorageContext* context_ = nullptr; |
| 270 scoped_refptr<storage::FileSystemContext> file_system_context_; | 268 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 271 scoped_refptr<TestableBlobDispatcherHost> host_; | 269 scoped_refptr<TestableBlobDispatcherHost> host_; |
| 272 }; | 270 }; |
| 273 | 271 |
| 274 TEST_F(BlobDispatcherHostTest, EmptyUUIDs) { | 272 TEST_F(BlobDispatcherHostTest, EmptyUUIDs) { |
| 275 host_->OnRegisterBlobUUID("", "", "", std::set<std::string>()); | 273 host_->OnRegisterBlob("", "", "", std::vector<DataElement>()); |
| 276 ExpectAndResetBadMessage(); | |
| 277 host_->OnStartBuildingBlob("", std::vector<DataElement>()); | |
| 278 ExpectAndResetBadMessage(); | 274 ExpectAndResetBadMessage(); |
| 279 host_->OnMemoryItemResponse("", std::vector<BlobItemBytesResponse>()); | 275 host_->OnMemoryItemResponse("", std::vector<BlobItemBytesResponse>()); |
| 280 ExpectAndResetBadMessage(); | 276 ExpectAndResetBadMessage(); |
| 281 host_->OnCancelBuildingBlob("", IPCBlobCreationCancelCode::UNKNOWN); | 277 host_->OnCancelBuildingBlob("", |
| 278 BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
| 282 ExpectAndResetBadMessage(); | 279 ExpectAndResetBadMessage(); |
| 283 } | 280 } |
| 284 | 281 |
| 285 TEST_F(BlobDispatcherHostTest, Shortcut) { | 282 TEST_F(BlobDispatcherHostTest, Shortcut) { |
| 286 const std::string kId = "uuid1"; | 283 const std::string kId = "uuid1"; |
| 287 AsyncShortcutBlobTransfer(kId); | 284 AsyncShortcutBlobTransfer(kId); |
| 288 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 285 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 289 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); | 286 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); |
| 290 EXPECT_TRUE(handle); | 287 EXPECT_TRUE(handle); |
| 291 | 288 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 304 | 301 |
| 305 DataElement expected; | 302 DataElement expected; |
| 306 expected.SetToBytes(kData, kDataSize); | 303 expected.SetToBytes(kData, kDataSize); |
| 307 std::vector<DataElement> elements = {expected}; | 304 std::vector<DataElement> elements = {expected}; |
| 308 ExpectHandleEqualsData(handle.get(), elements); | 305 ExpectHandleEqualsData(handle.get(), elements); |
| 309 } | 306 } |
| 310 | 307 |
| 311 TEST_F(BlobDispatcherHostTest, MultipleTransfers) { | 308 TEST_F(BlobDispatcherHostTest, MultipleTransfers) { |
| 312 const std::string kId = "uuid"; | 309 const std::string kId = "uuid"; |
| 313 const int kNumIters = 10; | 310 const int kNumIters = 10; |
| 311 sink_.ClearMessages(); |
| 314 for (int i = 0; i < kNumIters; i++) { | 312 for (int i = 0; i < kNumIters; i++) { |
| 315 std::string id = kId; | 313 std::string id = kId; |
| 316 id += ('0' + i); | 314 id += ('0' + i); |
| 317 ExpectBlobNotExist(id); | 315 ExpectBlobNotExist(id); |
| 318 host_->OnRegisterBlobUUID(id, std::string(kContentType), | |
| 319 std::string(kContentDisposition), | |
| 320 std::set<std::string>()); | |
| 321 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 322 } | |
| 323 sink_.ClearMessages(); | |
| 324 for (int i = 0; i < kNumIters; i++) { | |
| 325 std::string id = kId; | |
| 326 id += ('0' + i); | |
| 327 DataElement element; | 316 DataElement element; |
| 328 element.SetToBytesDescription(kDataSize); | 317 element.SetToBytesDescription(kDataSize); |
| 329 std::vector<DataElement> elements = {element}; | 318 std::vector<DataElement> elements = {element}; |
| 330 host_->OnStartBuildingBlob(id, elements); | 319 host_->OnRegisterBlob(id, std::string(kContentType), |
| 320 std::string(kContentDisposition), elements); |
| 331 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 321 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 332 // Expect our request. | 322 // Expect our request. |
| 333 std::vector<BlobItemBytesRequest> expected_requests = { | 323 std::vector<BlobItemBytesRequest> expected_requests = { |
| 334 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; | 324 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; |
| 335 ExpectRequest(id, expected_requests); | 325 ExpectRequest(id, expected_requests); |
| 336 sink_.ClearMessages(); | 326 sink_.ClearMessages(); |
| 337 } | 327 } |
| 338 for (int i = 0; i < kNumIters; i++) { | 328 for (int i = 0; i < kNumIters; i++) { |
| 339 std::string id = kId; | 329 std::string id = kId; |
| 340 id += ('0' + i); | 330 id += ('0' + i); |
| 341 // Send results; | 331 // Send results; |
| 342 BlobItemBytesResponse response(0); | 332 BlobItemBytesResponse response(0); |
| 343 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); | 333 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); |
| 344 std::vector<BlobItemBytesResponse> responses = {response}; | 334 std::vector<BlobItemBytesResponse> responses = {response}; |
| 345 host_->OnMemoryItemResponse(id, responses); | 335 host_->OnMemoryItemResponse(id, responses); |
| 346 ExpectDone(id); | 336 ExpectDone(id); |
| 347 sink_.ClearMessages(); | 337 sink_.ClearMessages(); |
| 348 } | 338 } |
| 349 } | 339 } |
| 350 | 340 |
| 351 TEST_F(BlobDispatcherHostTest, SharedMemoryTransfer) { | 341 TEST_F(BlobDispatcherHostTest, SharedMemoryTransfer) { |
| 352 const std::string kId = "uuid1"; | 342 const std::string kId = "uuid1"; |
| 353 const size_t kLargeSize = kTestBlobStorageMaxSharedMemoryBytes * 2; | 343 const size_t kLargeSize = kTestBlobStorageMaxSharedMemoryBytes * 2; |
| 354 std::vector<base::SharedMemoryHandle> shared_memory_handles; | 344 std::vector<base::SharedMemoryHandle> shared_memory_handles; |
| 355 | 345 |
| 356 ExpectBlobNotExist(kId); | 346 ExpectBlobNotExist(kId); |
| 357 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 347 DataElement element; |
| 358 std::string(kContentDisposition), | 348 element.SetToBytesDescription(kLargeSize); |
| 359 std::set<std::string>()); | 349 std::vector<DataElement> elements = {element}; |
| 350 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 351 std::string(kContentDisposition), elements); |
| 352 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 360 | 353 |
| 361 // Grab the handle. | 354 // Grab the handle. |
| 362 std::unique_ptr<BlobDataHandle> blob_data_handle = | 355 std::unique_ptr<BlobDataHandle> blob_data_handle = |
| 363 context_->GetBlobDataFromUUID(kId); | 356 context_->GetBlobDataFromUUID(kId); |
| 364 bool built = false; | 357 bool built = false; |
| 365 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 358 BlobStatus error_code = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS; |
| 366 blob_data_handle->RunOnConstructionComplete( | 359 blob_data_handle->RunOnConstructionComplete( |
| 367 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 360 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
| 368 EXPECT_FALSE(built); | 361 EXPECT_FALSE(built); |
| 369 | 362 |
| 370 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 363 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 371 DataElement element; | |
| 372 element.SetToBytesDescription(kLargeSize); | |
| 373 std::vector<DataElement> elements = {element}; | |
| 374 host_->OnStartBuildingBlob(kId, elements); | |
| 375 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 376 | 364 |
| 377 // Expect our first request. | 365 // Expect our first request. |
| 378 std::vector<BlobItemBytesRequest> expected_requests = { | 366 std::vector<BlobItemBytesRequest> expected_requests = { |
| 379 BlobItemBytesRequest::CreateSharedMemoryRequest( | 367 BlobItemBytesRequest::CreateSharedMemoryRequest( |
| 380 0 /* request_number */, 0 /* renderer_item_index */, | 368 0 /* request_number */, 0 /* renderer_item_index */, |
| 381 0 /* renderer_item_offset */, | 369 0 /* renderer_item_offset */, |
| 382 static_cast<uint64_t>( | 370 static_cast<uint64_t>( |
| 383 kTestBlobStorageMaxSharedMemoryBytes) /* size */, | 371 kTestBlobStorageMaxSharedMemoryBytes) /* size */, |
| 384 0 /* handle_index */, 0 /* handle_offset */)}; | 372 0 /* handle_index */, 0 /* handle_offset */)}; |
| 385 ExpectRequestWithSharedMemoryHandles(kId, expected_requests, | 373 ExpectRequestWithSharedMemoryHandles(kId, expected_requests, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 elements = {expected}; | 428 elements = {expected}; |
| 441 std::memset(expected.mutable_bytes(), 'Z', kLargeSize / 2); | 429 std::memset(expected.mutable_bytes(), 'Z', kLargeSize / 2); |
| 442 elements.push_back(expected); | 430 elements.push_back(expected); |
| 443 ExpectHandleEqualsData(handle.get(), elements); | 431 ExpectHandleEqualsData(handle.get(), elements); |
| 444 } | 432 } |
| 445 | 433 |
| 446 TEST_F(BlobDispatcherHostTest, OnCancelBuildingBlob) { | 434 TEST_F(BlobDispatcherHostTest, OnCancelBuildingBlob) { |
| 447 const std::string kId("id"); | 435 const std::string kId("id"); |
| 448 // We ignore blobs that are unknown, as it could have been cancelled earlier | 436 // We ignore blobs that are unknown, as it could have been cancelled earlier |
| 449 // and the renderer didn't know about it yet. | 437 // and the renderer didn't know about it yet. |
| 450 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); | 438 host_->OnCancelBuildingBlob(kId, |
| 439 BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
| 451 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 440 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 452 | 441 |
| 453 // Start building blob. | 442 // Start building blob. |
| 454 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | |
| 455 std::string(kContentDisposition), | |
| 456 std::set<std::string>()); | |
| 457 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 458 DataElement element; | 443 DataElement element; |
| 459 element.SetToBytesDescription(kDataSize); | 444 element.SetToBytesDescription(kDataSize); |
| 460 std::vector<DataElement> elements = {element}; | 445 std::vector<DataElement> elements = {element}; |
| 461 host_->OnStartBuildingBlob(kId, elements); | 446 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 447 std::string(kContentDisposition), elements); |
| 462 // It should have requested memory here. | 448 // It should have requested memory here. |
| 463 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 449 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 464 sink_.ClearMessages(); | 450 sink_.ClearMessages(); |
| 465 | 451 |
| 466 // Cancel in middle of construction. | 452 // Cancel in middle of construction. |
| 467 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); | 453 host_->OnCancelBuildingBlob(kId, |
| 454 BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
| 468 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 455 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 469 EXPECT_TRUE(host_->IsInUseInHost(kId)); | 456 EXPECT_TRUE(host_->IsInUseInHost(kId)); |
| 470 EXPECT_FALSE(IsBeingBuiltInHost(kId)); | 457 EXPECT_FALSE(IsBeingBuiltInHost(kId)); |
| 471 // Check that's it's broken. | 458 // Check that's it's broken. |
| 472 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); | 459 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); |
| 473 EXPECT_TRUE(handle->IsBroken()); | 460 EXPECT_TRUE(handle->IsBroken()); |
| 474 handle.reset(); | 461 handle.reset(); |
| 475 base::RunLoop().RunUntilIdle(); | 462 base::RunLoop().RunUntilIdle(); |
| 476 | 463 |
| 477 // Get rid of it in the host. | 464 // Get rid of it in the host. |
| 478 host_->OnDecrementBlobRefCount(kId); | 465 host_->OnDecrementBlobRefCount(kId); |
| 479 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 466 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 480 ExpectBlobNotExist(kId); | 467 ExpectBlobNotExist(kId); |
| 481 | 468 |
| 482 // Create blob again to verify we don't have any old construction state lying | 469 // Create blob again to verify we don't have any old construction state lying |
| 483 // around. | 470 // around. |
| 484 AsyncBlobTransfer(kId); | 471 AsyncBlobTransfer(kId); |
| 485 | 472 |
| 486 // Check data. | 473 // Check data. |
| 487 handle = context_->GetBlobDataFromUUID(kId); | 474 handle = context_->GetBlobDataFromUUID(kId); |
| 488 EXPECT_TRUE(handle); | 475 EXPECT_TRUE(handle); |
| 489 DataElement expected; | 476 DataElement expected; |
| 490 expected.SetToBytes(kData, kDataSize); | 477 expected.SetToBytes(kData, kDataSize); |
| 491 std::vector<DataElement> expecteds = {expected}; | 478 std::vector<DataElement> expecteds = {expected}; |
| 492 ExpectHandleEqualsData(handle.get(), expecteds); | 479 ExpectHandleEqualsData(handle.get(), expecteds); |
| 493 | 480 |
| 494 // Verify we can't cancel after the fact. | 481 // Verify we can't cancel after the fact. |
| 495 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); | 482 host_->OnCancelBuildingBlob(kId, |
| 483 BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
| 496 ExpectAndResetBadMessage(); | 484 ExpectAndResetBadMessage(); |
| 497 } | 485 } |
| 498 | 486 |
| 499 TEST_F(BlobDispatcherHostTest, BlobDataWithHostDeletion) { | 487 TEST_F(BlobDispatcherHostTest, BlobDataWithHostDeletion) { |
| 500 // Build up a basic blob. | 488 // Build up a basic blob. |
| 501 const std::string kId("id"); | 489 const std::string kId("id"); |
| 502 AsyncShortcutBlobTransfer(kId); | 490 AsyncShortcutBlobTransfer(kId); |
| 503 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); | 491 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); |
| 504 EXPECT_TRUE(handle); | 492 EXPECT_TRUE(handle); |
| 505 | 493 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 517 base::RunLoop().RunUntilIdle(); | 505 base::RunLoop().RunUntilIdle(); |
| 518 | 506 |
| 519 handle = context_->GetBlobDataFromUUID(kId); | 507 handle = context_->GetBlobDataFromUUID(kId); |
| 520 EXPECT_FALSE(handle); | 508 EXPECT_FALSE(handle); |
| 521 } | 509 } |
| 522 | 510 |
| 523 TEST_F(BlobDispatcherHostTest, BlobReferenceWhileConstructing) { | 511 TEST_F(BlobDispatcherHostTest, BlobReferenceWhileConstructing) { |
| 524 const std::string kId("id"); | 512 const std::string kId("id"); |
| 525 | 513 |
| 526 // Start building blob. | 514 // Start building blob. |
| 527 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 515 DataElement element; |
| 528 std::string(kContentDisposition), | 516 element.SetToBytesDescription(kDataSize); |
| 529 std::set<std::string>()); | 517 std::vector<DataElement> elements = {element}; |
| 518 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 519 std::string(kContentDisposition), elements); |
| 530 | 520 |
| 531 // Grab the handle. | 521 // Grab the handle. |
| 532 std::unique_ptr<BlobDataHandle> blob_data_handle = | 522 std::unique_ptr<BlobDataHandle> blob_data_handle = |
| 533 context_->GetBlobDataFromUUID(kId); | 523 context_->GetBlobDataFromUUID(kId); |
| 534 EXPECT_TRUE(blob_data_handle); | 524 EXPECT_TRUE(blob_data_handle); |
| 535 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); | 525 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); |
| 536 bool built = false; | 526 bool built = false; |
| 537 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 527 BlobStatus error_code = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS; |
| 538 blob_data_handle->RunOnConstructionComplete( | 528 blob_data_handle->RunOnConstructionComplete( |
| 539 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 529 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
| 540 | 530 |
| 541 // Continue building. | |
| 542 DataElement element; | |
| 543 element.SetToBytesDescription(kDataSize); | |
| 544 std::vector<DataElement> elements = {element}; | |
| 545 host_->OnStartBuildingBlob(kId, elements); | |
| 546 sink_.ClearMessages(); | 531 sink_.ClearMessages(); |
| 547 | 532 |
| 548 // Send data. | 533 // Send data. |
| 549 BlobItemBytesResponse response(0); | 534 BlobItemBytesResponse response(0); |
| 550 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); | 535 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); |
| 551 std::vector<BlobItemBytesResponse> responses = {response}; | 536 std::vector<BlobItemBytesResponse> responses = {response}; |
| 552 sink_.ClearMessages(); | 537 sink_.ClearMessages(); |
| 553 host_->OnMemoryItemResponse(kId, responses); | 538 host_->OnMemoryItemResponse(kId, responses); |
| 554 | 539 |
| 555 ExpectDone(kId); | 540 ExpectDone(kId); |
| 556 base::RunLoop().RunUntilIdle(); | 541 base::RunLoop().RunUntilIdle(); |
| 557 EXPECT_TRUE(built) << "Error code: " << static_cast<int>(error_code); | 542 EXPECT_TRUE(built) << "Error code: " << static_cast<int>(error_code); |
| 558 } | 543 } |
| 559 | 544 |
| 560 TEST_F(BlobDispatcherHostTest, BlobReferenceWhileShortcutConstructing) { | |
| 561 const std::string kId("id"); | |
| 562 | |
| 563 // Start building blob. | |
| 564 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | |
| 565 std::string(kContentDisposition), | |
| 566 std::set<std::string>()); | |
| 567 | |
| 568 // Grab the handle. | |
| 569 std::unique_ptr<BlobDataHandle> blob_data_handle = | |
| 570 context_->GetBlobDataFromUUID(kId); | |
| 571 EXPECT_TRUE(blob_data_handle); | |
| 572 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); | |
| 573 bool built = false; | |
| 574 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | |
| 575 blob_data_handle->RunOnConstructionComplete( | |
| 576 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | |
| 577 | |
| 578 // Continue building. | |
| 579 DataElement element; | |
| 580 element.SetToBytes(kData, kDataSize); | |
| 581 std::vector<DataElement> elements = {element}; | |
| 582 host_->OnStartBuildingBlob(kId, elements); | |
| 583 ExpectDone(kId); | |
| 584 base::RunLoop().RunUntilIdle(); | |
| 585 EXPECT_TRUE(built) << "Error code: " << static_cast<int>(error_code); | |
| 586 } | |
| 587 | |
| 588 TEST_F(BlobDispatcherHostTest, BlobReferenceWhileConstructingCancelled) { | 545 TEST_F(BlobDispatcherHostTest, BlobReferenceWhileConstructingCancelled) { |
| 589 const std::string kId("id"); | 546 const std::string kId("id"); |
| 590 | 547 |
| 591 // Start building blob. | 548 // Start building blob. |
| 592 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 549 DataElement element; |
| 593 std::string(kContentDisposition), | 550 element.SetToBytesDescription(kDataSize); |
| 594 std::set<std::string>()); | 551 std::vector<DataElement> elements = {element}; |
| 552 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 553 std::string(kContentDisposition), elements); |
| 595 | 554 |
| 596 // Grab the handle. | 555 // Grab the handle. |
| 597 std::unique_ptr<BlobDataHandle> blob_data_handle = | 556 std::unique_ptr<BlobDataHandle> blob_data_handle = |
| 598 context_->GetBlobDataFromUUID(kId); | 557 context_->GetBlobDataFromUUID(kId); |
| 599 EXPECT_TRUE(blob_data_handle); | 558 EXPECT_TRUE(blob_data_handle); |
| 600 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); | 559 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); |
| 601 bool built = true; | 560 bool built = true; |
| 602 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 561 BlobStatus error_code = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS; |
| 603 blob_data_handle->RunOnConstructionComplete( | 562 blob_data_handle->RunOnConstructionComplete( |
| 604 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 563 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
| 605 | 564 |
| 606 // Cancel in middle of construction. | 565 // Cancel in middle of construction. |
| 607 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); | 566 host_->OnCancelBuildingBlob(kId, |
| 567 BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
| 608 base::RunLoop().RunUntilIdle(); | 568 base::RunLoop().RunUntilIdle(); |
| 609 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 569 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 610 EXPECT_TRUE(host_->IsInUseInHost(kId)); | 570 EXPECT_TRUE(host_->IsInUseInHost(kId)); |
| 611 EXPECT_FALSE(IsBeingBuiltInHost(kId)); | 571 EXPECT_FALSE(IsBeingBuiltInHost(kId)); |
| 612 EXPECT_TRUE(blob_data_handle->IsBroken()); | 572 EXPECT_TRUE(blob_data_handle->IsBroken()); |
| 613 EXPECT_FALSE(built); | 573 EXPECT_FALSE(built); |
| 614 EXPECT_EQ(IPCBlobCreationCancelCode::UNKNOWN, error_code); | 574 EXPECT_EQ(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS, error_code); |
| 615 error_code = IPCBlobCreationCancelCode::UNKNOWN; | 575 error_code = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS; |
| 616 built = true; | 576 built = true; |
| 617 blob_data_handle->RunOnConstructionComplete( | 577 blob_data_handle->RunOnConstructionComplete( |
| 618 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 578 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
| 619 EXPECT_FALSE(built); | 579 EXPECT_FALSE(built); |
| 620 EXPECT_EQ(IPCBlobCreationCancelCode::UNKNOWN, error_code); | 580 EXPECT_EQ(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS, error_code); |
| 621 | 581 |
| 622 // Remove it. | 582 // Remove it. |
| 623 blob_data_handle.reset(); | 583 blob_data_handle.reset(); |
| 624 base::RunLoop().RunUntilIdle(); | 584 base::RunLoop().RunUntilIdle(); |
| 625 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 585 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 626 host_->OnDecrementBlobRefCount(kId); | 586 host_->OnDecrementBlobRefCount(kId); |
| 627 ExpectBlobNotExist(kId); | 587 ExpectBlobNotExist(kId); |
| 628 } | 588 } |
| 629 | 589 |
| 630 TEST_F(BlobDispatcherHostTest, DecrementRefAfterRegister) { | |
| 631 const std::string kId("id"); | |
| 632 // Decrement the refcount while building (renderer blob gc'd before | |
| 633 // construction was completed). | |
| 634 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | |
| 635 std::string(kContentDisposition), | |
| 636 std::set<std::string>()); | |
| 637 EXPECT_TRUE(context_->registry().HasEntry(kId)); | |
| 638 host_->OnDecrementBlobRefCount(kId); | |
| 639 EXPECT_FALSE(context_->registry().HasEntry(kId)); | |
| 640 EXPECT_FALSE(IsBeingBuiltInHost(kId)); | |
| 641 ExpectCancel(kId, | |
| 642 IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING); | |
| 643 sink_.ClearMessages(); | |
| 644 | |
| 645 // Do the same, but this time grab a handle before we decrement. | |
| 646 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | |
| 647 std::string(kContentDisposition), | |
| 648 std::set<std::string>()); | |
| 649 std::unique_ptr<BlobDataHandle> blob_data_handle = | |
| 650 context_->GetBlobDataFromUUID(kId); | |
| 651 host_->OnDecrementBlobRefCount(kId); | |
| 652 EXPECT_TRUE(context_->registry().HasEntry(kId)); | |
| 653 EXPECT_TRUE(IsBeingBuiltInHost(kId)); | |
| 654 | |
| 655 // Finish up the blob, and verify we got the done message. | |
| 656 DataElement element; | |
| 657 element.SetToBytes(kData, kDataSize); | |
| 658 std::vector<DataElement> elements = {element}; | |
| 659 host_->OnStartBuildingBlob(kId, elements); | |
| 660 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 661 ExpectDone(kId); | |
| 662 sink_.ClearMessages(); | |
| 663 // Get rid of the handle, and verify it's gone. | |
| 664 blob_data_handle.reset(); | |
| 665 base::RunLoop().RunUntilIdle(); | |
| 666 // Check that it's no longer around. | |
| 667 EXPECT_FALSE(context_->registry().HasEntry(kId)); | |
| 668 EXPECT_FALSE(IsBeingBuiltInHost(kId)); | |
| 669 } | |
| 670 | |
| 671 TEST_F(BlobDispatcherHostTest, DecrementRefAfterOnStart) { | 590 TEST_F(BlobDispatcherHostTest, DecrementRefAfterOnStart) { |
| 672 const std::string kId("id"); | 591 const std::string kId("id"); |
| 673 | 592 |
| 674 // Decrement the refcount while building, after we call OnStartBuildlingBlob. | 593 // Decrement the refcount while building, after we call OnStartBuildlingBlob. |
| 675 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | |
| 676 std::string(kContentDisposition), | |
| 677 std::set<std::string>()); | |
| 678 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 679 DataElement element; | 594 DataElement element; |
| 680 element.SetToBytesDescription(kDataSize); | 595 element.SetToBytesDescription(kDataSize); |
| 681 std::vector<DataElement> elements = {element}; | 596 std::vector<DataElement> elements = {element}; |
| 682 host_->OnStartBuildingBlob(kId, elements); | 597 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 598 std::string(kContentDisposition), elements); |
| 683 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 599 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 684 | 600 |
| 685 std::vector<BlobItemBytesRequest> expected_requests = { | 601 std::vector<BlobItemBytesRequest> expected_requests = { |
| 686 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; | 602 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; |
| 687 ExpectRequest(kId, expected_requests); | 603 ExpectRequest(kId, expected_requests); |
| 688 sink_.ClearMessages(); | 604 sink_.ClearMessages(); |
| 689 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 605 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 690 host_->OnDecrementBlobRefCount(kId); | 606 host_->OnDecrementBlobRefCount(kId); |
| 691 EXPECT_FALSE(context_->registry().HasEntry(kId)); | 607 EXPECT_FALSE(context_->registry().HasEntry(kId)); |
| 692 EXPECT_FALSE(IsBeingBuiltInHost(kId)); | 608 EXPECT_FALSE(IsBeingBuiltInHost(kId)); |
| 693 ExpectCancel(kId, | 609 ExpectCancel(kId, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING); |
| 694 IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING); | |
| 695 sink_.ClearMessages(); | 610 sink_.ClearMessages(); |
| 696 | 611 |
| 697 // Do the same, but this time grab a handle to keep it alive. | 612 // Do the same, but this time grab a handle to keep it alive. |
| 698 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 613 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 699 std::string(kContentDisposition), | 614 std::string(kContentDisposition), elements); |
| 700 std::set<std::string>()); | |
| 701 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 702 host_->OnStartBuildingBlob(kId, elements); | |
| 703 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 615 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 704 ExpectRequest(kId, expected_requests); | 616 ExpectRequest(kId, expected_requests); |
| 705 sink_.ClearMessages(); | 617 sink_.ClearMessages(); |
| 706 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 618 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 707 // Grab the handle before decrementing. | 619 // Grab the handle before decrementing. |
| 708 std::unique_ptr<BlobDataHandle> blob_data_handle = | 620 std::unique_ptr<BlobDataHandle> blob_data_handle = |
| 709 context_->GetBlobDataFromUUID(kId); | 621 context_->GetBlobDataFromUUID(kId); |
| 710 host_->OnDecrementBlobRefCount(kId); | 622 host_->OnDecrementBlobRefCount(kId); |
| 711 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 623 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 712 EXPECT_TRUE(IsBeingBuiltInHost(kId)); | 624 EXPECT_TRUE(IsBeingBuiltInHost(kId)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 727 base::RunLoop().RunUntilIdle(); | 639 base::RunLoop().RunUntilIdle(); |
| 728 // Check that it's no longer around. | 640 // Check that it's no longer around. |
| 729 EXPECT_FALSE(context_->registry().HasEntry(kId)); | 641 EXPECT_FALSE(context_->registry().HasEntry(kId)); |
| 730 EXPECT_FALSE(IsBeingBuiltInHost(kId)); | 642 EXPECT_FALSE(IsBeingBuiltInHost(kId)); |
| 731 } | 643 } |
| 732 | 644 |
| 733 TEST_F(BlobDispatcherHostTest, DecrementRefAfterOnStartWithHandle) { | 645 TEST_F(BlobDispatcherHostTest, DecrementRefAfterOnStartWithHandle) { |
| 734 const std::string kId("id"); | 646 const std::string kId("id"); |
| 735 // Decrement the refcount while building, after we call | 647 // Decrement the refcount while building, after we call |
| 736 // OnStartBuildlingBlob, except we have another handle. | 648 // OnStartBuildlingBlob, except we have another handle. |
| 737 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 649 DataElement element; |
| 738 std::string(kContentDisposition), | 650 element.SetToBytesDescription(kDataSize); |
| 739 std::set<std::string>()); | 651 std::vector<DataElement> elements = {element}; |
| 652 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 653 std::string(kContentDisposition), elements); |
| 740 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 654 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 741 | 655 |
| 742 std::unique_ptr<BlobDataHandle> blob_data_handle = | 656 std::unique_ptr<BlobDataHandle> blob_data_handle = |
| 743 context_->GetBlobDataFromUUID(kId); | 657 context_->GetBlobDataFromUUID(kId); |
| 744 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); | 658 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); |
| 745 bool built = true; | 659 bool built = true; |
| 746 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 660 BlobStatus error_code = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS; |
| 747 blob_data_handle->RunOnConstructionComplete( | 661 blob_data_handle->RunOnConstructionComplete( |
| 748 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 662 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
| 749 | 663 |
| 750 DataElement element; | |
| 751 element.SetToBytesDescription(kDataSize); | |
| 752 std::vector<DataElement> elements = {element}; | |
| 753 host_->OnStartBuildingBlob(kId, elements); | |
| 754 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 755 | |
| 756 // Check that we got the expected request. | 664 // Check that we got the expected request. |
| 757 std::vector<BlobItemBytesRequest> expected_requests = { | 665 std::vector<BlobItemBytesRequest> expected_requests = { |
| 758 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; | 666 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; |
| 759 ExpectRequest(kId, expected_requests); | 667 ExpectRequest(kId, expected_requests); |
| 760 sink_.ClearMessages(); | 668 sink_.ClearMessages(); |
| 761 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 669 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 762 EXPECT_TRUE(IsBeingBuiltInHost(kId)); | 670 EXPECT_TRUE(IsBeingBuiltInHost(kId)); |
| 763 // Decrement, simulating where the ref goes out of scope in renderer. | 671 // Decrement, simulating where the ref goes out of scope in renderer. |
| 764 host_->OnDecrementBlobRefCount(kId); | 672 host_->OnDecrementBlobRefCount(kId); |
| 765 // We still have the blob as it's not done. | 673 // We still have the blob as it's not done. |
| 766 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 674 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 767 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); | 675 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); |
| 768 EXPECT_TRUE(IsBeingBuiltInHost(kId)); | 676 EXPECT_TRUE(IsBeingBuiltInHost(kId)); |
| 769 // Cancel to clean up. | 677 // Cancel to clean up. |
| 770 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); | 678 host_->OnCancelBuildingBlob(kId, |
| 679 BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
| 771 // Run loop to propagate the handle decrement in the host. | 680 // Run loop to propagate the handle decrement in the host. |
| 772 base::RunLoop().RunUntilIdle(); | 681 base::RunLoop().RunUntilIdle(); |
| 773 // We still have the entry because of our earlier handle. | 682 // We still have the entry because of our earlier handle. |
| 774 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 683 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 775 EXPECT_FALSE(IsBeingBuiltInHost(kId)); | 684 EXPECT_FALSE(IsBeingBuiltInHost(kId)); |
| 776 EXPECT_FALSE(built); | 685 EXPECT_FALSE(built); |
| 777 EXPECT_EQ(IPCBlobCreationCancelCode::UNKNOWN, error_code); | 686 EXPECT_EQ(BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS, error_code); |
| 778 sink_.ClearMessages(); | 687 sink_.ClearMessages(); |
| 779 | 688 |
| 780 // Should disappear after dropping the handle. | 689 // Should disappear after dropping the handle. |
| 781 EXPECT_TRUE(blob_data_handle->IsBroken()); | 690 EXPECT_TRUE(blob_data_handle->IsBroken()); |
| 782 blob_data_handle.reset(); | 691 blob_data_handle.reset(); |
| 783 base::RunLoop().RunUntilIdle(); | 692 base::RunLoop().RunUntilIdle(); |
| 784 EXPECT_FALSE(context_->registry().HasEntry(kId)); | 693 EXPECT_FALSE(context_->registry().HasEntry(kId)); |
| 785 } | 694 } |
| 786 | 695 |
| 787 TEST_F(BlobDispatcherHostTest, HostDisconnectAfterRegisterWithHandle) { | |
| 788 const std::string kId("id"); | |
| 789 | |
| 790 // Delete host with a handle to the blob. | |
| 791 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | |
| 792 std::string(kContentDisposition), | |
| 793 std::set<std::string>()); | |
| 794 | |
| 795 std::unique_ptr<BlobDataHandle> blob_data_handle = | |
| 796 context_->GetBlobDataFromUUID(kId); | |
| 797 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); | |
| 798 bool built = true; | |
| 799 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | |
| 800 blob_data_handle->RunOnConstructionComplete( | |
| 801 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | |
| 802 // Get rid of host, which was doing the constructing. | |
| 803 host_ = nullptr; | |
| 804 EXPECT_FALSE(blob_data_handle->IsBeingBuilt()); | |
| 805 base::RunLoop().RunUntilIdle(); | |
| 806 EXPECT_FALSE(built); | |
| 807 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, error_code); | |
| 808 | |
| 809 // Should still be there due to the handle. | |
| 810 std::unique_ptr<BlobDataHandle> another_handle = | |
| 811 context_->GetBlobDataFromUUID(kId); | |
| 812 EXPECT_TRUE(another_handle); | |
| 813 | |
| 814 // Should disappear after dropping both handles. | |
| 815 blob_data_handle.reset(); | |
| 816 another_handle.reset(); | |
| 817 base::RunLoop().RunUntilIdle(); | |
| 818 EXPECT_FALSE(context_->registry().HasEntry(kId)); | |
| 819 } | |
| 820 | |
| 821 TEST_F(BlobDispatcherHostTest, HostDisconnectAfterOnStart) { | 696 TEST_F(BlobDispatcherHostTest, HostDisconnectAfterOnStart) { |
| 822 const std::string kId("id"); | 697 const std::string kId("id"); |
| 823 | 698 |
| 824 // Host deleted after OnStartBuilding. | 699 // Host deleted after OnStartBuilding. |
| 825 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | |
| 826 std::string(kContentDisposition), | |
| 827 std::set<std::string>()); | |
| 828 | |
| 829 DataElement element; | 700 DataElement element; |
| 830 element.SetToBytesDescription(kDataSize); | 701 element.SetToBytesDescription(kDataSize); |
| 831 std::vector<DataElement> elements = {element}; | 702 std::vector<DataElement> elements = {element}; |
| 832 host_->OnStartBuildingBlob(kId, elements); | 703 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 704 std::string(kContentDisposition), elements); |
| 833 | 705 |
| 834 std::vector<BlobItemBytesRequest> expected_requests = { | 706 std::vector<BlobItemBytesRequest> expected_requests = { |
| 835 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; | 707 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; |
| 836 ExpectRequest(kId, expected_requests); | 708 ExpectRequest(kId, expected_requests); |
| 837 sink_.ClearMessages(); | 709 sink_.ClearMessages(); |
| 838 host_ = nullptr; | 710 host_ = nullptr; |
| 839 // We need to run the message loop because of the handle in the async builder. | 711 // We need to run the message loop because of the handle in the async builder. |
| 840 base::RunLoop().RunUntilIdle(); | 712 base::RunLoop().RunUntilIdle(); |
| 841 EXPECT_FALSE(context_->registry().HasEntry(kId)); | 713 EXPECT_FALSE(context_->registry().HasEntry(kId)); |
| 842 } | 714 } |
| 843 | 715 |
| 844 TEST_F(BlobDispatcherHostTest, HostDisconnectAfterOnMemoryResponse) { | 716 TEST_F(BlobDispatcherHostTest, HostDisconnectAfterOnMemoryResponse) { |
| 845 const std::string kId("id"); | 717 const std::string kId("id"); |
| 846 | 718 |
| 847 // Host deleted after OnMemoryItemResponse. | 719 // Host deleted after OnMemoryItemResponse. |
| 848 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | |
| 849 std::string(kContentDisposition), | |
| 850 std::set<std::string>()); | |
| 851 | |
| 852 // Create list of two items. | |
| 853 DataElement element; | 720 DataElement element; |
| 854 element.SetToBytesDescription(kDataSize); | 721 element.SetToBytesDescription(kDataSize); |
| 855 std::vector<DataElement> elements = {element, element}; | 722 std::vector<DataElement> elements = {element, element}; |
| 856 host_->OnStartBuildingBlob(kId, elements); | 723 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 724 std::string(kContentDisposition), elements); |
| 725 |
| 726 // Create list of two items. |
| 857 std::vector<BlobItemBytesRequest> expected_requests = { | 727 std::vector<BlobItemBytesRequest> expected_requests = { |
| 858 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize), | 728 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize), |
| 859 BlobItemBytesRequest::CreateIPCRequest(1, 1, 0, kDataSize)}; | 729 BlobItemBytesRequest::CreateIPCRequest(1, 1, 0, kDataSize)}; |
| 860 ExpectRequest(kId, expected_requests); | 730 ExpectRequest(kId, expected_requests); |
| 861 sink_.ClearMessages(); | 731 sink_.ClearMessages(); |
| 862 | 732 |
| 863 // Send just one response so the blob isn't 'done' yet. | 733 // Send just one response so the blob isn't 'done' yet. |
| 864 BlobItemBytesResponse response(0); | 734 BlobItemBytesResponse response(0); |
| 865 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); | 735 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); |
| 866 std::vector<BlobItemBytesResponse> responses = {response}; | 736 std::vector<BlobItemBytesResponse> responses = {response}; |
| 867 host_->OnMemoryItemResponse(kId, responses); | 737 host_->OnMemoryItemResponse(kId, responses); |
| 868 EXPECT_EQ(0u, sink_.message_count()); | 738 EXPECT_EQ(0u, sink_.message_count()); |
| 869 | 739 |
| 870 host_ = nullptr; | 740 host_ = nullptr; |
| 871 base::RunLoop().RunUntilIdle(); | 741 base::RunLoop().RunUntilIdle(); |
| 872 EXPECT_FALSE(context_->registry().HasEntry(kId)); | 742 EXPECT_FALSE(context_->registry().HasEntry(kId)); |
| 873 } | 743 } |
| 874 | 744 |
| 875 TEST_F(BlobDispatcherHostTest, CreateBlobWithBrokenReference) { | 745 TEST_F(BlobDispatcherHostTest, CreateBlobWithBrokenReference) { |
| 876 const std::string kBrokenId("id1"); | 746 const std::string kBrokenId("id1"); |
| 877 const std::string kReferencingId("id2"); | 747 const std::string kReferencingId("id2"); |
| 878 | 748 |
| 879 // First, let's test a circular reference. | 749 // First, let's test a circular reference. |
| 880 const std::string kCircularId("id1"); | 750 const std::string kCircularId("id1"); |
| 881 host_->OnRegisterBlobUUID(kCircularId, std::string(kContentType), | 751 DataElement element; |
| 882 std::string(kContentDisposition), {kCircularId}); | 752 element.SetToBlob(kCircularId); |
| 753 std::vector<DataElement> elements = {element}; |
| 754 host_->OnRegisterBlob(kCircularId, std::string(kContentType), |
| 755 std::string(kContentDisposition), elements); |
| 883 ExpectAndResetBadMessage(); | 756 ExpectAndResetBadMessage(); |
| 884 | 757 |
| 885 // Next, test a blob that references a broken blob. | 758 // Next, test a blob that references a broken blob. |
| 886 host_->OnRegisterBlobUUID(kBrokenId, std::string(kContentType), | 759 element.SetToBytesDescription(kDataSize); |
| 887 std::string(kContentDisposition), | 760 elements = {element}; |
| 888 std::set<std::string>()); | 761 host_->OnRegisterBlob(kBrokenId, std::string(kContentType), |
| 889 host_->OnCancelBuildingBlob(kBrokenId, IPCBlobCreationCancelCode::UNKNOWN); | 762 std::string(kContentDisposition), elements); |
| 763 sink_.ClearMessages(); |
| 764 host_->OnCancelBuildingBlob(kBrokenId, |
| 765 BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
| 890 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 766 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 891 EXPECT_TRUE(context_->GetBlobDataFromUUID(kBrokenId)->IsBroken()); | 767 EXPECT_TRUE(context_->GetBlobDataFromUUID(kBrokenId)->IsBroken()); |
| 892 | 768 |
| 893 // Create referencing blob. We should be broken right away, but also ignore | 769 // Create referencing blob. We should be broken right away, but also ignore |
| 894 // the subsequent OnStart message. | 770 // the subsequent OnStart message. |
| 895 host_->OnRegisterBlobUUID(kReferencingId, std::string(kContentType), | 771 element.SetToBytesDescription(kDataSize); |
| 896 std::string(kContentDisposition), {kBrokenId}); | 772 elements = {element}; |
| 773 element.SetToBlob(kBrokenId); |
| 774 elements.push_back(element); |
| 775 host_->OnRegisterBlob(kReferencingId, std::string(kContentType), |
| 776 std::string(kContentDisposition), elements); |
| 897 EXPECT_TRUE(context_->GetBlobDataFromUUID(kReferencingId)->IsBroken()); | 777 EXPECT_TRUE(context_->GetBlobDataFromUUID(kReferencingId)->IsBroken()); |
| 898 EXPECT_FALSE(IsBeingBuiltInHost(kReferencingId)); | 778 EXPECT_FALSE(IsBeingBuiltInHost(kReferencingId)); |
| 899 EXPECT_TRUE(context_->registry().HasEntry(kReferencingId)); | 779 EXPECT_TRUE(context_->registry().HasEntry(kReferencingId)); |
| 900 ExpectCancel(kReferencingId, | 780 ExpectCancel(kReferencingId, BlobStatus::ERR_REFERENCED_BLOB_BROKEN); |
| 901 IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN); | |
| 902 sink_.ClearMessages(); | 781 sink_.ClearMessages(); |
| 903 | |
| 904 DataElement element; | |
| 905 element.SetToBytesDescription(kDataSize); | |
| 906 std::vector<DataElement> elements = {element}; | |
| 907 element.SetToBlob(kBrokenId); | |
| 908 elements.push_back(element); | |
| 909 host_->OnStartBuildingBlob(kReferencingId, elements); | |
| 910 EXPECT_EQ(0u, sink_.message_count()); | |
| 911 base::RunLoop().RunUntilIdle(); | |
| 912 } | 782 } |
| 913 | 783 |
| 914 TEST_F(BlobDispatcherHostTest, DeferenceBlobOnDifferentHost) { | 784 TEST_F(BlobDispatcherHostTest, DeferenceBlobOnDifferentHost) { |
| 915 const std::string kId("id"); | 785 const std::string kId("id"); |
| 916 // Data elements for our transfer & checking messages. | 786 // Data elements for our transfer & checking messages. |
| 917 DataElement element; | 787 DataElement element; |
| 918 element.SetToBytesDescription(kDataSize); | 788 element.SetToBytesDescription(kDataSize); |
| 919 std::vector<DataElement> elements = {element}; | 789 std::vector<DataElement> elements = {element}; |
| 920 std::vector<BlobItemBytesRequest> expected_requests = { | 790 std::vector<BlobItemBytesRequest> expected_requests = { |
| 921 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; | 791 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; |
| 922 BlobItemBytesResponse response(0); | 792 BlobItemBytesResponse response(0); |
| 923 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); | 793 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); |
| 924 std::vector<BlobItemBytesResponse> responses = {response}; | 794 std::vector<BlobItemBytesResponse> responses = {response}; |
| 925 | 795 |
| 926 scoped_refptr<TestableBlobDispatcherHost> host2( | 796 scoped_refptr<TestableBlobDispatcherHost> host2( |
| 927 new TestableBlobDispatcherHost(chrome_blob_storage_context_, | 797 new TestableBlobDispatcherHost(chrome_blob_storage_context_, |
| 928 file_system_context_.get(), &sink_)); | 798 file_system_context_.get(), &sink_)); |
| 929 | 799 |
| 930 // Delete host with another host having a referencing, then dereference on | 800 // Delete host with another host having a referencing, then dereference on |
| 931 // second host. Verify we're still building it on first host, and then | 801 // second host. Verify we're still building it on first host, and then |
| 932 // verify that a building message from the renderer will kill it. | 802 // verify that a building message from the renderer will kill it. |
| 933 | 803 |
| 934 // Test OnStartBuilding after double dereference. | 804 // Test OnStartBuilding after double dereference. |
| 935 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 805 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 936 std::string(kContentDisposition), | 806 std::string(kContentDisposition), elements); |
| 937 std::set<std::string>()); | 807 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 808 ExpectRequest(kId, expected_requests); |
| 809 sink_.ClearMessages(); |
| 938 host2->OnIncrementBlobRefCount(kId); | 810 host2->OnIncrementBlobRefCount(kId); |
| 939 host_->OnDecrementBlobRefCount(kId); | 811 host_->OnDecrementBlobRefCount(kId); |
| 940 EXPECT_FALSE(host_->IsInUseInHost(kId)); | 812 EXPECT_FALSE(host_->IsInUseInHost(kId)); |
| 941 host2->OnDecrementBlobRefCount(kId); | 813 host2->OnDecrementBlobRefCount(kId); |
| 942 // So no more blob in the context, but we're still being built in host 1. | 814 // So no more blob in the context, but we're still being built in host 1. |
| 943 EXPECT_FALSE(context_->registry().HasEntry(kId)); | 815 EXPECT_FALSE(context_->registry().HasEntry(kId)); |
| 816 // Send the memory. When the host sees the entry doesn't exist, it should |
| 817 // cancel and clean up. |
| 944 EXPECT_TRUE(host_->async_builder_.IsBeingBuilt(kId)); | 818 EXPECT_TRUE(host_->async_builder_.IsBeingBuilt(kId)); |
| 945 host_->OnStartBuildingBlob(kId, elements); | 819 host_->OnMemoryItemResponse(kId, responses); |
| 946 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 947 // We should be cleaned up. | 820 // We should be cleaned up. |
| 948 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kId)); | 821 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kId)); |
| 949 ExpectCancel(kId, | 822 ExpectCancel(kId, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING); |
| 950 IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING); | |
| 951 sink_.ClearMessages(); | 823 sink_.ClearMessages(); |
| 952 | 824 |
| 953 // Same as above, but test OnMemoryItemResponse after double dereference. | 825 // Same, but now for OnCancel. |
| 954 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 826 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 955 std::string(kContentDisposition), | 827 std::string(kContentDisposition), elements); |
| 956 std::set<std::string>()); | |
| 957 host2->OnIncrementBlobRefCount(kId); | 828 host2->OnIncrementBlobRefCount(kId); |
| 958 host_->OnDecrementBlobRefCount(kId); | 829 host_->OnDecrementBlobRefCount(kId); |
| 959 EXPECT_FALSE(host_->IsInUseInHost(kId)); | 830 EXPECT_FALSE(host_->IsInUseInHost(kId)); |
| 960 host_->OnStartBuildingBlob(kId, elements); | |
| 961 ExpectRequest(kId, expected_requests); | 831 ExpectRequest(kId, expected_requests); |
| 962 sink_.ClearMessages(); | 832 sink_.ClearMessages(); |
| 963 | 833 |
| 964 host2->OnDecrementBlobRefCount(kId); | |
| 965 // So no more blob in the context, but we're still being built in host 1. | |
| 966 EXPECT_FALSE(context_->registry().HasEntry(kId)); | |
| 967 EXPECT_TRUE(host_->async_builder_.IsBeingBuilt(kId)); | |
| 968 host_->OnMemoryItemResponse(kId, responses); | |
| 969 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 970 // We should be cleaned up. | |
| 971 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kId)); | |
| 972 ExpectCancel(kId, | |
| 973 IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING); | |
| 974 sink_.ClearMessages(); | |
| 975 | |
| 976 // Same, but now for OnCancel. | |
| 977 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | |
| 978 std::string(kContentDisposition), | |
| 979 std::set<std::string>()); | |
| 980 host2->OnIncrementBlobRefCount(kId); | |
| 981 host_->OnDecrementBlobRefCount(kId); | |
| 982 EXPECT_FALSE(host_->IsInUseInHost(kId)); | |
| 983 host_->OnStartBuildingBlob(kId, elements); | |
| 984 ExpectRequest(kId, expected_requests); | |
| 985 sink_.ClearMessages(); | |
| 986 | |
| 987 host2->OnDecrementBlobRefCount(kId); | 834 host2->OnDecrementBlobRefCount(kId); |
| 988 // So no more blob in the context, but we're still being built in host 1. | 835 // So no more blob in the context, but we're still being built in host 1. |
| 989 EXPECT_FALSE(context_->registry().HasEntry(kId)); | 836 EXPECT_FALSE(context_->registry().HasEntry(kId)); |
| 990 EXPECT_TRUE(host_->async_builder_.IsBeingBuilt(kId)); | 837 EXPECT_TRUE(host_->async_builder_.IsBeingBuilt(kId)); |
| 991 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); | 838 host_->OnCancelBuildingBlob(kId, |
| 839 BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
| 992 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 840 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 993 // We should be cleaned up. | 841 // We should be cleaned up. |
| 994 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kId)); | 842 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kId)); |
| 995 } | 843 } |
| 996 | 844 |
| 997 TEST_F(BlobDispatcherHostTest, BuildingReferenceChain) { | 845 TEST_F(BlobDispatcherHostTest, BuildingReferenceChain) { |
| 998 const std::string kId("id"); | 846 const std::string kId("id"); |
| 999 const std::string kSameHostReferencingId("id2"); | 847 const std::string kSameHostReferencingId("id2"); |
| 1000 const std::string kDifferentHostReferencingId("id3"); | 848 const std::string kDifferentHostReferencingId("id3"); |
| 1001 // Data elements for our transfer & checking messages. | 849 // Data elements for our transfer & checking messages. |
| 1002 DataElement element; | 850 DataElement element; |
| 1003 element.SetToBytes(kData, kDataSize); | 851 element.SetToBytesDescription(kDataSize); |
| 1004 std::vector<DataElement> elements = {element}; | |
| 1005 DataElement referencing_element; | 852 DataElement referencing_element; |
| 1006 referencing_element.SetToBlob(kId); | 853 referencing_element.SetToBlob(kId); |
| 854 std::vector<DataElement> elements = {element}; |
| 1007 std::vector<DataElement> referencing_elements = {referencing_element}; | 855 std::vector<DataElement> referencing_elements = {referencing_element}; |
| 1008 std::set<std::string> referenced_blobs_set = {kId}; | 856 std::vector<BlobItemBytesRequest> expected_requests = { |
| 857 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; |
| 858 BlobItemBytesResponse response(0); |
| 859 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); |
| 860 std::vector<BlobItemBytesResponse> responses = {response}; |
| 1009 | 861 |
| 1010 scoped_refptr<TestableBlobDispatcherHost> host2( | 862 scoped_refptr<TestableBlobDispatcherHost> host2( |
| 1011 new TestableBlobDispatcherHost(chrome_blob_storage_context_, | 863 new TestableBlobDispatcherHost(chrome_blob_storage_context_, |
| 1012 file_system_context_.get(), &sink_)); | 864 file_system_context_.get(), &sink_)); |
| 1013 | 865 |
| 1014 // We want to have a blob referencing another blob that is building, both on | 866 // We want to have a blob referencing another blob that is building, both on |
| 1015 // the same host and a different host. We should successfully build all blobs | 867 // the same host and a different host. We should successfully build all blobs |
| 1016 // after the referenced blob is finished. | 868 // after the referenced blob is finished. |
| 1017 | 869 |
| 1018 // First we start the referenced blob. | 870 // First we start the referenced blob. |
| 1019 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 871 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 1020 std::string(kContentDisposition), | 872 std::string(kContentDisposition), elements); |
| 1021 std::set<std::string>()); | 873 ExpectRequest(kId, expected_requests); |
| 874 sink_.ClearMessages(); |
| 1022 EXPECT_TRUE(host_->IsInUseInHost(kId)); | 875 EXPECT_TRUE(host_->IsInUseInHost(kId)); |
| 876 EXPECT_TRUE(IsBeingBuiltInContext(kId)); |
| 1023 | 877 |
| 1024 // Next we start the referencing blobs in both the same and different host. | 878 // Next we start the referencing blobs in both the same and different host. |
| 1025 host_->OnRegisterBlobUUID(kSameHostReferencingId, std::string(kContentType), | 879 host_->OnRegisterBlob(kSameHostReferencingId, std::string(kContentType), |
| 1026 std::string(kContentDisposition), | 880 std::string(kContentDisposition), referencing_elements); |
| 1027 referenced_blobs_set); | |
| 1028 EXPECT_FALSE(host_->shutdown_for_bad_message_); | |
| 1029 host_->OnStartBuildingBlob(kSameHostReferencingId, referencing_elements); | |
| 1030 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 881 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 1031 ExpectDone(kSameHostReferencingId); | 882 ExpectDone(kSameHostReferencingId); |
| 1032 EXPECT_TRUE(host_->async_builder_.IsBeingBuilt(kSameHostReferencingId)); | |
| 1033 sink_.ClearMessages(); | 883 sink_.ClearMessages(); |
| 884 EXPECT_FALSE( |
| 885 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); |
| 886 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kSameHostReferencingId)); |
| 887 EXPECT_TRUE(IsBeingBuiltInContext(kSameHostReferencingId)); |
| 888 |
| 1034 // Now the other host. | 889 // Now the other host. |
| 1035 host2->OnRegisterBlobUUID( | 890 host2->OnRegisterBlob(kDifferentHostReferencingId, std::string(kContentType), |
| 1036 kDifferentHostReferencingId, std::string(kContentType), | 891 std::string(kContentDisposition), referencing_elements); |
| 1037 std::string(kContentDisposition), referenced_blobs_set); | |
| 1038 EXPECT_FALSE(host2->shutdown_for_bad_message_); | |
| 1039 host2->OnStartBuildingBlob(kDifferentHostReferencingId, referencing_elements); | |
| 1040 EXPECT_FALSE(host2->shutdown_for_bad_message_); | 892 EXPECT_FALSE(host2->shutdown_for_bad_message_); |
| 1041 ExpectDone(kDifferentHostReferencingId); | 893 ExpectDone(kDifferentHostReferencingId); |
| 1042 EXPECT_TRUE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); | |
| 1043 sink_.ClearMessages(); | 894 sink_.ClearMessages(); |
| 895 EXPECT_FALSE( |
| 896 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); |
| 897 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); |
| 898 EXPECT_TRUE(IsBeingBuiltInContext(kDifferentHostReferencingId)); |
| 1044 | 899 |
| 1045 // Now we finish the first blob, and we expect all blobs to finish. | 900 // Now we finish the first blob, and we expect all blobs to finish. |
| 1046 host_->OnStartBuildingBlob(kId, elements); | 901 host_->OnMemoryItemResponse(kId, responses); |
| 1047 ExpectDone(kId); | 902 ExpectDone(kId); |
| 1048 // We need to run the message loop to propagate the construction callbacks. | 903 // We need to run the message loop to propagate the construction callbacks. |
| 1049 base::RunLoop().RunUntilIdle(); | 904 base::RunLoop().RunUntilIdle(); |
| 1050 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); | 905 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); |
| 1051 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kSameHostReferencingId)); | 906 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kSameHostReferencingId)); |
| 1052 EXPECT_FALSE( | 907 EXPECT_FALSE( |
| 1053 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); | 908 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); |
| 1054 EXPECT_FALSE( | 909 EXPECT_FALSE( |
| 1055 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); | 910 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); |
| 1056 sink_.ClearMessages(); | 911 sink_.ClearMessages(); |
| 1057 | 912 |
| 1058 // Finally check that our data is correct in the child elements. | 913 // Finally check that our data is correct in the child elements. |
| 1059 std::unique_ptr<BlobDataHandle> handle = | 914 std::unique_ptr<BlobDataHandle> handle = |
| 1060 context_->GetBlobDataFromUUID(kDifferentHostReferencingId); | 915 context_->GetBlobDataFromUUID(kDifferentHostReferencingId); |
| 1061 ExpectHandleEqualsData(handle.get(), elements); | 916 DataElement expected; |
| 917 expected.SetToBytes(kData, kDataSize); |
| 918 std::vector<DataElement> expecteds = {expected}; |
| 919 ExpectHandleEqualsData(handle.get(), expecteds); |
| 1062 } | 920 } |
| 1063 | 921 |
| 1064 TEST_F(BlobDispatcherHostTest, BuildingReferenceChainWithCancel) { | 922 TEST_F(BlobDispatcherHostTest, BuildingReferenceChainWithCancel) { |
| 1065 const std::string kId("id"); | 923 const std::string kId("id"); |
| 1066 const std::string kSameHostReferencingId("id2"); | 924 const std::string kSameHostReferencingId("id2"); |
| 1067 const std::string kDifferentHostReferencingId("id3"); | 925 const std::string kDifferentHostReferencingId("id3"); |
| 1068 // Data elements for our transfer & checking messages. | 926 // Data elements for our transfer & checking messages. |
| 927 DataElement element; |
| 928 element.SetToBytesDescription(kDataSize); |
| 1069 DataElement referencing_element; | 929 DataElement referencing_element; |
| 1070 referencing_element.SetToBlob(kId); | 930 referencing_element.SetToBlob(kId); |
| 931 std::vector<DataElement> elements = {element}; |
| 1071 std::vector<DataElement> referencing_elements = {referencing_element}; | 932 std::vector<DataElement> referencing_elements = {referencing_element}; |
| 1072 std::set<std::string> referenced_blobs_set = {kId}; | 933 std::vector<BlobItemBytesRequest> expected_requests = { |
| 934 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; |
| 1073 | 935 |
| 1074 scoped_refptr<TestableBlobDispatcherHost> host2( | 936 scoped_refptr<TestableBlobDispatcherHost> host2( |
| 1075 new TestableBlobDispatcherHost(chrome_blob_storage_context_, | 937 new TestableBlobDispatcherHost(chrome_blob_storage_context_, |
| 1076 file_system_context_.get(), &sink_)); | 938 file_system_context_.get(), &sink_)); |
| 1077 | 939 |
| 1078 // We want to have a blob referencing another blob that is building, both on | 940 // We want to have a blob referencing another blob that is building, both on |
| 1079 // the same host and a different host. After we cancel the first blob, the | 941 // the same host and a different host. We should successfully build all blobs |
| 1080 // others should cancel as well. | 942 // after the referenced blob is finished. |
| 1081 | 943 |
| 1082 // First we start the referenced blob. | 944 // First we start the referenced blob. |
| 1083 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 945 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 1084 std::string(kContentDisposition), | 946 std::string(kContentDisposition), elements); |
| 1085 std::set<std::string>()); | 947 ExpectRequest(kId, expected_requests); |
| 948 sink_.ClearMessages(); |
| 1086 EXPECT_TRUE(host_->IsInUseInHost(kId)); | 949 EXPECT_TRUE(host_->IsInUseInHost(kId)); |
| 950 EXPECT_TRUE(IsBeingBuiltInContext(kId)); |
| 1087 | 951 |
| 1088 // Next we start the referencing blobs in both the same and different host. | 952 // Next we start the referencing blobs in both the same and different host. |
| 1089 host_->OnRegisterBlobUUID(kSameHostReferencingId, std::string(kContentType), | 953 host_->OnRegisterBlob(kSameHostReferencingId, std::string(kContentType), |
| 1090 std::string(kContentDisposition), | 954 std::string(kContentDisposition), referencing_elements); |
| 1091 referenced_blobs_set); | 955 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 1092 host_->OnStartBuildingBlob(kSameHostReferencingId, referencing_elements); | |
| 1093 ExpectDone(kSameHostReferencingId); | 956 ExpectDone(kSameHostReferencingId); |
| 1094 EXPECT_TRUE(host_->async_builder_.IsBeingBuilt(kSameHostReferencingId)); | |
| 1095 sink_.ClearMessages(); | 957 sink_.ClearMessages(); |
| 958 EXPECT_FALSE( |
| 959 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); |
| 960 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kSameHostReferencingId)); |
| 961 EXPECT_TRUE(IsBeingBuiltInContext(kSameHostReferencingId)); |
| 962 |
| 1096 // Now the other host. | 963 // Now the other host. |
| 1097 host2->OnRegisterBlobUUID( | 964 host2->OnRegisterBlob(kDifferentHostReferencingId, std::string(kContentType), |
| 1098 kDifferentHostReferencingId, std::string(kContentType), | 965 std::string(kContentDisposition), referencing_elements); |
| 1099 std::string(kContentDisposition), referenced_blobs_set); | 966 EXPECT_FALSE(host2->shutdown_for_bad_message_); |
| 1100 host2->OnStartBuildingBlob(kDifferentHostReferencingId, referencing_elements); | |
| 1101 ExpectDone(kDifferentHostReferencingId); | 967 ExpectDone(kDifferentHostReferencingId); |
| 1102 EXPECT_TRUE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); | |
| 1103 sink_.ClearMessages(); | 968 sink_.ClearMessages(); |
| 969 EXPECT_FALSE( |
| 970 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); |
| 971 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); |
| 972 EXPECT_TRUE(IsBeingBuiltInContext(kDifferentHostReferencingId)); |
| 973 |
| 1104 bool built = false; | 974 bool built = false; |
| 1105 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 975 BlobStatus error_code = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS; |
| 1106 context_->GetBlobDataFromUUID(kDifferentHostReferencingId) | 976 context_->GetBlobDataFromUUID(kDifferentHostReferencingId) |
| 1107 ->RunOnConstructionComplete( | 977 ->RunOnConstructionComplete( |
| 1108 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 978 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
| 1109 | 979 |
| 1110 // Now we cancel the first blob, and we expect all blobs to cancel. | 980 // Now we cancel the first blob, and we expect all blobs to cancel. |
| 1111 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); | 981 host_->OnCancelBuildingBlob(kId, |
| 982 BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
| 1112 // We need to run the message loop to propagate the construction callbacks. | 983 // We need to run the message loop to propagate the construction callbacks. |
| 1113 base::RunLoop().RunUntilIdle(); | 984 base::RunLoop().RunUntilIdle(); |
| 1114 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); | 985 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); |
| 1115 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kSameHostReferencingId)); | 986 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kSameHostReferencingId)); |
| 1116 EXPECT_TRUE( | 987 EXPECT_TRUE( |
| 1117 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); | 988 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); |
| 1118 EXPECT_TRUE( | 989 EXPECT_TRUE( |
| 1119 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); | 990 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); |
| 1120 EXPECT_FALSE(built); | 991 EXPECT_FALSE(built); |
| 1121 EXPECT_EQ(IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN, error_code); | 992 EXPECT_EQ(BlobStatus::ERR_REFERENCED_BLOB_BROKEN, error_code); |
| 1122 sink_.ClearMessages(); | 993 sink_.ClearMessages(); |
| 1123 } | 994 } |
| 1124 | 995 |
| 1125 TEST_F(BlobDispatcherHostTest, BuildingReferenceChainWithSourceDeath) { | 996 TEST_F(BlobDispatcherHostTest, BuildingReferenceChainWithSourceDeath) { |
| 1126 const std::string kId("id"); | 997 const std::string kId("id"); |
| 1127 const std::string kSameHostReferencingId("id2"); | 998 const std::string kSameHostReferencingId("id2"); |
| 1128 const std::string kDifferentHostReferencingId("id3"); | 999 const std::string kDifferentHostReferencingId("id3"); |
| 1129 // Data elements for our transfer & checking messages. | 1000 // Data elements for our transfer & checking messages. |
| 1001 DataElement element; |
| 1002 element.SetToBytesDescription(kDataSize); |
| 1130 DataElement referencing_element; | 1003 DataElement referencing_element; |
| 1131 referencing_element.SetToBlob(kId); | 1004 referencing_element.SetToBlob(kId); |
| 1005 std::vector<DataElement> elements = {element}; |
| 1132 std::vector<DataElement> referencing_elements = {referencing_element}; | 1006 std::vector<DataElement> referencing_elements = {referencing_element}; |
| 1133 std::set<std::string> referenced_blobs_set = {kId}; | 1007 std::vector<BlobItemBytesRequest> expected_requests = { |
| 1008 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)}; |
| 1009 BlobItemBytesResponse response(0); |
| 1010 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); |
| 1011 std::vector<BlobItemBytesResponse> responses = {response}; |
| 1134 | 1012 |
| 1135 scoped_refptr<TestableBlobDispatcherHost> host2( | 1013 scoped_refptr<TestableBlobDispatcherHost> host2( |
| 1136 new TestableBlobDispatcherHost(chrome_blob_storage_context_, | 1014 new TestableBlobDispatcherHost(chrome_blob_storage_context_, |
| 1137 file_system_context_.get(), &sink_)); | 1015 file_system_context_.get(), &sink_)); |
| 1138 | 1016 |
| 1139 // We want to have a blob referencing another blob that is building, both on | 1017 // We want to have a blob referencing another blob that is building, both on |
| 1140 // the same host and a different host. When we destroy the host, the other | 1018 // the same host and a different host. We should successfully build all blobs |
| 1141 // blob should cancel, as well as the blob on the other host. | 1019 // after the referenced blob is finished. |
| 1142 | 1020 |
| 1143 // First we start the referenced blob. | 1021 // First we start the referenced blob. |
| 1144 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 1022 host_->OnRegisterBlob(kId, std::string(kContentType), |
| 1145 std::string(kContentDisposition), | 1023 std::string(kContentDisposition), elements); |
| 1146 std::set<std::string>()); | 1024 ExpectRequest(kId, expected_requests); |
| 1025 sink_.ClearMessages(); |
| 1147 EXPECT_TRUE(host_->IsInUseInHost(kId)); | 1026 EXPECT_TRUE(host_->IsInUseInHost(kId)); |
| 1027 EXPECT_TRUE(IsBeingBuiltInContext(kId)); |
| 1148 | 1028 |
| 1149 // Next we start the referencing blobs in both the same and different host. | 1029 // Next we start the referencing blobs in both the same and different host. |
| 1150 host_->OnRegisterBlobUUID(kSameHostReferencingId, std::string(kContentType), | 1030 host_->OnRegisterBlob(kSameHostReferencingId, std::string(kContentType), |
| 1151 std::string(kContentDisposition), | 1031 std::string(kContentDisposition), referencing_elements); |
| 1152 referenced_blobs_set); | 1032 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 1153 host_->OnStartBuildingBlob(kSameHostReferencingId, referencing_elements); | |
| 1154 ExpectDone(kSameHostReferencingId); | 1033 ExpectDone(kSameHostReferencingId); |
| 1155 EXPECT_TRUE(host_->async_builder_.IsBeingBuilt(kSameHostReferencingId)); | |
| 1156 sink_.ClearMessages(); | 1034 sink_.ClearMessages(); |
| 1035 |
| 1157 // Now the other host. | 1036 // Now the other host. |
| 1158 host2->OnRegisterBlobUUID( | 1037 host2->OnRegisterBlob(kDifferentHostReferencingId, std::string(kContentType), |
| 1159 kDifferentHostReferencingId, std::string(kContentType), | 1038 std::string(kContentDisposition), referencing_elements); |
| 1160 std::string(kContentDisposition), referenced_blobs_set); | 1039 EXPECT_FALSE(host2->shutdown_for_bad_message_); |
| 1161 host2->OnStartBuildingBlob(kDifferentHostReferencingId, referencing_elements); | |
| 1162 ExpectDone(kDifferentHostReferencingId); | 1040 ExpectDone(kDifferentHostReferencingId); |
| 1163 EXPECT_TRUE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); | |
| 1164 sink_.ClearMessages(); | 1041 sink_.ClearMessages(); |
| 1165 | 1042 |
| 1166 // Grab handles & add listeners. | 1043 // Grab handles & add listeners. |
| 1167 bool built = true; | 1044 bool built = true; |
| 1168 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 1045 BlobStatus error_code = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS; |
| 1169 std::unique_ptr<BlobDataHandle> blob_handle = | 1046 std::unique_ptr<BlobDataHandle> blob_handle = |
| 1170 context_->GetBlobDataFromUUID(kId); | 1047 context_->GetBlobDataFromUUID(kId); |
| 1171 blob_handle->RunOnConstructionComplete( | 1048 blob_handle->RunOnConstructionComplete( |
| 1172 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 1049 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
| 1173 | 1050 |
| 1174 bool same_host_built = true; | 1051 bool same_host_built = true; |
| 1175 IPCBlobCreationCancelCode same_host_error_code = | 1052 BlobStatus same_host_error_code = |
| 1176 IPCBlobCreationCancelCode::UNKNOWN; | 1053 BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS; |
| 1177 std::unique_ptr<BlobDataHandle> same_host_blob_handle = | 1054 std::unique_ptr<BlobDataHandle> same_host_blob_handle = |
| 1178 context_->GetBlobDataFromUUID(kSameHostReferencingId); | 1055 context_->GetBlobDataFromUUID(kSameHostReferencingId); |
| 1179 same_host_blob_handle->RunOnConstructionComplete(base::Bind( | 1056 same_host_blob_handle->RunOnConstructionComplete(base::Bind( |
| 1180 &ConstructionCompletePopulator, &same_host_built, &same_host_error_code)); | 1057 &ConstructionCompletePopulator, &same_host_built, &same_host_error_code)); |
| 1181 | 1058 |
| 1182 bool other_host_built = true; | 1059 bool other_host_built = true; |
| 1183 IPCBlobCreationCancelCode other_host_error_code = | 1060 BlobStatus other_host_error_code = |
| 1184 IPCBlobCreationCancelCode::UNKNOWN; | 1061 BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS; |
| 1185 std::unique_ptr<BlobDataHandle> other_host_blob_handle = | 1062 std::unique_ptr<BlobDataHandle> other_host_blob_handle = |
| 1186 context_->GetBlobDataFromUUID(kDifferentHostReferencingId); | 1063 context_->GetBlobDataFromUUID(kDifferentHostReferencingId); |
| 1187 other_host_blob_handle->RunOnConstructionComplete( | 1064 other_host_blob_handle->RunOnConstructionComplete( |
| 1188 base::Bind(&ConstructionCompletePopulator, &other_host_built, | 1065 base::Bind(&ConstructionCompletePopulator, &other_host_built, |
| 1189 &other_host_error_code)); | 1066 &other_host_error_code)); |
| 1190 | 1067 |
| 1191 // Now we kill the host. | 1068 // Now we kill the host. |
| 1192 host_ = nullptr; | 1069 host_ = nullptr; |
| 1193 // We need to run the message loop to propagate the construction callbacks. | 1070 // We need to run the message loop to propagate the construction callbacks. |
| 1194 base::RunLoop().RunUntilIdle(); | 1071 base::RunLoop().RunUntilIdle(); |
| 1195 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); | 1072 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); |
| 1196 EXPECT_TRUE( | 1073 EXPECT_TRUE( |
| 1197 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); | 1074 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); |
| 1198 EXPECT_TRUE( | 1075 EXPECT_TRUE( |
| 1199 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); | 1076 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); |
| 1200 | 1077 |
| 1201 // Check our callbacks | 1078 // Check our callbacks |
| 1202 EXPECT_FALSE(built); | 1079 EXPECT_FALSE(built); |
| 1203 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, error_code); | 1080 EXPECT_EQ(BlobStatus::ERR_SOURCE_DIED_IN_TRANSIT, error_code); |
| 1204 EXPECT_FALSE(same_host_built); | 1081 EXPECT_FALSE(same_host_built); |
| 1205 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, | 1082 EXPECT_EQ(BlobStatus::ERR_REFERENCED_BLOB_BROKEN, same_host_error_code); |
| 1206 same_host_error_code); | |
| 1207 EXPECT_FALSE(other_host_built); | 1083 EXPECT_FALSE(other_host_built); |
| 1208 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, | 1084 EXPECT_EQ(BlobStatus::ERR_REFERENCED_BLOB_BROKEN, other_host_error_code); |
| 1209 other_host_error_code); | |
| 1210 | 1085 |
| 1211 sink_.ClearMessages(); | 1086 sink_.ClearMessages(); |
| 1212 } | 1087 } |
| 1213 | 1088 |
| 1214 } // namespace content | 1089 } // namespace content |
| OLD | NEW |