blob: a214c7c5e46b331e4eb878a82436990c6c35fc94 [file] [log] [blame]
<!doctype html>
<title>Notifications: NotificationEvent exposure in a 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>
// Tests that the NotificationEvent object is exposed in a ServiceWorker
// and exposes the "notification", "action" and "waitUntil" members.
// Because the NotificationEvent must be created with a notification, a
// notification is shown and clicked on prior to running the actual test
// in the Service Worker (serviceworker-notification-event.js).
async_test(function(test) {
var scope = 'resources/scope/' + location.pathname,
script = 'resources/serviceworker-notification-event.js';
testRunner.setPermission('notifications', 'granted', location.origin, location.origin);
var workerInfo = null;
getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(info) {
workerInfo = info;
// (1) Display a Web Notification from the document.
assert_inherits(workerInfo.registration, 'showNotification', 'showNotification() must be exposed.');
return workerInfo.registration.showNotification(scope, {
body: 'Hello, world!',
icon: '/icon.png'
}).then(function() {
// (2) Simulate a click on the notification that has been displayed.
workerInfo.port.addEventListener('message', function(event) {
if (typeof != 'object' || typeof != 'boolean') {
assert_unreached('Received an invalid message from the Service Worker.');
// (3) Verify that the tests were successful in the Service Worker.
'Expected tests to pass, but assertion failed:' + '\n' + + '\n');
}, 'The NotificationEvent exposes the expected semantics in a Service Worker.');