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..34bee090f502cf9fe7cccbed8ad5cdef792d1d5d |
--- /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 run_install_event = false; |
falken
2017/02/08 05:01:54
nit: maybe did_install or did_run_install_event is
nhiroki
2017/02/09 05:11:32
Done.
|
+ |
+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()); |
+ } |
+ run_install_event = true; |
+}); |
+ |
+onmessage = e => { |
+ if (e.data.type == 'COUNT_FEATURE') { |
+ internals.countFeature(e.data.feature); |
+ e.source.postMessage({type: 'COUNTED'}); |
+ } else if (e.data.type == 'COUNT_DEPRECATION') { |
+ internals.countDeprecation(e.data.feature); |
+ e.source.postMessage({type: 'COUNTED'}); |
+ } else if (e.data.type == 'CLAIM') { |
+ let promise = self.clients.claim() |
+ .then(() => e.source.postMessage( |
+ {type: 'CLAIMED', restarted: !run_install_event})); |
+ e.waitUntil(promise); |
+ } |
+}; |