| 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 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 assert_equals(notification.body, options.body); | 38 assert_equals(notification.body, options.body); |
| 39 assert_equals(notification.tag, options.tag); | 39 assert_equals(notification.tag, options.tag); |
| 40 assert_equals(notification.icon, options.icon); | 40 assert_equals(notification.icon, options.icon); |
| 41 assert_equals(notification.badge, options.badge); | 41 assert_equals(notification.badge, options.badge); |
| 42 assert_equals(notification.timestamp, options.timestamp); | 42 assert_equals(notification.timestamp, options.timestamp); |
| 43 assert_true(notification.silent); | 43 assert_true(notification.silent); |
| 44 assert_true(notification.requireInteraction); | 44 assert_true(notification.requireInteraction); |
| 45 assert_equals(notification.data, options.data); | 45 assert_equals(notification.data, options.data); |
| 46 assert_array_equals(notification.actions, options.actions); | 46 assert_array_equals(notification.actions, options.actions); |
| 47 | 47 |
| 48 // The `actions` field should be immutable. |
| 49 assert_throws(null, () => notification.actions.push(null)); |
| 50 |
| 51 notification.actions.foo = 'bar'; |
| 52 assert_false(notification.actions.hasOwnProperty('foo')); |
| 53 |
| 48 var emptyNotification = new Notification("My Notification"); | 54 var emptyNotification = new Notification("My Notification"); |
| 49 | 55 |
| 50 assert_equals(emptyNotification.title, "My Notification"); | 56 assert_equals(emptyNotification.title, "My Notification"); |
| 51 assert_equals(emptyNotification.dir, "auto"); | 57 assert_equals(emptyNotification.dir, "auto"); |
| 52 assert_equals(emptyNotification.lang, ""); | 58 assert_equals(emptyNotification.lang, ""); |
| 53 assert_equals(emptyNotification.body, ""); | 59 assert_equals(emptyNotification.body, ""); |
| 54 assert_equals(emptyNotification.tag, ""); | 60 assert_equals(emptyNotification.tag, ""); |
| 55 assert_equals(emptyNotification.icon, ""); | 61 assert_equals(emptyNotification.icon, ""); |
| 56 assert_equals(emptyNotification.badge, ""); | 62 assert_equals(emptyNotification.badge, ""); |
| 57 assert_equals(notification.vibrate, null); | 63 assert_array_equals(emptyNotification.vibrate, []); |
| 58 assert_false(emptyNotification.silent); | 64 assert_false(emptyNotification.silent); |
| 59 assert_false(emptyNotification.requireInteraction); | 65 assert_false(emptyNotification.requireInteraction); |
| 60 assert_equals(emptyNotification.data, null); | 66 assert_equals(emptyNotification.data, null); |
| 61 assert_array_equals(emptyNotification.actions, []); | 67 assert_array_equals(emptyNotification.actions, []); |
| 62 | 68 |
| 63 var timeDifference = Math.abs(Date.now() - emptyNotification.timesta
mp); | 69 var timeDifference = Math.abs(Date.now() - emptyNotification.timesta
mp); |
| 64 assert_true(timeDifference < 16); // 16 is not significant, just to
reduce flakiness. | 70 assert_true(timeDifference < 16); // 16 is not significant, just to
reduce flakiness. |
| 65 | 71 |
| 66 var equalNotification = new Notification("My Notification", { | 72 var equalNotification = new Notification("My Notification", { |
| 67 vibrate: [50, 10, 50, 10, 50], | 73 vibrate: [50, 10, 50, 10, 50], |
| 68 data: { hello: "World!" } | 74 data: { hello: "World!" } |
| 69 }); | 75 }); |
| 70 | 76 |
| 71 // Test equality of the object attributes. | 77 // Test equality of the object attributes. |
| 72 assert_true(equalNotification.data === equalNotification.data, '`dat
a` object equality'); | 78 assert_equals(equalNotification.data, equalNotification.data, '`data
` object equality'); |
| 73 | 79 assert_equals(equalNotification.vibrate, equalNotification.vibrate,
'`vibrate` object equality'); |
| 74 // TODO(peter): This should pass before shipping Notification.vibrat
e. | |
| 75 //assert_true(equalNotification.vibrate === equalNotification.vibrat
e, '`vibrate` object equality'); | |
| 76 | 80 |
| 77 var serializedUrlNotification = new Notification("My Notification",
{ | 81 var serializedUrlNotification = new Notification("My Notification",
{ |
| 78 icon: "https://example.com/icon.png", | 82 icon: "https://example.com/icon.png", |
| 79 badge: "https://example.com/badge.png" | 83 badge: "https://example.com/badge.png" |
| 80 }); | 84 }); |
| 81 | 85 |
| 82 // Icon URLs should be returned in serialized form. | 86 // Icon URLs should be returned in serialized form. |
| 83 assert_equals(serializedUrlNotification.icon, "https://example.com/i
con.png"); | 87 assert_equals(serializedUrlNotification.icon, "https://example.com/i
con.png"); |
| 84 assert_equals(serializedUrlNotification.badge, "https://example.com/
badge.png"); | 88 assert_equals(serializedUrlNotification.badge, "https://example.com/
badge.png"); |
| 85 | 89 |
| 86 var noTagNotification = new Notification("My Notification"), | 90 var noTagNotification = new Notification("My Notification"), |
| 87 emptyTagNotification = new Notification("My Notification", { tag
: "" }); | 91 emptyTagNotification = new Notification("My Notification", { tag
: "" }); |
| 88 | 92 |
| 89 // Setting an empty string as the tag should be equal to not setting
the tag at all. | 93 // Setting an empty string as the tag should be equal to not setting
the tag at all. |
| 90 assert_equals(noTagNotification.tag, emptyTagNotification.tag); | 94 assert_equals(noTagNotification.tag, emptyTagNotification.tag); |
| 91 | 95 |
| 92 var vibrateNotification = new Notification("My Notification", { | 96 var vibrateNotification = new Notification("My Notification", { |
| 93 vibrate: 1000 | 97 vibrate: 1000 |
| 94 }); | 98 }); |
| 95 | 99 |
| 96 // vibrate pattern should be returned in serialized form. | 100 // vibrate pattern should be returned in serialized form. |
| 97 assert_array_equals(vibrateNotification.vibrate, [1000]); | 101 assert_array_equals(vibrateNotification.vibrate, [1000]); |
| 98 | 102 |
| 103 // The `vibrate` property should be immutable. |
| 104 assert_throws(null, () => vibrateNotification.vibrate.push(1000)); |
| 105 |
| 106 vibrateNotification.vibrate[0] = 2000; |
| 107 assert_equals(vibrateNotification.vibrate[0], 1000); |
| 108 |
| 99 // Tests that it must be a valid vibration sequence. | 109 // Tests that it must be a valid vibration sequence. |
| 100 var pattern = new Array(100, 200, 300); | 110 var pattern = new Array(100, 200, 300); |
| 101 var sequenceVibrateNotification = new Notification("My Notification"
, { | 111 var sequenceVibrateNotification = new Notification("My Notification"
, { |
| 102 vibrate: pattern | 112 vibrate: pattern |
| 103 }); | 113 }); |
| 104 assert_array_equals(sequenceVibrateNotification.vibrate, pattern); | 114 assert_array_equals(sequenceVibrateNotification.vibrate, pattern); |
| 105 | 115 |
| 106 // Invalid vibrate pattern should be reset to 0. | 116 // Invalid vibrate pattern should be reset to 0. |
| 107 var invalidVibrateNotification = new Notification("My Notification",
{ | 117 var invalidVibrateNotification = new Notification("My Notification",
{ |
| 108 vibrate: [100, 200, "invalid"] | 118 vibrate: [100, 200, "invalid"] |
| (...skipping 18 matching lines...) Expand all Loading... |
| 127 assert_throws(new TypeError(), function() { | 137 assert_throws(new TypeError(), function() { |
| 128 new Notification("My Notification", { | 138 new Notification("My Notification", { |
| 129 actions: [{ type: "blah", action: "foo", title: "Foo" }] | 139 actions: [{ type: "blah", action: "foo", title: "Foo" }] |
| 130 }); | 140 }); |
| 131 }, 'Providing an invalid type for an action should throw a TypeError
.'); | 141 }, 'Providing an invalid type for an action should throw a TypeError
.'); |
| 132 | 142 |
| 133 }, 'Checks the properties exposed on the Notification object.'); | 143 }, 'Checks the properties exposed on the Notification object.'); |
| 134 </script> | 144 </script> |
| 135 </body> | 145 </body> |
| 136 </html> | 146 </html> |
| OLD | NEW |