4 <title>Notifications: Property reflection in the
"notificationclick" event.
</title>
5 <script src=
"../resources/testharness.js"></script>
6 <script src=
"../resources/testharnessreport.js"></script>
7 <script src=
"../serviceworker/resources/test-helpers.js"></script>
8 <script src=
"resources/test-helpers.js"></script>
12 // Tests that the notification available in the "notificationclick" event in the
13 // Service Worker accurately reflects the attributes with which the notification
14 // was created (for this test --) in the document.
16 async_test(function(test
) {
17 var scope
= 'resources/scope/' + location
.pathname
,
18 script
= 'resources/instrumentation-service-worker.js';
24 body
: 'Hello, world!',
26 // FIXME: Relative URLs for the icon attribute currently get reflected as
27 // an absolute URL, which should probably be the given relative URL.
28 icon
: 'https://example/icon.png',
29 vibrate
: [100, 200, 300],
31 requireInteraction
: true,
34 string
: '\uDFFF\u0000\uDBFF',
38 actions
: [{ action
: 'one', title
: 'Action 1' },
39 { action
: 'two', title
: 'Action 2' },
40 { action
: 'three', title
: 'Action 3' }]
43 testRunner
.setPermission('notifications', 'granted', location
.origin
, location
.origin
);
44 getActiveServiceWorkerWithMessagePort(test
, script
, scope
).then(function(workerInfo
) {
45 // (1) Tell the Service Worker to display a Web Notification.
46 workerInfo
.port
.postMessage({
53 workerInfo
.port
.addEventListener('message', function(event
) {
54 if (typeof event
.data
!= 'object' || !event
.data
.command
) {
55 assert_unreached('Invalid message from the Service Worker.');
59 // (2) Listen for confirmation from the Service Worker that the
60 // notification's display promise has been resolved.
61 if (event
.data
.command
== 'show') {
62 assert_true(event
.data
.success
, 'The notification must have been displayed.');
63 testRunner
.simulateWebNotificationClick(scope
);
67 // (3) Listen for confirmation from the Service Worker that the
68 // notification has been clicked on. Make sure that all properties
69 // set on the Notification object are as expected.
70 assert_equals(event
.data
.command
, 'click', 'The notification was expected to be clicked.');
72 options
.actions
= options
.actions
.slice(0, Notification
.maxActions
);
73 Object
.keys(options
).forEach(function(key
) {
74 if (typeof options
[key
] == 'object')
75 assert_object_equals(event
.data
.notification
[key
], options
[key
], 'The ' + key
+ ' field must be the same.');
77 assert_equals(event
.data
.notification
[key
], options
[key
], 'The ' + key
+ ' field must be the same.');
82 }).catch(unreached_rejection(test
));
84 }, 'Clicking on a notification displayed by a Service Worker the notificationclick event.');