Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1372)

Side by Side Diff: content/browser/blob_storage/blob_dispatcher_host_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698