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 timestamp: 621046800000, |
25 silent: true, | 26 silent: true, |
26 requireInteraction: true, | 27 requireInteraction: true, |
27 data: "my data", | 28 data: "my data", |
28 actions: [] | 29 actions: [] |
29 }; | 30 }; |
30 | 31 |
31 var notification = new Notification("My Notification", options); | 32 var notification = new Notification("My Notification", options); |
32 | 33 |
33 assert_equals(notification.title, "My Notification"); | 34 assert_equals(notification.title, "My Notification"); |
34 assert_equals(notification.dir, options.dir); | 35 assert_equals(notification.dir, options.dir); |
35 assert_equals(notification.lang, options.lang); | 36 assert_equals(notification.lang, options.lang); |
36 assert_equals(notification.body, options.body); | 37 assert_equals(notification.body, options.body); |
37 assert_equals(notification.tag, options.tag); | 38 assert_equals(notification.tag, options.tag); |
38 assert_equals(notification.icon, options.icon); | 39 assert_equals(notification.icon, options.icon); |
| 40 assert_equals(notification.timestamp, options.timestamp); |
39 assert_true(notification.silent); | 41 assert_true(notification.silent); |
40 assert_true(notification.requireInteraction); | 42 assert_true(notification.requireInteraction); |
41 assert_equals(notification.data, options.data); | 43 assert_equals(notification.data, options.data); |
42 assert_array_equals(notification.actions, options.actions); | 44 assert_array_equals(notification.actions, options.actions); |
43 | 45 |
44 var emptyNotification = new Notification("My Notification"); | 46 var emptyNotification = new Notification("My Notification"); |
45 | 47 |
46 assert_equals(emptyNotification.title, "My Notification"); | 48 assert_equals(emptyNotification.title, "My Notification"); |
47 assert_equals(emptyNotification.dir, "auto"); | 49 assert_equals(emptyNotification.dir, "auto"); |
48 assert_equals(emptyNotification.lang, ""); | 50 assert_equals(emptyNotification.lang, ""); |
49 assert_equals(emptyNotification.body, ""); | 51 assert_equals(emptyNotification.body, ""); |
50 assert_equals(emptyNotification.tag, ""); | 52 assert_equals(emptyNotification.tag, ""); |
51 assert_equals(emptyNotification.icon, ""); | 53 assert_equals(emptyNotification.icon, ""); |
52 assert_equals(notification.vibrate, null); | 54 assert_equals(notification.vibrate, null); |
53 assert_false(emptyNotification.silent); | 55 assert_false(emptyNotification.silent); |
54 assert_false(emptyNotification.requireInteraction); | 56 assert_false(emptyNotification.requireInteraction); |
55 assert_equals(emptyNotification.data, null); | 57 assert_equals(emptyNotification.data, null); |
56 assert_array_equals(emptyNotification.actions, []); | 58 assert_array_equals(emptyNotification.actions, []); |
57 | 59 |
| 60 var timeDifference = Math.abs(Date.now() - emptyNotification.timesta
mp); |
| 61 assert_true(timeDifference < 16); // 16 is not significant, just to
reduce flakiness. |
| 62 |
58 var equalNotification = new Notification("My Notification", { | 63 var equalNotification = new Notification("My Notification", { |
59 vibrate: [50, 10, 50, 10, 50], | 64 vibrate: [50, 10, 50, 10, 50], |
60 data: { hello: "World!" } | 65 data: { hello: "World!" } |
61 }); | 66 }); |
62 | 67 |
63 // Test equality of the object attributes. | 68 // Test equality of the object attributes. |
64 assert_true(equalNotification.data === equalNotification.data, '`dat
a` object equality'); | 69 assert_true(equalNotification.data === equalNotification.data, '`dat
a` object equality'); |
65 | 70 |
66 // TODO(peter): This should pass before shipping Notification.vibrat
e. | 71 // TODO(peter): This should pass before shipping Notification.vibrat
e. |
67 //assert_true(equalNotification.vibrate === equalNotification.vibrat
e, '`vibrate` object equality'); | 72 //assert_true(equalNotification.vibrate === equalNotification.vibrat
e, '`vibrate` object equality'); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 assert_throws(new TypeError(), function() { | 108 assert_throws(new TypeError(), function() { |
104 new Notification("My Notification", { | 109 new Notification("My Notification", { |
105 actions: [{ action: "foo", title: "Foo" }] | 110 actions: [{ action: "foo", title: "Foo" }] |
106 }); | 111 }); |
107 }, 'Providing non-empty `actions` for a non-persistent notification
should throw a TypeError.'); | 112 }, 'Providing non-empty `actions` for a non-persistent notification
should throw a TypeError.'); |
108 | 113 |
109 }, 'Checks the properties exposed on the Notification object.'); | 114 }, 'Checks the properties exposed on the Notification object.'); |
110 </script> | 115 </script> |
111 </body> | 116 </body> |
112 </html> | 117 </html> |
OLD | NEW |