Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / notifications / notification-properties.html
blobcddb8d0ea27b9e7b3ed345a01a268564961e2256
1 <!doctype html>
2 <html>
3 <head>
4 <title>Notifications: The Notification object exposes the expected properties.</title>
5 <script src="../resources/testharness.js"></script>
6 <script src="../resources/testharnessreport.js"></script>
7 </head>
8 <body>
9 <script>
10 // Tests that the Notification object exposes the properties per the
11 // semantics defined by the specification. When the test is being ran
12 // manually, grant Notification permission first.
13 test(function () {
14 assert_greater_than_equal(Notification.maxActions, 0);
16 var options = {
17 dir: "rtl",
18 lang: "nl-NL",
19 body: "Hallo, wereld!",
20 tag: "notification",
21 icon: "http://localhost/my_icon.png",
22 silent: true,
23 requireInteraction: true,
24 data: "my data",
25 actions: []
27 // Deliberately add more actions than are supported.
28 for (var i = 0; i < 2 * Notification.maxActions; i++) {
29 options.actions.push({
30 action: "" + i,
31 title: "Action " + i
32 });
35 var notification = new Notification("My Notification", options);
37 assert_equals(notification.title, "My Notification");
38 assert_equals(notification.dir, options.dir);
39 assert_equals(notification.lang, options.lang);
40 assert_equals(notification.body, options.body);
41 assert_equals(notification.tag, options.tag);
42 assert_equals(notification.icon, options.icon);
43 assert_true(notification.silent);
44 assert_true(notification.requireInteraction);
45 assert_equals(notification.data, options.data);
46 // Only the first maxActions actions should be reflected.
47 assert_object_equals(notification.actions, options.actions.slice(0, Notification.maxActions));
49 // Notification.actions should be immutable.
50 notification.actions.push({ title: "Foo" });
51 notification.actions.foo = "bar";
52 if (notification.actions.length) {
53 notification.actions[0].title = "Changed";
54 notification.actions[0].foo = "bar";
56 assert_object_equals(notification.actions, options.actions.slice(0, Notification.maxActions));
58 var emptyNotification = new Notification("My Notification");
60 assert_equals(emptyNotification.title, "My Notification");
61 assert_equals(emptyNotification.dir, "auto");
62 assert_equals(emptyNotification.lang, "");
63 assert_equals(emptyNotification.body, "");
64 assert_equals(emptyNotification.tag, "");
65 assert_equals(emptyNotification.icon, "");
66 assert_equals(notification.vibrate, null);
67 assert_false(emptyNotification.silent);
68 assert_false(emptyNotification.requireInteraction);
69 assert_equals(emptyNotification.data, null);
70 assert_array_equals(emptyNotification.actions, []);
72 var equalNotification = new Notification("My Notification", {
73 vibrate: [50, 10, 50, 10, 50],
74 data: { hello: "World!" },
75 actions: [
76 { action: "foo", title: "Foo" },
77 { action: "bar", title: "Bar" }
79 });
81 // Test equality of the object attributes.
82 assert_true(equalNotification.data === equalNotification.data, '`data` object equality');
84 // TODO(peter): This should pass before shipping Notification.vibrate.
85 //assert_true(equalNotification.vibrate === equalNotification.vibrate, '`vibrate` object equality');
87 // TODO(johnme): This should pass before shipping Notification.actions.
88 //assert_true(equalNotification.actions === equalNotification.actions, '`actions` object equality');
90 var serializedUrlNotification = new Notification("My Notification", {
91 icon: "http://example.com"
92 });
94 // Icon URLs should be returned in serialized form.
95 assert_equals(serializedUrlNotification.icon, "http://example.com/");
97 var noTagNotification = new Notification("My Notification"),
98 emptyTagNotification = new Notification("My Notification", { tag: "" });
100 // Setting an empty string as the tag should be equal to not setting the tag at all.
101 assert_equals(noTagNotification.tag, emptyTagNotification.tag);
103 var vibrateNotification = new Notification("My Notification", {
104 vibrate: 1000
107 // vibrate pattern should be returned in serialized form.
108 assert_array_equals(vibrateNotification.vibrate, [1000]);
110 // Tests that it must be a valid vibration sequence.
111 var pattern = new Array(100, 200, 300);
112 var sequenceVibrateNotification = new Notification("My Notification", {
113 vibrate: pattern
115 assert_array_equals(sequenceVibrateNotification.vibrate, pattern);
117 // Invalid vibrate pattern should be reset to 0.
118 var invalidVibrateNotification = new Notification("My Notification", {
119 vibrate: [100, 200, "invalid"]
121 assert_array_equals(invalidVibrateNotification.vibrate, [100, 200, 0]);
123 }, 'Checks the properties exposed on the Notification object.');
124 </script>
125 </body>
126 </html>