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

Unified Diff: third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/resources/postmessage-msgport-to-client-worker.js

Issue 2415873002: Import w3c tests for the service workers (Closed)
Patch Set: Rebase Created 4 years, 2 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/imported/wpt/service-workers/service-worker/resources/postmessage-msgport-to-client-worker.js
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/resources/postmessage-msgport-to-client-worker.js b/third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/resources/postmessage-msgport-to-client-worker.js
new file mode 100644
index 0000000000000000000000000000000000000000..3475321f4a6813e808bdc969d86240b62cafd12d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/resources/postmessage-msgport-to-client-worker.js
@@ -0,0 +1,20 @@
+self.onmessage = function(e) {
+ self.clients.matchAll().then(function(clients) {
+ clients.forEach(function(client) {
+ var messageChannel = new MessageChannel();
+ messageChannel.port1.onmessage =
+ onMessageViaMessagePort.bind(null, client);
+ client.postMessage({port: messageChannel.port2},
+ [messageChannel.port2]);
+ });
+ });
+};
+
+function onMessageViaMessagePort(client, e) {
+ var message = e.data;
+ if ('value' in message) {
+ client.postMessage({ack: 'Acking value: ' + message.value});
+ } else if ('done' in message) {
+ client.postMessage({done: true});
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698