blob: f813359fc172c8de84d41bfca110f37e61b652c0 [file] [log] [blame]
<!doctype html>
<html>
<head>
<title>Notifications: ServiceWorkerRegistration.getNotifications() when created by the Service Worker.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
<script src="resources/test-helpers.js"></script>
</head>
<body>
<script>
// Tests that the getNotifications() function when used in a document returns
// an array of the notifications which were previously displayed by the
// Service Worker.
async_test(function(test) {
var scope = 'resources/scope/' + location.pathname;
var script = 'instrumentation-service-worker.js';
var port;
var registration;
testRunner.setPermission('notifications', 'granted', location.origin, location.origin);
getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(info) {
port = info.port;
registration = info.registration;
// (1) Tell the Service Worker to display a new Notification and wait for it
// to have been displayed to the user.
return sendCommand(port, {
command: 'show',
title: scope,
options: { body: 'Hello, world!' }
});
}).then(function(data) {
assert_true(data.success);
// (2) Get a list of all notifications in the document.
return registration.getNotifications();
}).then(function(notifications) {
// (3) Verify that there's only one notification: the one we just showed.
assert_equals(notifications.length, 1);
assert_equals(notifications[0].title, scope);
assert_equals(notifications[0].body, 'Hello, world!');
test.done();
}).catch(unreached_rejection(test));
}, 'ServiceWorkerRegistration.getNotifications() when created by a Service Worker.');
</script>
</body>
</html>