| OLD | NEW |
| 1 importScripts('/resources/testharness-helpers.js'); | 1 importScripts('/resources/testharness-helpers.js'); |
| 2 | 2 |
| 3 // Copies the serializable attributes of |notification|. | 3 // Copies the serializable attributes of |notification|. |
| 4 function cloneNotification(notification) { | 4 function cloneNotification(notification) { |
| 5 return JSON.parse(stringifyDOMObject(notification)); | 5 return JSON.parse(stringifyDOMObject(notification)); |
| 6 } | 6 } |
| 7 | 7 |
| 8 // Allows a document to exercise the Notifications API within a service worker b
y sending commands. | 8 // Allows a document to exercise the Notifications API within a service worker b
y sending commands. |
| 9 var messagePort = null; | 9 var messagePort = null; |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 messagePort.postMessage({ command: event.data.command, | 46 messagePort.postMessage({ command: event.data.command, |
| 47 success: true, | 47 success: true, |
| 48 notifications: clonedNotifications
}); | 48 notifications: clonedNotifications
}); |
| 49 }, function(error) { | 49 }, function(error) { |
| 50 messagePort.postMessage({ command: event.data.command, | 50 messagePort.postMessage({ command: event.data.command, |
| 51 success: false, | 51 success: false, |
| 52 message: error.message }); | 52 message: error.message }); |
| 53 }); | 53 }); |
| 54 break; | 54 break; |
| 55 | 55 |
| 56 case 'request-permission-exists': |
| 57 messagePort.postMessage({ command: event.data.command, |
| 58 value: 'requestPermission' in Notifica
tion }); |
| 59 break; |
| 60 |
| 56 default: | 61 default: |
| 57 messagePort.postMessage({ command: 'error', message: 'Invalid co
mmand: ' + event.data.command }); | 62 messagePort.postMessage({ command: 'error', message: 'Invalid co
mmand: ' + event.data.command }); |
| 58 break; | 63 break; |
| 59 } | 64 } |
| 60 }; | 65 }; |
| 61 | 66 |
| 62 // Notify the controller that the worker is now available. | 67 // Notify the controller that the worker is now available. |
| 63 messagePort.postMessage('ready'); | 68 messagePort.postMessage('ready'); |
| 64 }); | 69 }); |
| 65 | 70 |
| 66 addEventListener('notificationclick', function(event) { | 71 addEventListener('notificationclick', function(event) { |
| 67 var notificationCopy = cloneNotification(event.notification); | 72 var notificationCopy = cloneNotification(event.notification); |
| 68 | 73 |
| 69 // Notifications containing "ACTION:CLOSE" in their message will be closed | 74 // Notifications containing "ACTION:CLOSE" in their message will be closed |
| 70 // immediately by the Service Worker. | 75 // immediately by the Service Worker. |
| 71 if (event.notification.body.indexOf('ACTION:CLOSE') != -1) | 76 if (event.notification.body.indexOf('ACTION:CLOSE') != -1) |
| 72 event.notification.close(); | 77 event.notification.close(); |
| 73 | 78 |
| 74 // Notifications containing "ACTION:OPENWINDOW" in their message will attemp
t | 79 // Notifications containing "ACTION:OPENWINDOW" in their message will attemp
t |
| 75 // to open a new window for an example URL. | 80 // to open a new window for an example URL. |
| 76 if (event.notification.body.indexOf('ACTION:OPENWINDOW') != -1) | 81 if (event.notification.body.indexOf('ACTION:OPENWINDOW') != -1) |
| 77 event.waitUntil(clients.openWindow('https://example.com/')); | 82 event.waitUntil(clients.openWindow('https://example.com/')); |
| 78 | 83 |
| 79 messagePort.postMessage({ command: 'click', | 84 messagePort.postMessage({ command: 'click', |
| 80 notification: notificationCopy, | 85 notification: notificationCopy, |
| 81 action: event.action }); | 86 action: event.action }); |
| 82 }); | 87 }); |
| OLD | NEW |