Index: LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js |
diff --git a/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js b/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0bb2e7403294617939140fd88a639912024a901e |
--- /dev/null |
+++ b/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js |
@@ -0,0 +1,45 @@ |
+// Allows the controlling document to instrument Web Notification behavior |
+// within a Service Worker by sending commands. |
+var messagePort = null; |
+ |
+addEventListener('message', function(workerEvent) { |
+ messagePort = workerEvent.data; |
+ |
+ // Listen to incoming commands on the message port. |
+ messagePort.onmessage = function(event) { |
+ if (typeof event.data != 'object' || !event.data.command) |
+ return; |
+ |
+ switch (event.data.command) { |
+ case 'permission': |
+ messagePort.postMessage({ command: 'permission', value: Notification.permission }); |
+ break; |
+ |
+ case 'show': |
+ registration.showNotification(event.data.title, event.data.options).then(function () { |
+ messagePort.postMessage({ command: 'show', success: true }); |
+ }, function (error) { |
+ messagePort.postMessage({ command: 'show', success: false, message: error.message }); |
+ }); |
+ break; |
+ |
+ default: |
+ messagePort.postMessage({ command: 'error', message: 'Invalid command: ' + event.data.command }); |
+ break; |
+ } |
+ }; |
+ |
+ // Notify the controller that the worker is now available. |
+ messagePort.postMessage('ready'); |
+}); |
+ |
+addEventListener('notificationclick', function(event) { |
+ messagePort.postMessage({ command: 'click', notification: { |
+ title: event.notification.title |
+ }}); |
+ |
+ // Notifications containing "ACTION:CLOSE" in their message will be closed |
+ // immediately by the Service Worker. |
+ if (event.notification.body.indexOf('ACTION:CLOSE') !== false) |
Michael van Ouwerkerk
2015/01/26 16:52:37
The return value of indexOf is an int, did you mea
Peter Beverloo
2015/01/27 11:16:56
Done.
|
+ event.notification.close(); |
+}); |