mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 13:44:39 +08:00
With this patch users are able to search for cache entries which contain a given URL path in Application panel's cache storage table. Only entries that have the matching URL paths will be displayed in the table, which supports pagination if there are too many entries returned. Bug: 884194 Change-Id: If285cc43859e82f5e59b80b1b761e9836aa5f510 Reviewed-on: https://chromium-review.googlesource.com/c/1345421 Reviewed-by: Dmitry Gozman <dgozman@chromium.org> Commit-Queue: Haihong Li (Harley) <hhli@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#613204} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 3c68e3a7bc37f6eeb338e7768735087ae469a329
202 lines
6.9 KiB
JavaScript
202 lines
6.9 KiB
JavaScript
// Copyright 2017 The Chromium Authors. All
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
/**
|
|
* @fileoverview using private properties isn't a Closure violation in tests.
|
|
* @suppress {accessControls}
|
|
*/
|
|
|
|
ApplicationTestRunner.dumpCacheTree = async function(pathFilter) {
|
|
UI.panels.resources._sidebar.cacheStorageListTreeElement.expand();
|
|
const promise = TestRunner.addSnifferPromise(SDK.ServiceWorkerCacheModel.prototype, '_updateCacheNames');
|
|
UI.panels.resources._sidebar.cacheStorageListTreeElement._refreshCaches();
|
|
await promise;
|
|
await ApplicationTestRunner.dumpCacheTreeNoRefresh(pathFilter);
|
|
};
|
|
|
|
ApplicationTestRunner.dumpCacheTreeNoRefresh = async function(pathFilter) {
|
|
function _dumpDataGrid(dataGrid, indentSpaces) {
|
|
for (const node of dataGrid.rootNode().children) {
|
|
const children = Array.from(node.element().children).filter(function(element) {
|
|
return !element.classList.contains('responseTime-column');
|
|
});
|
|
|
|
const entries = Array.from(children, td => td.textContent).filter(text => text);
|
|
TestRunner.addResult(' '.repeat(8) + entries.join(', '));
|
|
}
|
|
}
|
|
|
|
UI.panels.resources._sidebar.cacheStorageListTreeElement.expand();
|
|
|
|
if (!pathFilter)
|
|
TestRunner.addResult('Dumping CacheStorage tree:');
|
|
else
|
|
TestRunner.addResult('Dumping CacheStorage tree with URL path filter string "' + pathFilter + '"');
|
|
|
|
const cachesTreeElement = UI.panels.resources._sidebar.cacheStorageListTreeElement;
|
|
|
|
if (!cachesTreeElement.childCount()) {
|
|
TestRunner.addResult(' (empty)');
|
|
return;
|
|
}
|
|
|
|
for (let i = 0; i < cachesTreeElement.childCount(); ++i) {
|
|
const cacheTreeElement = cachesTreeElement.childAt(i);
|
|
TestRunner.addResult(' cache: ' + cacheTreeElement.title);
|
|
let view = cacheTreeElement._view;
|
|
|
|
if (!view)
|
|
cacheTreeElement.onselect(false);
|
|
view = cacheTreeElement._view;
|
|
await view._updateData(true);
|
|
if (cacheTreeElement._view._entriesForTest.length === 0) {
|
|
TestRunner.addResult(' (cache empty)');
|
|
continue;
|
|
}
|
|
|
|
if (!pathFilter) {
|
|
_dumpDataGrid(view._dataGrid);
|
|
continue;
|
|
}
|
|
|
|
cacheTreeElement._view._entryPathFilter = pathFilter;
|
|
await view._updateData(true);
|
|
if (cacheTreeElement._view._entriesForTest.length === 0) {
|
|
TestRunner.addResult(' (no matching entries)');
|
|
continue;
|
|
}
|
|
|
|
_dumpDataGrid(cacheTreeElement._view._dataGrid);
|
|
}
|
|
};
|
|
|
|
ApplicationTestRunner.deleteCacheFromInspector = async function(cacheName, optionalEntry) {
|
|
UI.panels.resources._sidebar.cacheStorageListTreeElement.expand();
|
|
|
|
if (optionalEntry)
|
|
TestRunner.addResult('Deleting CacheStorage entry ' + optionalEntry + ' in cache ' + cacheName);
|
|
else
|
|
TestRunner.addResult('Deleting CacheStorage cache ' + cacheName);
|
|
|
|
const cachesTreeElement = UI.panels.resources._sidebar.cacheStorageListTreeElement;
|
|
let promise = TestRunner.addSnifferPromise(SDK.ServiceWorkerCacheModel.prototype, '_updateCacheNames');
|
|
UI.panels.resources._sidebar.cacheStorageListTreeElement._refreshCaches();
|
|
await promise;
|
|
|
|
if (!cachesTreeElement.childCount())
|
|
throw 'Error: Could not find CacheStorage cache ' + cacheName;
|
|
|
|
|
|
for (let i = 0; i < cachesTreeElement.childCount(); i++) {
|
|
const cacheTreeElement = cachesTreeElement.childAt(i);
|
|
const title = cacheTreeElement.title;
|
|
const elementCacheName = title.substring(0, title.lastIndexOf(' - '));
|
|
|
|
if (elementCacheName !== cacheName)
|
|
continue;
|
|
|
|
if (!optionalEntry) {
|
|
promise = TestRunner.addSnifferPromise(SDK.ServiceWorkerCacheModel.prototype, '_cacheRemoved');
|
|
cacheTreeElement._clearCache();
|
|
await promise;
|
|
return;
|
|
}
|
|
|
|
promise = TestRunner.addSnifferPromise(Resources.ServiceWorkerCacheView.prototype, '_updateDataCallback');
|
|
let view = cacheTreeElement._view;
|
|
|
|
if (!view)
|
|
cacheTreeElement.onselect(false);
|
|
else
|
|
view._updateData(true);
|
|
|
|
view = cacheTreeElement._view;
|
|
await promise;
|
|
const entry = view._entriesForTest.find(entry => entry.requestURL === optionalEntry);
|
|
|
|
if (!entry)
|
|
throw 'Error: Could not find cache entry to delete: ' + optionalEntry;
|
|
|
|
await view._model.deleteCacheEntry(view._cache, entry.requestURL);
|
|
return;
|
|
}
|
|
|
|
throw 'Error: Could not find CacheStorage cache ' + cacheName;
|
|
};
|
|
|
|
ApplicationTestRunner.waitForCacheRefresh = function(callback) {
|
|
TestRunner.addSniffer(SDK.ServiceWorkerCacheModel.prototype, '_updateCacheNames', callback, false);
|
|
};
|
|
|
|
ApplicationTestRunner.createCache = function(cacheName) {
|
|
return TestRunner.callFunctionInPageAsync('createCache', [cacheName]);
|
|
};
|
|
|
|
ApplicationTestRunner.addCacheEntry = function(cacheName, requestUrl, responseText) {
|
|
return TestRunner.callFunctionInPageAsync('addCacheEntry', [cacheName, requestUrl, responseText]);
|
|
};
|
|
|
|
ApplicationTestRunner.addCacheEntryWithNoCorsRequest = function(cacheName, requestUrl) {
|
|
return TestRunner.callFunctionInPageAsync('addCacheEntryWithNoCorsRequest', [cacheName, requestUrl]);
|
|
};
|
|
|
|
ApplicationTestRunner.deleteCache = function(cacheName) {
|
|
return TestRunner.callFunctionInPageAsync('deleteCache', [cacheName]);
|
|
};
|
|
|
|
ApplicationTestRunner.deleteCacheEntry = function(cacheName, requestUrl) {
|
|
return TestRunner.callFunctionInPageAsync('deleteCacheEntry', [cacheName, requestUrl]);
|
|
};
|
|
|
|
ApplicationTestRunner.clearAllCaches = function() {
|
|
return TestRunner.callFunctionInPageAsync('clearAllCaches');
|
|
};
|
|
|
|
TestRunner.deprecatedInitAsync(`
|
|
function onCacheStorageError(e) {
|
|
console.error('CacheStorage error: ' + e);
|
|
}
|
|
|
|
function createCache(cacheName) {
|
|
return caches.open(cacheName).catch(onCacheStorageError);
|
|
}
|
|
|
|
function addCacheEntry(cacheName, requestUrl, responseText) {
|
|
return caches.open(cacheName).then(function(cache) {
|
|
let request = new Request(requestUrl);
|
|
let myBlob = new Blob();
|
|
|
|
let init = {
|
|
'status': 200,
|
|
'statusText': responseText
|
|
};
|
|
|
|
let response = new Response(myBlob, init);
|
|
return cache.put(request, response);
|
|
}).catch(onCacheStorageError);
|
|
}
|
|
|
|
function addCacheEntryWithNoCorsRequest(cacheName, requestUrl) {
|
|
return caches.open(cacheName).then(async function(cache) {
|
|
let request = new Request(requestUrl, {mode: 'no-cors'});
|
|
return cache.put(request, await fetch(request));
|
|
}).catch(onCacheStorageError);
|
|
}
|
|
|
|
function deleteCache(cacheName) {
|
|
return caches.delete(cacheName).then(function(success) {
|
|
if (!success)
|
|
onCacheStorageError('Could not find cache ' + cacheName);
|
|
}).catch(onCacheStorageError);
|
|
}
|
|
|
|
function deleteCacheEntry(cacheName, requestUrl) {
|
|
return caches.open(cacheName).then(cache => cache.delete(new Request(requestUrl))).catch(onCacheStorageError);
|
|
}
|
|
|
|
function clearAllCaches() {
|
|
return caches.keys().then(keys => Promise.all(keys.map(key => caches.delete(key)))).catch(onCacheStorageError.bind(this, undefined));
|
|
}
|
|
`);
|