Commit 3dc09a0d authored by Harley Li's avatar Harley Li Committed by Commit Bot

[DevTools] Application>Clear Site Data: stop service worker when unregistering it

We should stop the service worker before unregistering it.

Originally, clicking "Clear site data" will unregister the service worker. In
Application>Service Workers, the service worker's tab title is marked as
"deleted", but its "status" says it's still running.

Bug: 894783
Change-Id: Ib1550cfab8274a27495bb795501f54e9a19f6a36
Reviewed-on: https://chromium-review.googlesource.com/c/1480725Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Haihong Li (Harley) <hhli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635263}
parent 9cdf4320
......@@ -183,6 +183,20 @@ Resources.ClearStorageView = class extends UI.ThrottledWidget {
appcacheModel.reset();
}
if (set.has(Protocol.Storage.StorageType.Service_workers) || hasAll) {
for (const serviceWorkerManager of SDK.targetManager.models(SDK.ServiceWorkerManager)) {
const securityOriginManager = serviceWorkerManager.target().model(SDK.SecurityOriginManager);
for (const registration of serviceWorkerManager.registrations().values()) {
if (!securityOriginManager.securityOrigins().includes(registration.securityOrigin))
continue;
const activeVersion = registration.versionsByMode().get(SDK.ServiceWorkerVersion.Modes.Active);
if (!activeVersion)
continue;
serviceWorkerManager.stopWorker(activeVersion.id);
}
}
}
this._clearButton.disabled = true;
const label = this._clearButton.textContent;
this._clearButton.textContent = Common.UIString('Clearing...');
......
......@@ -2,6 +2,8 @@ Tests quota reporting.
Tree element found: true
Clear storage view is visible: true
Running: Clear all data
-- B used out of -- storage quota
Usage breakdown:
......@@ -9,4 +11,10 @@ Running: Now with data
-- KB used out of -- storage quota
Usage breakdown:
IndexedDB: --.- KB
Service Workers: --.- B
Running: Clear all data, again
service worker is stopping
-- B used out of -- storage quota
Usage breakdown:
......@@ -13,7 +13,7 @@
var updateListener = null;
async function writeArray() {
async function writeToIndexdDB() {
var array = [];
for (var i = 0; i < 20000; i++)
array.push(i % 10);
......@@ -51,13 +51,23 @@
typeUsage = children[j].textContent + typeUsage;
if (children[j].classList.contains('usage-breakdown-legend-value')) {
// Clean usage value because it's platform-dependent.
var cleanedValue = children[j].textContent.replace(/\d+.\d\sKB/, '--.- KB');
var cleanedValue = children[j].textContent.replace(/\d+(.\d+)?\sKB/, '--.- KB')
.replace(/\d+(.\d+)?\sB/, '--.- B');
typeUsage = typeUsage + cleanedValue;
}
}
TestRunner.addResult(typeUsage);
}
}
function isServiceWorkerStopping(registration) {
const version = registration.versionsByMode().get(SDK.ServiceWorkerVersion.Modes.Redundant);
if (!version)
return null;
const status = version ? version.runningStatus : null;
return status === 'stopping';
}
UI.viewManager.showView('resources');
var parent = UI.panels.resources._sidebar._applicationTreeElement;
......@@ -69,13 +79,33 @@
var clearStorageView = UI.panels.resources.visibleView;
TestRunner.addResult('Clear storage view is visible: ' + (clearStorageView instanceof Resources.ClearStorageView));
TestRunner.markStep('Clear all data');
clearStorageView._clearButton.click();
await dumpWhenMatches(clearStorageView, usage => usage === 0);
TestRunner.markStep('Now with data');
await writeArray();
await writeToIndexdDB();
var scriptURL = 'http://127.0.0.1:8000/devtools/service-workers/resources/service-worker-empty.js';
var scope = 'http://127.0.0.1:8000/devtools/service-workers/resources/scope/';
await ApplicationTestRunner.registerServiceWorker(scriptURL, scope);
await dumpWhenMatches(clearStorageView, usage => usage > 20000);
TestRunner.markStep('Clear all data, again');
for (const serviceWorkerManager of SDK.targetManager.models(SDK.ServiceWorkerManager)) {
serviceWorkerManager.addEventListener(
SDK.ServiceWorkerManager.Events.RegistrationUpdated, (event) => {
if (isServiceWorkerStopping(event.data))
TestRunner.addResult('service worker is stopping');
}, this);
}
clearStorageView._clearButton.click();
await dumpWhenMatches(clearStorageView, usage => usage === 0);
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