| 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 |
| 29 // Cancels a notification with the given id. The notification must be showing, | 46 // Cancels a notification with the given id. The notification must be showing, |
| 30 // as opposed to waiting to be shown in the display queue. | 47 // as opposed to waiting to be shown in the display queue. |
| 31 // Returns '1' on success. | 48 // Returns '1' on success. |
| 32 function cancelNotification(id) { | 49 function cancelNotification(id) { |
| 33 if (id < 0 || id > g_notifications.length) { | 50 if (id < 0 || id > g_notifications.length) { |
| 34 var errorMsg = "Attempted to cancel notification with invalid ID.\n" + | 51 var errorMsg = "Attempted to cancel notification with invalid ID.\n" + |
| 35 "ID: " + id + "\n# of notifications: " + g_notifications.length; | 52 "ID: " + id + "\n# of notifications: " + g_notifications.length; |
| 36 sendResultToTest(errorMsg); | 53 sendResultToTest(errorMsg); |
| 37 } | 54 } |
| 38 g_notifications[id].onclose = function() { | 55 g_notifications[id].onclose = function() { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 stringResult = JSON.stringify(result); | 107 stringResult = JSON.stringify(result); |
| 91 window.domAutomationController.send(stringResult); | 108 window.domAutomationController.send(stringResult); |
| 92 } | 109 } |
| 93 | 110 |
| 94 </script> | 111 </script> |
| 95 | 112 |
| 96 <body> | 113 <body> |
| 97 This page is used for testing HTML5 notifications. | 114 This page is used for testing HTML5 notifications. |
| 98 </body> | 115 </body> |
| 99 </html> | 116 </html> |
| OLD | NEW |