OLD | NEW |
1 importScripts('/resources/testharness-helpers.js'); | 1 // Deep-copies the attributes of |notification|. Note that the |
2 | 2 // robustness of this function (and also |assert_object_equals| in |
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. | 3 // testharness.js) affects the types of possible testing can be done. |
6 // TODO(peter): change this to a structured clone algorithm. | 4 // TODO(peter): change this to a structured clone algorithm. |
7 function cloneObject(src) { | 5 function cloneNotification(notification) { |
8 if (typeof src != 'object' || src === null) | 6 function deepCopy(src) { |
9 return src; | 7 if (typeof src !== 'object' || src === null) |
10 var dst = Array.isArray(src) ? [] : {}; | 8 return src; |
11 for (var property in src) { | 9 var dst = Array.isArray(src) ? [] : {}; |
12 if (src.hasOwnProperty(property)) | 10 for (var property in src) { |
13 dst[property] = cloneObject(src[property]); | 11 if (typeof src[property] === 'function') |
| 12 continue; |
| 13 dst[property] = deepCopy(src[property]); |
| 14 } |
| 15 return dst; |
14 } | 16 } |
15 return dst; | |
16 } | |
17 | 17 |
18 // Copies the serializable attributes of |notification|. | 18 return deepCopy(notification); |
19 function cloneNotification(notification) { | |
20 var copiedNotification = JSON.parse(stringifyDOMObject(notification)); | |
21 copiedNotification.data = cloneObject(notification.data); | |
22 return copiedNotification; | |
23 } | 19 } |
24 | 20 |
25 // Allows a document to exercise the Notifications API within a service worker b
y sending commands. | 21 // Allows a document to exercise the Notifications API within a service worker b
y sending commands. |
26 var messagePort = null; | 22 var messagePort = null; |
27 | 23 |
28 // All urls of requests that have been routed through the fetch event handler. | 24 // All urls of requests that have been routed through the fetch event handler. |
29 var fetchHistory = []; | 25 var fetchHistory = []; |
30 | 26 |
31 addEventListener('install', event => { | 27 addEventListener('install', event => { |
32 event.waitUntil(skipWaiting()); | 28 event.waitUntil(skipWaiting()); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 addEventListener('notificationclose', event => { | 118 addEventListener('notificationclose', event => { |
123 var notificationCopy = cloneNotification(event.notification); | 119 var notificationCopy = cloneNotification(event.notification); |
124 messagePort.postMessage({ command: 'close', | 120 messagePort.postMessage({ command: 'close', |
125 notification: notificationCopy }); | 121 notification: notificationCopy }); |
126 }); | 122 }); |
127 | 123 |
128 addEventListener('fetch', event => { | 124 addEventListener('fetch', event => { |
129 fetchHistory.push(event.request.url); | 125 fetchHistory.push(event.request.url); |
130 event.respondWith(fetch(event.request)); | 126 event.respondWith(fetch(event.request)); |
131 }); | 127 }); |
OLD | NEW |