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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 CacheStorageBatchOperation operation; | 414 CacheStorageBatchOperation operation; |
415 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE; | 415 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE; |
416 operation.request = request; | 416 operation.request = request; |
417 operation.match_params = match_params; | 417 operation.match_params = match_params; |
418 | 418 |
419 CacheStorageError error = | 419 CacheStorageError error = |
420 BatchOperation(std::vector<CacheStorageBatchOperation>(1, operation)); | 420 BatchOperation(std::vector<CacheStorageBatchOperation>(1, operation)); |
421 return error == CACHE_STORAGE_OK; | 421 return error == CACHE_STORAGE_OK; |
422 } | 422 } |
423 | 423 |
424 bool Keys() { | 424 bool Keys( |
| 425 const ServiceWorkerFetchRequest& request = ServiceWorkerFetchRequest(), |
| 426 const CacheStorageCacheQueryParams& match_params = |
| 427 CacheStorageCacheQueryParams()) { |
425 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); | 428 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); |
426 | 429 |
427 cache_->Keys(base::Bind(&CacheStorageCacheTest::RequestsCallback, | 430 cache_->Keys( |
428 base::Unretained(this), | 431 CopyFetchRequest(request), match_params, |
429 base::Unretained(loop.get()))); | 432 base::Bind(&CacheStorageCacheTest::RequestsCallback, |
| 433 base::Unretained(this), base::Unretained(loop.get()))); |
430 loop->Run(); | 434 loop->Run(); |
431 | 435 |
432 return callback_error_ == CACHE_STORAGE_OK; | 436 return callback_error_ == CACHE_STORAGE_OK; |
433 } | 437 } |
434 | 438 |
435 bool Close() { | 439 bool Close() { |
436 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); | 440 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); |
437 | 441 |
438 cache_->Close(base::Bind(&CacheStorageCacheTest::CloseCallback, | 442 cache_->Close(base::Bind(&CacheStorageCacheTest::CloseCallback, |
439 base::Unretained(this), | 443 base::Unretained(this), |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 EXPECT_TRUE(VerifyKeys(expected_keys)); | 920 EXPECT_TRUE(VerifyKeys(expected_keys)); |
917 | 921 |
918 EXPECT_TRUE(Delete(body_request_)); | 922 EXPECT_TRUE(Delete(body_request_)); |
919 EXPECT_TRUE(Keys()); | 923 EXPECT_TRUE(Keys()); |
920 EXPECT_EQ(1u, callback_strings_.size()); | 924 EXPECT_EQ(1u, callback_strings_.size()); |
921 std::vector<std::string> expected_key; | 925 std::vector<std::string> expected_key; |
922 expected_key.push_back(no_body_request_.url.spec()); | 926 expected_key.push_back(no_body_request_.url.spec()); |
923 EXPECT_TRUE(VerifyKeys(expected_key)); | 927 EXPECT_TRUE(VerifyKeys(expected_key)); |
924 } | 928 } |
925 | 929 |
| 930 TEST_P(CacheStorageCacheTestP, KeysWithIgnoreSearchTrue) { |
| 931 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| 932 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 933 EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_)); |
| 934 |
| 935 CacheStorageCacheQueryParams match_params; |
| 936 match_params.ignore_search = true; |
| 937 |
| 938 EXPECT_TRUE(Keys(body_request_with_query_, match_params)); |
| 939 EXPECT_EQ(2u, callback_strings_.size()); |
| 940 std::vector<std::string> expected_keys; |
| 941 expected_keys.push_back(body_request_.url.spec()); |
| 942 expected_keys.push_back(body_request_with_query_.url.spec()); |
| 943 EXPECT_TRUE(VerifyKeys(expected_keys)); |
| 944 } |
| 945 |
| 946 TEST_P(CacheStorageCacheTestP, KeysWithIgnoreSearchFalse) { |
| 947 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| 948 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 949 EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_)); |
| 950 |
| 951 // Default value of ignore_search is false. |
| 952 CacheStorageCacheQueryParams match_params; |
| 953 match_params.ignore_search = false; |
| 954 EXPECT_EQ(match_params.ignore_search, |
| 955 CacheStorageCacheQueryParams().ignore_search); |
| 956 |
| 957 EXPECT_TRUE(Keys(body_request_with_query_, match_params)); |
| 958 EXPECT_EQ(1u, callback_strings_.size()); |
| 959 std::vector<std::string> expected_keys; |
| 960 expected_keys.push_back(body_request_with_query_.url.spec()); |
| 961 EXPECT_TRUE(VerifyKeys(expected_keys)); |
| 962 } |
| 963 |
926 TEST_P(CacheStorageCacheTestP, DeleteNoBody) { | 964 TEST_P(CacheStorageCacheTestP, DeleteNoBody) { |
927 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 965 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
928 EXPECT_TRUE(Match(no_body_request_)); | 966 EXPECT_TRUE(Match(no_body_request_)); |
929 EXPECT_TRUE(Delete(no_body_request_)); | 967 EXPECT_TRUE(Delete(no_body_request_)); |
930 EXPECT_FALSE(Match(no_body_request_)); | 968 EXPECT_FALSE(Match(no_body_request_)); |
931 EXPECT_FALSE(Delete(no_body_request_)); | 969 EXPECT_FALSE(Delete(no_body_request_)); |
932 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 970 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
933 EXPECT_TRUE(Match(no_body_request_)); | 971 EXPECT_TRUE(Match(no_body_request_)); |
934 EXPECT_TRUE(Delete(no_body_request_)); | 972 EXPECT_TRUE(Delete(no_body_request_)); |
935 } | 973 } |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 EXPECT_EQ(1, sequence_out); | 1205 EXPECT_EQ(1, sequence_out); |
1168 close_loop2->Run(); | 1206 close_loop2->Run(); |
1169 EXPECT_EQ(2, sequence_out); | 1207 EXPECT_EQ(2, sequence_out); |
1170 } | 1208 } |
1171 | 1209 |
1172 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 1210 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
1173 CacheStorageCacheTestP, | 1211 CacheStorageCacheTestP, |
1174 ::testing::Values(false, true)); | 1212 ::testing::Values(false, true)); |
1175 | 1213 |
1176 } // namespace content | 1214 } // namespace content |
OLD | NEW |