| Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/resources/usecounter-worker.js
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/resources/usecounter-worker.js b/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/resources/usecounter-worker.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..44a340023be34de979a2c2bf6caa52ea9ee0daeb
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/resources/usecounter-worker.js
|
| @@ -0,0 +1,30 @@
|
| +// This should be accessed only in the install event or the message event. When
|
| +// this is false, it implies that this service worker is restarted after the
|
| +// install event.
|
| +let did_run_install_event = false;
|
| +
|
| +self.addEventListener('install', e => {
|
| + var scope = new URL(self.registration.scope);
|
| + if (scope.searchParams.get('type') == 'features-during-install') {
|
| + internals.countFeature(scope.searchParams.get('feature'));
|
| + internals.countDeprecation(scope.searchParams.get('deprecated'));
|
| + } else if (scope.searchParams.get('type') == 'skip-waiting') {
|
| + e.waitUntil(self.skipWaiting());
|
| + }
|
| + did_run_install_event = true;
|
| +});
|
| +
|
| +onmessage = e => {
|
| + if (e.data.type == 'COUNT_FEATURE') {
|
| + internals.countFeature(e.data.feature);
|
| + } else if (e.data.type == 'COUNT_DEPRECATION') {
|
| + internals.countDeprecation(e.data.feature);
|
| + } else if (e.data.type == 'CLAIM') {
|
| + let promise = self.clients.claim()
|
| + .then(() => e.source.postMessage(
|
| + {type: 'CLAIMED', restarted: !did_run_install_event}));
|
| + e.waitUntil(promise);
|
| + } else if (e.data.type == 'PING') {
|
| + e.source.postMessage({type: 'PONG'});
|
| + }
|
| +};
|
|
|