Chromium Code Reviews| Index: chrome/test/data/push_messaging/push_messaging_test_worker_android.js |
| diff --git a/chrome/test/data/push_messaging/push_messaging_test_worker_android.js b/chrome/test/data/push_messaging/push_messaging_test_worker_android.js |
| index 92c8e5e8e8de791e235ceeb6d24bfa8aa952a868..442a20afca8d184c21b1645b010dad05250be657 100644 |
| --- a/chrome/test/data/push_messaging/push_messaging_test_worker_android.js |
| +++ b/chrome/test/data/push_messaging/push_messaging_test_worker_android.js |
| @@ -2,12 +2,45 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +// The MessagePort to communicate with the client. |
| var messagePort = null; |
| +// If true this service worker will show a notification when a push message is |
| +// received. |
| +var notifyOnPush = true; |
| + |
| +// The number of notifications shown. |
| +var notificationCounter = 0; |
| + |
| +// Sends a message to the test, via the page. |
| +function sendToTest(message) { |
| + messagePort.postMessage(JSON.stringify({ |
| + 'type': 'sendToTest', |
| + 'data': message |
| + })); |
| +} |
| + |
| onmessage = event => { |
|
Bernhard Bauer
2015/12/11 12:28:42
Nit: Use window.onmessage to make the scope of the
Michael van Ouwerkerk
2015/12/11 16:05:56
This is service worker code, there is no window ob
Bernhard Bauer
2015/12/11 16:35:57
Oh, right. See, all the more reason to make the sc
Michael van Ouwerkerk
2015/12/11 17:57:02
Acknowledged.
|
| - messagePort = event.data; |
| - messagePort.postMessage('ready'); |
| + if (event.data instanceof MessagePort) { |
| + messagePort = event.data; |
| + messagePort.postMessage('ready'); |
| + return; |
| + } |
| + |
| + var message = JSON.parse(event.data); |
| + if (message.type == 'setNotifyOnPush') { |
| + notifyOnPush = message.data; |
| + sendToTest('setNotifyOnPush ' + message.data + ' ok'); |
| + return; |
| + } |
| + |
| + sendToTest('Unknown message type.'); |
| }; |
| -onpush = event => |
| - event.waitUntil(registration.showNotification('push notification')); |
| +onpush = event => { |
| + if (notifyOnPush) { |
| + notificationCounter++; |
| + event.waitUntil(registration.showNotification( |
| + 'push notification ' + notificationCounter)); |
| + } |
| +}; |