5 <title>Platform Notification Service BrowserTest service page
</title>
8 <!-- This page is intended to be used by the cross-platform
9 PlatformNotificationServiceBrowserTest. -->
10 <script src=
"notification_test_utils.js"></script>
12 var messagePort
= null,
14 expectingMessage
= false;
16 // Requests permission to display Web Notifications. Will return the
17 // permission level to the DOM Automation Controller.
18 function RequestPermission() {
19 Notification
.requestPermission(function (level
) {
20 domAutomationController
.send(level
);
24 // Renews the registered Service Worker registration for this page, then
25 // displays a notification on the activated ServiceWorkerRegistration.
26 function DisplayPersistentNotification(title
, options
) {
27 options
= options
|| { body
: 'Hello, world!',
30 GetActivatedServiceWorker('platform_notification_service.js',
32 .then(function (registration
) {
33 return registration
.showNotification(title
, options
);
35 messagePort
.addEventListener('message', function (event
) {
37 domAutomationController
.send(event
.data
);
39 messageStack
.push(event
.data
);
42 domAutomationController
.send('ok');
43 }).catch(function (error
) {
44 domAutomationController
.send('' + error
);
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', {
64 // Displays a persistent notification with vibrate field.
65 function DisplayPersistentNotificationVibrate() {
66 DisplayPersistentNotification('Title', {
68 vibrate
: [100, 200, 300]
72 // Displays a persistent notification with a data: URL as its image.
73 function DisplayPersistentNotificationDataUrlImage() {
74 fetch('icon.png').then(function(response
) {
75 return response
.blob();
76 }).then(function(blob
) {
77 var reader
= new FileReader();
78 reader
.readAsDataURL(blob
);
79 reader
.onloadend = function() {
80 DisplayPersistentNotification('Data URL Title', {
88 // Displays a persistent notification with a blob URL as its image.
89 function DisplayPersistentNotificationBlobImage() {
90 fetch('icon.png').then(function(response
) {
91 return response
.blob();
92 }).then(function(blob
) {
93 DisplayPersistentNotification('Blob Title', {
95 icon
: URL
.createObjectURL(blob
)
100 // Returns the latest received message from the worker. If no message has
101 // been received, nothing will be done. For successfully registered
102 // Service Workers this is OK, however, since the "message" event handler
103 // in DisplayPersistentNotification will take care of notifying the DOM
104 // Automation Controller instead.
105 function GetMessageFromWorker() {
106 if (!messageStack
.length
) {
107 expectingMessage
= true;
111 domAutomationController
.send('' + messageStack
.pop());