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 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 CacheStorageBatchOperation operation; | 497 CacheStorageBatchOperation operation; |
498 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE; | 498 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE; |
499 operation.request = request; | 499 operation.request = request; |
500 operation.match_params = match_params; | 500 operation.match_params = match_params; |
501 | 501 |
502 CacheStorageError error = | 502 CacheStorageError error = |
503 BatchOperation(std::vector<CacheStorageBatchOperation>(1, operation)); | 503 BatchOperation(std::vector<CacheStorageBatchOperation>(1, operation)); |
504 return error == CACHE_STORAGE_OK; | 504 return error == CACHE_STORAGE_OK; |
505 } | 505 } |
506 | 506 |
507 bool Keys() { | 507 bool Keys( |
508 const ServiceWorkerFetchRequest& request = ServiceWorkerFetchRequest(), | |
509 const CacheStorageCacheQueryParams& match_params = | |
510 CacheStorageCacheQueryParams()) { | |
508 std::unique_ptr<base::RunLoop> loop(new base::RunLoop()); | 511 std::unique_ptr<base::RunLoop> loop(new base::RunLoop()); |
509 | 512 |
510 cache_->Keys(base::Bind(&CacheStorageCacheTest::RequestsCallback, | 513 cache_->Keys( |
511 base::Unretained(this), | 514 CopyFetchRequest(request), match_params, |
512 base::Unretained(loop.get()))); | 515 base::Bind(&CacheStorageCacheTest::RequestsCallback, |
516 base::Unretained(this), base::Unretained(loop.get()))); | |
513 loop->Run(); | 517 loop->Run(); |
514 | 518 |
515 return callback_error_ == CACHE_STORAGE_OK; | 519 return callback_error_ == CACHE_STORAGE_OK; |
516 } | 520 } |
517 | 521 |
518 bool Close() { | 522 bool Close() { |
519 std::unique_ptr<base::RunLoop> loop(new base::RunLoop()); | 523 std::unique_ptr<base::RunLoop> loop(new base::RunLoop()); |
520 | 524 |
521 cache_->Close(base::Bind(&CacheStorageCacheTest::CloseCallback, | 525 cache_->Close(base::Bind(&CacheStorageCacheTest::CloseCallback, |
522 base::Unretained(this), | 526 base::Unretained(this), |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1031 EXPECT_TRUE(VerifyKeys(expected_keys)); | 1035 EXPECT_TRUE(VerifyKeys(expected_keys)); |
1032 | 1036 |
1033 EXPECT_TRUE(Delete(body_request_)); | 1037 EXPECT_TRUE(Delete(body_request_)); |
1034 EXPECT_TRUE(Keys()); | 1038 EXPECT_TRUE(Keys()); |
1035 EXPECT_EQ(1u, callback_strings_.size()); | 1039 EXPECT_EQ(1u, callback_strings_.size()); |
1036 std::vector<std::string> expected_key; | 1040 std::vector<std::string> expected_key; |
1037 expected_key.push_back(no_body_request_.url.spec()); | 1041 expected_key.push_back(no_body_request_.url.spec()); |
1038 EXPECT_TRUE(VerifyKeys(expected_key)); | 1042 EXPECT_TRUE(VerifyKeys(expected_key)); |
1039 } | 1043 } |
1040 | 1044 |
1045 TEST_P(CacheStorageCacheTestP, KeysWithIgnoreSearchTrue) { | |
1046 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | |
1047 EXPECT_TRUE(Put(body_request_, body_response_)); | |
1048 EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_)); | |
1049 | |
1050 CacheStorageCacheQueryParams match_params; | |
1051 match_params.ignore_search = true; | |
1052 | |
1053 EXPECT_TRUE(Keys(body_request_with_query_, match_params)); | |
1054 EXPECT_EQ(2u, callback_strings_.size()); | |
1055 std::vector<std::string> expected_keys; | |
1056 expected_keys.push_back(body_request_.url.spec()); | |
1057 expected_keys.push_back(body_request_with_query_.url.spec()); | |
jkarlin
2016/08/02 12:06:20
You can use vector initializers now, so this can p
zino
2016/08/08 16:36:02
Done.
| |
1058 EXPECT_TRUE(VerifyKeys(expected_keys)); | |
1059 } | |
1060 | |
1061 TEST_P(CacheStorageCacheTestP, KeysWithIgnoreSearchFalse) { | |
1062 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | |
1063 EXPECT_TRUE(Put(body_request_, body_response_)); | |
1064 EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_)); | |
1065 | |
1066 // Default value of ignore_search is false. | |
1067 CacheStorageCacheQueryParams match_params; | |
1068 match_params.ignore_search = false; | |
1069 EXPECT_EQ(match_params.ignore_search, | |
1070 CacheStorageCacheQueryParams().ignore_search); | |
1071 | |
1072 EXPECT_TRUE(Keys(body_request_with_query_, match_params)); | |
1073 EXPECT_EQ(1u, callback_strings_.size()); | |
1074 std::vector<std::string> expected_keys; | |
1075 expected_keys.push_back(body_request_with_query_.url.spec()); | |
jkarlin
2016/08/02 12:06:20
Ditto
zino
2016/08/08 16:36:03
Done.
| |
1076 EXPECT_TRUE(VerifyKeys(expected_keys)); | |
1077 } | |
1078 | |
1041 TEST_P(CacheStorageCacheTestP, DeleteNoBody) { | 1079 TEST_P(CacheStorageCacheTestP, DeleteNoBody) { |
1042 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 1080 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
1043 EXPECT_TRUE(Match(no_body_request_)); | 1081 EXPECT_TRUE(Match(no_body_request_)); |
1044 EXPECT_TRUE(Delete(no_body_request_)); | 1082 EXPECT_TRUE(Delete(no_body_request_)); |
1045 EXPECT_FALSE(Match(no_body_request_)); | 1083 EXPECT_FALSE(Match(no_body_request_)); |
1046 EXPECT_FALSE(Delete(no_body_request_)); | 1084 EXPECT_FALSE(Delete(no_body_request_)); |
1047 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 1085 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
1048 EXPECT_TRUE(Match(no_body_request_)); | 1086 EXPECT_TRUE(Match(no_body_request_)); |
1049 EXPECT_TRUE(Delete(no_body_request_)); | 1087 EXPECT_TRUE(Delete(no_body_request_)); |
1050 } | 1088 } |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1375 EXPECT_EQ(1, sequence_out); | 1413 EXPECT_EQ(1, sequence_out); |
1376 close_loop2->Run(); | 1414 close_loop2->Run(); |
1377 EXPECT_EQ(2, sequence_out); | 1415 EXPECT_EQ(2, sequence_out); |
1378 } | 1416 } |
1379 | 1417 |
1380 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 1418 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
1381 CacheStorageCacheTestP, | 1419 CacheStorageCacheTestP, |
1382 ::testing::Values(false, true)); | 1420 ::testing::Values(false, true)); |
1383 | 1421 |
1384 } // namespace content | 1422 } // namespace content |
OLD | NEW |