| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Notifications: The Notification object exposes the expected propertie
s.</title> | 4 <title>Notifications: The Notification object exposes the expected propertie
s.</title> |
| 5 <script src="../resources/testharness.js"></script> | 5 <script src="../resources/testharness.js"></script> |
| 6 <script src="../resources/testharnessreport.js"></script> | 6 <script src="../resources/testharnessreport.js"></script> |
| 7 </head> | 7 </head> |
| 8 <body> | 8 <body> |
| 9 <script> | 9 <script> |
| 10 // Tests that the Notification object exposes the properties per the | 10 // Tests that the Notification object exposes the properties per the |
| 11 // semantics defined by the specification. When the test is being ran | 11 // semantics defined by the specification. When the test is being ran |
| 12 // manually, grant Notification permission first. | 12 // manually, grant Notification permission first. |
| 13 test(function () { | 13 test(function () { |
| 14 assert_greater_than_equal(Notification.maxActions, 0); | 14 assert_greater_than_equal(Notification.maxActions, 0); |
| 15 | 15 |
| 16 var options = { | 16 var options = { |
| 17 dir: "rtl", | 17 dir: "rtl", |
| 18 lang: "nl-NL", | 18 lang: "nl-NL", |
| 19 body: "Hallo, wereld!", | 19 body: "Hallo, wereld!", |
| 20 tag: "notification", | 20 tag: "notification", |
| 21 icon: "http://localhost/my_icon.png", | 21 icon: "http://localhost/my_icon.png", |
| 22 silent: true, | 22 silent: true, |
| 23 data: "my data" | 23 data: "my data", |
| 24 actions: [] |
| 24 }; | 25 }; |
| 26 // Deliberately add more actions than are supported. |
| 27 for (var i = 0; i < 2 * Notification.maxActions; i++) { |
| 28 options.actions.push({ |
| 29 title: "Action " + i |
| 30 }); |
| 31 } |
| 25 | 32 |
| 26 var notification = new Notification("My Notification", options); | 33 var notification = new Notification("My Notification", options); |
| 27 | 34 |
| 28 assert_equals(notification.title, "My Notification"); | 35 assert_equals(notification.title, "My Notification"); |
| 29 assert_equals(notification.dir, options.dir); | 36 assert_equals(notification.dir, options.dir); |
| 30 assert_equals(notification.lang, options.lang); | 37 assert_equals(notification.lang, options.lang); |
| 31 assert_equals(notification.body, options.body); | 38 assert_equals(notification.body, options.body); |
| 32 assert_equals(notification.tag, options.tag); | 39 assert_equals(notification.tag, options.tag); |
| 33 assert_equals(notification.icon, options.icon); | 40 assert_equals(notification.icon, options.icon); |
| 34 assert_true(notification.silent); | 41 assert_true(notification.silent); |
| 35 assert_equals(notification.data, options.data); | 42 assert_equals(notification.data, options.data); |
| 43 // Only the first maxActions actions should be reflected. |
| 44 assert_object_equals(notification.actions, options.actions.slice(0,
Notification.maxActions)); |
| 45 |
| 46 // Notification.actions should be immutable. |
| 47 notification.actions.push({ title: "Foo" }); |
| 48 notification.actions.foo = "bar"; |
| 49 if (notification.actions.length) { |
| 50 notification.actions[0].title = "Changed"; |
| 51 notification.actions[0].foo = "bar"; |
| 52 } |
| 53 assert_object_equals(notification.actions, options.actions.slice(0,
Notification.maxActions)); |
| 36 | 54 |
| 37 var emptyNotification = new Notification("My Notification"); | 55 var emptyNotification = new Notification("My Notification"); |
| 38 | 56 |
| 39 assert_equals(emptyNotification.title, "My Notification"); | 57 assert_equals(emptyNotification.title, "My Notification"); |
| 40 assert_equals(emptyNotification.dir, "auto"); | 58 assert_equals(emptyNotification.dir, "auto"); |
| 41 assert_equals(emptyNotification.lang, ""); | 59 assert_equals(emptyNotification.lang, ""); |
| 42 assert_equals(emptyNotification.body, ""); | 60 assert_equals(emptyNotification.body, ""); |
| 43 assert_equals(emptyNotification.tag, ""); | 61 assert_equals(emptyNotification.tag, ""); |
| 44 assert_equals(emptyNotification.icon, ""); | 62 assert_equals(emptyNotification.icon, ""); |
| 45 assert_equals(notification.vibrate, null); | 63 assert_equals(notification.vibrate, null); |
| 46 assert_false(emptyNotification.silent); | 64 assert_false(emptyNotification.silent); |
| 47 assert_equals(emptyNotification.data, null); | 65 assert_equals(emptyNotification.data, null); |
| 66 assert_array_equals(emptyNotification.actions, []); |
| 48 | 67 |
| 49 var invalidIconNotification = new Notification("My Notification", { | 68 var invalidIconNotification = new Notification("My Notification", { |
| 50 icon: "http://test:test/" | 69 icon: "http://test:test/" |
| 51 }); | 70 }); |
| 52 | 71 |
| 53 // Invalid icon URLs should be reset to an empty string. | 72 // Invalid icon URLs should be reset to an empty string. |
| 54 assert_equals(invalidIconNotification.icon, ""); | 73 assert_equals(invalidIconNotification.icon, ""); |
| 55 | 74 |
| 56 var serializedUrlNotification = new Notification("My Notification",
{ | 75 var serializedUrlNotification = new Notification("My Notification",
{ |
| 57 icon: "http://example.com" | 76 icon: "http://example.com" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 Array.apply(null, new Array(99)).map(Number.prototype.valueO
f, 10000)); | 116 Array.apply(null, new Array(99)).map(Number.prototype.valueO
f, 10000)); |
| 98 | 117 |
| 99 // Verifying the exception throwing behavior, when silent set true a
nd vibrate is presented. | 118 // Verifying the exception throwing behavior, when silent set true a
nd vibrate is presented. |
| 100 assert_throws(new TypeError(), function() { | 119 assert_throws(new TypeError(), function() { |
| 101 var notification = new Notification("My Notification", { | 120 var notification = new Notification("My Notification", { |
| 102 silent: true, | 121 silent: true, |
| 103 vibrate: 1000 | 122 vibrate: 1000 |
| 104 }); | 123 }); |
| 105 }, 'Set vibrate, when silent is true.'); | 124 }, 'Set vibrate, when silent is true.'); |
| 106 | 125 |
| 126 // Check exception is thrown when an action doesn't contain title, |
| 127 // or title is an empty string. |
| 128 assert_throws(new TypeError(), function() { |
| 129 var notification = new Notification("My Notification", { |
| 130 actions: [{}] |
| 131 }); |
| 132 }, 'Provide action without title.'); |
| 133 assert_throws(new TypeError(), function() { |
| 134 var notification = new Notification("My Notification", { |
| 135 actions: [{title: ""}] |
| 136 }); |
| 137 }, 'Provide action with empty title.'); |
| 138 |
| 107 }, 'Checks the properties exposed on the Notification object.'); | 139 }, 'Checks the properties exposed on the Notification object.'); |
| 108 </script> | 140 </script> |
| 109 </body> | 141 </body> |
| 110 </html> | 142 </html> |
| OLD | NEW |