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

Side by Side Diff: content/browser/cache_storage/cache_storage_manager_unittest.cc

Issue 2232223003: [CacheStorage] Check doomed caches first when dropping cache handles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Rebase Created 4 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/cache_storage/cache_storage_manager.h" 5 #include "content/browser/cache_storage/cache_storage_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 TEST_P(CacheStorageManagerTestP, DeleteCacheReducesOriginSize) { 443 TEST_P(CacheStorageManagerTestP, DeleteCacheReducesOriginSize) {
444 EXPECT_TRUE(Open(origin1_, "foo")); 444 EXPECT_TRUE(Open(origin1_, "foo"));
445 EXPECT_TRUE(CachePut(callback_cache_handle_->value(), 445 EXPECT_TRUE(CachePut(callback_cache_handle_->value(),
446 GURL("http://example.com/foo"))); 446 GURL("http://example.com/foo")));
447 // The quota manager gets updated after the put operation runs its callback so 447 // The quota manager gets updated after the put operation runs its callback so
448 // run the event loop. 448 // run the event loop.
449 base::RunLoop().RunUntilIdle(); 449 base::RunLoop().RunUntilIdle();
450 int64_t put_delta = quota_manager_proxy_->last_notified_delta(); 450 int64_t put_delta = quota_manager_proxy_->last_notified_delta();
451 EXPECT_LT(0, put_delta); 451 EXPECT_LT(0, put_delta);
452 EXPECT_TRUE(Delete(origin1_, "foo")); 452 EXPECT_TRUE(Delete(origin1_, "foo"));
453 EXPECT_EQ(put_delta, -1 * quota_manager_proxy_->last_notified_delta()); 453
454 // Drop the cache handle so that the cache can be erased from disk.
455 callback_cache_handle_ = nullptr;
456 base::RunLoop().RunUntilIdle();
457
458 EXPECT_EQ(-1 * quota_manager_proxy_->last_notified_delta(), put_delta);
454 } 459 }
455 460
456 TEST_P(CacheStorageManagerTestP, EmptyKeys) { 461 TEST_P(CacheStorageManagerTestP, EmptyKeys) {
457 EXPECT_TRUE(Keys(origin1_)); 462 EXPECT_TRUE(Keys(origin1_));
458 EXPECT_TRUE(callback_strings_.empty()); 463 EXPECT_TRUE(callback_strings_.empty());
459 } 464 }
460 465
461 TEST_P(CacheStorageManagerTestP, SomeKeys) { 466 TEST_P(CacheStorageManagerTestP, SomeKeys) {
462 EXPECT_TRUE(Open(origin1_, "foo")); 467 EXPECT_TRUE(Open(origin1_, "foo"));
463 EXPECT_TRUE(Open(origin1_, "bar")); 468 EXPECT_TRUE(Open(origin1_, "bar"));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 std::unique_ptr<storage::BlobDataHandle> data_handle = 541 std::unique_ptr<storage::BlobDataHandle> data_handle =
537 std::move(callback_data_handle_); 542 std::move(callback_data_handle_);
538 543
539 EXPECT_TRUE(Delete(origin1_, "foo")); 544 EXPECT_TRUE(Delete(origin1_, "foo"));
540 // The cache is deleted but the handle to one of its entries is still 545 // The cache is deleted but the handle to one of its entries is still
541 // open. Creating a new cache in the same directory would fail on Windows. 546 // open. Creating a new cache in the same directory would fail on Windows.
542 EXPECT_TRUE(Open(origin1_, "foo")); 547 EXPECT_TRUE(Open(origin1_, "foo"));
543 EXPECT_TRUE(CachePut(callback_cache_handle_->value(), kTestURL)); 548 EXPECT_TRUE(CachePut(callback_cache_handle_->value(), kTestURL));
544 } 549 }
545 550
551 TEST_P(CacheStorageManagerTestP, DropRefAfterNewCacheWithSameNameCreated) {
552 // Make sure that dropping the final cache handle to a doomed cache doesn't
553 // affect newer caches with the same name. (see crbug.com/631467)
554
555 // 1. Create cache A and hang onto the handle
556 const GURL kTestURL = GURL("http://example.com/foo");
557 EXPECT_TRUE(Open(origin1_, "foo"));
558 EXPECT_FALSE(CacheMatch(callback_cache_handle_->value(), kTestURL));
559 std::unique_ptr<CacheStorageCacheHandle> cache_handle =
560 std::move(callback_cache_handle_);
561
562 // 2. Doom the cache
563 EXPECT_TRUE(Delete(origin1_, "foo"));
564
565 // 3. Create cache B (with the same name)
566 EXPECT_TRUE(Open(origin1_, "foo"));
567 EXPECT_FALSE(CacheMatch(callback_cache_handle_->value(), kTestURL));
568
569 // 4. Drop handle to A
570 cache_handle.reset();
571
572 // 5. Verify that B still works
573 EXPECT_FALSE(CacheMatch(callback_cache_handle_->value(), kTestURL));
574 }
575
546 TEST_P(CacheStorageManagerTestP, StorageMatchAllEntryExistsTwice) { 576 TEST_P(CacheStorageManagerTestP, StorageMatchAllEntryExistsTwice) {
547 EXPECT_TRUE(Open(origin1_, "foo")); 577 EXPECT_TRUE(Open(origin1_, "foo"));
548 EXPECT_TRUE(CachePutWithStatusCode(callback_cache_handle_->value(), 578 EXPECT_TRUE(CachePutWithStatusCode(callback_cache_handle_->value(),
549 GURL("http://example.com/foo"), 200)); 579 GURL("http://example.com/foo"), 200));
550 EXPECT_TRUE(Open(origin1_, "bar")); 580 EXPECT_TRUE(Open(origin1_, "bar"));
551 EXPECT_TRUE(CachePutWithStatusCode(callback_cache_handle_->value(), 581 EXPECT_TRUE(CachePutWithStatusCode(callback_cache_handle_->value(),
552 GURL("http://example.com/foo"), 201)); 582 GURL("http://example.com/foo"), 201));
553 583
554 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo"))); 584 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo")));
555 585
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 // With a persistent cache if the client drops its reference to a 672 // With a persistent cache if the client drops its reference to a
643 // CacheStorageCache it should be deleted. 673 // CacheStorageCache it should be deleted.
644 TEST_F(CacheStorageManagerTest, DropReference) { 674 TEST_F(CacheStorageManagerTest, DropReference) {
645 EXPECT_TRUE(Open(origin1_, "foo")); 675 EXPECT_TRUE(Open(origin1_, "foo"));
646 base::WeakPtr<CacheStorageCache> cache = 676 base::WeakPtr<CacheStorageCache> cache =
647 callback_cache_handle_->value()->AsWeakPtr(); 677 callback_cache_handle_->value()->AsWeakPtr();
648 callback_cache_handle_ = nullptr; 678 callback_cache_handle_ = nullptr;
649 EXPECT_FALSE(cache); 679 EXPECT_FALSE(cache);
650 } 680 }
651 681
682 // A cache continues to work so long as there is a handle to it. Only after the
683 // last cache handle is deleted can the cache be freed.
684 TEST_P(CacheStorageManagerTestP, CacheWorksAfterDelete) {
685 const GURL kFooURL("http://example.com/foo");
686 const GURL kBarURL("http://example.com/bar");
687 const GURL kBazURL("http://example.com/baz");
688 EXPECT_TRUE(Open(origin1_, "foo"));
689 std::unique_ptr<CacheStorageCacheHandle> original_handle =
690 std::move(callback_cache_handle_);
691 EXPECT_TRUE(CachePut(original_handle->value(), kFooURL));
692 EXPECT_TRUE(Delete(origin1_, "foo"));
693
694 // Verify that the existing cache handle still works.
695 EXPECT_TRUE(CacheMatch(original_handle->value(), kFooURL));
696 EXPECT_TRUE(CachePut(original_handle->value(), kBarURL));
697 EXPECT_TRUE(CacheMatch(original_handle->value(), kBarURL));
698
699 // The cache shouldn't be visible to subsequent storage operations.
700 EXPECT_TRUE(Keys(origin1_));
701 EXPECT_TRUE(callback_strings_.empty());
702
703 // Open a new cache with the same name, it should create a new cache, but not
704 // interfere with the original cache.
705 EXPECT_TRUE(Open(origin1_, "foo"));
706 std::unique_ptr<CacheStorageCacheHandle> new_handle =
707 std::move(callback_cache_handle_);
708 EXPECT_TRUE(CachePut(new_handle->value(), kBazURL));
709
710 EXPECT_FALSE(CacheMatch(new_handle->value(), kFooURL));
711 EXPECT_FALSE(CacheMatch(new_handle->value(), kBarURL));
712 EXPECT_TRUE(CacheMatch(new_handle->value(), kBazURL));
713
714 EXPECT_TRUE(CacheMatch(original_handle->value(), kFooURL));
715 EXPECT_TRUE(CacheMatch(original_handle->value(), kBarURL));
716 EXPECT_FALSE(CacheMatch(original_handle->value(), kBazURL));
717 }
718
652 // With a memory cache the cache can't be freed from memory until the client 719 // With a memory cache the cache can't be freed from memory until the client
653 // calls delete. 720 // calls delete.
654 TEST_F(CacheStorageManagerMemoryOnlyTest, MemoryLosesReferenceOnlyAfterDelete) { 721 TEST_F(CacheStorageManagerMemoryOnlyTest, MemoryLosesReferenceOnlyAfterDelete) {
655 EXPECT_TRUE(Open(origin1_, "foo")); 722 EXPECT_TRUE(Open(origin1_, "foo"));
656 base::WeakPtr<CacheStorageCache> cache = 723 base::WeakPtr<CacheStorageCache> cache =
657 callback_cache_handle_->value()->AsWeakPtr(); 724 callback_cache_handle_->value()->AsWeakPtr();
658 callback_cache_handle_ = nullptr; 725 callback_cache_handle_ = nullptr;
659 EXPECT_TRUE(cache); 726 EXPECT_TRUE(cache);
660 EXPECT_TRUE(Delete(origin1_, "foo")); 727 EXPECT_TRUE(Delete(origin1_, "foo"));
728 base::RunLoop().RunUntilIdle();
661 EXPECT_FALSE(cache); 729 EXPECT_FALSE(cache);
662 } 730 }
663 731
664 TEST_P(CacheStorageManagerTestP, DeleteBeforeRelease) { 732 TEST_P(CacheStorageManagerTestP, DeleteBeforeRelease) {
665 EXPECT_TRUE(Open(origin1_, "foo")); 733 EXPECT_TRUE(Open(origin1_, "foo"));
666 EXPECT_TRUE(Delete(origin1_, "foo")); 734 EXPECT_TRUE(Delete(origin1_, "foo"));
667 EXPECT_TRUE(callback_cache_handle_->value()); 735 EXPECT_TRUE(callback_cache_handle_->value());
668 } 736 }
669 737
670 TEST_P(CacheStorageManagerTestP, OpenRunsSerially) { 738 TEST_P(CacheStorageManagerTestP, OpenRunsSerially) {
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 1266
1199 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, 1267 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests,
1200 CacheStorageManagerTestP, 1268 CacheStorageManagerTestP,
1201 ::testing::Values(false, true)); 1269 ::testing::Values(false, true));
1202 1270
1203 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, 1271 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests,
1204 CacheStorageQuotaClientTestP, 1272 CacheStorageQuotaClientTestP,
1205 ::testing::Values(false, true)); 1273 ::testing::Values(false, true));
1206 1274
1207 } // namespace content 1275 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698