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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/resources/usecounter-worker.js

Issue 2658603003: ServiceWorker: Enable UseCounter for ServiceWorkerGlobalScope (Closed)
Patch Set: int32_t -> uint32_t Created 3 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: 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'});
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698