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 // Renews the registered Service Worker registration for this page, then | 24 // Renews the registered Service Worker registration for this page, then |
25 // displays a notification on the activated ServiceWorkerRegistration. | 25 // displays a notification on the activated ServiceWorkerRegistration. |
26 function DisplayPersistentNotification(title) { | 26 function DisplayPersistentNotification(title, options) { |
| 27 options = options || { body: 'Hello, world!', |
| 28 icon: 'icon.png' }; |
| 29 |
27 GetActivatedServiceWorker('platform_notification_service.js', | 30 GetActivatedServiceWorker('platform_notification_service.js', |
28 location.pathname) | 31 location.pathname) |
29 .then(function (registration) { | 32 .then(function (registration) { |
30 return registration.showNotification(title, { | 33 return registration.showNotification(title, options); |
31 body: 'Hello, world!', | |
32 icon: 'icon.png' | |
33 }); | |
34 }).then(function () { | 34 }).then(function () { |
35 messagePort.addEventListener('message', function (event) { | 35 messagePort.addEventListener('message', function (event) { |
36 if (expectingMessage) | 36 if (expectingMessage) |
37 domAutomationController.send(event.data); | 37 domAutomationController.send(event.data); |
38 else | 38 else |
39 messageStack.push(event.data); | 39 messageStack.push(event.data); |
40 }); | 40 }); |
41 | 41 |
42 domAutomationController.send('ok'); | 42 domAutomationController.send('ok'); |
43 }).catch(function (error) { | 43 }).catch(function (error) { |
44 domAutomationController.send('' + error); | 44 domAutomationController.send('' + error); |
45 }); | 45 }); |
46 } | 46 } |
47 | 47 |
| 48 // Displays a persistent notification having every field in its options |
| 49 // bag filled out with non-default values. |
| 50 function DisplayPersistentAllOptionsNotification() { |
| 51 DisplayPersistentNotification('Title', { |
| 52 dir: 'rtl', |
| 53 lang: 'nl-NL', |
| 54 body: 'Contents', |
| 55 tag: 'replace-id', |
| 56 icon: 'icon.png', |
| 57 silent: true |
| 58 }); |
| 59 } |
| 60 |
48 // Returns the latest received message from the worker. If no message has | 61 // Returns the latest received message from the worker. If no message has |
49 // been received, nothing will be done. For successfully registered | 62 // been received, nothing will be done. For successfully registered |
50 // Service Workers this is OK, however, since the "message" event handler | 63 // Service Workers this is OK, however, since the "message" event handler |
51 // in DisplayPersistentNotification will take care of notifying the DOM | 64 // in DisplayPersistentNotification will take care of notifying the DOM |
52 // Automation Controller instead. | 65 // Automation Controller instead. |
53 function GetMessageFromWorker() { | 66 function GetMessageFromWorker() { |
54 if (!messageStack.length) { | 67 if (!messageStack.length) { |
55 expectingMessage = true; | 68 expectingMessage = true; |
56 return; | 69 return; |
57 } | 70 } |
58 | 71 |
59 domAutomationController.send('' + messageStack.pop()); | 72 domAutomationController.send('' + messageStack.pop()); |
60 } | 73 } |
61 </script> | 74 </script> |
62 </body> | 75 </body> |
63 </html> | 76 </html> |
OLD | NEW |