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(notification.vibrate, []); |
Michael van Ouwerkerk
2016/05/12 15:04:59
nit: use emptyNotification here
Peter Beverloo
2016/05/12 15:10:13
Done.
| |
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_true(equalNotification.data === equalNotification.data, '`dat a` object equality'); |
73 | 79 |
74 // TODO(peter): This should pass before shipping Notification.vibrat e. | |
75 //assert_true(equalNotification.vibrate === equalNotification.vibrat e, '`vibrate` object equality'); | |
76 | |
77 var serializedUrlNotification = new Notification("My Notification", { | 80 var serializedUrlNotification = new Notification("My Notification", { |
78 icon: "https://example.com/icon.png", | 81 icon: "https://example.com/icon.png", |
79 badge: "https://example.com/badge.png" | 82 badge: "https://example.com/badge.png" |
80 }); | 83 }); |
81 | 84 |
82 // Icon URLs should be returned in serialized form. | 85 // Icon URLs should be returned in serialized form. |
83 assert_equals(serializedUrlNotification.icon, "https://example.com/i con.png"); | 86 assert_equals(serializedUrlNotification.icon, "https://example.com/i con.png"); |
84 assert_equals(serializedUrlNotification.badge, "https://example.com/ badge.png"); | 87 assert_equals(serializedUrlNotification.badge, "https://example.com/ badge.png"); |
85 | 88 |
86 var noTagNotification = new Notification("My Notification"), | 89 var noTagNotification = new Notification("My Notification"), |
87 emptyTagNotification = new Notification("My Notification", { tag : "" }); | 90 emptyTagNotification = new Notification("My Notification", { tag : "" }); |
88 | 91 |
89 // Setting an empty string as the tag should be equal to not setting the tag at all. | 92 // Setting an empty string as the tag should be equal to not setting the tag at all. |
90 assert_equals(noTagNotification.tag, emptyTagNotification.tag); | 93 assert_equals(noTagNotification.tag, emptyTagNotification.tag); |
91 | 94 |
92 var vibrateNotification = new Notification("My Notification", { | 95 var vibrateNotification = new Notification("My Notification", { |
93 vibrate: 1000 | 96 vibrate: 1000 |
94 }); | 97 }); |
95 | 98 |
96 // vibrate pattern should be returned in serialized form. | 99 // vibrate pattern should be returned in serialized form. |
97 assert_array_equals(vibrateNotification.vibrate, [1000]); | 100 assert_array_equals(vibrateNotification.vibrate, [1000]); |
98 | 101 |
102 // The `vibrate` property should be immutable. | |
103 assert_throws(null, () => vibrateNotification.vibrate.push(1000)); | |
104 | |
105 vibrateNotification.vibrate[0] = 2000; | |
106 assert_equals(vibrateNotification.vibrate[0], 1000); | |
107 | |
99 // Tests that it must be a valid vibration sequence. | 108 // Tests that it must be a valid vibration sequence. |
100 var pattern = new Array(100, 200, 300); | 109 var pattern = new Array(100, 200, 300); |
101 var sequenceVibrateNotification = new Notification("My Notification" , { | 110 var sequenceVibrateNotification = new Notification("My Notification" , { |
102 vibrate: pattern | 111 vibrate: pattern |
103 }); | 112 }); |
104 assert_array_equals(sequenceVibrateNotification.vibrate, pattern); | 113 assert_array_equals(sequenceVibrateNotification.vibrate, pattern); |
105 | 114 |
106 // Invalid vibrate pattern should be reset to 0. | 115 // Invalid vibrate pattern should be reset to 0. |
107 var invalidVibrateNotification = new Notification("My Notification", { | 116 var invalidVibrateNotification = new Notification("My Notification", { |
108 vibrate: [100, 200, "invalid"] | 117 vibrate: [100, 200, "invalid"] |
(...skipping 18 matching lines...) Expand all Loading... | |
127 assert_throws(new TypeError(), function() { | 136 assert_throws(new TypeError(), function() { |
128 new Notification("My Notification", { | 137 new Notification("My Notification", { |
129 actions: [{ type: "blah", action: "foo", title: "Foo" }] | 138 actions: [{ type: "blah", action: "foo", title: "Foo" }] |
130 }); | 139 }); |
131 }, 'Providing an invalid type for an action should throw a TypeError .'); | 140 }, 'Providing an invalid type for an action should throw a TypeError .'); |
132 | 141 |
133 }, 'Checks the properties exposed on the Notification object.'); | 142 }, 'Checks the properties exposed on the Notification object.'); |
134 </script> | 143 </script> |
135 </body> | 144 </body> |
136 </html> | 145 </html> |
OLD | NEW |