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

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: add missing file 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 worker_url = 'resources/click-forward-service-worker.js';
Michael van Ouwerkerk 2014/12/09 19:38:04 nit: workerUrl
Peter Beverloo 2014/12/10 13:24:36 Done.
17
18 testRunner.grantWebNotificationPermission("http://127.0.0.1:8000", tru e);
Michael van Ouwerkerk 2014/12/09 19:38:04 Nit: just location.origin should be enough
Peter Beverloo 2014/12/10 13:24:36 Done.
19
20 var registration = null,
21 messagePort = null;
22 service_worker_unregister_and_register(test, worker_url, scope).then(f unction (swRegistration) {
23 registration = swRegistration;
24 return wait_for_update(test, registration);
Michael van Ouwerkerk 2014/12/09 19:38:04 I don't think you need this if you use wait_for_ac
Peter Beverloo 2014/12/10 13:24:36 Done.
25 }).then(function (serviceWorker) {
26 return wait_for_state(test, serviceWorker, 'activating');
Michael van Ouwerkerk 2014/12/09 19:38:04 nit: return wait_for_activated(test, registration)
Peter Beverloo 2014/12/10 13:24:36 Cool, thanks! You do want to take note of https://
27 }).then(function () {
28 assert_not_equals(registration.active, null, 'The Service Worker n eeds to be activated.');
29 return new Promise(function (resolve) {
30 var messageChannel = new MessageChannel();
31 messageChannel.port1.addEventListener('message', function(even t) {
32 if (event.data == 'ready')
33 resolve();
34 });
35
36 registration.active.postMessage(messageChannel.port2, [message Channel.port2]);
37
38 messagePort = messageChannel.port1;
39 messagePort.start();
40 });
41 }).then(function () {
42 assert_inherits(registration, 'showNotification', 'showNotificatio n() must be exposed.');
43
44 return registration.showNotification(scope, {
45 body: 'Hello, world!',
46 icon: '/icon.png'
47 });
48 }).then(function () {
49 messagePort.addEventListener('message', function(event) {
50 assert_equals(event.data, 'The notification has been clicked o n.');
51 test.done();
52 });
53
54 testRunner.simulateWebNotificationClick(scope);
55
56 }).catch(unreached_rejection(test));
57
58 }, 'Clicking on a notification displayed through showNotification() fires a Service Worker event.');
59 </script>
60 </body>
61 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698