Commit 68d2f1a3 authored by Jan Scheffler's avatar Jan Scheffler Committed by Commit Bot

[devtools] Make requestEntries parameters optional

This patch makes the pageSize and skipCount parameters
for the requestEntries protocol method optional. The call
will return all available entries if pageSize is not set
and default to 0 for skipCount.

Bug: chromium:988038
Change-Id: I6257f1beb07be1a87652334df9cd169d5f65724b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875751Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Jan Scheffler <janscheffler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708969}
parent 63eea054
......@@ -1368,9 +1368,9 @@ experimental domain CacheStorage
# ID of cache to get entries from.
CacheId cacheId
# Number of records to skip.
integer skipCount
optional integer skipCount
# Number of records to fetch.
integer pageSize
optional integer pageSize
# If present, only return the entries containing this substring in the path
optional string pathFilter
returns
......
......@@ -198,6 +198,8 @@ CachedResponseType ResponseTypeToString(
struct DataRequestParams {
String cache_name;
int skip_count;
// If set to -1, pagination is disabled and all available requests are
// returned.
int page_size;
String path_filter;
};
......@@ -318,7 +320,8 @@ class ResponsesAccumulator : public RefCounted<ResponsesAccumulator> {
size_t returned_entries_count = responses_.size();
if (params_.skip_count > 0)
responses_.EraseAt(0, params_.skip_count);
if (static_cast<size_t>(params_.page_size) < responses_.size()) {
if (params_.page_size != -1 &&
static_cast<size_t>(params_.page_size) < responses_.size()) {
responses_.EraseAt(params_.page_size,
responses_.size() - params_.page_size);
}
......@@ -547,8 +550,8 @@ void InspectorCacheStorageAgent::requestCacheNames(
void InspectorCacheStorageAgent::requestEntries(
const String& cache_id,
int skip_count,
int page_size,
protocol::Maybe<int> skip_count,
protocol::Maybe<int> page_size,
protocol::Maybe<String> path_filter,
std::unique_ptr<RequestEntriesCallback> callback) {
int64_t trace_id = blink::cache_storage::CreateTraceId();
......@@ -566,8 +569,8 @@ void InspectorCacheStorageAgent::requestEntries(
}
DataRequestParams params;
params.cache_name = cache_name;
params.page_size = page_size;
params.skip_count = skip_count;
params.page_size = page_size.fromMaybe(-1);
params.skip_count = skip_count.fromMaybe(0);
params.path_filter = path_filter.fromMaybe("");
cache_storage->Open(
......
......@@ -31,8 +31,8 @@ class MODULES_EXPORT InspectorCacheStorageAgent final
void requestCacheNames(const String& security_origin,
std::unique_ptr<RequestCacheNamesCallback>) override;
void requestEntries(const String& cache_id,
int skip_count,
int page_size,
protocol::Maybe<int> skip_count,
protocol::Maybe<int> page_size,
protocol::Maybe<String> path_filter,
std::unique_ptr<RequestEntriesCallback>) override;
void deleteCache(const String& cache_id,
......
Tests fetch cached response entries from the protocol.
Expecting skipCount and pageSize to slice the results
Cached requests (-/1):
http://127.0.0.1:8000/inspector-protocol/cachestorage/resources/service-worker.html
Cached requests (1/1):
http://127.0.0.1:8000/inspector-protocol/cachestorage/resources/service-worker.js
Cached requests (-/2):
http://127.0.0.1:8000/inspector-protocol/cachestorage/resources/service-worker.html
http://127.0.0.1:8000/inspector-protocol/cachestorage/resources/service-worker.js
Expecting skipCount to default to 0
Cached requests (-/1):
http://127.0.0.1:8000/inspector-protocol/cachestorage/resources/service-worker.html
Expecting pageSize to default to all
Cached requests (-/-):
http://127.0.0.1:8000/inspector-protocol/cachestorage/resources/service-worker.html
http://127.0.0.1:8000/inspector-protocol/cachestorage/resources/service-worker.js
(async function(testRunner) {
const {page, session, dp} = await testRunner.startURL(
'resources/service-worker.html',
`Tests fetch cached response entries from the protocol.`);
async function waitForServiceWorkerActivation() {
let versions;
do {
const result = await dp.ServiceWorker.onceWorkerVersionUpdated();
versions = result.params.versions;
} while (!versions.length || versions[0].status !== "activated");
}
async function dumpEntries(skipCount, pageSize) {
const result = await dp.CacheStorage.requestEntries({cacheId, skipCount, pageSize});
const entries = result.result.cacheDataEntries;
entries.sort((a, b) => a.requestURL.localeCompare(b.requestURL));
testRunner.log(`Cached requests (${skipCount || '-'}/${pageSize || '-'}): `);
for (let entry of entries)
testRunner.log(' ' + entry.requestURL);
testRunner.log('');
}
const swActivatedPromise = waitForServiceWorkerActivation();
await dp.Runtime.enable();
await dp.ServiceWorker.enable();
await swActivatedPromise;
const {result} = await dp.CacheStorage.requestCacheNames({securityOrigin: "http://127.0.0.1:8000"});
const cacheId = result.caches[0].cacheId;
testRunner.log(`Expecting skipCount and pageSize to slice the results`);
await dumpEntries(0, 1);
await dumpEntries(1, 1);
await dumpEntries(0, 2);
testRunner.log(`Expecting skipCount to default to 0`);
await dumpEntries(undefined, 1);
testRunner.log(`Expecting pageSize to default to all`);
await dumpEntries(0, undefined)
testRunner.completeTest()
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment