Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / notifications / serviceworkerregistration-document-close.html
blob965fba84c6a15c51fb2f4e0b4c6cd5d8b26eb24f
1 <!doctype html>
2 <html>
3 <head>
4 <title>Notifications: ServiceWorkerRegistration.showNotification().</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>
9 </head>
10 <body>
11 <script>
12 // Tests that the showNotification() function resolves a promise, that the
13 // notificationclick event gets fired on the Service Worker when we simulate a
14 // click on it, and the notification can then be closed. This test requires
15 // the test runner.
16 async_test(function(test) {
17 var scope = 'resources/scope/serviceworkerregistration-document-close',
18 script = 'resources/instrumentation-service-worker.js';
20 testRunner.setPermission('notifications', 'granted', location.origin, location.origin);
22 var workerInfo = null;
23 getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(info) {
24 workerInfo = info;
26 // (1) Display a Web Notification from the document.
27 assert_inherits(workerInfo.registration, 'showNotification', 'showNotification() must be exposed.');
28 return workerInfo.registration.showNotification(scope, {
29 body: 'ACTION:CLOSE',
30 icon: '/icon.png'
31 });
32 }).then(function() {
33 // (2) Simulate a click on the notification that has been displayed.
34 testRunner.simulateWebNotificationClick(scope);
36 workerInfo.port.addEventListener('message', function(event) {
37 if (typeof event.data != 'object' || !event.data.command) {
38 assert_unreached('Received an invalid message from the Service Worker.');
39 return;
42 // (3) Verify that the click event was received by the Service Worker.
43 assert_equals(event.data.command, 'click');
44 assert_equals(event.data.notification.title, scope);
46 // FIXME: The notification has now been closed by the Service Worker. In
47 // order to verify that this works correctly, we need to support the
48 // Notification.get() getter, which is not implemented yet.
50 test.done();
51 });
52 }).catch(unreached_rejection(test));
54 }, 'Clicking on a notification displayed through showNotification() fires a Service Worker event, and can be closed there.');
55 </script>
56 </body>
57 </html>