| OLD | NEW |
| 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 Loading... |
| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 // With a persistent cache if the client drops its reference to a | 647 // With a persistent cache if the client drops its reference to a |
| 643 // CacheStorageCache it should be deleted. | 648 // CacheStorageCache it should be deleted. |
| 644 TEST_F(CacheStorageManagerTest, DropReference) { | 649 TEST_F(CacheStorageManagerTest, DropReference) { |
| 645 EXPECT_TRUE(Open(origin1_, "foo")); | 650 EXPECT_TRUE(Open(origin1_, "foo")); |
| 646 base::WeakPtr<CacheStorageCache> cache = | 651 base::WeakPtr<CacheStorageCache> cache = |
| 647 callback_cache_handle_->value()->AsWeakPtr(); | 652 callback_cache_handle_->value()->AsWeakPtr(); |
| 648 callback_cache_handle_ = nullptr; | 653 callback_cache_handle_ = nullptr; |
| 649 EXPECT_FALSE(cache); | 654 EXPECT_FALSE(cache); |
| 650 } | 655 } |
| 651 | 656 |
| 657 // A cache continues to work so long as there is a handle to it. Only after the |
| 658 // last cache handle is deleted can the cache be freed. |
| 659 TEST_P(CacheStorageManagerTestP, CacheWorksAfterDelete) { |
| 660 const GURL kFooURL("http://example.com/foo"); |
| 661 const GURL kBarURL("http://example.com/bar"); |
| 662 const GURL kBazURL("http://example.com/baz"); |
| 663 EXPECT_TRUE(Open(origin1_, "foo")); |
| 664 std::unique_ptr<CacheStorageCacheHandle> original_handle = |
| 665 std::move(callback_cache_handle_); |
| 666 EXPECT_TRUE(CachePut(original_handle->value(), kFooURL)); |
| 667 EXPECT_TRUE(Delete(origin1_, "foo")); |
| 668 |
| 669 // Verify that the existing cache handle still works. |
| 670 EXPECT_TRUE(CacheMatch(original_handle->value(), kFooURL)); |
| 671 EXPECT_TRUE(CachePut(original_handle->value(), kBarURL)); |
| 672 EXPECT_TRUE(CacheMatch(original_handle->value(), kBarURL)); |
| 673 |
| 674 // The cache shouldn't be visible to subsequent storage operations. |
| 675 EXPECT_TRUE(Keys(origin1_)); |
| 676 EXPECT_TRUE(callback_strings_.empty()); |
| 677 |
| 678 // Open a new cache with the same name, it should create a new cache, but not |
| 679 // interfere with the original cache. |
| 680 EXPECT_TRUE(Open(origin1_, "foo")); |
| 681 std::unique_ptr<CacheStorageCacheHandle> new_handle = |
| 682 std::move(callback_cache_handle_); |
| 683 EXPECT_TRUE(CachePut(new_handle->value(), kBazURL)); |
| 684 |
| 685 EXPECT_FALSE(CacheMatch(new_handle->value(), kFooURL)); |
| 686 EXPECT_FALSE(CacheMatch(new_handle->value(), kBarURL)); |
| 687 EXPECT_TRUE(CacheMatch(new_handle->value(), kBazURL)); |
| 688 |
| 689 EXPECT_TRUE(CacheMatch(original_handle->value(), kFooURL)); |
| 690 EXPECT_TRUE(CacheMatch(original_handle->value(), kBarURL)); |
| 691 EXPECT_FALSE(CacheMatch(original_handle->value(), kBazURL)); |
| 692 } |
| 693 |
| 652 // With a memory cache the cache can't be freed from memory until the client | 694 // With a memory cache the cache can't be freed from memory until the client |
| 653 // calls delete. | 695 // calls delete. |
| 654 TEST_F(CacheStorageManagerMemoryOnlyTest, MemoryLosesReferenceOnlyAfterDelete) { | 696 TEST_F(CacheStorageManagerMemoryOnlyTest, MemoryLosesReferenceOnlyAfterDelete) { |
| 655 EXPECT_TRUE(Open(origin1_, "foo")); | 697 EXPECT_TRUE(Open(origin1_, "foo")); |
| 656 base::WeakPtr<CacheStorageCache> cache = | 698 base::WeakPtr<CacheStorageCache> cache = |
| 657 callback_cache_handle_->value()->AsWeakPtr(); | 699 callback_cache_handle_->value()->AsWeakPtr(); |
| 658 callback_cache_handle_ = nullptr; | 700 callback_cache_handle_ = nullptr; |
| 659 EXPECT_TRUE(cache); | 701 EXPECT_TRUE(cache); |
| 660 EXPECT_TRUE(Delete(origin1_, "foo")); | 702 EXPECT_TRUE(Delete(origin1_, "foo")); |
| 703 base::RunLoop().RunUntilIdle(); |
| 661 EXPECT_FALSE(cache); | 704 EXPECT_FALSE(cache); |
| 662 } | 705 } |
| 663 | 706 |
| 664 TEST_P(CacheStorageManagerTestP, DeleteBeforeRelease) { | 707 TEST_P(CacheStorageManagerTestP, DeleteBeforeRelease) { |
| 665 EXPECT_TRUE(Open(origin1_, "foo")); | 708 EXPECT_TRUE(Open(origin1_, "foo")); |
| 666 EXPECT_TRUE(Delete(origin1_, "foo")); | 709 EXPECT_TRUE(Delete(origin1_, "foo")); |
| 667 EXPECT_TRUE(callback_cache_handle_->value()); | 710 EXPECT_TRUE(callback_cache_handle_->value()); |
| 668 } | 711 } |
| 669 | 712 |
| 670 TEST_P(CacheStorageManagerTestP, OpenRunsSerially) { | 713 TEST_P(CacheStorageManagerTestP, OpenRunsSerially) { |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 | 1241 |
| 1199 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, | 1242 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, |
| 1200 CacheStorageManagerTestP, | 1243 CacheStorageManagerTestP, |
| 1201 ::testing::Values(false, true)); | 1244 ::testing::Values(false, true)); |
| 1202 | 1245 |
| 1203 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, | 1246 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, |
| 1204 CacheStorageQuotaClientTestP, | 1247 CacheStorageQuotaClientTestP, |
| 1205 ::testing::Values(false, true)); | 1248 ::testing::Values(false, true)); |
| 1206 | 1249 |
| 1207 } // namespace content | 1250 } // namespace content |
| OLD | NEW |