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 <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/shared_memory.h" | 11 #include "base/memory/shared_memory.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/tuple.h" | 13 #include "base/tuple.h" |
14 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 14 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
15 #include "content/common/fileapi/webblob_messages.h" | 15 #include "content/common/fileapi/webblob_messages.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 #include "content/public/test/test_browser_context.h" | 17 #include "content/public/test/test_browser_context.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "ipc/ipc_sender.h" | 19 #include "ipc/ipc_sender.h" |
20 #include "ipc/ipc_test_sink.h" | 20 #include "ipc/ipc_test_sink.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 sink_.ClearMessages(); | 157 sink_.ClearMessages(); |
158 } | 158 } |
159 | 159 |
160 void ExpectAndResetBadMessage() { | 160 void ExpectAndResetBadMessage() { |
161 EXPECT_TRUE(host_->shutdown_for_bad_message_); | 161 EXPECT_TRUE(host_->shutdown_for_bad_message_); |
162 host_->shutdown_for_bad_message_ = false; | 162 host_->shutdown_for_bad_message_ = false; |
163 } | 163 } |
164 | 164 |
165 void ExpectHandleEqualsData(BlobDataHandle* handle, | 165 void ExpectHandleEqualsData(BlobDataHandle* handle, |
166 const std::vector<DataElement>& data) { | 166 const std::vector<DataElement>& data) { |
167 scoped_ptr<storage::BlobDataSnapshot> snapshot = handle->CreateSnapshot(); | 167 std::unique_ptr<storage::BlobDataSnapshot> snapshot = |
| 168 handle->CreateSnapshot(); |
168 EXPECT_FALSE(handle->IsBeingBuilt()); | 169 EXPECT_FALSE(handle->IsBeingBuilt()); |
169 for (size_t i = 0; i < data.size(); i++) { | 170 for (size_t i = 0; i < data.size(); i++) { |
170 const DataElement& expected = data[i]; | 171 const DataElement& expected = data[i]; |
171 const DataElement& actual = snapshot->items()[i]->data_element(); | 172 const DataElement& actual = snapshot->items()[i]->data_element(); |
172 EXPECT_EQ(expected, actual); | 173 EXPECT_EQ(expected, actual); |
173 } | 174 } |
174 EXPECT_EQ(data.size(), snapshot->items().size()); | 175 EXPECT_EQ(data.size(), snapshot->items().size()); |
175 } | 176 } |
176 | 177 |
177 void ExpectRequest( | 178 void ExpectRequest( |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 host_->OnMemoryItemResponse("", std::vector<BlobItemBytesResponse>()); | 270 host_->OnMemoryItemResponse("", std::vector<BlobItemBytesResponse>()); |
270 ExpectAndResetBadMessage(); | 271 ExpectAndResetBadMessage(); |
271 host_->OnCancelBuildingBlob("", IPCBlobCreationCancelCode::UNKNOWN); | 272 host_->OnCancelBuildingBlob("", IPCBlobCreationCancelCode::UNKNOWN); |
272 ExpectAndResetBadMessage(); | 273 ExpectAndResetBadMessage(); |
273 } | 274 } |
274 | 275 |
275 TEST_F(BlobDispatcherHostTest, Shortcut) { | 276 TEST_F(BlobDispatcherHostTest, Shortcut) { |
276 const std::string kId = "uuid1"; | 277 const std::string kId = "uuid1"; |
277 AsyncShortcutBlobTransfer(kId); | 278 AsyncShortcutBlobTransfer(kId); |
278 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 279 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
279 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); | 280 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); |
280 EXPECT_TRUE(handle); | 281 EXPECT_TRUE(handle); |
281 | 282 |
282 DataElement expected; | 283 DataElement expected; |
283 expected.SetToBytes(kData, kDataSize); | 284 expected.SetToBytes(kData, kDataSize); |
284 std::vector<DataElement> elements = {expected}; | 285 std::vector<DataElement> elements = {expected}; |
285 ExpectHandleEqualsData(handle.get(), elements); | 286 ExpectHandleEqualsData(handle.get(), elements); |
286 } | 287 } |
287 | 288 |
288 TEST_F(BlobDispatcherHostTest, RegularTransfer) { | 289 TEST_F(BlobDispatcherHostTest, RegularTransfer) { |
289 const std::string kId = "uuid1"; | 290 const std::string kId = "uuid1"; |
290 AsyncBlobTransfer(kId); | 291 AsyncBlobTransfer(kId); |
291 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 292 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
292 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); | 293 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); |
293 EXPECT_TRUE(handle); | 294 EXPECT_TRUE(handle); |
294 | 295 |
295 DataElement expected; | 296 DataElement expected; |
296 expected.SetToBytes(kData, kDataSize); | 297 expected.SetToBytes(kData, kDataSize); |
297 std::vector<DataElement> elements = {expected}; | 298 std::vector<DataElement> elements = {expected}; |
298 ExpectHandleEqualsData(handle.get(), elements); | 299 ExpectHandleEqualsData(handle.get(), elements); |
299 } | 300 } |
300 | 301 |
301 TEST_F(BlobDispatcherHostTest, MultipleTransfers) { | 302 TEST_F(BlobDispatcherHostTest, MultipleTransfers) { |
302 const std::string kId = "uuid"; | 303 const std::string kId = "uuid"; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 const std::string kId = "uuid1"; | 343 const std::string kId = "uuid1"; |
343 const size_t kLargeSize = kTestBlobStorageMaxSharedMemoryBytes * 2; | 344 const size_t kLargeSize = kTestBlobStorageMaxSharedMemoryBytes * 2; |
344 std::vector<base::SharedMemoryHandle> shared_memory_handles; | 345 std::vector<base::SharedMemoryHandle> shared_memory_handles; |
345 | 346 |
346 ExpectBlobNotExist(kId); | 347 ExpectBlobNotExist(kId); |
347 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 348 host_->OnRegisterBlobUUID(kId, std::string(kContentType), |
348 std::string(kContentDisposition), | 349 std::string(kContentDisposition), |
349 std::set<std::string>()); | 350 std::set<std::string>()); |
350 | 351 |
351 // Grab the handle. | 352 // Grab the handle. |
352 scoped_ptr<BlobDataHandle> blob_data_handle = | 353 std::unique_ptr<BlobDataHandle> blob_data_handle = |
353 context_->GetBlobDataFromUUID(kId); | 354 context_->GetBlobDataFromUUID(kId); |
354 bool built = false; | 355 bool built = false; |
355 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 356 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; |
356 blob_data_handle->RunOnConstructionComplete( | 357 blob_data_handle->RunOnConstructionComplete( |
357 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 358 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
358 EXPECT_FALSE(built); | 359 EXPECT_FALSE(built); |
359 | 360 |
360 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 361 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
361 DataElement element; | 362 DataElement element; |
362 element.SetToBytesDescription(kLargeSize); | 363 element.SetToBytesDescription(kLargeSize); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 415 } |
415 // Send the confirmation. | 416 // Send the confirmation. |
416 responses = {BlobItemBytesResponse(1)}; | 417 responses = {BlobItemBytesResponse(1)}; |
417 host_->OnMemoryItemResponse(kId, responses); | 418 host_->OnMemoryItemResponse(kId, responses); |
418 | 419 |
419 ExpectDone(kId); | 420 ExpectDone(kId); |
420 sink_.ClearMessages(); | 421 sink_.ClearMessages(); |
421 base::RunLoop().RunUntilIdle(); | 422 base::RunLoop().RunUntilIdle(); |
422 EXPECT_TRUE(built) << "Error code: " << static_cast<int>(error_code); | 423 EXPECT_TRUE(built) << "Error code: " << static_cast<int>(error_code); |
423 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 424 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
424 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); | 425 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); |
425 EXPECT_TRUE(handle); | 426 EXPECT_TRUE(handle); |
426 | 427 |
427 DataElement expected; | 428 DataElement expected; |
428 expected.SetToAllocatedBytes(kLargeSize / 2); | 429 expected.SetToAllocatedBytes(kLargeSize / 2); |
429 std::memset(expected.mutable_bytes(), 'X', kLargeSize / 2); | 430 std::memset(expected.mutable_bytes(), 'X', kLargeSize / 2); |
430 elements = {expected}; | 431 elements = {expected}; |
431 std::memset(expected.mutable_bytes(), 'Z', kLargeSize / 2); | 432 std::memset(expected.mutable_bytes(), 'Z', kLargeSize / 2); |
432 elements.push_back(expected); | 433 elements.push_back(expected); |
433 ExpectHandleEqualsData(handle.get(), elements); | 434 ExpectHandleEqualsData(handle.get(), elements); |
434 } | 435 } |
(...skipping 17 matching lines...) Expand all Loading... |
452 // It should have requested memory here. | 453 // It should have requested memory here. |
453 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 454 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
454 sink_.ClearMessages(); | 455 sink_.ClearMessages(); |
455 | 456 |
456 // Cancel in middle of construction. | 457 // Cancel in middle of construction. |
457 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); | 458 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); |
458 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 459 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
459 EXPECT_TRUE(host_->IsInUseInHost(kId)); | 460 EXPECT_TRUE(host_->IsInUseInHost(kId)); |
460 EXPECT_FALSE(IsBeingBuiltInHost(kId)); | 461 EXPECT_FALSE(IsBeingBuiltInHost(kId)); |
461 // Check that's it's broken. | 462 // Check that's it's broken. |
462 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); | 463 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); |
463 EXPECT_TRUE(handle->IsBroken()); | 464 EXPECT_TRUE(handle->IsBroken()); |
464 handle.reset(); | 465 handle.reset(); |
465 base::RunLoop().RunUntilIdle(); | 466 base::RunLoop().RunUntilIdle(); |
466 | 467 |
467 // Get rid of it in the host. | 468 // Get rid of it in the host. |
468 host_->OnDecrementBlobRefCount(kId); | 469 host_->OnDecrementBlobRefCount(kId); |
469 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 470 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
470 ExpectBlobNotExist(kId); | 471 ExpectBlobNotExist(kId); |
471 | 472 |
472 // Create blob again to verify we don't have any old construction state lying | 473 // Create blob again to verify we don't have any old construction state lying |
(...skipping 10 matching lines...) Expand all Loading... |
483 | 484 |
484 // Verify we can't cancel after the fact. | 485 // Verify we can't cancel after the fact. |
485 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); | 486 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); |
486 ExpectAndResetBadMessage(); | 487 ExpectAndResetBadMessage(); |
487 } | 488 } |
488 | 489 |
489 TEST_F(BlobDispatcherHostTest, BlobDataWithHostDeletion) { | 490 TEST_F(BlobDispatcherHostTest, BlobDataWithHostDeletion) { |
490 // Build up a basic blob. | 491 // Build up a basic blob. |
491 const std::string kId("id"); | 492 const std::string kId("id"); |
492 AsyncShortcutBlobTransfer(kId); | 493 AsyncShortcutBlobTransfer(kId); |
493 scoped_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); | 494 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); |
494 EXPECT_TRUE(handle); | 495 EXPECT_TRUE(handle); |
495 | 496 |
496 // Kill the host. | 497 // Kill the host. |
497 host_ = nullptr; | 498 host_ = nullptr; |
498 base::RunLoop().RunUntilIdle(); | 499 base::RunLoop().RunUntilIdle(); |
499 // Should still be there due to the handle. | 500 // Should still be there due to the handle. |
500 scoped_ptr<BlobDataHandle> another_handle = | 501 std::unique_ptr<BlobDataHandle> another_handle = |
501 context_->GetBlobDataFromUUID(kId); | 502 context_->GetBlobDataFromUUID(kId); |
502 EXPECT_TRUE(another_handle); | 503 EXPECT_TRUE(another_handle); |
503 | 504 |
504 // Should disappear after dropping both handles. | 505 // Should disappear after dropping both handles. |
505 handle.reset(); | 506 handle.reset(); |
506 another_handle.reset(); | 507 another_handle.reset(); |
507 base::RunLoop().RunUntilIdle(); | 508 base::RunLoop().RunUntilIdle(); |
508 | 509 |
509 handle = context_->GetBlobDataFromUUID(kId); | 510 handle = context_->GetBlobDataFromUUID(kId); |
510 EXPECT_FALSE(handle); | 511 EXPECT_FALSE(handle); |
511 } | 512 } |
512 | 513 |
513 TEST_F(BlobDispatcherHostTest, BlobReferenceWhileConstructing) { | 514 TEST_F(BlobDispatcherHostTest, BlobReferenceWhileConstructing) { |
514 const std::string kId("id"); | 515 const std::string kId("id"); |
515 | 516 |
516 // Start building blob. | 517 // Start building blob. |
517 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 518 host_->OnRegisterBlobUUID(kId, std::string(kContentType), |
518 std::string(kContentDisposition), | 519 std::string(kContentDisposition), |
519 std::set<std::string>()); | 520 std::set<std::string>()); |
520 | 521 |
521 // Grab the handle. | 522 // Grab the handle. |
522 scoped_ptr<BlobDataHandle> blob_data_handle = | 523 std::unique_ptr<BlobDataHandle> blob_data_handle = |
523 context_->GetBlobDataFromUUID(kId); | 524 context_->GetBlobDataFromUUID(kId); |
524 EXPECT_TRUE(blob_data_handle); | 525 EXPECT_TRUE(blob_data_handle); |
525 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); | 526 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); |
526 bool built = false; | 527 bool built = false; |
527 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 528 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; |
528 blob_data_handle->RunOnConstructionComplete( | 529 blob_data_handle->RunOnConstructionComplete( |
529 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 530 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
530 | 531 |
531 // Continue building. | 532 // Continue building. |
532 DataElement element; | 533 DataElement element; |
(...skipping 16 matching lines...) Expand all Loading... |
549 | 550 |
550 TEST_F(BlobDispatcherHostTest, BlobReferenceWhileShortcutConstructing) { | 551 TEST_F(BlobDispatcherHostTest, BlobReferenceWhileShortcutConstructing) { |
551 const std::string kId("id"); | 552 const std::string kId("id"); |
552 | 553 |
553 // Start building blob. | 554 // Start building blob. |
554 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 555 host_->OnRegisterBlobUUID(kId, std::string(kContentType), |
555 std::string(kContentDisposition), | 556 std::string(kContentDisposition), |
556 std::set<std::string>()); | 557 std::set<std::string>()); |
557 | 558 |
558 // Grab the handle. | 559 // Grab the handle. |
559 scoped_ptr<BlobDataHandle> blob_data_handle = | 560 std::unique_ptr<BlobDataHandle> blob_data_handle = |
560 context_->GetBlobDataFromUUID(kId); | 561 context_->GetBlobDataFromUUID(kId); |
561 EXPECT_TRUE(blob_data_handle); | 562 EXPECT_TRUE(blob_data_handle); |
562 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); | 563 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); |
563 bool built = false; | 564 bool built = false; |
564 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 565 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; |
565 blob_data_handle->RunOnConstructionComplete( | 566 blob_data_handle->RunOnConstructionComplete( |
566 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 567 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
567 | 568 |
568 // Continue building. | 569 // Continue building. |
569 DataElement element; | 570 DataElement element; |
570 element.SetToBytes(kData, kDataSize); | 571 element.SetToBytes(kData, kDataSize); |
571 std::vector<DataElement> elements = {element}; | 572 std::vector<DataElement> elements = {element}; |
572 host_->OnStartBuildingBlob(kId, elements); | 573 host_->OnStartBuildingBlob(kId, elements); |
573 ExpectDone(kId); | 574 ExpectDone(kId); |
574 base::RunLoop().RunUntilIdle(); | 575 base::RunLoop().RunUntilIdle(); |
575 EXPECT_TRUE(built) << "Error code: " << static_cast<int>(error_code); | 576 EXPECT_TRUE(built) << "Error code: " << static_cast<int>(error_code); |
576 } | 577 } |
577 | 578 |
578 TEST_F(BlobDispatcherHostTest, BlobReferenceWhileConstructingCancelled) { | 579 TEST_F(BlobDispatcherHostTest, BlobReferenceWhileConstructingCancelled) { |
579 const std::string kId("id"); | 580 const std::string kId("id"); |
580 | 581 |
581 // Start building blob. | 582 // Start building blob. |
582 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 583 host_->OnRegisterBlobUUID(kId, std::string(kContentType), |
583 std::string(kContentDisposition), | 584 std::string(kContentDisposition), |
584 std::set<std::string>()); | 585 std::set<std::string>()); |
585 | 586 |
586 // Grab the handle. | 587 // Grab the handle. |
587 scoped_ptr<BlobDataHandle> blob_data_handle = | 588 std::unique_ptr<BlobDataHandle> blob_data_handle = |
588 context_->GetBlobDataFromUUID(kId); | 589 context_->GetBlobDataFromUUID(kId); |
589 EXPECT_TRUE(blob_data_handle); | 590 EXPECT_TRUE(blob_data_handle); |
590 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); | 591 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); |
591 bool built = true; | 592 bool built = true; |
592 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 593 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; |
593 blob_data_handle->RunOnConstructionComplete( | 594 blob_data_handle->RunOnConstructionComplete( |
594 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 595 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
595 | 596 |
596 // Cancel in middle of construction. | 597 // Cancel in middle of construction. |
597 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); | 598 host_->OnCancelBuildingBlob(kId, IPCBlobCreationCancelCode::UNKNOWN); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 EXPECT_FALSE(context_->registry().HasEntry(kId)); | 630 EXPECT_FALSE(context_->registry().HasEntry(kId)); |
630 EXPECT_FALSE(IsBeingBuiltInHost(kId)); | 631 EXPECT_FALSE(IsBeingBuiltInHost(kId)); |
631 ExpectCancel(kId, | 632 ExpectCancel(kId, |
632 IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING); | 633 IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING); |
633 sink_.ClearMessages(); | 634 sink_.ClearMessages(); |
634 | 635 |
635 // Do the same, but this time grab a handle before we decrement. | 636 // Do the same, but this time grab a handle before we decrement. |
636 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 637 host_->OnRegisterBlobUUID(kId, std::string(kContentType), |
637 std::string(kContentDisposition), | 638 std::string(kContentDisposition), |
638 std::set<std::string>()); | 639 std::set<std::string>()); |
639 scoped_ptr<BlobDataHandle> blob_data_handle = | 640 std::unique_ptr<BlobDataHandle> blob_data_handle = |
640 context_->GetBlobDataFromUUID(kId); | 641 context_->GetBlobDataFromUUID(kId); |
641 host_->OnDecrementBlobRefCount(kId); | 642 host_->OnDecrementBlobRefCount(kId); |
642 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 643 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
643 EXPECT_TRUE(IsBeingBuiltInHost(kId)); | 644 EXPECT_TRUE(IsBeingBuiltInHost(kId)); |
644 | 645 |
645 // Finish up the blob, and verify we got the done message. | 646 // Finish up the blob, and verify we got the done message. |
646 DataElement element; | 647 DataElement element; |
647 element.SetToBytes(kData, kDataSize); | 648 element.SetToBytes(kData, kDataSize); |
648 std::vector<DataElement> elements = {element}; | 649 std::vector<DataElement> elements = {element}; |
649 host_->OnStartBuildingBlob(kId, elements); | 650 host_->OnStartBuildingBlob(kId, elements); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 689 host_->OnRegisterBlobUUID(kId, std::string(kContentType), |
689 std::string(kContentDisposition), | 690 std::string(kContentDisposition), |
690 std::set<std::string>()); | 691 std::set<std::string>()); |
691 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 692 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
692 host_->OnStartBuildingBlob(kId, elements); | 693 host_->OnStartBuildingBlob(kId, elements); |
693 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 694 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
694 ExpectRequest(kId, expected_requests); | 695 ExpectRequest(kId, expected_requests); |
695 sink_.ClearMessages(); | 696 sink_.ClearMessages(); |
696 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 697 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
697 // Grab the handle before decrementing. | 698 // Grab the handle before decrementing. |
698 scoped_ptr<BlobDataHandle> blob_data_handle = | 699 std::unique_ptr<BlobDataHandle> blob_data_handle = |
699 context_->GetBlobDataFromUUID(kId); | 700 context_->GetBlobDataFromUUID(kId); |
700 host_->OnDecrementBlobRefCount(kId); | 701 host_->OnDecrementBlobRefCount(kId); |
701 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 702 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
702 EXPECT_TRUE(IsBeingBuiltInHost(kId)); | 703 EXPECT_TRUE(IsBeingBuiltInHost(kId)); |
703 | 704 |
704 // We finish the blob, and verify that we send 'Done' back to the renderer. | 705 // We finish the blob, and verify that we send 'Done' back to the renderer. |
705 BlobItemBytesResponse response(0); | 706 BlobItemBytesResponse response(0); |
706 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); | 707 std::memcpy(response.allocate_mutable_data(kDataSize), kData, kDataSize); |
707 std::vector<BlobItemBytesResponse> responses = {response}; | 708 std::vector<BlobItemBytesResponse> responses = {response}; |
708 host_->OnMemoryItemResponse(kId, responses); | 709 host_->OnMemoryItemResponse(kId, responses); |
(...skipping 13 matching lines...) Expand all Loading... |
722 | 723 |
723 TEST_F(BlobDispatcherHostTest, DecrementRefAfterOnStartWithHandle) { | 724 TEST_F(BlobDispatcherHostTest, DecrementRefAfterOnStartWithHandle) { |
724 const std::string kId("id"); | 725 const std::string kId("id"); |
725 // Decrement the refcount while building, after we call | 726 // Decrement the refcount while building, after we call |
726 // OnStartBuildlingBlob, except we have another handle. | 727 // OnStartBuildlingBlob, except we have another handle. |
727 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 728 host_->OnRegisterBlobUUID(kId, std::string(kContentType), |
728 std::string(kContentDisposition), | 729 std::string(kContentDisposition), |
729 std::set<std::string>()); | 730 std::set<std::string>()); |
730 EXPECT_FALSE(host_->shutdown_for_bad_message_); | 731 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
731 | 732 |
732 scoped_ptr<BlobDataHandle> blob_data_handle = | 733 std::unique_ptr<BlobDataHandle> blob_data_handle = |
733 context_->GetBlobDataFromUUID(kId); | 734 context_->GetBlobDataFromUUID(kId); |
734 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); | 735 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); |
735 bool built = true; | 736 bool built = true; |
736 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 737 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; |
737 blob_data_handle->RunOnConstructionComplete( | 738 blob_data_handle->RunOnConstructionComplete( |
738 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 739 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
739 | 740 |
740 DataElement element; | 741 DataElement element; |
741 element.SetToBytesDescription(kDataSize); | 742 element.SetToBytesDescription(kDataSize); |
742 std::vector<DataElement> elements = {element}; | 743 std::vector<DataElement> elements = {element}; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 } | 776 } |
776 | 777 |
777 TEST_F(BlobDispatcherHostTest, HostDisconnectAfterRegisterWithHandle) { | 778 TEST_F(BlobDispatcherHostTest, HostDisconnectAfterRegisterWithHandle) { |
778 const std::string kId("id"); | 779 const std::string kId("id"); |
779 | 780 |
780 // Delete host with a handle to the blob. | 781 // Delete host with a handle to the blob. |
781 host_->OnRegisterBlobUUID(kId, std::string(kContentType), | 782 host_->OnRegisterBlobUUID(kId, std::string(kContentType), |
782 std::string(kContentDisposition), | 783 std::string(kContentDisposition), |
783 std::set<std::string>()); | 784 std::set<std::string>()); |
784 | 785 |
785 scoped_ptr<BlobDataHandle> blob_data_handle = | 786 std::unique_ptr<BlobDataHandle> blob_data_handle = |
786 context_->GetBlobDataFromUUID(kId); | 787 context_->GetBlobDataFromUUID(kId); |
787 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); | 788 EXPECT_TRUE(blob_data_handle->IsBeingBuilt()); |
788 bool built = true; | 789 bool built = true; |
789 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 790 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; |
790 blob_data_handle->RunOnConstructionComplete( | 791 blob_data_handle->RunOnConstructionComplete( |
791 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 792 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
792 // Get rid of host, which was doing the constructing. | 793 // Get rid of host, which was doing the constructing. |
793 host_ = nullptr; | 794 host_ = nullptr; |
794 EXPECT_FALSE(blob_data_handle->IsBeingBuilt()); | 795 EXPECT_FALSE(blob_data_handle->IsBeingBuilt()); |
795 base::RunLoop().RunUntilIdle(); | 796 base::RunLoop().RunUntilIdle(); |
796 EXPECT_FALSE(built); | 797 EXPECT_FALSE(built); |
797 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, error_code); | 798 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, error_code); |
798 | 799 |
799 // Should still be there due to the handle. | 800 // Should still be there due to the handle. |
800 scoped_ptr<BlobDataHandle> another_handle = | 801 std::unique_ptr<BlobDataHandle> another_handle = |
801 context_->GetBlobDataFromUUID(kId); | 802 context_->GetBlobDataFromUUID(kId); |
802 EXPECT_TRUE(another_handle); | 803 EXPECT_TRUE(another_handle); |
803 | 804 |
804 // Should disappear after dropping both handles. | 805 // Should disappear after dropping both handles. |
805 blob_data_handle.reset(); | 806 blob_data_handle.reset(); |
806 another_handle.reset(); | 807 another_handle.reset(); |
807 base::RunLoop().RunUntilIdle(); | 808 base::RunLoop().RunUntilIdle(); |
808 EXPECT_FALSE(context_->registry().HasEntry(kId)); | 809 EXPECT_FALSE(context_->registry().HasEntry(kId)); |
809 } | 810 } |
810 | 811 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 base::RunLoop().RunUntilIdle(); | 1038 base::RunLoop().RunUntilIdle(); |
1038 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); | 1039 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); |
1039 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kSameHostReferencingId)); | 1040 EXPECT_FALSE(host_->async_builder_.IsBeingBuilt(kSameHostReferencingId)); |
1040 EXPECT_FALSE( | 1041 EXPECT_FALSE( |
1041 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); | 1042 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); |
1042 EXPECT_FALSE( | 1043 EXPECT_FALSE( |
1043 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); | 1044 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); |
1044 sink_.ClearMessages(); | 1045 sink_.ClearMessages(); |
1045 | 1046 |
1046 // Finally check that our data is correct in the child elements. | 1047 // Finally check that our data is correct in the child elements. |
1047 scoped_ptr<BlobDataHandle> handle = | 1048 std::unique_ptr<BlobDataHandle> handle = |
1048 context_->GetBlobDataFromUUID(kDifferentHostReferencingId); | 1049 context_->GetBlobDataFromUUID(kDifferentHostReferencingId); |
1049 ExpectHandleEqualsData(handle.get(), elements); | 1050 ExpectHandleEqualsData(handle.get(), elements); |
1050 } | 1051 } |
1051 | 1052 |
1052 TEST_F(BlobDispatcherHostTest, BuildingReferenceChainWithCancel) { | 1053 TEST_F(BlobDispatcherHostTest, BuildingReferenceChainWithCancel) { |
1053 const std::string kId("id"); | 1054 const std::string kId("id"); |
1054 const std::string kSameHostReferencingId("id2"); | 1055 const std::string kSameHostReferencingId("id2"); |
1055 const std::string kDifferentHostReferencingId("id3"); | 1056 const std::string kDifferentHostReferencingId("id3"); |
1056 // Data elements for our transfer & checking messages. | 1057 // Data elements for our transfer & checking messages. |
1057 DataElement referencing_element; | 1058 DataElement referencing_element; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 kDifferentHostReferencingId, std::string(kContentType), | 1146 kDifferentHostReferencingId, std::string(kContentType), |
1146 std::string(kContentDisposition), referenced_blobs_set); | 1147 std::string(kContentDisposition), referenced_blobs_set); |
1147 host2->OnStartBuildingBlob(kDifferentHostReferencingId, referencing_elements); | 1148 host2->OnStartBuildingBlob(kDifferentHostReferencingId, referencing_elements); |
1148 ExpectDone(kDifferentHostReferencingId); | 1149 ExpectDone(kDifferentHostReferencingId); |
1149 EXPECT_TRUE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); | 1150 EXPECT_TRUE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); |
1150 sink_.ClearMessages(); | 1151 sink_.ClearMessages(); |
1151 | 1152 |
1152 // Grab handles & add listeners. | 1153 // Grab handles & add listeners. |
1153 bool built = true; | 1154 bool built = true; |
1154 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; | 1155 IPCBlobCreationCancelCode error_code = IPCBlobCreationCancelCode::UNKNOWN; |
1155 scoped_ptr<BlobDataHandle> blob_handle = context_->GetBlobDataFromUUID(kId); | 1156 std::unique_ptr<BlobDataHandle> blob_handle = |
| 1157 context_->GetBlobDataFromUUID(kId); |
1156 blob_handle->RunOnConstructionComplete( | 1158 blob_handle->RunOnConstructionComplete( |
1157 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); | 1159 base::Bind(&ConstructionCompletePopulator, &built, &error_code)); |
1158 | 1160 |
1159 bool same_host_built = true; | 1161 bool same_host_built = true; |
1160 IPCBlobCreationCancelCode same_host_error_code = | 1162 IPCBlobCreationCancelCode same_host_error_code = |
1161 IPCBlobCreationCancelCode::UNKNOWN; | 1163 IPCBlobCreationCancelCode::UNKNOWN; |
1162 scoped_ptr<BlobDataHandle> same_host_blob_handle = | 1164 std::unique_ptr<BlobDataHandle> same_host_blob_handle = |
1163 context_->GetBlobDataFromUUID(kSameHostReferencingId); | 1165 context_->GetBlobDataFromUUID(kSameHostReferencingId); |
1164 same_host_blob_handle->RunOnConstructionComplete(base::Bind( | 1166 same_host_blob_handle->RunOnConstructionComplete(base::Bind( |
1165 &ConstructionCompletePopulator, &same_host_built, &same_host_error_code)); | 1167 &ConstructionCompletePopulator, &same_host_built, &same_host_error_code)); |
1166 | 1168 |
1167 bool other_host_built = true; | 1169 bool other_host_built = true; |
1168 IPCBlobCreationCancelCode other_host_error_code = | 1170 IPCBlobCreationCancelCode other_host_error_code = |
1169 IPCBlobCreationCancelCode::UNKNOWN; | 1171 IPCBlobCreationCancelCode::UNKNOWN; |
1170 scoped_ptr<BlobDataHandle> other_host_blob_handle = | 1172 std::unique_ptr<BlobDataHandle> other_host_blob_handle = |
1171 context_->GetBlobDataFromUUID(kDifferentHostReferencingId); | 1173 context_->GetBlobDataFromUUID(kDifferentHostReferencingId); |
1172 other_host_blob_handle->RunOnConstructionComplete( | 1174 other_host_blob_handle->RunOnConstructionComplete( |
1173 base::Bind(&ConstructionCompletePopulator, &other_host_built, | 1175 base::Bind(&ConstructionCompletePopulator, &other_host_built, |
1174 &other_host_error_code)); | 1176 &other_host_error_code)); |
1175 | 1177 |
1176 // Now we kill the host. | 1178 // Now we kill the host. |
1177 host_ = nullptr; | 1179 host_ = nullptr; |
1178 // We need to run the message loop to propagate the construction callbacks. | 1180 // We need to run the message loop to propagate the construction callbacks. |
1179 base::RunLoop().RunUntilIdle(); | 1181 base::RunLoop().RunUntilIdle(); |
1180 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); | 1182 EXPECT_FALSE(host2->async_builder_.IsBeingBuilt(kDifferentHostReferencingId)); |
1181 EXPECT_TRUE( | 1183 EXPECT_TRUE( |
1182 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); | 1184 context_->GetBlobDataFromUUID(kSameHostReferencingId)->IsBroken()); |
1183 EXPECT_TRUE( | 1185 EXPECT_TRUE( |
1184 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); | 1186 context_->GetBlobDataFromUUID(kDifferentHostReferencingId)->IsBroken()); |
1185 | 1187 |
1186 // Check our callbacks | 1188 // Check our callbacks |
1187 EXPECT_FALSE(built); | 1189 EXPECT_FALSE(built); |
1188 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, error_code); | 1190 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, error_code); |
1189 EXPECT_FALSE(same_host_built); | 1191 EXPECT_FALSE(same_host_built); |
1190 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, | 1192 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, |
1191 same_host_error_code); | 1193 same_host_error_code); |
1192 EXPECT_FALSE(other_host_built); | 1194 EXPECT_FALSE(other_host_built); |
1193 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, | 1195 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, |
1194 other_host_error_code); | 1196 other_host_error_code); |
1195 | 1197 |
1196 sink_.ClearMessages(); | 1198 sink_.ClearMessages(); |
1197 } | 1199 } |
1198 | 1200 |
1199 } // namespace content | 1201 } // namespace content |
OLD | NEW |