4 <title>Notifications: Calling openWindow() in a Service Worker should not crash.
</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 calling openWindow() in a Service Worker in response to a
13 // notificationclick event does not cause the browser to crash.
15 async_test(function(test
) {
16 var scope
= 'resources/scope/' + location
.pathname
,
17 script
= 'resources/instrumentation-service-worker.js',
20 testRunner
.setPermission('notifications', 'granted', location
.origin
, location
.origin
);
21 getActiveServiceWorkerWithMessagePort(test
, script
, scope
).then(function(info
) {
24 // (1) Display a persistent notification with an OPENWINDOW trigger.
25 return workerInfo
.registration
.showNotification(scope
, {
26 body
: 'ACTION:OPENWINDOW'
29 // (2) Simulate a click on the notification, invokes the Service Worker event.
30 testRunner
.simulateWebNotificationClick(scope
);
32 workerInfo
.port
.addEventListener('message', function(event
) {
33 if (typeof event
.data
!= 'object' || !event
.data
.command
) {
34 assert_unreached('Invalid message from the Service Worker.');
38 // (3) Listen for confirmation by the Service Worker that the notificationclick
39 // event has been executed successfully.
40 assert_equals(event
.data
.command
, 'click');
41 assert_equals(event
.data
.notification
.title
, scope
);
45 }).catch(unreached_rejection(test
));
47 }, 'Opening a window in a Service Worker should not trigger a DCHECK.');