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

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

Issue 1719103002: CacheStorage: Expand cache.keys() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 4 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 9
10 #include <memory> 10 #include <memory>
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 body_request_.url.spec(), body_request_with_query_.url.spec()};
1057 EXPECT_TRUE(VerifyKeys(expected_keys));
1058 }
1059
1060 TEST_P(CacheStorageCacheTestP, KeysWithIgnoreSearchFalse) {
1061 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
1062 EXPECT_TRUE(Put(body_request_, body_response_));
1063 EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_));
1064
1065 // Default value of ignore_search is false.
1066 CacheStorageCacheQueryParams match_params;
1067 match_params.ignore_search = false;
1068 EXPECT_EQ(match_params.ignore_search,
1069 CacheStorageCacheQueryParams().ignore_search);
1070
1071 EXPECT_TRUE(Keys(body_request_with_query_, match_params));
1072 EXPECT_EQ(1u, callback_strings_.size());
1073 std::vector<std::string> expected_keys = {
1074 body_request_with_query_.url.spec()};
1075 EXPECT_TRUE(VerifyKeys(expected_keys));
1076 }
1077
1041 TEST_P(CacheStorageCacheTestP, DeleteNoBody) { 1078 TEST_P(CacheStorageCacheTestP, DeleteNoBody) {
1042 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); 1079 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
1043 EXPECT_TRUE(Match(no_body_request_)); 1080 EXPECT_TRUE(Match(no_body_request_));
1044 EXPECT_TRUE(Delete(no_body_request_)); 1081 EXPECT_TRUE(Delete(no_body_request_));
1045 EXPECT_FALSE(Match(no_body_request_)); 1082 EXPECT_FALSE(Match(no_body_request_));
1046 EXPECT_FALSE(Delete(no_body_request_)); 1083 EXPECT_FALSE(Delete(no_body_request_));
1047 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); 1084 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
1048 EXPECT_TRUE(Match(no_body_request_)); 1085 EXPECT_TRUE(Match(no_body_request_));
1049 EXPECT_TRUE(Delete(no_body_request_)); 1086 EXPECT_TRUE(Delete(no_body_request_));
1050 } 1087 }
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 EXPECT_EQ(1, sequence_out); 1412 EXPECT_EQ(1, sequence_out);
1376 close_loop2->Run(); 1413 close_loop2->Run();
1377 EXPECT_EQ(2, sequence_out); 1414 EXPECT_EQ(2, sequence_out);
1378 } 1415 }
1379 1416
1380 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 1417 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
1381 CacheStorageCacheTestP, 1418 CacheStorageCacheTestP,
1382 ::testing::Values(false, true)); 1419 ::testing::Values(false, true));
1383 1420
1384 } // namespace content 1421 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.cc ('k') | content/browser/cache_storage/cache_storage_dispatcher_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698