blob: ec54c8814b7cde2e7f91caef8bc5e7abcc3aebd7 [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 resolves a promise, and that the
// notificationclick event gets fired on the Service Worker when we simulate a
// click on it. This test requires the test runner.
async_test(function(test) {
var scope = 'resources/scope/serviceworkerregistration-document-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) Display a Web Notification from the document.
assert_inherits(info.registration, 'showNotification', 'showNotification() must be exposed.');
return info.registration.showNotification(scope, {
body: 'Hello, world!',
icon: '/icon.png'
}).then(function() {
// (2) Simulate a click on the notification that has been displayed.
return simulateNotificationClick(scope, -1 /* action_index */, port);
}).then(function(data) {
// (3) Verify that the correct notification was clicked.
assert_equals(, scope);
}, 'Clicking on a notification displayed through showNotification() fires a Service Worker event.');