| 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 icon: "http://localhost/my_icon.png", | 24 icon: "http://localhost/my_icon.png", |
| 25 silent: true, | 25 silent: true, |
| 26 requireInteraction: true, | 26 requireInteraction: true, |
| 27 data: "my data", | 27 data: "my data", |
| 28 actions: [] | 28 actions: [] |
| 29 }; | 29 }; |
| 30 // Deliberately add more actions than are supported. | |
| 31 for (var i = 0; i < 2 * Notification.maxActions; i++) { | |
| 32 options.actions.push({ | |
| 33 action: "" + i, | |
| 34 title: "Action " + i | |
| 35 }); | |
| 36 } | |
| 37 | 30 |
| 38 var notification = new Notification("My Notification", options); | 31 var notification = new Notification("My Notification", options); |
| 39 | 32 |
| 40 assert_equals(notification.title, "My Notification"); | 33 assert_equals(notification.title, "My Notification"); |
| 41 assert_equals(notification.dir, options.dir); | 34 assert_equals(notification.dir, options.dir); |
| 42 assert_equals(notification.lang, options.lang); | 35 assert_equals(notification.lang, options.lang); |
| 43 assert_equals(notification.body, options.body); | 36 assert_equals(notification.body, options.body); |
| 44 assert_equals(notification.tag, options.tag); | 37 assert_equals(notification.tag, options.tag); |
| 45 assert_equals(notification.icon, options.icon); | 38 assert_equals(notification.icon, options.icon); |
| 46 assert_true(notification.silent); | 39 assert_true(notification.silent); |
| 47 assert_true(notification.requireInteraction); | 40 assert_true(notification.requireInteraction); |
| 48 assert_equals(notification.data, options.data); | 41 assert_equals(notification.data, options.data); |
| 49 // Only the first maxActions actions should be reflected. | 42 assert_array_equals(notification.actions, options.actions); |
| 50 assert_object_equals(notification.actions, options.actions.slice(0,
Notification.maxActions)); | |
| 51 | |
| 52 // Notification.actions should be immutable. | |
| 53 notification.actions.push({ title: "Foo" }); | |
| 54 notification.actions.foo = "bar"; | |
| 55 if (notification.actions.length) { | |
| 56 notification.actions[0].title = "Changed"; | |
| 57 notification.actions[0].foo = "bar"; | |
| 58 } | |
| 59 assert_object_equals(notification.actions, options.actions.slice(0,
Notification.maxActions)); | |
| 60 | 43 |
| 61 var emptyNotification = new Notification("My Notification"); | 44 var emptyNotification = new Notification("My Notification"); |
| 62 | 45 |
| 63 assert_equals(emptyNotification.title, "My Notification"); | 46 assert_equals(emptyNotification.title, "My Notification"); |
| 64 assert_equals(emptyNotification.dir, "auto"); | 47 assert_equals(emptyNotification.dir, "auto"); |
| 65 assert_equals(emptyNotification.lang, ""); | 48 assert_equals(emptyNotification.lang, ""); |
| 66 assert_equals(emptyNotification.body, ""); | 49 assert_equals(emptyNotification.body, ""); |
| 67 assert_equals(emptyNotification.tag, ""); | 50 assert_equals(emptyNotification.tag, ""); |
| 68 assert_equals(emptyNotification.icon, ""); | 51 assert_equals(emptyNotification.icon, ""); |
| 69 assert_equals(notification.vibrate, null); | 52 assert_equals(notification.vibrate, null); |
| 70 assert_false(emptyNotification.silent); | 53 assert_false(emptyNotification.silent); |
| 71 assert_false(emptyNotification.requireInteraction); | 54 assert_false(emptyNotification.requireInteraction); |
| 72 assert_equals(emptyNotification.data, null); | 55 assert_equals(emptyNotification.data, null); |
| 73 assert_array_equals(emptyNotification.actions, []); | 56 assert_array_equals(emptyNotification.actions, []); |
| 74 | 57 |
| 75 var equalNotification = new Notification("My Notification", { | 58 var equalNotification = new Notification("My Notification", { |
| 76 vibrate: [50, 10, 50, 10, 50], | 59 vibrate: [50, 10, 50, 10, 50], |
| 77 data: { hello: "World!" }, | 60 data: { hello: "World!" } |
| 78 actions: [ | |
| 79 { action: "foo", title: "Foo" }, | |
| 80 { action: "bar", title: "Bar" } | |
| 81 ] | |
| 82 }); | 61 }); |
| 83 | 62 |
| 84 // Test equality of the object attributes. | 63 // Test equality of the object attributes. |
| 85 assert_true(equalNotification.data === equalNotification.data, '`dat
a` object equality'); | 64 assert_true(equalNotification.data === equalNotification.data, '`dat
a` object equality'); |
| 86 | 65 |
| 87 // TODO(peter): This should pass before shipping Notification.vibrat
e. | 66 // TODO(peter): This should pass before shipping Notification.vibrat
e. |
| 88 //assert_true(equalNotification.vibrate === equalNotification.vibrat
e, '`vibrate` object equality'); | 67 //assert_true(equalNotification.vibrate === equalNotification.vibrat
e, '`vibrate` object equality'); |
| 89 | 68 |
| 90 // TODO(johnme): This should pass before shipping Notification.actio
ns. | |
| 91 //assert_true(equalNotification.actions === equalNotification.action
s, '`actions` object equality'); | |
| 92 | |
| 93 var serializedUrlNotification = new Notification("My Notification",
{ | 69 var serializedUrlNotification = new Notification("My Notification",
{ |
| 94 icon: "http://example.com" | 70 icon: "http://example.com" |
| 95 }); | 71 }); |
| 96 | 72 |
| 97 // Icon URLs should be returned in serialized form. | 73 // Icon URLs should be returned in serialized form. |
| 98 assert_equals(serializedUrlNotification.icon, "http://example.com/")
; | 74 assert_equals(serializedUrlNotification.icon, "http://example.com/")
; |
| 99 | 75 |
| 100 var noTagNotification = new Notification("My Notification"), | 76 var noTagNotification = new Notification("My Notification"), |
| 101 emptyTagNotification = new Notification("My Notification", { tag
: "" }); | 77 emptyTagNotification = new Notification("My Notification", { tag
: "" }); |
| 102 | 78 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 116 vibrate: pattern | 92 vibrate: pattern |
| 117 }); | 93 }); |
| 118 assert_array_equals(sequenceVibrateNotification.vibrate, pattern); | 94 assert_array_equals(sequenceVibrateNotification.vibrate, pattern); |
| 119 | 95 |
| 120 // Invalid vibrate pattern should be reset to 0. | 96 // Invalid vibrate pattern should be reset to 0. |
| 121 var invalidVibrateNotification = new Notification("My Notification",
{ | 97 var invalidVibrateNotification = new Notification("My Notification",
{ |
| 122 vibrate: [100, 200, "invalid"] | 98 vibrate: [100, 200, "invalid"] |
| 123 }); | 99 }); |
| 124 assert_array_equals(invalidVibrateNotification.vibrate, [100, 200, 0
]); | 100 assert_array_equals(invalidVibrateNotification.vibrate, [100, 200, 0
]); |
| 125 | 101 |
| 102 // Notification actions should only be supported for persistent noti
fications. |
| 103 assert_throws(new TypeError(), function() { |
| 104 new Notification("My Notification", { |
| 105 actions: [{ action: "foo", title: "Foo" }] |
| 106 }); |
| 107 }, 'Providing non-empty `actions` for a non-persistent notification
should throw a TypeError.'); |
| 108 |
| 126 }, 'Checks the properties exposed on the Notification object.'); | 109 }, 'Checks the properties exposed on the Notification object.'); |
| 127 </script> | 110 </script> |
| 128 </body> | 111 </body> |
| 129 </html> | 112 </html> |
| OLD | NEW |