Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / data / notifications / platform_notification_service.html
blob56529ddb71d77bb580cfda747058c7cc8dfff598
1 <!doctype html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <title>Platform Notification Service BrowserTest service page</title>
6 </head>
7 <body>
8 <!-- This page is intended to be used by the cross-platform
9 PlatformNotificationServiceBrowserTest. -->
10 <script src="notification_test_utils.js"></script>
11 <script>
12 var messagePort = null,
13 messageStack = [],
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);
21 });
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!',
28 icon: 'icon.png' };
30 GetActivatedServiceWorker('platform_notification_service.js',
31 location.pathname)
32 .then(function (registration) {
33 return registration.showNotification(title, options);
34 }).then(function () {
35 messagePort.addEventListener('message', function (event) {
36 if (expectingMessage)
37 domAutomationController.send(event.data);
38 else
39 messageStack.push(event.data);
40 });
42 domAutomationController.send('ok');
43 }).catch(function (error) {
44 domAutomationController.send('' + error);
45 });
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 requireInteraction: true,
59 data: [
60 { property: 'value' }
62 });
65 // Displays a persistent notification with vibrate field.
66 function DisplayPersistentNotificationVibrate() {
67 DisplayPersistentNotification('Title', {
68 body: 'Contents',
69 vibrate: [100, 200, 300]
70 });
73 // Displays a persistent notification with a data: URL as its image.
74 function DisplayPersistentNotificationDataUrlImage() {
75 fetch('icon.png').then(function(response) {
76 return response.blob();
77 }).then(function(blob) {
78 var reader = new FileReader();
79 reader.readAsDataURL(blob);
80 reader.onloadend = function() {
81 DisplayPersistentNotification('Data URL Title', {
82 body: 'Contents',
83 icon: reader.result
84 });
86 });
89 // Displays a persistent notification with a blob URL as its image.
90 function DisplayPersistentNotificationBlobImage() {
91 fetch('icon.png').then(function(response) {
92 return response.blob();
93 }).then(function(blob) {
94 DisplayPersistentNotification('Blob Title', {
95 body: 'Contents',
96 icon: URL.createObjectURL(blob)
97 });
98 });
101 // Returns the latest received message from the worker. If no message has
102 // been received, nothing will be done. For successfully registered
103 // Service Workers this is OK, however, since the "message" event handler
104 // in DisplayPersistentNotification will take care of notifying the DOM
105 // Automation Controller instead.
106 function GetMessageFromWorker() {
107 if (!messageStack.length) {
108 expectingMessage = true;
109 return;
112 domAutomationController.send('' + messageStack.pop());
114 </script>
115 </body>
116 </html>