Chromium Code Reviews| 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') | |
|
Peter Beverloo
2015/09/01 15:31:44
nit: could change this to the following, which mat
lwchkg
2015/09/01 16:21:09
Sounds good.
| |
| 9 return src; | |
| 10 if (src === null) | |
| 11 return null; | |
| 12 var dst = Array.isArray(src) ? [] : {}; | |
| 13 for (var property in src) { | |
| 14 if (src.hasOwnProperty(property)) { | |
|
Peter Beverloo
2015/09/01 15:31:44
nit: no need for {} (one-statement if clause)
lwchkg
2015/09/01 16:21:09
Acknowledged.
| |
| 15 dst[property] = cloneObject(src[property]); | |
| 16 } | |
| 17 } | |
| 18 return dst; | |
| 19 } | |
| 20 | |
| 3 // Copies the serializable attributes of |notification|. | 21 // Copies the serializable attributes of |notification|. |
| 4 function cloneNotification(notification) { | 22 function cloneNotification(notification) { |
| 5 return JSON.parse(stringifyDOMObject(notification)); | 23 var dst = JSON.parse(stringifyDOMObject(notification)); |
|
Peter Beverloo
2015/09/01 15:31:44
nit: could we name this "copiedNotification"? We p
lwchkg
2015/09/01 16:21:09
Sounds good. Agree that "dst" is not clear enough.
| |
| 24 dst.data = cloneObject(notification.data); | |
| 25 return dst; | |
| 6 } | 26 } |
| 7 | 27 |
| 8 // Allows a document to exercise the Notifications API within a service worker b y sending commands. | 28 // Allows a document to exercise the Notifications API within a service worker b y sending commands. |
| 9 var messagePort = null; | 29 var messagePort = null; |
| 10 | 30 |
| 11 addEventListener('message', function(workerEvent) { | 31 addEventListener('message', function(workerEvent) { |
| 12 messagePort = workerEvent.data; | 32 messagePort = workerEvent.data; |
| 13 | 33 |
| 14 // Listen to incoming commands on the message port. | 34 // Listen to incoming commands on the message port. |
| 15 messagePort.onmessage = function(event) { | 35 messagePort.onmessage = function(event) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 93 |
| 74 // Notifications containing "ACTION:OPENWINDOW" in their message will attemp t | 94 // Notifications containing "ACTION:OPENWINDOW" in their message will attemp t |
| 75 // to open a new window for an example URL. | 95 // to open a new window for an example URL. |
| 76 if (event.notification.body.indexOf('ACTION:OPENWINDOW') != -1) | 96 if (event.notification.body.indexOf('ACTION:OPENWINDOW') != -1) |
| 77 event.waitUntil(clients.openWindow('https://example.com/')); | 97 event.waitUntil(clients.openWindow('https://example.com/')); |
| 78 | 98 |
| 79 messagePort.postMessage({ command: 'click', | 99 messagePort.postMessage({ command: 'click', |
| 80 notification: notificationCopy, | 100 notification: notificationCopy, |
| 81 action: event.action }); | 101 action: event.action }); |
| 82 }); | 102 }); |
| OLD | NEW |