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

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

Issue 787893002: Actually hook up ServiceWorkerRegistration.showNotification() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years 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, and that the
12 // notificationclick event gets fired on the Service Worker when we simula te a
13 // click on it. This test requires the test runner.
14 async_test(function (test) {
15 var scope = 'resources/scope/service-worker-show-notification-click',
16 workerUrl = 'resources/click-forward-service-worker.js';
17
18 testRunner.grantWebNotificationPermission(location.origin, true);
19
20 var registration = null,
21 messagePort = null;
22 service_worker_unregister_and_register(test, workerUrl, scope).then(fu nction (swRegistration) {
23 registration = swRegistration;
24 return wait_for_state(test, registration.installing, 'activated');
25 }).then(function () {
26 assert_not_equals(registration.active, null, 'The Service Worker n eeds to be activated.');
27 return new Promise(function (resolve) {
28 var messageChannel = new MessageChannel();
29 messageChannel.port1.addEventListener('message', function(even t) {
30 if (event.data == 'ready')
31 resolve();
32 });
33
34 registration.active.postMessage(messageChannel.port2, [message Channel.port2]);
35
36 messagePort = messageChannel.port1;
37 messagePort.start();
38 });
39 }).then(function () {
40 assert_inherits(registration, 'showNotification', 'showNotificatio n() must be exposed.');
41 return registration.showNotification(scope, {
42 body: 'Hello, world!',
43 icon: '/icon.png'
44 });
45 }).then(function () {
46 messagePort.addEventListener('message', function(event) {
47 assert_equals(event.data, 'The notification has been clicked o n.');
48 test.done();
49 });
50
51 testRunner.simulateWebNotificationClick(scope);
52
53 }).catch(unreached_rejection(test));
54
55 }, 'Clicking on a notification displayed through showNotification() fires a Service Worker event.');
56 </script>
57 </body>
58 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698