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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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()) { | |
jkarlin
2016/02/24 16:35:34
I see that default arguments are now allowed by th
| |
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 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 EXPECT_TRUE(Delete(no_body_request_)); | 1032 EXPECT_TRUE(Delete(no_body_request_)); |
1030 EXPECT_EQ(0, Size()); | 1033 EXPECT_EQ(0, Size()); |
1031 | 1034 |
1032 EXPECT_TRUE(Put(body_request_, body_response_)); | 1035 EXPECT_TRUE(Put(body_request_, body_response_)); |
1033 EXPECT_LT(no_body_size, Size()); | 1036 EXPECT_LT(no_body_size, Size()); |
1034 | 1037 |
1035 EXPECT_TRUE(Delete(body_request_)); | 1038 EXPECT_TRUE(Delete(body_request_)); |
1036 EXPECT_EQ(0, Size()); | 1039 EXPECT_EQ(0, Size()); |
1037 } | 1040 } |
1038 | 1041 |
1042 TEST_P(CacheStorageCacheTestP, DeleteWithIgnoreSearch) { | |
1043 EXPECT_EQ(0, Size()); | |
1044 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | |
1045 EXPECT_LT(0, Size()); | |
jkarlin
2016/02/24 16:35:34
Prefer to use Keys() instead of Size() in this tes
zino
2016/02/24 18:05:21
Done.
| |
1046 int64_t no_body_size = Size(); | |
1047 | |
1048 EXPECT_TRUE(Put(body_request_, body_response_)); | |
1049 EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_)); | |
1050 EXPECT_LT(no_body_size, Size()); | |
1051 | |
1052 CacheStorageCacheQueryParams match_params; | |
1053 match_params.ignore_search = true; | |
1054 | |
1055 // The following delete operation will remove both of body_reqeust_ and | |
jkarlin
2016/02/24 16:35:34
typo: s/body_reqeust_/body_request_/
zino
2016/02/24 18:05:21
Nice catch!
Thank you.
Done.
| |
1056 // body_request_with_query_ from cache storage. | |
1057 EXPECT_TRUE(Delete(body_request_with_query_, match_params)); | |
1058 | |
1059 EXPECT_EQ(no_body_size, Size()); | |
1060 } | |
jkarlin
2016/02/24 16:35:34
Add a second test that deletes with default option
zino
2016/02/24 18:05:21
Done.
| |
1061 | |
1039 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) { | 1062 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackendNeverCreated) { |
1040 cache_->set_delay_backend_creation( | 1063 cache_->set_delay_backend_creation( |
1041 true); // Will hang the test if a backend is created. | 1064 true); // Will hang the test if a backend is created. |
1042 EXPECT_TRUE(Close()); | 1065 EXPECT_TRUE(Close()); |
1043 VerifyAllOpsFail(); | 1066 VerifyAllOpsFail(); |
1044 } | 1067 } |
1045 | 1068 |
1046 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackend) { | 1069 TEST_P(CacheStorageCacheTestP, OpsFailOnClosedBackend) { |
1047 // Create the backend and put something in it. | 1070 // Create the backend and put something in it. |
1048 EXPECT_TRUE(Put(body_request_, body_response_)); | 1071 EXPECT_TRUE(Put(body_request_, body_response_)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1094 EXPECT_EQ(1, sequence_out); | 1117 EXPECT_EQ(1, sequence_out); |
1095 close_loop2->Run(); | 1118 close_loop2->Run(); |
1096 EXPECT_EQ(2, sequence_out); | 1119 EXPECT_EQ(2, sequence_out); |
1097 } | 1120 } |
1098 | 1121 |
1099 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 1122 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
1100 CacheStorageCacheTestP, | 1123 CacheStorageCacheTestP, |
1101 ::testing::Values(false, true)); | 1124 ::testing::Values(false, true)); |
1102 | 1125 |
1103 } // namespace content | 1126 } // namespace content |
OLD | NEW |