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

Unified Diff: content/browser/cache_storage/cache_storage_cache_unittest.cc

Issue 1578363009: CacheStorage: Add ignoreSearch option to cache.matchAll(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/cache_storage/cache_storage_cache_unittest.cc
diff --git a/content/browser/cache_storage/cache_storage_cache_unittest.cc b/content/browser/cache_storage/cache_storage_cache_unittest.cc
index e4b94edcfa50587930426e6f1086c77e9b9ab521..363281adda339882a77fb5d17e982fb562435e7f 100644
--- a/content/browser/cache_storage/cache_storage_cache_unittest.cc
+++ b/content/browser/cache_storage/cache_storage_cache_unittest.cc
@@ -306,6 +306,9 @@ class CacheStorageCacheTest : public testing::Test {
body_request_ =
ServiceWorkerFetchRequest(GURL("http://example.com/body.html"), "GET",
headers, Referrer(), false);
+ body_request_with_query_ = ServiceWorkerFetchRequest(
+ GURL("http://example.com/body.html?query=test"), "GET", headers,
+ Referrer(), false);
no_body_request_ =
ServiceWorkerFetchRequest(GURL("http://example.com/no_body.html"),
"GET", headers, Referrer(), false);
@@ -327,6 +330,12 @@ class CacheStorageCacheTest : public testing::Test {
blob_handle_->uuid(), expected_blob_data_.size(), GURL(),
blink::WebServiceWorkerResponseErrorUnknown);
+ body_response_with_query_ = ServiceWorkerResponse(
+ GURL("http://example.com/body.html?query=test"), 200, "OK",
+ blink::WebServiceWorkerResponseTypeDefault, headers,
+ blob_handle_->uuid(), expected_blob_data_.size(), GURL(),
+ blink::WebServiceWorkerResponseErrorUnknown);
+
no_body_response_ = ServiceWorkerResponse(
GURL("http://example.com/no_body.html"), 200, "OK",
blink::WebServiceWorkerResponseTypeDefault, headers, "", 0, GURL(),
@@ -379,16 +388,26 @@ class CacheStorageCacheTest : public testing::Test {
return callback_error_ == CACHE_STORAGE_OK;
}
- bool MatchAll(scoped_ptr<CacheStorageCache::Responses>* responses,
+ bool MatchAll(const ServiceWorkerFetchRequest& request,
+ const CacheStorageCacheQueryParams& match_params,
+ scoped_ptr<CacheStorageCache::Responses>* responses,
scoped_ptr<CacheStorageCache::BlobDataHandles>* body_handles) {
base::RunLoop loop;
- cache_->MatchAll(base::Bind(
- &CacheStorageCacheTest::ResponsesAndErrorCallback,
- base::Unretained(this), loop.QuitClosure(), responses, body_handles));
+ cache_->MatchAll(
+ CopyFetchRequest(request), match_params,
+ base::Bind(&CacheStorageCacheTest::ResponsesAndErrorCallback,
+ base::Unretained(this), loop.QuitClosure(), responses,
+ body_handles));
loop.Run();
return callback_error_ == CACHE_STORAGE_OK;
}
+ bool MatchAll(scoped_ptr<CacheStorageCache::Responses>* responses,
+ scoped_ptr<CacheStorageCache::BlobDataHandles>* body_handles) {
+ return MatchAll(ServiceWorkerFetchRequest(), CacheStorageCacheQueryParams(),
+ responses, body_handles);
+ }
+
bool Delete(const ServiceWorkerFetchRequest& request) {
CacheStorageBatchOperation operation;
operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE;
@@ -548,6 +567,8 @@ class CacheStorageCacheTest : public testing::Test {
ServiceWorkerFetchRequest body_request_;
ServiceWorkerResponse body_response_;
+ ServiceWorkerFetchRequest body_request_with_query_;
+ ServiceWorkerResponse body_response_with_query_;
ServiceWorkerFetchRequest no_body_request_;
ServiceWorkerResponse no_body_response_;
scoped_ptr<storage::BlobDataHandle> blob_handle_;
@@ -769,6 +790,34 @@ TEST_P(CacheStorageCacheTestP, MatchAll_TwoResponsesThenOne) {
EXPECT_TRUE(body_handles->empty());
}
+TEST_P(CacheStorageCacheTestP, MatchAll_IgnoreSearch) {
+ EXPECT_TRUE(Put(body_request_, body_response_));
+ EXPECT_TRUE(Put(body_request_with_query_, body_response_with_query_));
+ EXPECT_TRUE(Put(no_body_request_, no_body_response_));
+
+ scoped_ptr<CacheStorageCache::Responses> responses;
+ scoped_ptr<CacheStorageCache::BlobDataHandles> body_handles;
+ CacheStorageCacheQueryParams match_params;
+ match_params.ignore_search = true;
+ EXPECT_TRUE(MatchAll(body_request_, match_params, &responses, &body_handles));
+
+ ASSERT_EQ(2u, responses->size());
+ ASSERT_EQ(2u, body_handles->size());
+
+ // Order of returned responses is not guaranteed.
+ std::set<std::string> matched_set;
+ for (const ServiceWorkerResponse& response : *responses) {
+ if (response.url.spec() == "http://example.com/body.html?query=test") {
+ EXPECT_TRUE(ResponseMetadataEqual(body_response_with_query_, response));
+ matched_set.insert(response.url.spec());
+ } else if (response.url.spec() == "http://example.com/body.html") {
+ EXPECT_TRUE(ResponseMetadataEqual(body_response_, response));
+ matched_set.insert(response.url.spec());
+ }
+ }
+ EXPECT_EQ(2u, matched_set.size());
+}
+
TEST_P(CacheStorageCacheTestP, Vary) {
body_request_.headers["vary_foo"] = "foo";
body_response_.headers["vary"] = "vary_foo";
« 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