OLD | NEW |
---|---|
1 <!doctype html> | 1 <!doctype html> |
2 <html lang="en"> | 2 <html lang="en"> |
3 <head> | 3 <head> |
4 <meta charset="utf-8"> | 4 <meta charset="utf-8"> |
5 <title>Platform Notification Service BrowserTest service page</title> | 5 <title>Platform Notification Service BrowserTest service page</title> |
6 </head> | 6 </head> |
7 <body> | 7 <body> |
8 <!-- This page is intended to be used by the cross-platform | 8 <!-- This page is intended to be used by the cross-platform |
9 PlatformNotificationServiceBrowserTest. --> | 9 PlatformNotificationServiceBrowserTest. --> |
10 <script src="notification_test_utils.js"></script> | 10 <script src="notification_test_utils.js"></script> |
11 <script> | 11 <script> |
12 var messagePort = null, | 12 var messagePort = null, |
13 messageStack = [], | 13 messageStack = [], |
14 expectingMessage = false; | 14 expectingMessage = false; |
15 | 15 |
16 // Requests permission to display Web Notifications. Will return the | 16 // Requests permission to display Web Notifications. Will return the |
17 // permission level to the DOM Automation Controller. | 17 // permission level to the DOM Automation Controller. |
18 function RequestPermission() { | 18 function RequestPermission() { |
19 Notification.requestPermission(function (level) { | 19 Notification.requestPermission(function (level) { |
20 domAutomationController.send(level); | 20 domAutomationController.send(level); |
21 }); | 21 }); |
22 } | 22 } |
23 | 23 |
24 function DisplayNonPersistentNotification(title, options) { | |
25 const notification = new Notification(title, options || {}); | |
26 notification.addEventListener('show', e => | |
27 domAutomationController.send('ok')); | |
28 notification.addEventListener('error', e => | |
29 domAutomationController.send('could not show notification')); | |
30 } | |
31 | |
24 // Renews the registered Service Worker registration for this page, then | 32 // Renews the registered Service Worker registration for this page, then |
25 // displays a notification on the activated ServiceWorkerRegistration. | 33 // displays a notification on the activated ServiceWorkerRegistration. |
26 function DisplayPersistentNotification(title, options) { | 34 function DisplayPersistentNotification(title, options) { |
27 options = options || { body: 'Hello, world!', | 35 options = options || { body: 'Hello, world!', |
28 icon: 'icon.png' }; | 36 icon: 'icon.png' }; |
29 | 37 |
30 GetActivatedServiceWorker('platform_notification_service.js', | 38 GetActivatedServiceWorker('platform_notification_service.js', |
31 location.pathname) | 39 location.pathname) |
32 .then(function (registration) { | 40 .then(function (registration) { |
33 return registration.showNotification(title, options); | 41 return registration.showNotification(title, options); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 function DisplayPersistentNotificationWithReplyButton() { | 128 function DisplayPersistentNotificationWithReplyButton() { |
121 DisplayPersistentNotification('action_button_click', { | 129 DisplayPersistentNotification('action_button_click', { |
122 body: 'Contents', | 130 body: 'Contents', |
123 actions: [ | 131 actions: [ |
124 { action: 'actionId1', title: 'actionTitle1', icon: 'icon.png', | 132 { action: 'actionId1', title: 'actionTitle1', icon: 'icon.png', |
125 type: 'text' } | 133 type: 'text' } |
126 ] | 134 ] |
127 }); | 135 }); |
128 } | 136 } |
129 | 137 |
138 // Gets a comma separated list of currently displayed notification titles | |
139 function GetDisplayedNotifications() { | |
140 GetActivatedServiceWorker('platform_notification_service.js', | |
141 location.pathname).then(function (sw) { | |
142 return sw.getNotifications(); | |
143 }).then(function (notifications) { | |
144 var notificationResult = ''; | |
145 for (var i = 0; i < notifications.length; ++i) { | |
146 notificationResult = notificationResult.concat(notifications[i]. title); | |
147 if (i < (notifications.length -1)) | |
148 notificationResult = notificationResult.concat(','); | |
149 } | |
150 if (expectingMessage) | |
151 domAutomationController.send(notificationResult); | |
152 else | |
153 messageStack.push(notificationResult); | |
Peter Beverloo
2016/12/06 13:04:02
micro nit: -2 space indent for lines 146-153
Miguel Garcia
2016/12/07 17:20:50
Done.
| |
154 | |
155 domAutomationController.send('ok'); | |
156 }).catch(function (error) { | |
157 domAutomationController.send('' + error); | |
158 }); | |
159 } | |
160 | |
130 // Returns the latest received message from the worker. If no message has | 161 // Returns the latest received message from the worker. If no message has |
131 // been received, nothing will be done. For successfully registered | 162 // been received, nothing will be done. For successfully registered |
132 // Service Workers this is OK, however, since the "message" event handler | 163 // Service Workers this is OK, however, since the "message" event handler |
133 // in DisplayPersistentNotification will take care of notifying the DOM | 164 // in DisplayPersistentNotification will take care of notifying the DOM |
134 // Automation Controller instead. | 165 // Automation Controller instead. |
135 function GetMessageFromWorker() { | 166 function GetMessageFromWorker() { |
136 if (!messageStack.length) { | 167 if (!messageStack.length) { |
137 expectingMessage = true; | 168 expectingMessage = true; |
138 return; | 169 return; |
139 } | 170 } |
140 | 171 |
141 domAutomationController.send('' + messageStack.pop()); | 172 domAutomationController.send('' + messageStack.pop()); |
142 } | 173 } |
143 </script> | 174 </script> |
144 </body> | 175 </body> |
145 </html> | 176 </html> |
OLD | NEW |