| 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 var oldMaxActions = Notification.maxActions; | 15 var oldMaxActions = Notification.maxActions; |
| 16 Notification.maxActions++; | 16 Notification.maxActions++; |
| 17 assert_equals(Notification.maxActions, oldMaxActions, 'Notification.ma
xActions should be immutable.'); | 17 assert_equals(Notification.maxActions, oldMaxActions, 'Notification.ma
xActions should be immutable.'); |
| 18 | 18 |
| 19 var options = { | 19 var options = { |
| 20 dir: "rtl", | 20 dir: "rtl", |
| 21 lang: "nl-NL", | 21 lang: "nl-NL", |
| 22 body: "Hallo, wereld!", | 22 body: "Hallo, wereld!", |
| 23 tag: "notification", | 23 tag: "notification", |
| 24 image: "http://localhost/image.jpg", |
| 24 icon: "http://localhost/my_icon.png", | 25 icon: "http://localhost/my_icon.png", |
| 25 badge: "http://localhost/badge.png", | 26 badge: "http://localhost/badge.png", |
| 26 timestamp: 621046800000, | 27 timestamp: 621046800000, |
| 27 silent: true, | 28 silent: true, |
| 28 requireInteraction: true, | 29 requireInteraction: true, |
| 29 data: "my data", | 30 data: "my data", |
| 30 actions: [] | 31 actions: [] |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 var notification = new Notification("My Notification", options); | 34 var notification = new Notification("My Notification", options); |
| 34 | 35 |
| 35 assert_equals(notification.title, "My Notification"); | 36 assert_equals(notification.title, "My Notification"); |
| 36 assert_equals(notification.dir, options.dir); | 37 assert_equals(notification.dir, options.dir); |
| 37 assert_equals(notification.lang, options.lang); | 38 assert_equals(notification.lang, options.lang); |
| 38 assert_equals(notification.body, options.body); | 39 assert_equals(notification.body, options.body); |
| 39 assert_equals(notification.tag, options.tag); | 40 assert_equals(notification.tag, options.tag); |
| 41 assert_equals(notification.image, options.image); |
| 40 assert_equals(notification.icon, options.icon); | 42 assert_equals(notification.icon, options.icon); |
| 41 assert_equals(notification.badge, options.badge); | 43 assert_equals(notification.badge, options.badge); |
| 42 assert_equals(notification.timestamp, options.timestamp); | 44 assert_equals(notification.timestamp, options.timestamp); |
| 43 assert_true(notification.silent); | 45 assert_true(notification.silent); |
| 44 assert_true(notification.requireInteraction); | 46 assert_true(notification.requireInteraction); |
| 45 assert_equals(notification.data, options.data); | 47 assert_equals(notification.data, options.data); |
| 46 assert_array_equals(notification.actions, options.actions); | 48 assert_array_equals(notification.actions, options.actions); |
| 47 | 49 |
| 48 // The `actions` field should be immutable. | 50 // The `actions` field should be immutable. |
| 49 assert_throws(null, () => notification.actions.push(null)); | 51 assert_throws(null, () => notification.actions.push(null)); |
| 50 | 52 |
| 51 notification.actions.foo = 'bar'; | 53 notification.actions.foo = 'bar'; |
| 52 assert_false(notification.actions.hasOwnProperty('foo')); | 54 assert_false(notification.actions.hasOwnProperty('foo')); |
| 53 | 55 |
| 54 var emptyNotification = new Notification("My Notification"); | 56 var emptyNotification = new Notification("My Notification"); |
| 55 | 57 |
| 56 assert_equals(emptyNotification.title, "My Notification"); | 58 assert_equals(emptyNotification.title, "My Notification"); |
| 57 assert_equals(emptyNotification.dir, "auto"); | 59 assert_equals(emptyNotification.dir, "auto"); |
| 58 assert_equals(emptyNotification.lang, ""); | 60 assert_equals(emptyNotification.lang, ""); |
| 59 assert_equals(emptyNotification.body, ""); | 61 assert_equals(emptyNotification.body, ""); |
| 60 assert_equals(emptyNotification.tag, ""); | 62 assert_equals(emptyNotification.tag, ""); |
| 63 assert_equals(emptyNotification.image, ""); |
| 61 assert_equals(emptyNotification.icon, ""); | 64 assert_equals(emptyNotification.icon, ""); |
| 62 assert_equals(emptyNotification.badge, ""); | 65 assert_equals(emptyNotification.badge, ""); |
| 63 assert_array_equals(emptyNotification.vibrate, []); | 66 assert_array_equals(emptyNotification.vibrate, []); |
| 64 assert_false(emptyNotification.silent); | 67 assert_false(emptyNotification.silent); |
| 65 assert_false(emptyNotification.requireInteraction); | 68 assert_false(emptyNotification.requireInteraction); |
| 66 assert_equals(emptyNotification.data, null); | 69 assert_equals(emptyNotification.data, null); |
| 67 assert_array_equals(emptyNotification.actions, []); | 70 assert_array_equals(emptyNotification.actions, []); |
| 68 | 71 |
| 69 var timeDifference = Math.abs(Date.now() - emptyNotification.timesta
mp); | 72 var timeDifference = Math.abs(Date.now() - emptyNotification.timesta
mp); |
| 70 assert_true(timeDifference < 16); // 16 is not significant, just to
reduce flakiness. | 73 assert_true(timeDifference < 16); // 16 is not significant, just to
reduce flakiness. |
| 71 | 74 |
| 72 var equalNotification = new Notification("My Notification", { | 75 var equalNotification = new Notification("My Notification", { |
| 73 vibrate: [50, 10, 50, 10, 50], | 76 vibrate: [50, 10, 50, 10, 50], |
| 74 data: { hello: "World!" } | 77 data: { hello: "World!" } |
| 75 }); | 78 }); |
| 76 | 79 |
| 77 // Test equality of the object attributes. | 80 // Test equality of the object attributes. |
| 78 assert_equals(equalNotification.data, equalNotification.data, '`data
` object equality'); | 81 assert_equals(equalNotification.data, equalNotification.data, '`data
` object equality'); |
| 79 assert_equals(equalNotification.vibrate, equalNotification.vibrate,
'`vibrate` object equality'); | 82 assert_equals(equalNotification.vibrate, equalNotification.vibrate,
'`vibrate` object equality'); |
| 80 | 83 |
| 81 var serializedUrlNotification = new Notification("My Notification",
{ | 84 var serializedUrlNotification = new Notification("My Notification",
{ |
| 85 image: "https://example.com/image.jpg", |
| 82 icon: "https://example.com/icon.png", | 86 icon: "https://example.com/icon.png", |
| 83 badge: "https://example.com/badge.png" | 87 badge: "https://example.com/badge.png" |
| 84 }); | 88 }); |
| 85 | 89 |
| 86 // Icon URLs should be returned in serialized form. | 90 // Icon URLs should be returned in serialized form. |
| 91 assert_equals(serializedUrlNotification.image, "https://example.com/
image.jpg"); |
| 87 assert_equals(serializedUrlNotification.icon, "https://example.com/i
con.png"); | 92 assert_equals(serializedUrlNotification.icon, "https://example.com/i
con.png"); |
| 88 assert_equals(serializedUrlNotification.badge, "https://example.com/
badge.png"); | 93 assert_equals(serializedUrlNotification.badge, "https://example.com/
badge.png"); |
| 89 | 94 |
| 90 var noTagNotification = new Notification("My Notification"), | 95 var noTagNotification = new Notification("My Notification"), |
| 91 emptyTagNotification = new Notification("My Notification", { tag
: "" }); | 96 emptyTagNotification = new Notification("My Notification", { tag
: "" }); |
| 92 | 97 |
| 93 // Setting an empty string as the tag should be equal to not setting
the tag at all. | 98 // Setting an empty string as the tag should be equal to not setting
the tag at all. |
| 94 assert_equals(noTagNotification.tag, emptyTagNotification.tag); | 99 assert_equals(noTagNotification.tag, emptyTagNotification.tag); |
| 95 | 100 |
| 96 var vibrateNotification = new Notification("My Notification", { | 101 var vibrateNotification = new Notification("My Notification", { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 assert_throws(new TypeError(), function() { | 142 assert_throws(new TypeError(), function() { |
| 138 new Notification("My Notification", { | 143 new Notification("My Notification", { |
| 139 actions: [{ type: "blah", action: "foo", title: "Foo" }] | 144 actions: [{ type: "blah", action: "foo", title: "Foo" }] |
| 140 }); | 145 }); |
| 141 }, 'Providing an invalid type for an action should throw a TypeError
.'); | 146 }, 'Providing an invalid type for an action should throw a TypeError
.'); |
| 142 | 147 |
| 143 }, 'Checks the properties exposed on the Notification object.'); | 148 }, 'Checks the properties exposed on the Notification object.'); |
| 144 </script> | 149 </script> |
| 145 </body> | 150 </body> |
| 146 </html> | 151 </html> |
| OLD | NEW |