Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: LayoutTests/http/tests/notifications/service-worker-show-notification-close.html

Issue 868053003: Expose ServiceWorkerRegistration.showNotification() in Service Workers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 </head>
9 <body>
10 <script>
11 // Tests that the showNotification() function resolves a promise, that the
12 // notificationclick event gets fired on the Service Worker when we simula te a
13 // click on it, and the notification can then be closed. This test require s
14 // the test runner.
15 async_test(function (test) {
16 var scope = 'resources/scope/service-worker-show-notification-close',
17 workerUrl = 'resources/click-close-service-worker.js';
18
19 testRunner.grantWebNotificationPermission(location.origin, true);
20
21 var registration = null,
22 messagePort = null;
23 service_worker_unregister_and_register(test, workerUrl, scope).then(fu nction (swRegistration) {
24 registration = swRegistration;
25 return wait_for_state(test, registration.installing, 'activated');
26 }).then(function () {
27 assert_not_equals(registration.active, null, 'The Service Worker n eeds to be activated.');
28 return new Promise(function (resolve) {
29 var messageChannel = new MessageChannel();
30 messageChannel.port1.addEventListener('message', function(even t) {
31 if (event.data == 'ready')
32 resolve();
33 });
34
35 registration.active.postMessage(messageChannel.port2, [message Channel.port2]);
36
37 messagePort = messageChannel.port1;
38 messagePort.start();
39 });
40 }).then(function () {
41 assert_inherits(registration, 'showNotification', 'showNotificatio n() must be exposed.');
42 return registration.showNotification(scope, {
43 body: 'Hello, world!',
44 icon: '/icon.png'
45 });
46 }).then(function () {
47 messagePort.addEventListener('message', function(event) {
48 assert_equals(event.data, 'Clicked on Notification: ' + scope) ;
49
50 // FIXME: The notification has now been closed by the Service Worker. In
51 // order to verify that this works correctly, we need to suppo rt the
52 // Notification.get() getter, which is not implemented yet.
53
54 service_worker_unregister_and_done(test, scope);
55 });
56
57 testRunner.simulateWebNotificationClick(scope);
58
59 }).catch(unreached_rejection(test));
60
61 }, 'Clicking on a notification displayed through showNotification() fires a Service Worker event, and can be closed there.');
62 </script>
63 </body>
64 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698