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 var options = { | 14 var options = { |
15 dir: "rtl", | 15 dir: "rtl", |
16 lang: "nl-NL", | 16 lang: "nl-NL", |
17 body: "Hallo, wereld!", | 17 body: "Hallo, wereld!", |
18 tag: "notification", | 18 tag: "notification", |
19 icon: "http://localhost/my_icon.png", | 19 icon: "http://localhost/my_icon.png", |
20 silent: true, | 20 silent: true, |
21 data: "my data" | 21 data: "my data", |
22 actions: [{title: "Action 1"}, {title: "Action 2"}, {title: "Act ion 3"}] | |
22 }; | 23 }; |
23 | 24 |
24 var notification = new Notification("My Notification", options); | 25 var notification = new Notification("My Notification", options); |
25 | 26 |
26 assert_equals(notification.title, "My Notification"); | 27 assert_equals(notification.title, "My Notification"); |
27 assert_equals(notification.dir, options.dir); | 28 assert_equals(notification.dir, options.dir); |
28 assert_equals(notification.lang, options.lang); | 29 assert_equals(notification.lang, options.lang); |
29 assert_equals(notification.body, options.body); | 30 assert_equals(notification.body, options.body); |
30 assert_equals(notification.tag, options.tag); | 31 assert_equals(notification.tag, options.tag); |
31 assert_equals(notification.icon, options.icon); | 32 assert_equals(notification.icon, options.icon); |
32 assert_true(notification.silent); | 33 assert_true(notification.silent); |
33 assert_equals(notification.data, options.data); | 34 assert_equals(notification.data, options.data); |
35 // We only support 2 actions; the rest should be skipped. | |
36 assert_object_equals(notification.actions, options.actions.slice(0, 2)); | |
Peter Beverloo
2015/07/30 16:24:07
Could you add a line testing that we can modify no
Peter Beverloo
2015/07/30 16:24:07
Please do not assume "2", and actually check Notif
johnme
2015/07/31 15:10:10
Done.
johnme
2015/07/31 15:10:10
Actually, no, we can't modify notification.actions
| |
34 | 37 |
35 var emptyNotification = new Notification("My Notification"); | 38 var emptyNotification = new Notification("My Notification"); |
36 | 39 |
37 assert_equals(emptyNotification.title, "My Notification"); | 40 assert_equals(emptyNotification.title, "My Notification"); |
38 assert_equals(emptyNotification.dir, "auto"); | 41 assert_equals(emptyNotification.dir, "auto"); |
39 assert_equals(emptyNotification.lang, ""); | 42 assert_equals(emptyNotification.lang, ""); |
40 assert_equals(emptyNotification.body, ""); | 43 assert_equals(emptyNotification.body, ""); |
41 assert_equals(emptyNotification.tag, ""); | 44 assert_equals(emptyNotification.tag, ""); |
42 assert_equals(emptyNotification.icon, ""); | 45 assert_equals(emptyNotification.icon, ""); |
43 assert_equals(notification.vibrate, null); | 46 assert_equals(notification.vibrate, null); |
44 assert_false(emptyNotification.silent); | 47 assert_false(emptyNotification.silent); |
45 assert_equals(emptyNotification.data, null); | 48 assert_equals(emptyNotification.data, null); |
49 assert_array_equals(emptyNotification.actions, []); | |
46 | 50 |
47 var invalidIconNotification = new Notification("My Notification", { | 51 var invalidIconNotification = new Notification("My Notification", { |
48 icon: "http://test:test/" | 52 icon: "http://test:test/" |
49 }); | 53 }); |
50 | 54 |
51 // Invalid icon URLs should be reset to an empty string. | 55 // Invalid icon URLs should be reset to an empty string. |
52 assert_equals(invalidIconNotification.icon, ""); | 56 assert_equals(invalidIconNotification.icon, ""); |
53 | 57 |
54 var serializedUrlNotification = new Notification("My Notification", { | 58 var serializedUrlNotification = new Notification("My Notification", { |
55 icon: "http://example.com" | 59 icon: "http://example.com" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 Array.apply(null, new Array(99)).map(Number.prototype.valueO f, 10000)); | 99 Array.apply(null, new Array(99)).map(Number.prototype.valueO f, 10000)); |
96 | 100 |
97 // Verifying the exception throwing behavior, when silent set true a nd vibrate is presented. | 101 // Verifying the exception throwing behavior, when silent set true a nd vibrate is presented. |
98 assert_throws(new TypeError(), function() { | 102 assert_throws(new TypeError(), function() { |
99 var notification = new Notification("My Notification", { | 103 var notification = new Notification("My Notification", { |
100 silent: true, | 104 silent: true, |
101 vibrate: 1000 | 105 vibrate: 1000 |
102 }); | 106 }); |
103 }, 'Set vibrate, when silent is true.'); | 107 }, 'Set vibrate, when silent is true.'); |
104 | 108 |
109 // Check exception is thrown when an action doesn't contain title, | |
110 // or title is an empty string. | |
111 assert_throws(new TypeError(), function() { | |
112 var notification = new Notification("My Notification", { | |
113 actions: [{}] | |
114 }); | |
115 }, 'Provide action without title.'); | |
116 assert_throws(new TypeError(), function() { | |
117 var notification = new Notification("My Notification", { | |
118 actions: [{title: ""}] | |
119 }); | |
120 }, 'Provide action with empty title.'); | |
121 | |
105 }, 'Checks the properties exposed on the Notification object.'); | 122 }, 'Checks the properties exposed on the Notification object.'); |
106 </script> | 123 </script> |
107 </body> | 124 </body> |
108 </html> | 125 </html> |
OLD | NEW |