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

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

Issue 1853333003: [BlobAsync] Faster shortcuttin, make renderer controller leaky & alive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 8 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 <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 EXPECT_TRUE(context_->registry().HasEntry(kId)); 288 EXPECT_TRUE(context_->registry().HasEntry(kId));
289 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); 289 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId);
290 EXPECT_TRUE(handle); 290 EXPECT_TRUE(handle);
291 291
292 DataElement expected; 292 DataElement expected;
293 expected.SetToBytes(kData, kDataSize); 293 expected.SetToBytes(kData, kDataSize);
294 std::vector<DataElement> elements = {expected}; 294 std::vector<DataElement> elements = {expected};
295 ExpectHandleEqualsData(handle.get(), elements); 295 ExpectHandleEqualsData(handle.get(), elements);
296 } 296 }
297 297
298 TEST_F(BlobDispatcherHostTest, MultipleTransfers) {
299 const std::string kId = "uuid";
300 const int kNumIters = 10;
301 for (int i = 0; i < kNumIters; i++) {
302 std::string id = kId;
303 id += ('0' + i);
304 ExpectBlobNotExist(id);
305 host_->OnRegisterBlobUUID(id, std::string(kContentType),
306 std::string(kContentDisposition),
307 std::set<std::string>());
308 EXPECT_FALSE(host_->shutdown_for_bad_message_);
309 }
310 sink_.ClearMessages();
311 for (int i = 0; i < kNumIters; i++) {
312 std::string id = kId;
313 id += ('0' + i);
314 DataElement element;
315 element.SetToBytesDescription(kDataSize);
316 std::vector<DataElement> elements = {element};
317 host_->OnStartBuildingBlob(id, elements);
318 EXPECT_FALSE(host_->shutdown_for_bad_message_);
319 // Expect our request.
320 std::vector<BlobItemBytesRequest> expected_requests = {
321 BlobItemBytesRequest::CreateIPCRequest(0, 0, 0, kDataSize)};
322 ExpectRequest(id, expected_requests);
323 sink_.ClearMessages();
324 }
325 for (int i = 0; i < kNumIters; i++) {
326 std::string id = kId;
327 id += ('0' + i);
328 // Send results;
329 BlobItemBytesResponse response(0);
330 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize);
331 std::vector<BlobItemBytesResponse> responses = {response};
332 host_->OnMemoryItemResponse(id, responses);
333 ExpectDone(id);
334 sink_.ClearMessages();
335 }
336 }
337
298 TEST_F(BlobDispatcherHostTest, SharedMemoryTransfer) { 338 TEST_F(BlobDispatcherHostTest, SharedMemoryTransfer) {
299 const std::string kId = "uuid1"; 339 const std::string kId = "uuid1";
300 const size_t kLargeSize = kTestBlobStorageMaxSharedMemoryBytes * 2; 340 const size_t kLargeSize = kTestBlobStorageMaxSharedMemoryBytes * 2;
301 std::vector<base::SharedMemoryHandle> shared_memory_handles; 341 std::vector<base::SharedMemoryHandle> shared_memory_handles;
302 342
303 ExpectBlobNotExist(kId); 343 ExpectBlobNotExist(kId);
304 host_->OnRegisterBlobUUID(kId, std::string(kContentType), 344 host_->OnRegisterBlobUUID(kId, std::string(kContentType),
305 std::string(kContentDisposition), 345 std::string(kContentDisposition),
306 std::set<std::string>()); 346 std::set<std::string>());
347
307 // Grab the handle. 348 // Grab the handle.
308 scoped_ptr<BlobDataHandle> blob_data_handle = 349 scoped_ptr<BlobDataHandle> blob_data_handle =
309 context_->GetBlobDataFromUUID(kId); 350 context_->GetBlobDataFromUUID(kId);
310 bool built = false; 351 bool built = false;
311 blob_data_handle->RunOnConstructionComplete( 352 blob_data_handle->RunOnConstructionComplete(
312 base::Bind(&SetPointerValue<bool>, &built)); 353 base::Bind(&SetPointerValue<bool>, &built));
313 EXPECT_FALSE(built); 354 EXPECT_FALSE(built);
314 355
315 EXPECT_FALSE(host_->shutdown_for_bad_message_); 356 EXPECT_FALSE(host_->shutdown_for_bad_message_);
316 DataElement element; 357 DataElement element;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 EXPECT_TRUE(host_->IsInUseInHost(kId)); 455 EXPECT_TRUE(host_->IsInUseInHost(kId));
415 EXPECT_FALSE(IsBeingBuiltInHost(kId)); 456 EXPECT_FALSE(IsBeingBuiltInHost(kId));
416 // Check that's it's broken. 457 // Check that's it's broken.
417 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); 458 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId);
418 EXPECT_TRUE(handle->IsBroken()); 459 EXPECT_TRUE(handle->IsBroken());
419 handle.reset(); 460 handle.reset();
420 base::RunLoop().RunUntilIdle(); 461 base::RunLoop().RunUntilIdle();
421 462
422 // Get rid of it in the host. 463 // Get rid of it in the host.
423 host_->OnDecrementBlobRefCount(kId); 464 host_->OnDecrementBlobRefCount(kId);
465 EXPECT_FALSE(host_->shutdown_for_bad_message_);
424 ExpectBlobNotExist(kId); 466 ExpectBlobNotExist(kId);
425 467
426 // Create blob again to verify we don't have any old construction state lying 468 // Create blob again to verify we don't have any old construction state lying
427 // around. 469 // around.
428 AsyncBlobTransfer(kId); 470 AsyncBlobTransfer(kId);
429 471
430 // Check data. 472 // Check data.
431 handle = context_->GetBlobDataFromUUID(kId); 473 handle = context_->GetBlobDataFromUUID(kId);
432 EXPECT_TRUE(handle); 474 EXPECT_TRUE(handle);
433 DataElement expected; 475 DataElement expected;
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 // So no more blob in the context, but we're still being built in host 1. 962 // So no more blob in the context, but we're still being built in host 1.
921 EXPECT_FALSE(context_->registry().HasEntry(kId)); 963 EXPECT_FALSE(context_->registry().HasEntry(kId));
922 EXPECT_TRUE(host_->async_builder_.IsBeingBuilt(kId)); 964 EXPECT_TRUE(host_->async_builder_.IsBeingBuilt(kId));
923 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); 965 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN);
924 EXPECT_FALSE(host_->shutdown_for_bad_message_); 966 EXPECT_FALSE(host_->shutdown_for_bad_message_);
925 // We should be cleaned up. 967 // We should be cleaned up.
926 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kId)); 968 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kId));
927 } 969 }
928 970
929 } // namespace content 971 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698