1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // The "onpush" event currently understands two values as message payload
6 // data coming from the test. Any other input is passed through to the
9 // "shownotification" - Display a Web Notification with event.waitUntil().
10 // "shownotification-without-waituntil"
11 // - Display a Web Notification without using event.waitUntil().
12 this.onpush = function(event
) {
13 var data
= event
.data
.text();
14 if (!data
.startsWith('shownotification')) {
15 sendMessageToClients('push', data
);
19 var result
= registration
.showNotification('Push test title', {
20 body
: 'Push test body',
24 if (data
== 'shownotification-without-waituntil') {
25 sendMessageToClients('push', 'immediate:' + data
);
29 event
.waitUntil(result
.then(function() {
30 sendMessageToClients('push', data
);
32 sendMessageToClients('push', String(ex
));
36 function sendMessageToClients(type
, data
) {
37 var message
= JSON
.stringify({
41 clients
.matchAll().then(function(clients
) {
42 clients
.forEach(function(client
) {
43 client
.postMessage(message
);