| 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_cache.h" | 5 #include "content/browser/cache_storage/cache_storage_cache.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 23 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 24 #include "content/browser/cache_storage/cache_storage_cache_handle.h" | 24 #include "content/browser/cache_storage/cache_storage_cache_handle.h" |
| 25 #include "content/common/cache_storage/cache_storage_types.h" | 25 #include "content/common/cache_storage/cache_storage_types.h" |
| 26 #include "content/common/service_worker/service_worker_types.h" | 26 #include "content/common/service_worker/service_worker_types.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/storage_partition.h" | 28 #include "content/public/browser/storage_partition.h" |
| 29 #include "content/public/common/referrer.h" | 29 #include "content/public/common/referrer.h" |
| 30 #include "content/public/test/test_browser_context.h" | 30 #include "content/public/test/test_browser_context.h" |
| 31 #include "content/public/test/test_browser_thread_bundle.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
| 32 #include "crypto/symmetric_key.h" |
| 32 #include "net/base/test_completion_callback.h" | 33 #include "net/base/test_completion_callback.h" |
| 33 #include "net/url_request/url_request_context.h" | 34 #include "net/url_request/url_request_context.h" |
| 34 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
| 35 #include "net/url_request/url_request_job_factory_impl.h" | 36 #include "net/url_request/url_request_job_factory_impl.h" |
| 36 #include "storage/browser/blob/blob_data_builder.h" | 37 #include "storage/browser/blob/blob_data_builder.h" |
| 37 #include "storage/browser/blob/blob_data_handle.h" | 38 #include "storage/browser/blob/blob_data_handle.h" |
| 38 #include "storage/browser/blob/blob_data_snapshot.h" | 39 #include "storage/browser/blob/blob_data_snapshot.h" |
| 39 #include "storage/browser/blob/blob_storage_context.h" | 40 #include "storage/browser/blob/blob_storage_context.h" |
| 40 #include "storage/browser/blob/blob_url_request_job_factory.h" | 41 #include "storage/browser/blob/blob_url_request_job_factory.h" |
| 41 #include "storage/browser/quota/quota_manager_proxy.h" | 42 #include "storage/browser/quota/quota_manager_proxy.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 56 std::unique_ptr<storage::BlobProtocolHandler> CreateMockBlobProtocolHandler( | 57 std::unique_ptr<storage::BlobProtocolHandler> CreateMockBlobProtocolHandler( |
| 57 storage::BlobStorageContext* blob_storage_context) { | 58 storage::BlobStorageContext* blob_storage_context) { |
| 58 return base::WrapUnique( | 59 return base::WrapUnique( |
| 59 new storage::BlobProtocolHandler(blob_storage_context, nullptr)); | 60 new storage::BlobProtocolHandler(blob_storage_context, nullptr)); |
| 60 } | 61 } |
| 61 | 62 |
| 62 // A disk_cache::Backend wrapper that can delay operations. | 63 // A disk_cache::Backend wrapper that can delay operations. |
| 63 class DelayableBackend : public disk_cache::Backend { | 64 class DelayableBackend : public disk_cache::Backend { |
| 64 public: | 65 public: |
| 65 explicit DelayableBackend(std::unique_ptr<disk_cache::Backend> backend) | 66 explicit DelayableBackend(std::unique_ptr<disk_cache::Backend> backend) |
| 66 : backend_(std::move(backend)), delay_doom_(false) {} | 67 : backend_(std::move(backend)), delay_open_entry_(false) {} |
| 67 | 68 |
| 68 // disk_cache::Backend overrides | 69 // disk_cache::Backend overrides |
| 69 net::CacheType GetCacheType() const override { | 70 net::CacheType GetCacheType() const override { |
| 70 return backend_->GetCacheType(); | 71 return backend_->GetCacheType(); |
| 71 } | 72 } |
| 72 int32_t GetEntryCount() const override { return backend_->GetEntryCount(); } | 73 int32_t GetEntryCount() const override { return backend_->GetEntryCount(); } |
| 73 int OpenEntry(const std::string& key, | 74 int OpenEntry(const std::string& key, |
| 74 disk_cache::Entry** entry, | 75 disk_cache::Entry** entry, |
| 75 const CompletionCallback& callback) override { | 76 const CompletionCallback& callback) override { |
| 77 if (delay_open_entry_ && open_entry_callback_.is_null()) { |
| 78 open_entry_callback_ = base::BindOnce( |
| 79 &DelayableBackend::OpenEntryDelayedImpl, base::Unretained(this), key, |
| 80 base::Unretained(entry), callback); |
| 81 return net::ERR_IO_PENDING; |
| 82 } |
| 76 return backend_->OpenEntry(key, entry, callback); | 83 return backend_->OpenEntry(key, entry, callback); |
| 77 } | 84 } |
| 78 | 85 |
| 79 int CreateEntry(const std::string& key, | 86 int CreateEntry(const std::string& key, |
| 80 disk_cache::Entry** entry, | 87 disk_cache::Entry** entry, |
| 81 const CompletionCallback& callback) override { | 88 const CompletionCallback& callback) override { |
| 82 return backend_->CreateEntry(key, entry, callback); | 89 return backend_->CreateEntry(key, entry, callback); |
| 83 } | 90 } |
| 84 int DoomEntry(const std::string& key, | 91 int DoomEntry(const std::string& key, |
| 85 const CompletionCallback& callback) override { | 92 const CompletionCallback& callback) override { |
| 86 if (delay_doom_) { | |
| 87 doom_entry_callback_ = | |
| 88 base::BindOnce(&DelayableBackend::DoomEntryDelayedImpl, | |
| 89 base::Unretained(this), key, callback); | |
| 90 return net::ERR_IO_PENDING; | |
| 91 } | |
| 92 | |
| 93 return backend_->DoomEntry(key, callback); | 93 return backend_->DoomEntry(key, callback); |
| 94 } | 94 } |
| 95 int DoomAllEntries(const CompletionCallback& callback) override { | 95 int DoomAllEntries(const CompletionCallback& callback) override { |
| 96 return backend_->DoomAllEntries(callback); | 96 return backend_->DoomAllEntries(callback); |
| 97 } | 97 } |
| 98 int DoomEntriesBetween(base::Time initial_time, | 98 int DoomEntriesBetween(base::Time initial_time, |
| 99 base::Time end_time, | 99 base::Time end_time, |
| 100 const CompletionCallback& callback) override { | 100 const CompletionCallback& callback) override { |
| 101 return backend_->DoomEntriesBetween(initial_time, end_time, callback); | 101 return backend_->DoomEntriesBetween(initial_time, end_time, callback); |
| 102 } | 102 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 118 return backend_->OnExternalCacheHit(key); | 118 return backend_->OnExternalCacheHit(key); |
| 119 } | 119 } |
| 120 | 120 |
| 121 size_t DumpMemoryStats( | 121 size_t DumpMemoryStats( |
| 122 base::trace_event::ProcessMemoryDump* pmd, | 122 base::trace_event::ProcessMemoryDump* pmd, |
| 123 const std::string& parent_absolute_name) const override { | 123 const std::string& parent_absolute_name) const override { |
| 124 NOTREACHED(); | 124 NOTREACHED(); |
| 125 return 0u; | 125 return 0u; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Call to continue a delayed doom. | 128 // Call to continue a delayed call to OpenEntry. |
| 129 void DoomEntryContinue() { | 129 bool OpenEntryContinue() { |
| 130 EXPECT_FALSE(doom_entry_callback_.is_null()); | 130 if (open_entry_callback_.is_null()) |
| 131 std::move(doom_entry_callback_).Run(); | 131 return false; |
| 132 std::move(open_entry_callback_).Run(); |
| 133 return true; |
| 132 } | 134 } |
| 133 | 135 |
| 134 void set_delay_doom(bool value) { delay_doom_ = value; } | 136 void set_delay_open_entry(bool value) { delay_open_entry_ = value; } |
| 135 | 137 |
| 136 private: | 138 private: |
| 137 void DoomEntryDelayedImpl(const std::string& key, | 139 void OpenEntryDelayedImpl(const std::string& key, |
| 140 disk_cache::Entry** entry, |
| 138 const CompletionCallback& callback) { | 141 const CompletionCallback& callback) { |
| 139 int rv = backend_->DoomEntry(key, callback); | 142 int rv = backend_->OpenEntry(key, entry, callback); |
| 140 if (rv != net::ERR_IO_PENDING) | 143 if (rv != net::ERR_IO_PENDING) |
| 141 callback.Run(rv); | 144 callback.Run(rv); |
| 142 } | 145 } |
| 143 | 146 |
| 144 std::unique_ptr<disk_cache::Backend> backend_; | 147 std::unique_ptr<disk_cache::Backend> backend_; |
| 145 bool delay_doom_; | 148 bool delay_open_entry_; |
| 146 base::OnceClosure doom_entry_callback_; | 149 base::OnceClosure open_entry_callback_; |
| 147 }; | 150 }; |
| 148 | 151 |
| 149 void CopyBody(const storage::BlobDataHandle& blob_handle, std::string* output) { | 152 void CopyBody(const storage::BlobDataHandle& blob_handle, std::string* output) { |
| 150 *output = std::string(); | 153 *output = std::string(); |
| 151 std::unique_ptr<storage::BlobDataSnapshot> data = | 154 std::unique_ptr<storage::BlobDataSnapshot> data = |
| 152 blob_handle.CreateSnapshot(); | 155 blob_handle.CreateSnapshot(); |
| 153 const auto& items = data->items(); | 156 const auto& items = data->items(); |
| 154 for (const auto& item : items) { | 157 for (const auto& item : items) { |
| 155 switch (item->type()) { | 158 switch (item->type()) { |
| 156 case storage::DataElement::TYPE_BYTES: { | 159 case storage::DataElement::TYPE_BYTES: { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 return expected_side_data == actual_body; | 266 return expected_side_data == actual_body; |
| 264 } | 267 } |
| 265 | 268 |
| 266 ServiceWorkerResponse SetCacheName(const ServiceWorkerResponse& original) { | 269 ServiceWorkerResponse SetCacheName(const ServiceWorkerResponse& original) { |
| 267 ServiceWorkerResponse result(original); | 270 ServiceWorkerResponse result(original); |
| 268 result.is_in_cache_storage = true; | 271 result.is_in_cache_storage = true; |
| 269 result.cache_storage_cache_name = kCacheName; | 272 result.cache_storage_cache_name = kCacheName; |
| 270 return result; | 273 return result; |
| 271 } | 274 } |
| 272 | 275 |
| 276 std::unique_ptr<crypto::SymmetricKey> CreateTestPaddingKey() { |
| 277 return crypto::SymmetricKey::Import(crypto::SymmetricKey::HMAC_SHA1, |
| 278 "abc123"); |
| 279 } |
| 280 |
| 273 } // namespace | 281 } // namespace |
| 274 | 282 |
| 275 // A CacheStorageCache that can optionally delay during backend creation. | 283 // A CacheStorageCache that can optionally delay during backend creation. |
| 276 class TestCacheStorageCache : public CacheStorageCache { | 284 class TestCacheStorageCache : public CacheStorageCache { |
| 277 public: | 285 public: |
| 278 TestCacheStorageCache( | 286 TestCacheStorageCache( |
| 279 const GURL& origin, | 287 const GURL& origin, |
| 280 const std::string& cache_name, | 288 const std::string& cache_name, |
| 281 const base::FilePath& path, | 289 const base::FilePath& path, |
| 282 CacheStorage* cache_storage, | 290 CacheStorage* cache_storage, |
| 283 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 291 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| 284 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, | 292 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, |
| 285 base::WeakPtr<storage::BlobStorageContext> blob_context) | 293 base::WeakPtr<storage::BlobStorageContext> blob_context) |
| 286 : CacheStorageCache(origin, | 294 : CacheStorageCache(origin, |
| 287 cache_name, | 295 cache_name, |
| 288 path, | 296 path, |
| 289 cache_storage, | 297 cache_storage, |
| 290 request_context_getter, | 298 request_context_getter, |
| 291 quota_manager_proxy, | 299 quota_manager_proxy, |
| 292 blob_context, | 300 blob_context, |
| 293 0 /* cache_size */), | 301 0 /* cache_size */, |
| 302 0 /* cache_padding */, |
| 303 CreateTestPaddingKey()), |
| 294 delay_backend_creation_(false) {} | 304 delay_backend_creation_(false) {} |
| 295 | 305 |
| 296 void CreateBackend(ErrorCallback callback) override { | 306 void CreateBackend(ErrorCallback callback) override { |
| 297 backend_creation_callback_ = std::move(callback); | 307 backend_creation_callback_ = std::move(callback); |
| 298 if (delay_backend_creation_) | 308 if (delay_backend_creation_) |
| 299 return; | 309 return; |
| 300 ContinueCreateBackend(); | 310 ContinueCreateBackend(); |
| 301 } | 311 } |
| 302 | 312 |
| 303 void ContinueCreateBackend() { | 313 void ContinueCreateBackend() { |
| (...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 EXPECT_TRUE(Delete(no_body_request_)); | 1598 EXPECT_TRUE(Delete(no_body_request_)); |
| 1589 EXPECT_EQ(0, Size()); | 1599 EXPECT_EQ(0, Size()); |
| 1590 | 1600 |
| 1591 EXPECT_TRUE(Put(body_request_, body_response_)); | 1601 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 1592 EXPECT_LT(no_body_size, Size()); | 1602 EXPECT_LT(no_body_size, Size()); |
| 1593 | 1603 |
| 1594 EXPECT_TRUE(Delete(body_request_)); | 1604 EXPECT_TRUE(Delete(body_request_)); |
| 1595 EXPECT_EQ(0, Size()); | 1605 EXPECT_EQ(0, Size()); |
| 1596 } | 1606 } |
| 1597 | 1607 |
| 1608 TEST_F(CacheStorageCacheTest, VerifyOpaqueSizePadding) { |
| 1609 base::Time response_time(base::Time::Now()); |
| 1610 |
| 1611 ServiceWorkerFetchRequest non_opaque_request(body_request_); |
| 1612 non_opaque_request.url = GURL("http://example.com/no-pad.html"); |
| 1613 ServiceWorkerResponse non_opaque_response(body_response_); |
| 1614 non_opaque_response.response_time = response_time; |
| 1615 EXPECT_EQ(0, CacheStorageCache::CalculateResponsePadding( |
| 1616 non_opaque_response, CreateTestPaddingKey().get(), |
| 1617 0 /* side_data_size */)); |
| 1618 EXPECT_TRUE(Put(non_opaque_request, non_opaque_response)); |
| 1619 int64_t unpadded_no_data_cache_size = Size(); |
| 1620 |
| 1621 // Now write some side data to that cache. |
| 1622 const std::string expected_side_data = "TheSideData"; |
| 1623 scoped_refptr<net::IOBuffer> side_data_buffer( |
| 1624 new net::StringIOBuffer(expected_side_data)); |
| 1625 EXPECT_TRUE(WriteSideData(non_opaque_request.url, response_time, |
| 1626 side_data_buffer, expected_side_data.length())); |
| 1627 int64_t unpadded_total_resource_size = Size(); |
| 1628 int64_t unpadded_side_data_size = |
| 1629 unpadded_total_resource_size - unpadded_no_data_cache_size; |
| 1630 EXPECT_EQ(expected_side_data.size(), |
| 1631 static_cast<size_t>(unpadded_side_data_size)); |
| 1632 EXPECT_EQ(0, CacheStorageCache::CalculateResponsePadding( |
| 1633 non_opaque_response, CreateTestPaddingKey().get(), |
| 1634 unpadded_side_data_size)); |
| 1635 |
| 1636 // Now write an identically sized opaque response. |
| 1637 ServiceWorkerFetchRequest opaque_request(non_opaque_request); |
| 1638 opaque_request.url = GURL("http://example.com/opaque.html"); |
| 1639 // Same URL length means same cache sizes (ignoring padding). |
| 1640 EXPECT_EQ(opaque_request.url.spec().length(), |
| 1641 non_opaque_request.url.spec().length()); |
| 1642 ServiceWorkerResponse opaque_response(non_opaque_response); |
| 1643 opaque_response.response_type = network::mojom::FetchResponseType::kOpaque; |
| 1644 opaque_response.response_time = response_time; |
| 1645 |
| 1646 EXPECT_TRUE(Put(opaque_request, opaque_response)); |
| 1647 // This test is fragile. Right now it deterministically adds non-zero padding. |
| 1648 // But if the url, padding key, or padding algorithm change it might become |
| 1649 // zero. |
| 1650 int64_t size_after_opaque_put = Size(); |
| 1651 int64_t opaque_padding = size_after_opaque_put - |
| 1652 2 * unpadded_no_data_cache_size - |
| 1653 unpadded_side_data_size; |
| 1654 ASSERT_GT(opaque_padding, 0); |
| 1655 |
| 1656 // Now write side data and expect to see the padding change. |
| 1657 EXPECT_TRUE(WriteSideData(opaque_request.url, response_time, side_data_buffer, |
| 1658 expected_side_data.length())); |
| 1659 int64_t current_padding = Size() - 2 * unpadded_total_resource_size; |
| 1660 EXPECT_NE(opaque_padding, current_padding); |
| 1661 |
| 1662 // Now reset opaque side data back to zero. |
| 1663 const std::string expected_side_data2 = ""; |
| 1664 scoped_refptr<net::IOBuffer> buffer2( |
| 1665 new net::StringIOBuffer(expected_side_data2)); |
| 1666 EXPECT_TRUE(WriteSideData(opaque_request.url, response_time, buffer2, |
| 1667 expected_side_data2.length())); |
| 1668 EXPECT_EQ(size_after_opaque_put, Size()); |
| 1669 |
| 1670 // And delete the opaque response entirely. |
| 1671 EXPECT_TRUE(Delete(opaque_request)); |
| 1672 EXPECT_EQ(unpadded_total_resource_size, Size()); |
| 1673 } |
| 1674 |
| 1675 TEST_F(CacheStorageCacheTest, TestDifferentOpaqueSideDataSizes) { |
| 1676 ServiceWorkerFetchRequest request(body_request_); |
| 1677 |
| 1678 ServiceWorkerResponse response(body_response_); |
| 1679 response.response_type = network::mojom::FetchResponseType::kOpaque; |
| 1680 base::Time response_time(base::Time::Now()); |
| 1681 response.response_time = response_time; |
| 1682 EXPECT_TRUE(Put(request, response)); |
| 1683 int64_t opaque_cache_size_no_side_data = Size(); |
| 1684 |
| 1685 const std::string small_side_data = "SmallSideData"; |
| 1686 scoped_refptr<net::IOBuffer> buffer1( |
| 1687 new net::StringIOBuffer(small_side_data)); |
| 1688 EXPECT_TRUE(WriteSideData(request.url, response_time, buffer1, |
| 1689 small_side_data.length())); |
| 1690 int64_t opaque_cache_size_with_side_data = Size(); |
| 1691 EXPECT_NE(opaque_cache_size_with_side_data, opaque_cache_size_no_side_data); |
| 1692 |
| 1693 // Write side data of a different size. The size should not affect the padding |
| 1694 // at all. |
| 1695 const std::string large_side_data = "LargerSideDataString"; |
| 1696 EXPECT_NE(large_side_data.length(), small_side_data.length()); |
| 1697 scoped_refptr<net::IOBuffer> buffer2( |
| 1698 new net::StringIOBuffer(large_side_data)); |
| 1699 EXPECT_TRUE(WriteSideData(request.url, response_time, buffer2, |
| 1700 large_side_data.length())); |
| 1701 int side_data_delta = large_side_data.length() - small_side_data.length(); |
| 1702 EXPECT_EQ(opaque_cache_size_with_side_data + side_data_delta, Size()); |
| 1703 } |
| 1704 |
| 1705 TEST_F(CacheStorageCacheTest, TestDoubleOpaquePut) { |
| 1706 ServiceWorkerFetchRequest request(body_request_); |
| 1707 |
| 1708 base::Time response_time(base::Time::Now()); |
| 1709 |
| 1710 ServiceWorkerResponse response(body_response_); |
| 1711 response.response_type = network::mojom::FetchResponseType::kOpaque; |
| 1712 response.response_time = response_time; |
| 1713 EXPECT_TRUE(Put(request, response)); |
| 1714 int64_t size_after_first_put = Size(); |
| 1715 |
| 1716 ServiceWorkerFetchRequest request2(body_request_); |
| 1717 ServiceWorkerResponse response2(body_response_); |
| 1718 response2.response_type = network::mojom::FetchResponseType::kOpaque; |
| 1719 response2.response_time = response_time; |
| 1720 EXPECT_TRUE(Put(request2, response2)); |
| 1721 |
| 1722 EXPECT_EQ(size_after_first_put, Size()); |
| 1723 } |
| 1724 |
| 1598 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) { | 1725 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) { |
| 1599 EXPECT_TRUE(Put(body_request_, body_response_)); | 1726 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 1600 int64_t cache_size = Size(); | 1727 int64_t cache_size = Size(); |
| 1601 EXPECT_EQ(cache_size, GetSizeThenClose()); | 1728 EXPECT_EQ(cache_size, GetSizeThenClose()); |
| 1602 VerifyAllOpsFail(); | 1729 VerifyAllOpsFail(); |
| 1603 } | 1730 } |
| 1604 | 1731 |
| 1605 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackend) { | 1732 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackend) { |
| 1606 // Create the backend and put something in it. | 1733 // Create the backend and put something in it. |
| 1607 EXPECT_TRUE(Put(body_request_, body_response_)); | 1734 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 1608 EXPECT_TRUE(Close()); | 1735 EXPECT_TRUE(Close()); |
| 1609 VerifyAllOpsFail(); | 1736 VerifyAllOpsFail(); |
| 1610 } | 1737 } |
| 1611 | 1738 |
| 1612 TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) { | 1739 TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) { |
| 1613 // Start two operations, the first one is delayed but the second isn't. The | 1740 // Start two operations, the first one is delayed but the second isn't. The |
| 1614 // second should wait for the first. | 1741 // second should wait for the first. |
| 1615 EXPECT_TRUE(Keys()); // Opens the backend. | 1742 EXPECT_TRUE(Keys()); // Opens the backend. |
| 1616 DelayableBackend* delayable_backend = cache_->UseDelayableBackend(); | 1743 DelayableBackend* delayable_backend = cache_->UseDelayableBackend(); |
| 1617 delayable_backend->set_delay_doom(true); | 1744 delayable_backend->set_delay_open_entry(true); |
| 1618 | 1745 |
| 1619 int sequence_out = -1; | 1746 int sequence_out = -1; |
| 1620 | 1747 |
| 1621 CacheStorageBatchOperation operation1; | 1748 CacheStorageBatchOperation operation1; |
| 1622 operation1.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; | 1749 operation1.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; |
| 1623 operation1.request = body_request_; | 1750 operation1.request = body_request_; |
| 1624 operation1.response = body_response_; | 1751 operation1.response = body_response_; |
| 1625 | 1752 |
| 1626 std::unique_ptr<base::RunLoop> close_loop1(new base::RunLoop()); | 1753 std::unique_ptr<base::RunLoop> close_loop1(new base::RunLoop()); |
| 1627 cache_->BatchOperation( | 1754 cache_->BatchOperation( |
| 1628 std::vector<CacheStorageBatchOperation>(1, operation1), | 1755 std::vector<CacheStorageBatchOperation>(1, operation1), |
| 1629 base::BindOnce(&CacheStorageCacheTest::SequenceCallback, | 1756 base::BindOnce(&CacheStorageCacheTest::SequenceCallback, |
| 1630 base::Unretained(this), 1, &sequence_out, | 1757 base::Unretained(this), 1, &sequence_out, |
| 1631 close_loop1.get())); | 1758 close_loop1.get())); |
| 1632 | 1759 |
| 1633 // Blocks on creating the cache entry. | 1760 // Blocks on creating the cache entry. |
| 1634 base::RunLoop().RunUntilIdle(); | 1761 base::RunLoop().RunUntilIdle(); |
| 1635 | 1762 |
| 1636 CacheStorageBatchOperation operation2; | 1763 CacheStorageBatchOperation operation2; |
| 1637 operation2.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; | 1764 operation2.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; |
| 1638 operation2.request = body_request_; | 1765 operation2.request = body_request_; |
| 1639 operation2.response = body_response_; | 1766 operation2.response = body_response_; |
| 1640 | 1767 |
| 1641 delayable_backend->set_delay_doom(false); | 1768 delayable_backend->set_delay_open_entry(false); |
| 1642 std::unique_ptr<base::RunLoop> close_loop2(new base::RunLoop()); | 1769 std::unique_ptr<base::RunLoop> close_loop2(new base::RunLoop()); |
| 1643 cache_->BatchOperation( | 1770 cache_->BatchOperation( |
| 1644 std::vector<CacheStorageBatchOperation>(1, operation2), | 1771 std::vector<CacheStorageBatchOperation>(1, operation2), |
| 1645 base::BindOnce(&CacheStorageCacheTest::SequenceCallback, | 1772 base::BindOnce(&CacheStorageCacheTest::SequenceCallback, |
| 1646 base::Unretained(this), 2, &sequence_out, | 1773 base::Unretained(this), 2, &sequence_out, |
| 1647 close_loop2.get())); | 1774 close_loop2.get())); |
| 1648 | 1775 |
| 1649 // The second put operation should wait for the first to complete. | 1776 // The second put operation should wait for the first to complete. |
| 1650 base::RunLoop().RunUntilIdle(); | 1777 base::RunLoop().RunUntilIdle(); |
| 1651 EXPECT_FALSE(callback_response_); | 1778 EXPECT_FALSE(callback_response_); |
| 1652 | 1779 |
| 1653 delayable_backend->DoomEntryContinue(); | 1780 EXPECT_TRUE(delayable_backend->OpenEntryContinue()); |
| 1654 close_loop1->Run(); | 1781 close_loop1->Run(); |
| 1655 EXPECT_EQ(1, sequence_out); | 1782 EXPECT_EQ(1, sequence_out); |
| 1656 close_loop2->Run(); | 1783 close_loop2->Run(); |
| 1657 EXPECT_EQ(2, sequence_out); | 1784 EXPECT_EQ(2, sequence_out); |
| 1658 } | 1785 } |
| 1659 | 1786 |
| 1660 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 1787 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
| 1661 CacheStorageCacheTestP, | 1788 CacheStorageCacheTestP, |
| 1662 ::testing::Values(false, true)); | 1789 ::testing::Values(false, true)); |
| 1663 | 1790 |
| 1664 } // namespace content | 1791 } // namespace content |
| OLD | NEW |