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

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: Address bauerb's comments. 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
« no previous file with comments | « chrome/test/data/push_messaging/push_messaging_test_android.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
7 onmessage = event => { 8 // If true this service worker will show a notification when a push message is
8 messagePort = event.data; 9 // received.
9 messagePort.postMessage('ready'); 10 var notifyOnPush = true;
11
12 // The number of notifications shown.
13 var notificationCounter = 0;
14
15 // Sends a message to the test, via the page.
16 function sendToTest(message) {
17 messagePort.postMessage(JSON.stringify({
18 'type': 'sendToTest',
19 'data': message
20 }));
21 }
22
23 self.onmessage = event => {
24 if (event.data instanceof MessagePort) {
25 messagePort = event.data;
26 messagePort.postMessage('ready');
27 return;
28 }
29
30 var message = JSON.parse(event.data);
31 if (message.type == 'setNotifyOnPush') {
32 notifyOnPush = message.data;
33 sendToTest('setNotifyOnPush ' + message.data + ' ok');
34 return;
35 }
36
37 sendToTest('Unknown message type.');
10 }; 38 };
11 39
12 onpush = event => 40 self.onpush = event => {
13 event.waitUntil(registration.showNotification('push notification')); 41 if (notifyOnPush) {
42 notificationCounter++;
43 event.waitUntil(registration.showNotification(
44 'push notification ' + notificationCounter));
45 }
46 };
OLDNEW
« no previous file with comments | « chrome/test/data/push_messaging/push_messaging_test_android.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698