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

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

Issue 1694213002: CacheStorage: Add ignoreSearch option to cache.delete(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary check Created 4 years, 10 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 #include <utility> 9 #include <utility>
10 10
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 loop.Run(); 401 loop.Run();
402 return callback_error_ == CACHE_STORAGE_OK; 402 return callback_error_ == CACHE_STORAGE_OK;
403 } 403 }
404 404
405 bool MatchAll(scoped_ptr<CacheStorageCache::Responses>* responses, 405 bool MatchAll(scoped_ptr<CacheStorageCache::Responses>* responses,
406 scoped_ptr<CacheStorageCache::BlobDataHandles>* body_handles) { 406 scoped_ptr<CacheStorageCache::BlobDataHandles>* body_handles) {
407 return MatchAll(ServiceWorkerFetchRequest(), CacheStorageCacheQueryParams(), 407 return MatchAll(ServiceWorkerFetchRequest(), CacheStorageCacheQueryParams(),
408 responses, body_handles); 408 responses, body_handles);
409 } 409 }
410 410
411 bool Delete(const ServiceWorkerFetchRequest& request) { 411 bool Delete(const ServiceWorkerFetchRequest& request,
412 const CacheStorageCacheQueryParams& match_params =
413 CacheStorageCacheQueryParams()) {
412 CacheStorageBatchOperation operation; 414 CacheStorageBatchOperation operation;
413 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE; 415 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE;
414 operation.request = request; 416 operation.request = request;
417 operation.match_params = match_params;
415 418
416 CacheStorageError error = 419 CacheStorageError error =
417 BatchOperation(std::vector<CacheStorageBatchOperation>(1, operation)); 420 BatchOperation(std::vector<CacheStorageBatchOperation>(1, operation));
418 return error == CACHE_STORAGE_OK; 421 return error == CACHE_STORAGE_OK;
419 } 422 }
420 423
421 bool Keys() { 424 bool Keys() {
422 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 425 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
423 426
424 cache_->Keys(base::Bind(&CacheStorageCacheTest::RequestsCallback, 427 cache_->Keys(base::Bind(&CacheStorageCacheTest::RequestsCallback,
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 EXPECT_TRUE(Put(body_request_, body_response_)); 938 EXPECT_TRUE(Put(body_request_, body_response_));
936 EXPECT_TRUE(Match(body_request_)); 939 EXPECT_TRUE(Match(body_request_));
937 EXPECT_TRUE(Delete(body_request_)); 940 EXPECT_TRUE(Delete(body_request_));
938 EXPECT_FALSE(Match(body_request_)); 941 EXPECT_FALSE(Match(body_request_));
939 EXPECT_FALSE(Delete(body_request_)); 942 EXPECT_FALSE(Delete(body_request_));
940 EXPECT_TRUE(Put(body_request_, body_response_)); 943 EXPECT_TRUE(Put(body_request_, body_response_));
941 EXPECT_TRUE(Match(body_request_)); 944 EXPECT_TRUE(Match(body_request_));
942 EXPECT_TRUE(Delete(body_request_)); 945 EXPECT_TRUE(Delete(body_request_));
943 } 946 }
944 947
948 TEST_P(CacheStorageCacheTestP, DeleteWithIgnoreSearchTrue) {
949 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
950 EXPECT_TRUE(Put(body_request_, body_response_));
951 EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_));
952
953 EXPECT_TRUE(Keys());
954 EXPECT_EQ(3u, callback_strings_.size());
955 std::vector<std::string> expected_keys;
956 expected_keys.push_back(no_body_request_.url.spec());
957 expected_keys.push_back(body_request_.url.spec());
958 expected_keys.push_back(body_request_with_query_.url.spec());
959 EXPECT_TRUE(VerifyKeys(expected_keys));
960
961 // The following delete operation will remove both of body_request_ and
962 // body_request_with_query_ from cache storage.
963 CacheStorageCacheQueryParams match_params;
964 match_params.ignore_search = true;
965 EXPECT_TRUE(Delete(body_request_with_query_, match_params));
966
967 EXPECT_TRUE(Keys());
968 EXPECT_EQ(1u, callback_strings_.size());
969 expected_keys.clear();
970 expected_keys.push_back(no_body_request_.url.spec());
971 EXPECT_TRUE(VerifyKeys(expected_keys));
972 }
973
974 TEST_P(CacheStorageCacheTestP, DeleteWithIgnoreSearchFalse) {
975 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
976 EXPECT_TRUE(Put(body_request_, body_response_));
977 EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_));
978
979 EXPECT_TRUE(Keys());
980 EXPECT_EQ(3u, callback_strings_.size());
981 std::vector<std::string> expected_keys;
982 expected_keys.push_back(no_body_request_.url.spec());
983 expected_keys.push_back(body_request_.url.spec());
984 expected_keys.push_back(body_request_with_query_.url.spec());
985 EXPECT_TRUE(VerifyKeys(expected_keys));
986
987 // Default value of ignore_search is false.
988 CacheStorageCacheQueryParams match_params;
989 match_params.ignore_search = false;
990 EXPECT_EQ(match_params.ignore_search,
991 CacheStorageCacheQueryParams().ignore_search);
992
993 EXPECT_TRUE(Delete(body_request_with_query_, match_params));
994
995 EXPECT_TRUE(Keys());
996 EXPECT_EQ(2u, callback_strings_.size());
997 expected_keys.clear();
998 expected_keys.push_back(no_body_request_.url.spec());
999 expected_keys.push_back(body_request_.url.spec());
1000 EXPECT_TRUE(VerifyKeys(expected_keys));
1001 }
1002
945 TEST_P(CacheStorageCacheTestP, QuickStressNoBody) { 1003 TEST_P(CacheStorageCacheTestP, QuickStressNoBody) {
946 for (int i = 0; i < 100; ++i) { 1004 for (int i = 0; i < 100; ++i) {
947 EXPECT_FALSE(Match(no_body_request_)); 1005 EXPECT_FALSE(Match(no_body_request_));
948 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); 1006 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
949 EXPECT_TRUE(Match(no_body_request_)); 1007 EXPECT_TRUE(Match(no_body_request_));
950 EXPECT_TRUE(Delete(no_body_request_)); 1008 EXPECT_TRUE(Delete(no_body_request_));
951 } 1009 }
952 } 1010 }
953 1011
954 TEST_P(CacheStorageCacheTestP, QuickStressBody) { 1012 TEST_P(CacheStorageCacheTestP, QuickStressBody) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 EXPECT_EQ(1, sequence_out); 1167 EXPECT_EQ(1, sequence_out);
1110 close_loop2->Run(); 1168 close_loop2->Run();
1111 EXPECT_EQ(2, sequence_out); 1169 EXPECT_EQ(2, sequence_out);
1112 } 1170 }
1113 1171
1114 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 1172 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
1115 CacheStorageCacheTestP, 1173 CacheStorageCacheTestP,
1116 ::testing::Values(false, true)); 1174 ::testing::Values(false, true));
1117 1175
1118 } // namespace content 1176 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698