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

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

Issue 2242883002: [CacheStorage] Use QueryCache everywhere (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 years, 4 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_manager.h" 5 #include "content/browser/cache_storage/cache_storage_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 cache_manager_->EnumerateCaches( 198 cache_manager_->EnumerateCaches(
199 origin, base::Bind(&CacheStorageManagerTest::StringsAndErrorCallback, 199 origin, base::Bind(&CacheStorageManagerTest::StringsAndErrorCallback,
200 base::Unretained(this), base::Unretained(&loop))); 200 base::Unretained(this), base::Unretained(&loop)));
201 loop.Run(); 201 loop.Run();
202 202
203 return callback_error_ == CACHE_STORAGE_OK; 203 return callback_error_ == CACHE_STORAGE_OK;
204 } 204 }
205 205
206 bool StorageMatch(const GURL& origin, 206 bool StorageMatch(const GURL& origin,
207 const std::string& cache_name, 207 const std::string& cache_name,
208 const GURL& url) { 208 const GURL& url,
209 std::unique_ptr<ServiceWorkerFetchRequest> request( 209 const CacheStorageCacheQueryParams& match_params =
210 new ServiceWorkerFetchRequest()); 210 CacheStorageCacheQueryParams()) {
211 request->url = url; 211 ServiceWorkerFetchRequest request;
212 request.url = url;
213 return StorageMatchWithRequest(origin, cache_name, request, match_params);
214 }
215
216 bool StorageMatchWithRequest(
217 const GURL& origin,
218 const std::string& cache_name,
219 const ServiceWorkerFetchRequest& request,
220 const CacheStorageCacheQueryParams& match_params =
221 CacheStorageCacheQueryParams()) {
222 std::unique_ptr<ServiceWorkerFetchRequest> unique_request =
223 base::MakeUnique<ServiceWorkerFetchRequest>(request);
224
212 base::RunLoop loop; 225 base::RunLoop loop;
213 cache_manager_->MatchCache( 226 cache_manager_->MatchCache(
214 origin, cache_name, std::move(request), 227 origin, cache_name, std::move(unique_request), match_params,
215 base::Bind(&CacheStorageManagerTest::CacheMatchCallback, 228 base::Bind(&CacheStorageManagerTest::CacheMatchCallback,
216 base::Unretained(this), base::Unretained(&loop))); 229 base::Unretained(this), base::Unretained(&loop)));
217 loop.Run(); 230 loop.Run();
218 231
219 return callback_error_ == CACHE_STORAGE_OK; 232 return callback_error_ == CACHE_STORAGE_OK;
220 } 233 }
221 234
222 bool StorageMatchAll(const GURL& origin, const GURL& url) { 235 bool StorageMatchAll(const GURL& origin,
223 std::unique_ptr<ServiceWorkerFetchRequest> request( 236 const GURL& url,
224 new ServiceWorkerFetchRequest()); 237 const CacheStorageCacheQueryParams& match_params =
225 request->url = url; 238 CacheStorageCacheQueryParams()) {
239 ServiceWorkerFetchRequest request;
240 request.url = url;
241 return StorageMatchAllWithRequest(origin, request, match_params);
242 }
243
244 bool StorageMatchAllWithRequest(
245 const GURL& origin,
246 const ServiceWorkerFetchRequest& request,
247 const CacheStorageCacheQueryParams& match_params =
248 CacheStorageCacheQueryParams()) {
249 std::unique_ptr<ServiceWorkerFetchRequest> unique_request =
250 base::MakeUnique<ServiceWorkerFetchRequest>(request);
226 base::RunLoop loop; 251 base::RunLoop loop;
227 cache_manager_->MatchAllCaches( 252 cache_manager_->MatchAllCaches(
228 origin, std::move(request), 253 origin, std::move(unique_request), match_params,
229 base::Bind(&CacheStorageManagerTest::CacheMatchCallback, 254 base::Bind(&CacheStorageManagerTest::CacheMatchCallback,
230 base::Unretained(this), base::Unretained(&loop))); 255 base::Unretained(this), base::Unretained(&loop)));
231 loop.Run(); 256 loop.Run();
232 257
233 return callback_error_ == CACHE_STORAGE_OK; 258 return callback_error_ == CACHE_STORAGE_OK;
259
nhiroki 2016/08/18 00:05:43 blank line
jkarlin 2016/08/18 14:08:23 Done.
234 } 260 }
235 261
236 bool CachePut(CacheStorageCache* cache, const GURL& url) { 262 bool CachePut(CacheStorageCache* cache, const GURL& url) {
237 return CachePutWithStatusCode(cache, url, 200); 263 ServiceWorkerFetchRequest request;
264 request.url = url;
265
266 return CachePutWithStatusCode(cache, request, 200);
267 }
268
269 bool CachePutWithRequestAndHeaders(
270 CacheStorageCache* cache,
271 const ServiceWorkerFetchRequest& request,
272 const ServiceWorkerHeaderMap& response_headers) {
273 return CachePutWithStatusCode(cache, request, 200, response_headers);
238 } 274 }
239 275
240 bool CachePutWithStatusCode(CacheStorageCache* cache, 276 bool CachePutWithStatusCode(CacheStorageCache* cache,
241 const GURL& url, 277 const ServiceWorkerFetchRequest& request,
242 int status_code) { 278 int status_code,
243 ServiceWorkerFetchRequest request; 279 const ServiceWorkerHeaderMap& response_headers =
244 request.url = url; 280 ServiceWorkerHeaderMap()) {
245
246 std::unique_ptr<storage::BlobDataBuilder> blob_data( 281 std::unique_ptr<storage::BlobDataBuilder> blob_data(
247 new storage::BlobDataBuilder(base::GenerateGUID())); 282 new storage::BlobDataBuilder(base::GenerateGUID()));
248 blob_data->AppendData(url.spec()); 283 blob_data->AppendData(request.url.spec());
249 284
250 std::unique_ptr<storage::BlobDataHandle> blob_handle = 285 std::unique_ptr<storage::BlobDataHandle> blob_handle =
251 blob_storage_context_->AddFinishedBlob(blob_data.get()); 286 blob_storage_context_->AddFinishedBlob(blob_data.get());
252 ServiceWorkerResponse response( 287 ServiceWorkerResponse response(
253 url, status_code, "OK", blink::WebServiceWorkerResponseTypeDefault, 288 request.url, status_code, "OK",
254 ServiceWorkerHeaderMap(), blob_handle->uuid(), url.spec().size(), 289 blink::WebServiceWorkerResponseTypeDefault, response_headers,
255 GURL(), blink::WebServiceWorkerResponseErrorUnknown, base::Time(), 290 blob_handle->uuid(), request.url.spec().size(), GURL(),
291 blink::WebServiceWorkerResponseErrorUnknown, base::Time(),
256 false /* is_in_cache_storage */, 292 false /* is_in_cache_storage */,
257 std::string() /* cache_storage_cache_name */, 293 std::string() /* cache_storage_cache_name */,
258 ServiceWorkerHeaderList() /* cors_exposed_header_names */); 294 ServiceWorkerHeaderList() /* cors_exposed_header_names */);
259 295
260 CacheStorageBatchOperation operation; 296 CacheStorageBatchOperation operation;
261 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; 297 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT;
262 operation.request = request; 298 operation.request = request;
263 operation.response = response; 299 operation.response = response;
264 300
265 base::RunLoop loop; 301 base::RunLoop loop;
266 cache->BatchOperation( 302 cache->BatchOperation(
267 std::vector<CacheStorageBatchOperation>(1, operation), 303 std::vector<CacheStorageBatchOperation>(1, operation),
268 base::Bind(&CacheStorageManagerTest::CachePutCallback, 304 base::Bind(&CacheStorageManagerTest::CachePutCallback,
269 base::Unretained(this), base::Unretained(&loop))); 305 base::Unretained(this), base::Unretained(&loop)));
270 loop.Run(); 306 loop.Run();
271 307
272 return callback_error_ == CACHE_STORAGE_OK; 308 return callback_error_ == CACHE_STORAGE_OK;
273 } 309 }
274 310
275 bool CacheMatch(CacheStorageCache* cache, const GURL& url) { 311 bool CacheMatch(CacheStorageCache* cache, const GURL& url) {
276 std::unique_ptr<ServiceWorkerFetchRequest> request( 312 std::unique_ptr<ServiceWorkerFetchRequest> request(
277 new ServiceWorkerFetchRequest()); 313 new ServiceWorkerFetchRequest());
278 request->url = url; 314 request->url = url;
279 base::RunLoop loop; 315 base::RunLoop loop;
280 cache->Match(std::move(request), 316 cache->Match(std::move(request), CacheStorageCacheQueryParams(),
281 base::Bind(&CacheStorageManagerTest::CacheMatchCallback, 317 base::Bind(&CacheStorageManagerTest::CacheMatchCallback,
282 base::Unretained(this), base::Unretained(&loop))); 318 base::Unretained(this), base::Unretained(&loop)));
283 loop.Run(); 319 loop.Run();
284 320
285 return callback_error_ == CACHE_STORAGE_OK; 321 return callback_error_ == CACHE_STORAGE_OK;
286 } 322 }
287 323
288 CacheStorage* CacheStorageForOrigin(const GURL& origin) { 324 CacheStorage* CacheStorageForOrigin(const GURL& origin) {
289 return cache_manager_->FindOrCreateCacheStorage(origin); 325 return cache_manager_->FindOrCreateCacheStorage(origin);
290 } 326 }
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 628
593 // Do some busy work on a different cache to move the cache pool threads 629 // Do some busy work on a different cache to move the cache pool threads
594 // along and trigger the bug. 630 // along and trigger the bug.
595 EXPECT_TRUE(Open(origin1_, "bar")); 631 EXPECT_TRUE(Open(origin1_, "bar"));
596 EXPECT_TRUE(CachePut(callback_cache_handle_->value(), kTestURL)); 632 EXPECT_TRUE(CachePut(callback_cache_handle_->value(), kTestURL));
597 EXPECT_TRUE(CacheMatch(callback_cache_handle_->value(), kTestURL)); 633 EXPECT_TRUE(CacheMatch(callback_cache_handle_->value(), kTestURL));
598 } 634 }
599 635
600 TEST_P(CacheStorageManagerTestP, StorageMatchAllEntryExistsTwice) { 636 TEST_P(CacheStorageManagerTestP, StorageMatchAllEntryExistsTwice) {
601 EXPECT_TRUE(Open(origin1_, "foo")); 637 EXPECT_TRUE(Open(origin1_, "foo"));
602 EXPECT_TRUE(CachePutWithStatusCode(callback_cache_handle_->value(), 638 ServiceWorkerFetchRequest request;
603 GURL("http://example.com/foo"), 200)); 639 request.url = GURL("http://example.com/foo");
640 EXPECT_TRUE(
641 CachePutWithStatusCode(callback_cache_handle_->value(), request, 200));
604 EXPECT_TRUE(Open(origin1_, "bar")); 642 EXPECT_TRUE(Open(origin1_, "bar"));
605 EXPECT_TRUE(CachePutWithStatusCode(callback_cache_handle_->value(), 643 EXPECT_TRUE(
606 GURL("http://example.com/foo"), 201)); 644 CachePutWithStatusCode(callback_cache_handle_->value(), request, 201));
607 645
608 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo"))); 646 EXPECT_TRUE(StorageMatchAll(origin1_, GURL("http://example.com/foo")));
609 647
610 // The caches need to be searched in order of creation, so verify that the 648 // The caches need to be searched in order of creation, so verify that the
611 // response came from the first cache. 649 // response came from the first cache.
612 EXPECT_EQ(200, callback_cache_handle_response_->status_code); 650 EXPECT_EQ(200, callback_cache_handle_response_->status_code);
613 } 651 }
614 652
615 TEST_P(CacheStorageManagerTestP, StorageMatchInOneOfMany) { 653 TEST_P(CacheStorageManagerTestP, StorageMatchInOneOfMany) {
616 EXPECT_TRUE(Open(origin1_, "foo")); 654 EXPECT_TRUE(Open(origin1_, "foo"));
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 EXPECT_EQ(0, quota_manager_proxy_->notify_storage_accessed_count()); 960 EXPECT_EQ(0, quota_manager_proxy_->notify_storage_accessed_count());
923 } 961 }
924 962
925 TEST_P(CacheStorageManagerTestP, SizeThenCloseStorageAccessed) { 963 TEST_P(CacheStorageManagerTestP, SizeThenCloseStorageAccessed) {
926 EXPECT_EQ(0, GetSizeThenCloseAllCaches(origin1_)); 964 EXPECT_EQ(0, GetSizeThenCloseAllCaches(origin1_));
927 // GetSizeThenCloseAllCaches is not part of the web API and should not notify 965 // GetSizeThenCloseAllCaches is not part of the web API and should not notify
928 // the quota manager of an access. 966 // the quota manager of an access.
929 EXPECT_EQ(0, quota_manager_proxy_->notify_storage_accessed_count()); 967 EXPECT_EQ(0, quota_manager_proxy_->notify_storage_accessed_count());
930 } 968 }
931 969
970 TEST_P(CacheStorageManagerTestP, StorageMatch_IgnoreSearch) {
971 EXPECT_TRUE(Open(origin1_, "foo"));
972 EXPECT_TRUE(CachePut(callback_cache_handle_->value(),
973 GURL("http://example.com/foo?bar")));
974
975 EXPECT_FALSE(StorageMatch(origin1_, "foo", GURL("http://example.com/foo")));
976
977 CacheStorageCacheQueryParams match_params;
978 match_params.ignore_search = true;
979 EXPECT_TRUE(StorageMatch(origin1_, "foo", GURL("http://example.com/foo"),
980 match_params));
981 }
982
983 TEST_P(CacheStorageManagerTestP, StorageMatch_IgnoreMethod) {
984 GURL url = GURL("http://example.com/foo");
985 EXPECT_TRUE(Open(origin1_, "foo"));
986 EXPECT_TRUE(CachePut(callback_cache_handle_->value(), url));
987
988 ServiceWorkerFetchRequest post_request;
989 post_request.url = url;
990 post_request.method = "POST";
991 EXPECT_FALSE(StorageMatchWithRequest(origin1_, "foo", post_request));
992
993 CacheStorageCacheQueryParams match_params;
994 match_params.ignore_method = true;
995 EXPECT_TRUE(
996 StorageMatchWithRequest(origin1_, "foo", post_request, match_params));
997 }
998
999 TEST_P(CacheStorageManagerTestP, StorageMatch_IgnoreVary) {
1000 GURL url = GURL("http://example.com/foo");
1001 EXPECT_TRUE(Open(origin1_, "foo"));
1002
1003 ServiceWorkerFetchRequest request;
1004 request.url = url;
1005 request.headers["vary_foo"] = "foo";
1006
1007 ServiceWorkerHeaderMap response_headers;
1008 response_headers["vary"] = "vary_foo";
1009
1010 EXPECT_TRUE(CachePutWithRequestAndHeaders(callback_cache_handle_->value(),
1011 request, response_headers));
1012 EXPECT_TRUE(StorageMatchWithRequest(origin1_, "foo", request));
1013
1014 request.headers["vary_foo"] = "bar";
1015 EXPECT_FALSE(StorageMatchWithRequest(origin1_, "foo", request));
1016
1017 CacheStorageCacheQueryParams match_params;
1018 match_params.ignore_vary = true;
1019 EXPECT_TRUE(StorageMatchWithRequest(origin1_, "foo", request, match_params));
1020 }
1021
1022 TEST_P(CacheStorageManagerTestP, StorageMatchAll_IgnoreSearch) {
1023 EXPECT_TRUE(Open(origin1_, "foo"));
1024 EXPECT_TRUE(CachePut(callback_cache_handle_->value(),
1025 GURL("http://example.com/foo?bar")));
1026
1027 EXPECT_FALSE(StorageMatchAll(origin1_, GURL("http://example.com/foo")));
1028
1029 CacheStorageCacheQueryParams match_params;
1030 match_params.ignore_search = true;
1031 EXPECT_TRUE(
1032 StorageMatchAll(origin1_, GURL("http://example.com/foo"), match_params));
1033 }
1034
1035 TEST_P(CacheStorageManagerTestP, StorageMatchAll_IgnoreMethod) {
1036 GURL url = GURL("http://example.com/foo");
1037 EXPECT_TRUE(Open(origin1_, "foo"));
1038 EXPECT_TRUE(CachePut(callback_cache_handle_->value(), url));
1039
1040 ServiceWorkerFetchRequest post_request;
1041 post_request.url = url;
1042 post_request.method = "POST";
1043 EXPECT_FALSE(StorageMatchAllWithRequest(origin1_, post_request));
1044
1045 CacheStorageCacheQueryParams match_params;
1046 match_params.ignore_method = true;
1047 EXPECT_TRUE(StorageMatchAllWithRequest(origin1_, post_request, match_params));
1048 }
1049
1050 TEST_P(CacheStorageManagerTestP, StorageMatchAll_IgnoreVary) {
1051 GURL url = GURL("http://example.com/foo");
1052 EXPECT_TRUE(Open(origin1_, "foo"));
1053
1054 ServiceWorkerFetchRequest request;
1055 request.url = url;
1056 request.headers["vary_foo"] = "foo";
1057
1058 ServiceWorkerHeaderMap response_headers;
1059 response_headers["vary"] = "vary_foo";
1060
1061 EXPECT_TRUE(CachePutWithRequestAndHeaders(callback_cache_handle_->value(),
1062 request, response_headers));
1063 EXPECT_TRUE(StorageMatchAllWithRequest(origin1_, request));
1064
1065 request.headers["vary_foo"] = "bar";
1066 EXPECT_FALSE(StorageMatchAllWithRequest(origin1_, request));
1067
1068 CacheStorageCacheQueryParams match_params;
1069 match_params.ignore_vary = true;
1070 EXPECT_TRUE(StorageMatchAllWithRequest(origin1_, request, match_params));
1071 }
1072
932 class CacheStorageMigrationTest : public CacheStorageManagerTest { 1073 class CacheStorageMigrationTest : public CacheStorageManagerTest {
933 protected: 1074 protected:
934 CacheStorageMigrationTest() : cache1_("foo"), cache2_("bar") {} 1075 CacheStorageMigrationTest() : cache1_("foo"), cache2_("bar") {}
935 1076
936 void SetUp() override { 1077 void SetUp() override {
937 CacheStorageManagerTest::SetUp(); 1078 CacheStorageManagerTest::SetUp();
938 1079
939 // Populate a cache, then move it to the "legacy" location 1080 // Populate a cache, then move it to the "legacy" location
940 // so that tests can verify the results of migration. 1081 // so that tests can verify the results of migration.
941 legacy_path_ = CacheStorageManager::ConstructLegacyOriginPath( 1082 legacy_path_ = CacheStorageManager::ConstructLegacyOriginPath(
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 1440
1300 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, 1441 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests,
1301 CacheStorageManagerTestP, 1442 CacheStorageManagerTestP,
1302 ::testing::Values(false, true)); 1443 ::testing::Values(false, true));
1303 1444
1304 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, 1445 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests,
1305 CacheStorageQuotaClientTestP, 1446 CacheStorageQuotaClientTestP,
1306 ::testing::Values(false, true)); 1447 ::testing::Values(false, true));
1307 1448
1308 } // namespace content 1449 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698