Chromium Code Reviews| 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()) { | |
| 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 Loading... | |
| 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(Keys()); | |
|
jkarlin
2016/02/24 18:14:03
This check before the puts is unnecessary
zino
2016/02/24 18:17:58
Done.
| |
| 950 EXPECT_EQ(0u, callback_strings_.size()); | |
| 951 | |
| 952 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | |
| 953 EXPECT_TRUE(Put(body_request_, body_response_)); | |
| 954 EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_)); | |
| 955 | |
| 956 EXPECT_TRUE(Keys()); | |
| 957 EXPECT_EQ(3u, callback_strings_.size()); | |
| 958 std::vector<std::string> expected_keys; | |
| 959 expected_keys.push_back(no_body_request_.url.spec()); | |
| 960 expected_keys.push_back(body_request_.url.spec()); | |
| 961 expected_keys.push_back(body_request_with_query_.url.spec()); | |
| 962 EXPECT_TRUE(VerifyKeys(expected_keys)); | |
| 963 | |
| 964 // The following delete operation will remove both of body_request_ and | |
| 965 // body_request_with_query_ from cache storage. | |
| 966 CacheStorageCacheQueryParams match_params; | |
| 967 match_params.ignore_search = true; | |
| 968 EXPECT_TRUE(Delete(body_request_with_query_, match_params)); | |
| 969 | |
| 970 EXPECT_TRUE(Keys()); | |
| 971 EXPECT_EQ(1u, callback_strings_.size()); | |
| 972 expected_keys.clear(); | |
| 973 expected_keys.push_back(no_body_request_.url.spec()); | |
| 974 EXPECT_TRUE(VerifyKeys(expected_keys)); | |
| 975 } | |
| 976 | |
| 977 TEST_P(CacheStorageCacheTestP, DeleteWithIgnoreSearchFalse) { | |
| 978 EXPECT_TRUE(Keys()); | |
| 979 EXPECT_EQ(0u, callback_strings_.size()); | |
|
jkarlin
2016/02/24 18:14:03
Ditto
zino
2016/02/24 18:17:58
Done.
| |
| 980 | |
| 981 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | |
| 982 EXPECT_TRUE(Put(body_request_, body_response_)); | |
| 983 EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_)); | |
| 984 | |
| 985 EXPECT_TRUE(Keys()); | |
| 986 EXPECT_EQ(3u, callback_strings_.size()); | |
| 987 std::vector<std::string> expected_keys; | |
| 988 expected_keys.push_back(no_body_request_.url.spec()); | |
| 989 expected_keys.push_back(body_request_.url.spec()); | |
| 990 expected_keys.push_back(body_request_with_query_.url.spec()); | |
| 991 EXPECT_TRUE(VerifyKeys(expected_keys)); | |
| 992 | |
| 993 // Default value of ignore_search is false. | |
| 994 CacheStorageCacheQueryParams match_params; | |
| 995 match_params.ignore_search = false; | |
| 996 EXPECT_EQ(match_params.ignore_search, | |
| 997 CacheStorageCacheQueryParams().ignore_search); | |
| 998 | |
| 999 EXPECT_TRUE(Delete(body_request_with_query_, match_params)); | |
| 1000 | |
| 1001 EXPECT_TRUE(Keys()); | |
| 1002 EXPECT_EQ(2u, callback_strings_.size()); | |
| 1003 expected_keys.clear(); | |
| 1004 expected_keys.push_back(no_body_request_.url.spec()); | |
| 1005 expected_keys.push_back(body_request_.url.spec()); | |
| 1006 EXPECT_TRUE(VerifyKeys(expected_keys)); | |
| 1007 } | |
| 1008 | |
| 945 TEST_P(CacheStorageCacheTestP, QuickStressNoBody) { | 1009 TEST_P(CacheStorageCacheTestP, QuickStressNoBody) { |
| 946 for (int i = 0; i < 100; ++i) { | 1010 for (int i = 0; i < 100; ++i) { |
| 947 EXPECT_FALSE(Match(no_body_request_)); | 1011 EXPECT_FALSE(Match(no_body_request_)); |
| 948 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 1012 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| 949 EXPECT_TRUE(Match(no_body_request_)); | 1013 EXPECT_TRUE(Match(no_body_request_)); |
| 950 EXPECT_TRUE(Delete(no_body_request_)); | 1014 EXPECT_TRUE(Delete(no_body_request_)); |
| 951 } | 1015 } |
| 952 } | 1016 } |
| 953 | 1017 |
| 954 TEST_P(CacheStorageCacheTestP, QuickStressBody) { | 1018 TEST_P(CacheStorageCacheTestP, QuickStressBody) { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1109 EXPECT_EQ(1, sequence_out); | 1173 EXPECT_EQ(1, sequence_out); |
| 1110 close_loop2->Run(); | 1174 close_loop2->Run(); |
| 1111 EXPECT_EQ(2, sequence_out); | 1175 EXPECT_EQ(2, sequence_out); |
| 1112 } | 1176 } |
| 1113 | 1177 |
| 1114 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 1178 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
| 1115 CacheStorageCacheTestP, | 1179 CacheStorageCacheTestP, |
| 1116 ::testing::Values(false, true)); | 1180 ::testing::Values(false, true)); |
| 1117 | 1181 |
| 1118 } // namespace content | 1182 } // namespace content |
| OLD | NEW |