| 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 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 EXPECT_TRUE(Match(body_request_)); | 1151 EXPECT_TRUE(Match(body_request_)); |
| 1152 EXPECT_TRUE(callback_response_data_); | 1152 EXPECT_TRUE(callback_response_data_); |
| 1153 EXPECT_TRUE( | 1153 EXPECT_TRUE( |
| 1154 ResponseBodiesEqual(expected_blob_data_, *callback_response_data_)); | 1154 ResponseBodiesEqual(expected_blob_data_, *callback_response_data_)); |
| 1155 EXPECT_TRUE( | 1155 EXPECT_TRUE( |
| 1156 ResponseSideDataEqual(expected_side_data2, *callback_response_data_)); | 1156 ResponseSideDataEqual(expected_side_data2, *callback_response_data_)); |
| 1157 | 1157 |
| 1158 ASSERT_TRUE(Delete(body_request_)); | 1158 ASSERT_TRUE(Delete(body_request_)); |
| 1159 } | 1159 } |
| 1160 | 1160 |
| 1161 TEST_P(CacheStorageCacheTestP, WriteSideData_QuotaExeeded) { | 1161 TEST_P(CacheStorageCacheTestP, WriteSideData_QuotaExceeded) { |
| 1162 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary, | 1162 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary, |
| 1163 1024 * 1024); | 1163 1024 * 1023); |
| 1164 base::Time response_time(base::Time::Now()); | 1164 base::Time response_time(base::Time::Now()); |
| 1165 ServiceWorkerResponse response; | 1165 ServiceWorkerResponse response; |
| 1166 response.response_time = response_time; | 1166 response.response_time = response_time; |
| 1167 EXPECT_TRUE(Put(no_body_request_, response)); | 1167 EXPECT_TRUE(Put(no_body_request_, response)); |
| 1168 | 1168 |
| 1169 const size_t kSize = 1024 * 1024; | 1169 const size_t kSize = 1024 * 1024; |
| 1170 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); | 1170 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); |
| 1171 memset(buffer->data(), 0, kSize); | 1171 memset(buffer->data(), 0, kSize); |
| 1172 EXPECT_FALSE( | 1172 EXPECT_FALSE( |
| 1173 WriteSideData(no_body_request_.url, response_time, buffer, kSize)); | 1173 WriteSideData(no_body_request_.url, response_time, buffer, kSize)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 base::RunLoop().RunUntilIdle(); | 1272 base::RunLoop().RunUntilIdle(); |
| 1273 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count()); | 1273 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count()); |
| 1274 sum_delta += quota_manager_proxy_->last_notified_delta(); | 1274 sum_delta += quota_manager_proxy_->last_notified_delta(); |
| 1275 | 1275 |
| 1276 EXPECT_EQ(0, sum_delta); | 1276 EXPECT_EQ(0, sum_delta); |
| 1277 } | 1277 } |
| 1278 | 1278 |
| 1279 TEST_P(CacheStorageCacheTestP, PutObeysQuotaLimits) { | 1279 TEST_P(CacheStorageCacheTestP, PutObeysQuotaLimits) { |
| 1280 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary, | 1280 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary, |
| 1281 0); | 1281 0); |
| 1282 EXPECT_FALSE(Put(no_body_request_, no_body_response_)); | 1282 EXPECT_FALSE(Put(body_request_, body_response_)); |
| 1283 EXPECT_EQ(CACHE_STORAGE_ERROR_QUOTA_EXCEEDED, callback_error_); | 1283 EXPECT_EQ(CACHE_STORAGE_ERROR_QUOTA_EXCEEDED, callback_error_); |
| 1284 } | 1284 } |
| 1285 | 1285 |
| 1286 TEST_P(CacheStorageCacheTestP, Size) { | 1286 TEST_P(CacheStorageCacheTestP, Size) { |
| 1287 EXPECT_EQ(0, Size()); | 1287 EXPECT_EQ(0, Size()); |
| 1288 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 1288 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| 1289 EXPECT_LT(0, Size()); | 1289 EXPECT_LT(0, Size()); |
| 1290 int64_t no_body_size = Size(); | 1290 int64_t no_body_size = Size(); |
| 1291 | 1291 |
| 1292 EXPECT_TRUE(Delete(no_body_request_)); | 1292 EXPECT_TRUE(Delete(no_body_request_)); |
| 1293 EXPECT_EQ(0, Size()); | 1293 EXPECT_EQ(0, Size()); |
| 1294 | 1294 |
| 1295 EXPECT_TRUE(Put(body_request_, body_response_)); | 1295 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 1296 EXPECT_LT(no_body_size, Size()); | 1296 EXPECT_LT(no_body_size, Size()); |
| 1297 | 1297 |
| 1298 EXPECT_TRUE(Delete(body_request_)); | 1298 EXPECT_TRUE(Delete(body_request_)); |
| 1299 EXPECT_EQ(0, Size()); | 1299 EXPECT_EQ(0, Size()); |
| 1300 } | 1300 } |
| 1301 | 1301 |
| 1302 TEST_P(CacheStorageCacheTestP, SizeOperationsArePrioritized) { | |
| 1303 // Test that pending size operations (those waiting for initialization) run | |
| 1304 // before other scheduler operations. | |
| 1305 cache_->set_delay_backend_creation(true); // Delay cache initialization | |
| 1306 | |
| 1307 CacheStorageBatchOperation operation; | |
| 1308 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; | |
| 1309 operation.request = body_request_; | |
| 1310 operation.response = body_response_; | |
| 1311 | |
| 1312 callback_error_ = CACHE_STORAGE_ERROR_NOT_FOUND; | |
| 1313 base::RunLoop run_loop; | |
| 1314 // Start a put operation that blocks on initialization. | |
| 1315 cache_->BatchOperation(std::vector<CacheStorageBatchOperation>(1, operation), | |
| 1316 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback, | |
| 1317 base::Unretained(this), &run_loop)); | |
| 1318 | |
| 1319 // Next start a size operation that also blocks on initialization. | |
| 1320 bool size_callback_called = false; | |
| 1321 cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback, | |
| 1322 base::Unretained(this), nullptr, | |
| 1323 &size_callback_called)); | |
| 1324 | |
| 1325 base::RunLoop().RunUntilIdle(); | |
| 1326 EXPECT_FALSE(size_callback_called); | |
| 1327 EXPECT_EQ(CACHE_STORAGE_ERROR_NOT_FOUND, callback_error_); | |
| 1328 | |
| 1329 // Finish initialization. The Size operation should complete before Put gets | |
| 1330 // to run as Size has priority. See crbug.com/605663. | |
| 1331 cache_->ContinueCreateBackend(); | |
| 1332 run_loop.Run(); | |
| 1333 EXPECT_TRUE(size_callback_called); | |
| 1334 EXPECT_EQ(CACHE_STORAGE_OK, callback_error_); | |
| 1335 } | |
| 1336 | |
| 1337 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) { | 1302 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) { |
| 1338 EXPECT_TRUE(Put(body_request_, body_response_)); | 1303 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 1339 int64_t cache_size = Size(); | 1304 int64_t cache_size = Size(); |
| 1340 EXPECT_EQ(cache_size, GetSizeThenClose()); | 1305 EXPECT_EQ(cache_size, GetSizeThenClose()); |
| 1341 VerifyAllOpsFail(); | 1306 VerifyAllOpsFail(); |
| 1342 } | 1307 } |
| 1343 | 1308 |
| 1344 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) { | 1309 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) { |
| 1345 cache_->set_delay_backend_creation( | 1310 cache_->set_delay_backend_creation( |
| 1346 true); // Will hang the test if a backend is created. | 1311 true); // Will hang the test if a backend is created. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1399 EXPECT_EQ(1, sequence_out); | 1364 EXPECT_EQ(1, sequence_out); |
| 1400 close_loop2->Run(); | 1365 close_loop2->Run(); |
| 1401 EXPECT_EQ(2, sequence_out); | 1366 EXPECT_EQ(2, sequence_out); |
| 1402 } | 1367 } |
| 1403 | 1368 |
| 1404 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 1369 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
| 1405 CacheStorageCacheTestP, | 1370 CacheStorageCacheTestP, |
| 1406 ::testing::Values(false, true)); | 1371 ::testing::Values(false, true)); |
| 1407 | 1372 |
| 1408 } // namespace content | 1373 } // namespace content |
| OLD | NEW |