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

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

Issue 2056983004: [CacheStorage] Give ownership of all CacheStorageCaches to CacheStorage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 21 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
22 #include "content/browser/cache_storage/cache_storage_cache_handle.h"
22 #include "content/browser/fileapi/mock_url_request_delegate.h" 23 #include "content/browser/fileapi/mock_url_request_delegate.h"
23 #include "content/browser/quota/mock_quota_manager_proxy.h" 24 #include "content/browser/quota/mock_quota_manager_proxy.h"
24 #include "content/common/cache_storage/cache_storage_types.h" 25 #include "content/common/cache_storage/cache_storage_types.h"
25 #include "content/common/service_worker/service_worker_types.h" 26 #include "content/common/service_worker/service_worker_types.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/storage_partition.h" 28 #include "content/public/browser/storage_partition.h"
28 #include "content/public/common/referrer.h" 29 #include "content/public/common/referrer.h"
29 #include "content/public/test/mock_special_storage_policy.h" 30 #include "content/public/test/mock_special_storage_policy.h"
30 #include "content/public/test/test_browser_context.h" 31 #include "content/public/test/test_browser_context.h"
31 #include "content/public/test/test_browser_thread_bundle.h" 32 #include "content/public/test/test_browser_thread_bundle.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 260
260 } // namespace 261 } // namespace
261 262
262 // A CacheStorageCache that can optionally delay during backend creation. 263 // A CacheStorageCache that can optionally delay during backend creation.
263 class TestCacheStorageCache : public CacheStorageCache { 264 class TestCacheStorageCache : public CacheStorageCache {
264 public: 265 public:
265 TestCacheStorageCache( 266 TestCacheStorageCache(
266 const GURL& origin, 267 const GURL& origin,
267 const std::string& cache_name, 268 const std::string& cache_name,
268 const base::FilePath& path, 269 const base::FilePath& path,
270 CacheStorage* cache_storage,
269 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 271 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
270 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 272 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
271 base::WeakPtr<storage::BlobStorageContext> blob_context) 273 base::WeakPtr<storage::BlobStorageContext> blob_context)
272 : CacheStorageCache(origin, 274 : CacheStorageCache(origin,
273 cache_name, 275 cache_name,
274 path, 276 path,
277 cache_storage,
275 request_context_getter, 278 request_context_getter,
276 quota_manager_proxy, 279 quota_manager_proxy,
277 blob_context), 280 blob_context),
278 delay_backend_creation_(false) {} 281 delay_backend_creation_(false) {}
279 282
280 void CreateBackend(const ErrorCallback& callback) override { 283 void CreateBackend(const ErrorCallback& callback) override {
281 backend_creation_callback_ = callback; 284 backend_creation_callback_ = callback;
282 if (delay_backend_creation_) 285 if (delay_backend_creation_)
283 return; 286 return;
284 ContinueCreateBackend(); 287 ContinueCreateBackend();
(...skipping 11 matching lines...) Expand all
296 // created before calling this. 299 // created before calling this.
297 DelayableBackend* UseDelayableBackend() { 300 DelayableBackend* UseDelayableBackend() {
298 EXPECT_TRUE(backend_); 301 EXPECT_TRUE(backend_);
299 DelayableBackend* delayable_backend = 302 DelayableBackend* delayable_backend =
300 new DelayableBackend(std::move(backend_)); 303 new DelayableBackend(std::move(backend_));
301 backend_.reset(delayable_backend); 304 backend_.reset(delayable_backend);
302 return delayable_backend; 305 return delayable_backend;
303 } 306 }
304 307
305 private: 308 private:
306 ~TestCacheStorageCache() override {} 309 std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle() override {
310 // Returns an empty handle. There is no need for CacheStorage and its
311 // handles in these tests.
312 return std::unique_ptr<CacheStorageCacheHandle>();
313 }
307 314
308 bool delay_backend_creation_; 315 bool delay_backend_creation_;
309 ErrorCallback backend_creation_callback_; 316 ErrorCallback backend_creation_callback_;
310 317
311 DISALLOW_COPY_AND_ASSIGN(TestCacheStorageCache); 318 DISALLOW_COPY_AND_ASSIGN(TestCacheStorageCache);
312 }; 319 };
313 320
314 class CacheStorageCacheTest : public testing::Test { 321 class CacheStorageCacheTest : public testing::Test {
315 public: 322 public:
316 CacheStorageCacheTest() 323 CacheStorageCacheTest()
(...skipping 25 matching lines...) Expand all
342 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context())); 349 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context()));
343 350
344 net::URLRequestContext* url_request_context = 351 net::URLRequestContext* url_request_context =
345 BrowserContext::GetDefaultStoragePartition(&browser_context_)-> 352 BrowserContext::GetDefaultStoragePartition(&browser_context_)->
346 GetURLRequestContext()->GetURLRequestContext(); 353 GetURLRequestContext()->GetURLRequestContext();
347 354
348 url_request_context->set_job_factory(url_request_job_factory_.get()); 355 url_request_context->set_job_factory(url_request_job_factory_.get());
349 356
350 CreateRequests(blob_storage_context); 357 CreateRequests(blob_storage_context);
351 358
352 cache_ = make_scoped_refptr(new TestCacheStorageCache( 359 cache_ = base::MakeUnique<TestCacheStorageCache>(
353 GURL(kOrigin), kCacheName, temp_dir_.path(), 360 GURL(kOrigin), kCacheName, temp_dir_.path(), nullptr /* CacheStorage */,
354 BrowserContext::GetDefaultStoragePartition(&browser_context_)-> 361 BrowserContext::GetDefaultStoragePartition(&browser_context_)
355 GetURLRequestContext(), 362 ->GetURLRequestContext(),
356 quota_manager_proxy_, blob_storage_context->context()->AsWeakPtr())); 363 quota_manager_proxy_, blob_storage_context->context()->AsWeakPtr());
357 } 364 }
358 365
359 void TearDown() override { 366 void TearDown() override {
360 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); 367 quota_manager_proxy_->SimulateQuotaManagerDestroyed();
361 base::RunLoop().RunUntilIdle(); 368 base::RunLoop().RunUntilIdle();
362 } 369 }
363 370
364 void CreateRequests(ChromeBlobStorageContext* blob_storage_context) { 371 void CreateRequests(ChromeBlobStorageContext* blob_storage_context) {
365 ServiceWorkerHeaderMap headers; 372 ServiceWorkerHeaderMap headers;
366 headers.insert(std::make_pair("a", "a")); 373 headers.insert(std::make_pair("a", "a"));
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 protected: 670 protected:
664 base::ScopedTempDir temp_dir_; 671 base::ScopedTempDir temp_dir_;
665 TestBrowserThreadBundle browser_thread_bundle_; 672 TestBrowserThreadBundle browser_thread_bundle_;
666 TestBrowserContext browser_context_; 673 TestBrowserContext browser_context_;
667 std::unique_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_; 674 std::unique_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_;
668 scoped_refptr<MockSpecialStoragePolicy> quota_policy_; 675 scoped_refptr<MockSpecialStoragePolicy> quota_policy_;
669 scoped_refptr<MockQuotaManager> mock_quota_manager_; 676 scoped_refptr<MockQuotaManager> mock_quota_manager_;
670 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; 677 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_;
671 storage::BlobStorageContext* blob_storage_context_; 678 storage::BlobStorageContext* blob_storage_context_;
672 679
673 scoped_refptr<TestCacheStorageCache> cache_; 680 std::unique_ptr<TestCacheStorageCache> cache_;
674 681
675 ServiceWorkerFetchRequest body_request_; 682 ServiceWorkerFetchRequest body_request_;
676 ServiceWorkerResponse body_response_; 683 ServiceWorkerResponse body_response_;
677 ServiceWorkerFetchRequest body_request_with_query_; 684 ServiceWorkerFetchRequest body_request_with_query_;
678 ServiceWorkerResponse body_response_with_query_; 685 ServiceWorkerResponse body_response_with_query_;
679 ServiceWorkerFetchRequest no_body_request_; 686 ServiceWorkerFetchRequest no_body_request_;
680 ServiceWorkerResponse no_body_response_; 687 ServiceWorkerResponse no_body_response_;
681 std::unique_ptr<storage::BlobDataHandle> blob_handle_; 688 std::unique_ptr<storage::BlobDataHandle> blob_handle_;
682 std::string expected_blob_data_; 689 std::string expected_blob_data_;
683 690
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 EXPECT_EQ(1, sequence_out); 1379 EXPECT_EQ(1, sequence_out);
1373 close_loop2->Run(); 1380 close_loop2->Run();
1374 EXPECT_EQ(2, sequence_out); 1381 EXPECT_EQ(2, sequence_out);
1375 } 1382 }
1376 1383
1377 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 1384 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
1378 CacheStorageCacheTestP, 1385 CacheStorageCacheTestP,
1379 ::testing::Values(false, true)); 1386 ::testing::Values(false, true));
1380 1387
1381 } // namespace content 1388 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698