OLD | NEW |
1 <html> | 1 <html> |
2 <!--notification_tester.html | 2 <!--notification_tester.html |
3 Script with javascript functions for creating and canceling notifications. | 3 Script with javascript functions for creating and canceling notifications. |
4 Also can be used to request permission for notifications. | 4 Also can be used to request permission for notifications. |
5 --> | 5 --> |
6 <script> | 6 <script> |
7 | 7 |
8 // Array of all notifications this page has created. | 8 // Array of all notifications this page has created. |
9 var g_notifications = []; | 9 var g_notifications = []; |
10 // Whether the site has requested and been granted permission. | 10 // Whether the site has requested and been granted permission. |
11 var g_permissionGranted = false; | 11 var g_permissionGranted = false; |
12 | 12 |
13 // Creates a notification with a iconUrl, title, text, and replaceId. | 13 // Creates a notification with a iconUrl, title, text, and replaceId. |
14 // Returns an id for the notification, which can be used to cancel it with | 14 // Returns an id for the notification, which can be used to cancel it with |
15 // |cancelNotification|. If two notifications are created with the same | 15 // |cancelNotification|. If two notifications are created with the same |
16 // replaceId, the second one should replace the first. | 16 // replaceId, the second one should replace the first. |
17 function createNotification(iconUrl, title, text, replaceId) { | 17 function createNotification(iconUrl, title, text, replaceId) { |
18 try { | 18 try { |
19 var note = webkitNotifications.createNotification(iconUrl, | 19 var note = webkitNotifications.createNotification(iconUrl, |
20 title, | 20 title, |
21 text); | 21 text); |
22 } catch (exception) { | 22 } catch (exception) { |
23 sendResultToTest(-1); | 23 sendResultToTest(-1); |
24 return; | 24 return; |
25 } | 25 } |
26 createNotificationHelper(note, replaceId, true); | 26 createNotificationHelper(note, replaceId, true); |
27 } | 27 } |
28 | 28 |
29 // Creates an HTML notification with a given content url. | |
30 // Returns an id for the notification, which can be used to cancel it with | |
31 // |cancelNotification|. If two notifications are created with the same | |
32 // replaceId, the second one should replace the first. If the notification | |
33 // cannot be created, this returns -1. | |
34 // If |waitForDisplay| is true, a response will not be sent until the | |
35 // notification is actually displayed. | |
36 function createHTMLNotification(contentUrl, replaceId, waitForDisplay) { | |
37 try { | |
38 var note = webkitNotifications.createHTMLNotification(contentUrl); | |
39 } catch (exception) { | |
40 sendResultToTest(-1); | |
41 return; | |
42 } | |
43 createNotificationHelper(note, replaceId, waitForDisplay); | |
44 } | |
45 | |
46 // Cancels a notification with the given id. The notification must be showing, | 29 // Cancels a notification with the given id. The notification must be showing, |
47 // as opposed to waiting to be shown in the display queue. | 30 // as opposed to waiting to be shown in the display queue. |
48 // Returns '1' on success. | 31 // Returns '1' on success. |
49 function cancelNotification(id) { | 32 function cancelNotification(id) { |
50 if (id < 0 || id > g_notifications.length) { | 33 if (id < 0 || id > g_notifications.length) { |
51 var errorMsg = "Attempted to cancel notification with invalid ID.\n" + | 34 var errorMsg = "Attempted to cancel notification with invalid ID.\n" + |
52 "ID: " + id + "\n# of notifications: " + g_notifications.length; | 35 "ID: " + id + "\n# of notifications: " + g_notifications.length; |
53 sendResultToTest(errorMsg); | 36 sendResultToTest(errorMsg); |
54 } | 37 } |
55 g_notifications[id].onclose = function() { | 38 g_notifications[id].onclose = function() { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 stringResult = JSON.stringify(result); | 90 stringResult = JSON.stringify(result); |
108 window.domAutomationController.send(stringResult); | 91 window.domAutomationController.send(stringResult); |
109 } | 92 } |
110 | 93 |
111 </script> | 94 </script> |
112 | 95 |
113 <body> | 96 <body> |
114 This page is used for testing HTML5 notifications. | 97 This page is used for testing HTML5 notifications. |
115 </body> | 98 </body> |
116 </html> | 99 </html> |
OLD | NEW |