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 options = options || { body: 'Hello, world!', |
| 26 icon: 'icon.png' }; |
| 27 var notification = null; |
| 28 try { |
| 29 notification = new Notification(title, options); |
| 30 domAutomationController.send('ok'); |
| 31 } catch (error) { |
| 32 domAutomationController.send('' + error); |
| 33 } |
| 34 } |
| 35 |
24 // Renews the registered Service Worker registration for this page, then | 36 // Renews the registered Service Worker registration for this page, then |
25 // displays a notification on the activated ServiceWorkerRegistration. | 37 // displays a notification on the activated ServiceWorkerRegistration. |
26 function DisplayPersistentNotification(title, options) { | 38 function DisplayPersistentNotification(title, options) { |
27 options = options || { body: 'Hello, world!', | 39 options = options || { body: 'Hello, world!', |
28 icon: 'icon.png' }; | 40 icon: 'icon.png' }; |
29 | 41 |
30 GetActivatedServiceWorker('platform_notification_service.js', | 42 GetActivatedServiceWorker('platform_notification_service.js', |
31 location.pathname) | 43 location.pathname) |
32 .then(function (registration) { | 44 .then(function (registration) { |
33 return registration.showNotification(title, options); | 45 return registration.showNotification(title, options); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 function DisplayPersistentNotificationWithReplyButton() { | 132 function DisplayPersistentNotificationWithReplyButton() { |
121 DisplayPersistentNotification('action_button_click', { | 133 DisplayPersistentNotification('action_button_click', { |
122 body: 'Contents', | 134 body: 'Contents', |
123 actions: [ | 135 actions: [ |
124 { action: 'actionId1', title: 'actionTitle1', icon: 'icon.png', | 136 { action: 'actionId1', title: 'actionTitle1', icon: 'icon.png', |
125 type: 'text' } | 137 type: 'text' } |
126 ] | 138 ] |
127 }); | 139 }); |
128 } | 140 } |
129 | 141 |
| 142 // Gets a comma separated list of currently displayed notification titles |
| 143 function GetDisplayedNotifications() { |
| 144 GetActivatedServiceWorker('platform_notification_service.js', |
| 145 location.pathname) |
| 146 .then(function (sw) { |
| 147 return sw.getNotifications(); |
| 148 }).then(function (notifications) { |
| 149 var notificationResult = ''; |
| 150 for (var i = 0; i < notifications.length; ++i) { |
| 151 notificationResult = notificationResult.concat(notifications[i].
title); |
| 152 if (i < (notifications.length -1)) |
| 153 notificationResult = notificationResult.concat(',');
|
| 154 } |
| 155 if (expectingMessage) |
| 156 domAutomationController.send(notificationResult); |
| 157 else |
| 158 messageStack.push(notificationResult); |
| 159 |
| 160 domAutomationController.send('ok'); |
| 161 }).catch(function (error) { |
| 162 domAutomationController.send('' + error); |
| 163 }); |
| 164 } |
| 165 |
130 // Returns the latest received message from the worker. If no message has | 166 // Returns the latest received message from the worker. If no message has |
131 // been received, nothing will be done. For successfully registered | 167 // been received, nothing will be done. For successfully registered |
132 // Service Workers this is OK, however, since the "message" event handler | 168 // Service Workers this is OK, however, since the "message" event handler |
133 // in DisplayPersistentNotification will take care of notifying the DOM | 169 // in DisplayPersistentNotification will take care of notifying the DOM |
134 // Automation Controller instead. | 170 // Automation Controller instead. |
135 function GetMessageFromWorker() { | 171 function GetMessageFromWorker() { |
136 if (!messageStack.length) { | 172 if (!messageStack.length) { |
137 expectingMessage = true; | 173 expectingMessage = true; |
138 return; | 174 return; |
139 } | 175 } |
140 | 176 |
141 domAutomationController.send('' + messageStack.pop()); | 177 domAutomationController.send('' + messageStack.pop()); |
142 } | 178 } |
143 </script> | 179 </script> |
144 </body> | 180 </body> |
145 </html> | 181 </html> |
OLD | NEW |