Chromium Code Reviews| 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 |
| index d77c1408235f5b5e45bd96b2d87510e98ea2fdff..4c540f77a592bbe8f7d57a20637c2bde811c7678 100644 |
| --- a/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js |
| +++ b/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js |
| @@ -1,5 +1,10 @@ |
| importScripts('/resources/testharness-helpers.js'); |
| +// Copies the serializable attributes of |notification|. |
| +function serializeNotification(notification) { |
|
johnme
2015/04/09 10:29:50
Optional nit: cloneNotification?
Peter Beverloo
2015/04/17 13:03:17
It doesn't clone the notification (cloning would i
johnme
2015/04/17 16:29:25
Yeah, but after serializing it to a string, it the
|
| + return JSON.parse(stringifyDOMObject(notification)); |
| +} |
| + |
| // Allows a document to exercise the Notifications API within a service worker by sending commands. |
| var messagePort = null; |
| @@ -28,6 +33,26 @@ addEventListener('message', function(workerEvent) { |
| }); |
| break; |
| + case 'get': |
| + var filter = {}; |
| + if (typeof (event.data.filter) !== 'undefined') |
| + filter = event.data.filter; |
| + |
| + registration.getNotifications(filter).then(function(notifications) { |
| + var serializedNotifications = []; |
| + for (var notification of notifications) |
| + serializedNotifications.push(serializeNotification(notification)); |
| + |
| + messagePort.postMessage({ command: event.data.command, |
| + success: true, |
| + notifications: serializedNotifications }); |
| + }, function(error) { |
| + messagePort.postMessage({ command: event.data.command, |
| + success: false, |
| + message: error.message }); |
| + }); |
| + break; |
| + |
| default: |
| messagePort.postMessage({ command: 'error', message: 'Invalid command: ' + event.data.command }); |
| break; |
| @@ -39,8 +64,7 @@ addEventListener('message', function(workerEvent) { |
| }); |
| addEventListener('notificationclick', function(event) { |
| - // Copies the serializable attributes of the Notification instance on |event|. |
| - var notificationCopy = JSON.parse(stringifyDOMObject(event.notification)); |
| + var notificationCopy = serializeNotification(event.notification); |
| // Notifications containing "ACTION:CLOSE" in their message will be closed |
| // immediately by the Service Worker. |