blob: 5dda76902db7595f2d929afb6f7450b013cf62c4 [file] [log] [blame]
<!doctype html>
<title>Notifications: ServiceWorkerRegistration.showNotification().</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>
// Tests that the showNotification() function when used in a Service Worker
// resolves a promise, and that the notificationclick event gets fired when
// we simulate a click on it. This test requires the test runner.
async_test(function(test) {
var scope = 'resources/scope/serviceworkerregistration-service-worker-click';
var script = 'instrumentation-service-worker.js';
var port;
testRunner.setPermission('notifications', 'granted', location.origin, location.origin);
getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(info) {
port = info.port;
// (1) Tell the Service Worker to display a Web Notification.
return sendCommand(port, {
command: 'show',
title: scope,
options: { body: 'Hello, world!' }
}).then(function(data) {
// (2) Confirm that the service worker displayed the notification successfully.
assert_true(data.success, 'The notification must have been displayed.');
return simulateNotificationClick(scope, -1 /* action_index */, port);
}).then(function(data) {
// (3) Confirm that the service worker handled the click on the correct notification.
assert_equals(data.notification.title, scope, 'The right notification must have been clicked.');
}, 'Clicking on a notification displayed by a Service Worker the notificationclick event.');