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

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

Issue 2112383002: [CacheStorage] Initialize the cache backend immediately upon opening (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 years, 5 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // Swap the existing backend with a delayable one. The backend must have been 298 // Swap the existing backend with a delayable one. The backend must have been
299 // created before calling this. 299 // created before calling this.
300 DelayableBackend* UseDelayableBackend() { 300 DelayableBackend* UseDelayableBackend() {
301 EXPECT_TRUE(backend_); 301 EXPECT_TRUE(backend_);
302 DelayableBackend* delayable_backend = 302 DelayableBackend* delayable_backend =
303 new DelayableBackend(std::move(backend_)); 303 new DelayableBackend(std::move(backend_));
304 backend_.reset(delayable_backend); 304 backend_.reset(delayable_backend);
305 return delayable_backend; 305 return delayable_backend;
306 } 306 }
307 307
308 void Init() { InitBackend(); }
309
308 private: 310 private:
309 std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle() override { 311 std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle() override {
310 // Returns an empty handle. There is no need for CacheStorage and its 312 // Returns an empty handle. There is no need for CacheStorage and its
311 // handles in these tests. 313 // handles in these tests.
312 return std::unique_ptr<CacheStorageCacheHandle>(); 314 return std::unique_ptr<CacheStorageCacheHandle>();
313 } 315 }
314 316
315 bool delay_backend_creation_; 317 bool delay_backend_creation_;
316 ErrorCallback backend_creation_callback_; 318 ErrorCallback backend_creation_callback_;
317 319
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 356
355 url_request_context->set_job_factory(url_request_job_factory_.get()); 357 url_request_context->set_job_factory(url_request_job_factory_.get());
356 358
357 CreateRequests(blob_storage_context); 359 CreateRequests(blob_storage_context);
358 360
359 cache_ = base::MakeUnique<TestCacheStorageCache>( 361 cache_ = base::MakeUnique<TestCacheStorageCache>(
360 GURL(kOrigin), kCacheName, temp_dir_.path(), nullptr /* CacheStorage */, 362 GURL(kOrigin), kCacheName, temp_dir_.path(), nullptr /* CacheStorage */,
361 BrowserContext::GetDefaultStoragePartition(&browser_context_) 363 BrowserContext::GetDefaultStoragePartition(&browser_context_)
362 ->GetURLRequestContext(), 364 ->GetURLRequestContext(),
363 quota_manager_proxy_, blob_storage_context->context()->AsWeakPtr()); 365 quota_manager_proxy_, blob_storage_context->context()->AsWeakPtr());
366 cache_->Init();
364 } 367 }
365 368
366 void TearDown() override { 369 void TearDown() override {
367 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); 370 quota_manager_proxy_->SimulateQuotaManagerDestroyed();
368 base::RunLoop().RunUntilIdle(); 371 base::RunLoop().RunUntilIdle();
369 } 372 }
370 373
371 void CreateRequests(ChromeBlobStorageContext* blob_storage_context) { 374 void CreateRequests(ChromeBlobStorageContext* blob_storage_context) {
372 ServiceWorkerHeaderMap headers; 375 ServiceWorkerHeaderMap headers;
373 headers.insert(std::make_pair("a", "a")); 376 headers.insert(std::make_pair("a", "a"));
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 EXPECT_EQ(0, Size()); 1317 EXPECT_EQ(0, Size());
1315 } 1318 }
1316 1319
1317 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) { 1320 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) {
1318 EXPECT_TRUE(Put(body_request_, body_response_)); 1321 EXPECT_TRUE(Put(body_request_, body_response_));
1319 int64_t cache_size = Size(); 1322 int64_t cache_size = Size();
1320 EXPECT_EQ(cache_size, GetSizeThenClose()); 1323 EXPECT_EQ(cache_size, GetSizeThenClose());
1321 VerifyAllOpsFail(); 1324 VerifyAllOpsFail();
1322 } 1325 }
1323 1326
1324 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) {
1325 cache_->set_delay_backend_creation(
1326 true); // Will hang the test if a backend is created.
1327 EXPECT_TRUE(Close());
1328 VerifyAllOpsFail();
1329 }
1330
1331 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackend) { 1327 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackend) {
1332 // Create the backend and put something in it. 1328 // Create the backend and put something in it.
1333 EXPECT_TRUE(Put(body_request_, body_response_)); 1329 EXPECT_TRUE(Put(body_request_, body_response_));
1334 EXPECT_TRUE(Close()); 1330 EXPECT_TRUE(Close());
1335 VerifyAllOpsFail(); 1331 VerifyAllOpsFail();
1336 } 1332 }
1337 1333
1338 TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) { 1334 TEST_P(CacheStorageCacheTestP, VerifySerialScheduling) {
1339 // Start two operations, the first one is delayed but the second isn't. The 1335 // Start two operations, the first one is delayed but the second isn't. The
1340 // second should wait for the first. 1336 // second should wait for the first.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 EXPECT_EQ(1, sequence_out); 1375 EXPECT_EQ(1, sequence_out);
1380 close_loop2->Run(); 1376 close_loop2->Run();
1381 EXPECT_EQ(2, sequence_out); 1377 EXPECT_EQ(2, sequence_out);
1382 } 1378 }
1383 1379
1384 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 1380 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
1385 CacheStorageCacheTestP, 1381 CacheStorageCacheTestP,
1386 ::testing::Values(false, true)); 1382 ::testing::Values(false, true));
1387 1383
1388 } // namespace content 1384 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.cc ('k') | content/browser/cache_storage/cache_storage_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698