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 badge: "http://localhost/badge.png", |
25 timestamp: 621046800000, | 26 timestamp: 621046800000, |
26 silent: true, | 27 silent: true, |
27 requireInteraction: true, | 28 requireInteraction: true, |
28 data: "my data", | 29 data: "my data", |
29 actions: [] | 30 actions: [] |
30 }; | 31 }; |
31 | 32 |
32 var notification = new Notification("My Notification", options); | 33 var notification = new Notification("My Notification", options); |
33 | 34 |
34 assert_equals(notification.title, "My Notification"); | 35 assert_equals(notification.title, "My Notification"); |
35 assert_equals(notification.dir, options.dir); | 36 assert_equals(notification.dir, options.dir); |
36 assert_equals(notification.lang, options.lang); | 37 assert_equals(notification.lang, options.lang); |
37 assert_equals(notification.body, options.body); | 38 assert_equals(notification.body, options.body); |
38 assert_equals(notification.tag, options.tag); | 39 assert_equals(notification.tag, options.tag); |
39 assert_equals(notification.icon, options.icon); | 40 assert_equals(notification.icon, options.icon); |
| 41 assert_equals(notification.badge, options.badge); |
40 assert_equals(notification.timestamp, options.timestamp); | 42 assert_equals(notification.timestamp, options.timestamp); |
41 assert_true(notification.silent); | 43 assert_true(notification.silent); |
42 assert_true(notification.requireInteraction); | 44 assert_true(notification.requireInteraction); |
43 assert_equals(notification.data, options.data); | 45 assert_equals(notification.data, options.data); |
44 assert_array_equals(notification.actions, options.actions); | 46 assert_array_equals(notification.actions, options.actions); |
45 | 47 |
46 var emptyNotification = new Notification("My Notification"); | 48 var emptyNotification = new Notification("My Notification"); |
47 | 49 |
48 assert_equals(emptyNotification.title, "My Notification"); | 50 assert_equals(emptyNotification.title, "My Notification"); |
49 assert_equals(emptyNotification.dir, "auto"); | 51 assert_equals(emptyNotification.dir, "auto"); |
50 assert_equals(emptyNotification.lang, ""); | 52 assert_equals(emptyNotification.lang, ""); |
51 assert_equals(emptyNotification.body, ""); | 53 assert_equals(emptyNotification.body, ""); |
52 assert_equals(emptyNotification.tag, ""); | 54 assert_equals(emptyNotification.tag, ""); |
53 assert_equals(emptyNotification.icon, ""); | 55 assert_equals(emptyNotification.icon, ""); |
| 56 assert_equals(emptyNotification.badge, ""); |
54 assert_equals(notification.vibrate, null); | 57 assert_equals(notification.vibrate, null); |
55 assert_false(emptyNotification.silent); | 58 assert_false(emptyNotification.silent); |
56 assert_false(emptyNotification.requireInteraction); | 59 assert_false(emptyNotification.requireInteraction); |
57 assert_equals(emptyNotification.data, null); | 60 assert_equals(emptyNotification.data, null); |
58 assert_array_equals(emptyNotification.actions, []); | 61 assert_array_equals(emptyNotification.actions, []); |
59 | 62 |
60 var timeDifference = Math.abs(Date.now() - emptyNotification.timesta
mp); | 63 var timeDifference = Math.abs(Date.now() - emptyNotification.timesta
mp); |
61 assert_true(timeDifference < 16); // 16 is not significant, just to
reduce flakiness. | 64 assert_true(timeDifference < 16); // 16 is not significant, just to
reduce flakiness. |
62 | 65 |
63 var equalNotification = new Notification("My Notification", { | 66 var equalNotification = new Notification("My Notification", { |
64 vibrate: [50, 10, 50, 10, 50], | 67 vibrate: [50, 10, 50, 10, 50], |
65 data: { hello: "World!" } | 68 data: { hello: "World!" } |
66 }); | 69 }); |
67 | 70 |
68 // Test equality of the object attributes. | 71 // Test equality of the object attributes. |
69 assert_true(equalNotification.data === equalNotification.data, '`dat
a` object equality'); | 72 assert_true(equalNotification.data === equalNotification.data, '`dat
a` object equality'); |
70 | 73 |
71 // TODO(peter): This should pass before shipping Notification.vibrat
e. | 74 // TODO(peter): This should pass before shipping Notification.vibrat
e. |
72 //assert_true(equalNotification.vibrate === equalNotification.vibrat
e, '`vibrate` object equality'); | 75 //assert_true(equalNotification.vibrate === equalNotification.vibrat
e, '`vibrate` object equality'); |
73 | 76 |
74 var serializedUrlNotification = new Notification("My Notification",
{ | 77 var serializedUrlNotification = new Notification("My Notification",
{ |
75 icon: "http://example.com" | 78 icon: "https://example.com/icon.png", |
| 79 badge: "https://example.com/badge.png" |
76 }); | 80 }); |
77 | 81 |
78 // Icon URLs should be returned in serialized form. | 82 // Icon URLs should be returned in serialized form. |
79 assert_equals(serializedUrlNotification.icon, "http://example.com/")
; | 83 assert_equals(serializedUrlNotification.icon, "https://example.com/i
con.png"); |
| 84 assert_equals(serializedUrlNotification.badge, "https://example.com/
badge.png"); |
80 | 85 |
81 var noTagNotification = new Notification("My Notification"), | 86 var noTagNotification = new Notification("My Notification"), |
82 emptyTagNotification = new Notification("My Notification", { tag
: "" }); | 87 emptyTagNotification = new Notification("My Notification", { tag
: "" }); |
83 | 88 |
84 // Setting an empty string as the tag should be equal to not setting
the tag at all. | 89 // Setting an empty string as the tag should be equal to not setting
the tag at all. |
85 assert_equals(noTagNotification.tag, emptyTagNotification.tag); | 90 assert_equals(noTagNotification.tag, emptyTagNotification.tag); |
86 | 91 |
87 var vibrateNotification = new Notification("My Notification", { | 92 var vibrateNotification = new Notification("My Notification", { |
88 vibrate: 1000 | 93 vibrate: 1000 |
89 }); | 94 }); |
(...skipping 18 matching lines...) Expand all Loading... |
108 assert_throws(new TypeError(), function() { | 113 assert_throws(new TypeError(), function() { |
109 new Notification("My Notification", { | 114 new Notification("My Notification", { |
110 actions: [{ action: "foo", title: "Foo" }] | 115 actions: [{ action: "foo", title: "Foo" }] |
111 }); | 116 }); |
112 }, 'Providing non-empty `actions` for a non-persistent notification
should throw a TypeError.'); | 117 }, 'Providing non-empty `actions` for a non-persistent notification
should throw a TypeError.'); |
113 | 118 |
114 }, 'Checks the properties exposed on the Notification object.'); | 119 }, 'Checks the properties exposed on the Notification object.'); |
115 </script> | 120 </script> |
116 </body> | 121 </body> |
117 </html> | 122 </html> |
OLD | NEW |