4 <title>Notifications: ServiceWorkerRegistration.getNotifications() when created by the Service Worker.
</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 by the
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
);
22 getActiveServiceWorkerWithMessagePort(test
, script
, scope
).then(function(workerInfo
) {
25 // (1) Tell the Service Worker to display a new Notification and wait for it
26 // to have been displayed to the user.
27 info
.port
.postMessage({
31 options
: { body
: 'Hello, world!' }
34 return new Promise(function(resolve
) {
35 info
.port
.addEventListener('message', function(event
) {
36 if (typeof event
.data
!= 'object' || !event
.data
.command
) {
37 assert_unreached('Invalid message from the Service Worker.');
41 assert_equals(event
.data
.command
, 'show');
46 // (2) Get a list of all notifications in the document.
47 return info
.registration
.getNotifications();
48 }).then(function(notifications
) {
49 // (3) Verify that there's only one notification: the one we just showed.
50 assert_equals(notifications
.length
, 1);
52 assert_equals(notifications
[0].title
, scope
);
53 assert_equals(notifications
[0].body
, 'Hello, world!');
57 }).catch(unreached_rejection(test
));
59 }, 'ServiceWorkerRegistration.getNotifications() when created by a Service Worker.');