OLD | NEW |
1 importScripts('/resources/testharness-helpers.js'); | 1 importScripts('/resources/testharness-helpers.js'); |
2 | 2 |
| 3 // For copying Notification.data. Currently a deep copy algorithm is used. Note |
| 4 // that the robustness of this function (and also |assert_object_equals| in |
| 5 // testharness.js) affects the types of possible testing can be done. |
| 6 // TODO(peter): change this to a structured clone algorithm. |
| 7 function cloneObject(src) { |
| 8 if (typeof src != 'object' || src === null) |
| 9 return src; |
| 10 var dst = Array.isArray(src) ? [] : {}; |
| 11 for (var property in src) { |
| 12 if (src.hasOwnProperty(property)) |
| 13 dst[property] = cloneObject(src[property]); |
| 14 } |
| 15 return dst; |
| 16 } |
| 17 |
3 // Copies the serializable attributes of |notification|. | 18 // Copies the serializable attributes of |notification|. |
4 function cloneNotification(notification) { | 19 function cloneNotification(notification) { |
5 return JSON.parse(stringifyDOMObject(notification)); | 20 var copiedNotification = JSON.parse(stringifyDOMObject(notification)); |
| 21 copiedNotification.data = cloneObject(notification.data); |
| 22 return copiedNotification; |
6 } | 23 } |
7 | 24 |
8 // Allows a document to exercise the Notifications API within a service worker b
y sending commands. | 25 // Allows a document to exercise the Notifications API within a service worker b
y sending commands. |
9 var messagePort = null; | 26 var messagePort = null; |
10 | 27 |
11 addEventListener('message', function(workerEvent) { | 28 addEventListener('message', function(workerEvent) { |
12 messagePort = workerEvent.data; | 29 messagePort = workerEvent.data; |
13 | 30 |
14 // Listen to incoming commands on the message port. | 31 // Listen to incoming commands on the message port. |
15 messagePort.onmessage = function(event) { | 32 messagePort.onmessage = function(event) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 90 |
74 // Notifications containing "ACTION:OPENWINDOW" in their message will attemp
t | 91 // Notifications containing "ACTION:OPENWINDOW" in their message will attemp
t |
75 // to open a new window for an example URL. | 92 // to open a new window for an example URL. |
76 if (event.notification.body.indexOf('ACTION:OPENWINDOW') != -1) | 93 if (event.notification.body.indexOf('ACTION:OPENWINDOW') != -1) |
77 event.waitUntil(clients.openWindow('https://example.com/')); | 94 event.waitUntil(clients.openWindow('https://example.com/')); |
78 | 95 |
79 messagePort.postMessage({ command: 'click', | 96 messagePort.postMessage({ command: 'click', |
80 notification: notificationCopy, | 97 notification: notificationCopy, |
81 action: event.action }); | 98 action: event.action }); |
82 }); | 99 }); |
OLD | NEW |