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