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

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

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

Powered by Google App Engine
This is Rietveld 408576698