4 <title>Notifications: ServiceWorkerRegistration.getNotifications() and closing notifications.
</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 getNotifications() function when used in a document returns
13 // an array of the notifications which were previously displayed, and that closing
14 // one of them reflects when getting the notifications again.
15 async_test(function(test
) {
16 var scope
= 'resources/scope/' + location
.pathname
,
17 script
= 'resources/instrumentation-service-worker.js';
19 testRunner
.setPermission('notifications', 'granted', location
.origin
, location
.origin
);
21 var registration
= null;
22 getActiveServiceWorkerWithMessagePort(test
, script
, scope
).then(function(workerInfo
) {
23 registration
= workerInfo
.registration
;
25 return registration
.showNotification('Hello, world!', {
26 body
: 'First notification'
29 return registration
.getNotifications();
30 }).then(function(notifications
) {
31 assert_equals(notifications
.length
, 1);
32 assert_equals(notifications
[0].title
, 'Hello, world!');
34 notifications
[0].close();
36 return registration
.getNotifications();
37 }).then(function(notifications
) {
38 assert_equals(notifications
.length
, 0);
40 }).catch(unreached_rejection(test
));
42 }, 'ServiceWorkerRegistration.getNotifications() reflects closing notifications.');