| 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 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 base::RunLoop().RunUntilIdle(); | 1121 base::RunLoop().RunUntilIdle(); |
| 1122 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count()); | 1122 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count()); |
| 1123 sum_delta += quota_manager_proxy_->last_notified_delta(); | 1123 sum_delta += quota_manager_proxy_->last_notified_delta(); |
| 1124 | 1124 |
| 1125 EXPECT_EQ(0, sum_delta); | 1125 EXPECT_EQ(0, sum_delta); |
| 1126 } | 1126 } |
| 1127 | 1127 |
| 1128 TEST_P(CacheStorageCacheTestP, PutObeysQuotaLimits) { | 1128 TEST_P(CacheStorageCacheTestP, PutObeysQuotaLimits) { |
| 1129 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary, | 1129 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary, |
| 1130 0); | 1130 0); |
| 1131 EXPECT_FALSE(Put(no_body_request_, no_body_response_)); | 1131 EXPECT_FALSE(Put(body_request_, body_response_)); |
| 1132 EXPECT_EQ(CACHE_STORAGE_ERROR_QUOTA_EXCEEDED, callback_error_); | 1132 EXPECT_EQ(CACHE_STORAGE_ERROR_QUOTA_EXCEEDED, callback_error_); |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 TEST_P(CacheStorageCacheTestP, Size) { | 1135 TEST_P(CacheStorageCacheTestP, Size) { |
| 1136 EXPECT_EQ(0, Size()); | 1136 EXPECT_EQ(0, Size()); |
| 1137 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 1137 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| 1138 EXPECT_LT(0, Size()); | 1138 EXPECT_LT(0, Size()); |
| 1139 int64_t no_body_size = Size(); | 1139 int64_t no_body_size = Size(); |
| 1140 | 1140 |
| 1141 EXPECT_TRUE(Delete(no_body_request_)); | 1141 EXPECT_TRUE(Delete(no_body_request_)); |
| 1142 EXPECT_EQ(0, Size()); | 1142 EXPECT_EQ(0, Size()); |
| 1143 | 1143 |
| 1144 EXPECT_TRUE(Put(body_request_, body_response_)); | 1144 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 1145 EXPECT_LT(no_body_size, Size()); | 1145 EXPECT_LT(no_body_size, Size()); |
| 1146 | 1146 |
| 1147 EXPECT_TRUE(Delete(body_request_)); | 1147 EXPECT_TRUE(Delete(body_request_)); |
| 1148 EXPECT_EQ(0, Size()); | 1148 EXPECT_EQ(0, Size()); |
| 1149 } | 1149 } |
| 1150 | 1150 |
| 1151 TEST_P(CacheStorageCacheTestP, SizeOperationsArePrioritized) { | |
| 1152 // Test that pending size operations (those waiting for initialization) run | |
| 1153 // before other scheduler operations. | |
| 1154 cache_->set_delay_backend_creation(true); // Delay cache initialization | |
| 1155 | |
| 1156 CacheStorageBatchOperation operation; | |
| 1157 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; | |
| 1158 operation.request = body_request_; | |
| 1159 operation.response = body_response_; | |
| 1160 | |
| 1161 callback_error_ = CACHE_STORAGE_ERROR_NOT_FOUND; | |
| 1162 base::RunLoop run_loop; | |
| 1163 // Start a put operation that blocks on initialization. | |
| 1164 cache_->BatchOperation(std::vector<CacheStorageBatchOperation>(1, operation), | |
| 1165 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback, | |
| 1166 base::Unretained(this), &run_loop)); | |
| 1167 | |
| 1168 // Next start a size operation that also blocks on initialization. | |
| 1169 bool size_callback_called = false; | |
| 1170 cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback, | |
| 1171 base::Unretained(this), nullptr, | |
| 1172 &size_callback_called)); | |
| 1173 | |
| 1174 base::RunLoop().RunUntilIdle(); | |
| 1175 EXPECT_FALSE(size_callback_called); | |
| 1176 EXPECT_EQ(CACHE_STORAGE_ERROR_NOT_FOUND, callback_error_); | |
| 1177 | |
| 1178 // Finish initialization. The Size operation should complete before Put gets | |
| 1179 // to run as Size has priority. See crbug.com/605663. | |
| 1180 cache_->ContinueCreateBackend(); | |
| 1181 run_loop.Run(); | |
| 1182 EXPECT_TRUE(size_callback_called); | |
| 1183 EXPECT_EQ(CACHE_STORAGE_OK, callback_error_); | |
| 1184 } | |
| 1185 | |
| 1186 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) { | 1151 TEST_P(CacheStorageCacheTestP, GetSizeThenClose) { |
| 1187 EXPECT_TRUE(Put(body_request_, body_response_)); | 1152 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 1188 int64_t cache_size = Size(); | 1153 int64_t cache_size = Size(); |
| 1189 EXPECT_EQ(cache_size, GetSizeThenClose()); | 1154 EXPECT_EQ(cache_size, GetSizeThenClose()); |
| 1190 VerifyAllOpsFail(); | 1155 VerifyAllOpsFail(); |
| 1191 } | 1156 } |
| 1192 | 1157 |
| 1193 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) { | 1158 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) { |
| 1194 cache_->set_delay_backend_creation( | 1159 cache_->set_delay_backend_creation( |
| 1195 true); // Will hang the test if a backend is created. | 1160 true); // Will hang the test if a backend is created. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 EXPECT_EQ(1, sequence_out); | 1213 EXPECT_EQ(1, sequence_out); |
| 1249 close_loop2->Run(); | 1214 close_loop2->Run(); |
| 1250 EXPECT_EQ(2, sequence_out); | 1215 EXPECT_EQ(2, sequence_out); |
| 1251 } | 1216 } |
| 1252 | 1217 |
| 1253 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 1218 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
| 1254 CacheStorageCacheTestP, | 1219 CacheStorageCacheTestP, |
| 1255 ::testing::Values(false, true)); | 1220 ::testing::Values(false, true)); |
| 1256 | 1221 |
| 1257 } // namespace content | 1222 } // namespace content |
| OLD | NEW |