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

Unified 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 side-by-side diff with in-line comments
Download patch
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..89151b7f916a690a729ca29d228bf2e51d1eede4 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,49 @@
// 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 push messages received.
+var pushCounter = 0;
+
+// The number of notifications shown.
+var notificationCounter = 0;
+
onmessage = event => {
- 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 ok');
+ return;
+ }
+
+ sendToTest('Unknown message type.');
+};
+
+onpush = event => {
+ pushCounter++;
+ if (notifyOnPush) {
+ notificationCounter++;
+ event.waitUntil(registration.showNotification(
+ 'push notification ' + notificationCounter));
+ }
+ 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
};
-onpush = event =>
- event.waitUntil(registration.showNotification('push notification'));
+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.
+ messagePort.postMessage(JSON.stringify({
+ 'type': 'sendToTest',
+ 'data': message
+ }));
+}

Powered by Google App Engine
This is Rietveld 408576698