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

Side by Side Diff: chrome/test/data/push_messaging/push_messaging_test_worker_android.js

Issue 1485743002: Push API: test that default notification is shown on Android when needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@PushMessagingInstrumentationTest
Patch Set: Tweak for build error. Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The MessagePort to communicate with the client.
5 var messagePort = null; 6 var messagePort = null;
6 7
8 // If true this service worker will show a notification when a push message is
9 // received.
10 var notifyOnPush = true;
11
12 // The number of push messages received.
13 var pushCounter = 0;
14
15 // The number of notifications shown.
16 var notificationCounter = 0;
17
7 onmessage = event => { 18 onmessage = event => {
8 messagePort = event.data; 19 if (event.data instanceof MessagePort) {
9 messagePort.postMessage('ready'); 20 messagePort = event.data;
21 messagePort.postMessage('ready');
22 return;
23 }
24
25 var message = JSON.parse(event.data);
26 if (message.type == 'setNotifyOnPush') {
27 notifyOnPush = message.data;
28 sendToTest('setNotifyOnPush ok');
29 return;
30 }
31
32 sendToTest('Unknown message type.');
10 }; 33 };
11 34
12 onpush = event => 35 onpush = event => {
13 event.waitUntil(registration.showNotification('push notification')); 36 pushCounter++;
37 if (notifyOnPush) {
38 notificationCounter++;
39 event.waitUntil(registration.showNotification(
40 'push notification ' + notificationCounter));
41 }
42 sendToTest('push ' + pushCounter + ' ok');
johnme 2015/12/08 17:12:31 Nit: when notifyOnPush is true, consider waiting f
Michael van Ouwerkerk 2015/12/09 15:02:52 Obsolete as this no longer relies on setting the t
43 };
44
45 function sendToTest(message) {
johnme 2015/12/08 17:12:31 Nit: maybe put this above onmessage?
Michael van Ouwerkerk 2015/12/09 15:02:52 Done.
46 messagePort.postMessage(JSON.stringify({
47 'type': 'sendToTest',
48 'data': message
49 }));
50 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698