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

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

Issue 2085583002: [CacheStorage] Don't call GetUsageAndQuota from a scheduled operation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes 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>
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 EXPECT_TRUE(Match(body_request_)); 1158 EXPECT_TRUE(Match(body_request_));
1159 EXPECT_TRUE(callback_response_data_); 1159 EXPECT_TRUE(callback_response_data_);
1160 EXPECT_TRUE( 1160 EXPECT_TRUE(
1161 ResponseBodiesEqual(expected_blob_data_, *callback_response_data_)); 1161 ResponseBodiesEqual(expected_blob_data_, *callback_response_data_));
1162 EXPECT_TRUE( 1162 EXPECT_TRUE(
1163 ResponseSideDataEqual(expected_side_data2, *callback_response_data_)); 1163 ResponseSideDataEqual(expected_side_data2, *callback_response_data_));
1164 1164
1165 ASSERT_TRUE(Delete(body_request_)); 1165 ASSERT_TRUE(Delete(body_request_));
1166 } 1166 }
1167 1167
1168 TEST_P(CacheStorageCacheTestP, WriteSideData_QuotaExeeded) { 1168 TEST_P(CacheStorageCacheTestP, WriteSideData_QuotaExceeded) {
1169 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary, 1169 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary,
1170 1024 * 1024); 1170 1024 * 1023);
1171 base::Time response_time(base::Time::Now()); 1171 base::Time response_time(base::Time::Now());
1172 ServiceWorkerResponse response; 1172 ServiceWorkerResponse response;
1173 response.response_time = response_time; 1173 response.response_time = response_time;
1174 EXPECT_TRUE(Put(no_body_request_, response)); 1174 EXPECT_TRUE(Put(no_body_request_, response));
1175 1175
1176 const size_t kSize = 1024 * 1024; 1176 const size_t kSize = 1024 * 1024;
1177 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 1177 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
1178 memset(buffer->data(), 0, kSize); 1178 memset(buffer->data(), 0, kSize);
1179 EXPECT_FALSE( 1179 EXPECT_FALSE(
1180 WriteSideData(no_body_request_.url, response_time, buffer, kSize)); 1180 WriteSideData(no_body_request_.url, response_time, buffer, kSize));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 base::RunLoop().RunUntilIdle(); 1280 base::RunLoop().RunUntilIdle();
1281 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count()); 1281 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count());
1282 sum_delta += quota_manager_proxy_->last_notified_delta(); 1282 sum_delta += quota_manager_proxy_->last_notified_delta();
1283 1283
1284 EXPECT_EQ(0, sum_delta); 1284 EXPECT_EQ(0, sum_delta);
1285 } 1285 }
1286 1286
1287 TEST_P(CacheStorageCacheTestP, PutObeysQuotaLimits) { 1287 TEST_P(CacheStorageCacheTestP, PutObeysQuotaLimits) {
1288 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary, 1288 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary,
1289 0); 1289 0);
1290 EXPECT_FALSE(Put(no_body_request_, no_body_response_)); 1290 EXPECT_FALSE(Put(body_request_, body_response_));
1291 EXPECT_EQ(CACHE_STORAGE_ERROR_QUOTA_EXCEEDED, callback_error_); 1291 EXPECT_EQ(CACHE_STORAGE_ERROR_QUOTA_EXCEEDED, callback_error_);
1292 } 1292 }
1293 1293
1294 TEST_P(CacheStorageCacheTestP, Size) { 1294 TEST_P(CacheStorageCacheTestP, Size) {
1295 EXPECT_EQ(0, Size()); 1295 EXPECT_EQ(0, Size());
1296 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); 1296 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
1297 EXPECT_LT(0, Size()); 1297 EXPECT_LT(0, Size());
1298 int64_t no_body_size = Size(); 1298 int64_t no_body_size = Size();
1299 1299
1300 EXPECT_TRUE(Delete(no_body_request_)); 1300 EXPECT_TRUE(Delete(no_body_request_));
1301 EXPECT_EQ(0, Size()); 1301 EXPECT_EQ(0, Size());
1302 1302
1303 EXPECT_TRUE(Put(body_request_, body_response_)); 1303 EXPECT_TRUE(Put(body_request_, body_response_));
1304 EXPECT_LT(no_body_size, Size()); 1304 EXPECT_LT(no_body_size, Size());
1305 1305
1306 EXPECT_TRUE(Delete(body_request_)); 1306 EXPECT_TRUE(Delete(body_request_));
1307 EXPECT_EQ(0, Size()); 1307 EXPECT_EQ(0, Size());
1308 } 1308 }
1309 1309
1310 TEST_P(CacheStorageCacheTestP, SizeOperationsArePrioritized) {
1311 // Test that pending size operations (those waiting for initialization) run
1312 // before other scheduler operations.
1313 cache_->set_delay_backend_creation(true); // Delay cache initialization
1314
1315 CacheStorageBatchOperation operation;
1316 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT;
1317 operation.request = body_request_;
1318 operation.response = body_response_;
1319
1320 callback_error_ = CACHE_STORAGE_ERROR_NOT_FOUND;
1321 base::RunLoop run_loop;
1322 // Start a put operation that blocks on initialization.
1323 cache_->BatchOperation(std::vector<CacheStorageBatchOperation>(1, operation),
1324 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback,
1325 base::Unretained(this), &run_loop));
1326
1327 // Next start a size operation that also blocks on initialization.
1328 bool size_callback_called = false;
1329 cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback,
1330 base::Unretained(this), nullptr,
1331 &size_callback_called));
1332
1333 base::RunLoop().RunUntilIdle();
1334 EXPECT_FALSE(size_callback_called);
1335 EXPECT_EQ(CACHE_STORAGE_ERROR_NOT_FOUND, callback_error_);
1336
1337 // Finish initialization. The Size operation should complete before Put gets
1338 // to run as Size has priority. See crbug.com/605663.
1339 cache_->ContinueCreateBackend();
1340 run_loop.Run();
1341 EXPECT_TRUE(size_callback_called);
1342 EXPECT_EQ(CACHE_STORAGE_OK, callback_error_);
1343 }
1344
1345 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) { 1310 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) {
1346 EXPECT_TRUE(Put(body_request_, body_response_)); 1311 EXPECT_TRUE(Put(body_request_, body_response_));
1347 int64_t cache_size = Size(); 1312 int64_t cache_size = Size();
1348 EXPECT_EQ(cache_size, GetSizeThenClose()); 1313 EXPECT_EQ(cache_size, GetSizeThenClose());
1349 VerifyAllOpsFail(); 1314 VerifyAllOpsFail();
1350 } 1315 }
1351 1316
1352 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) { 1317 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) {
1353 cache_->set_delay_backend_creation( 1318 cache_->set_delay_backend_creation(
1354 true); // Will hang the test if a backend is created. 1319 true); // Will hang the test if a backend is created.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 EXPECT_EQ(1, sequence_out); 1372 EXPECT_EQ(1, sequence_out);
1408 close_loop2->Run(); 1373 close_loop2->Run();
1409 EXPECT_EQ(2, sequence_out); 1374 EXPECT_EQ(2, sequence_out);
1410 } 1375 }
1411 1376
1412 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 1377 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
1413 CacheStorageCacheTestP, 1378 CacheStorageCacheTestP,
1414 ::testing::Values(false, true)); 1379 ::testing::Values(false, true));
1415 1380
1416 } // namespace content 1381 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698