Chromium Code Reviews| Index: LayoutTests/http/tests/notifications/service-worker-show-notification-click.html |
| diff --git a/LayoutTests/http/tests/notifications/service-worker-show-notification-click.html b/LayoutTests/http/tests/notifications/service-worker-show-notification-click.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..132e67d3aecd591d74e05e40bc9aef0bfbdc186d |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/notifications/service-worker-show-notification-click.html |
| @@ -0,0 +1,61 @@ |
| +<!doctype html> |
| +<html> |
| + <head> |
| + <title>Notifications: ServiceWorkerRegistration.showNotification().</title> |
| + <script src="../resources/testharness.js"></script> |
| + <script src="../resources/testharnessreport.js"></script> |
| + <script src="../serviceworker/resources/test-helpers.js"></script> |
| + </head> |
| + <body> |
| + <script> |
| + // Tests that the showNotification() function resolves a promise, and that the |
| + // notificationclick event gets fired on the Service Worker when we simulate a |
| + // click on it. This test requires the test runner. |
| + async_test(function (test) { |
| + var scope = 'resources/scope/service-worker-show-notification-click', |
| + 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.
|
| + |
| + testRunner.grantWebNotificationPermission("http://127.0.0.1:8000", true); |
|
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.
|
| + |
| + var registration = null, |
| + messagePort = null; |
| + service_worker_unregister_and_register(test, worker_url, scope).then(function (swRegistration) { |
| + registration = swRegistration; |
| + 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.
|
| + }).then(function (serviceWorker) { |
| + 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://
|
| + }).then(function () { |
| + assert_not_equals(registration.active, null, 'The Service Worker needs to be activated.'); |
| + return new Promise(function (resolve) { |
| + var messageChannel = new MessageChannel(); |
| + messageChannel.port1.addEventListener('message', function(event) { |
| + if (event.data == 'ready') |
| + resolve(); |
| + }); |
| + |
| + registration.active.postMessage(messageChannel.port2, [messageChannel.port2]); |
| + |
| + messagePort = messageChannel.port1; |
| + messagePort.start(); |
| + }); |
| + }).then(function () { |
| + assert_inherits(registration, 'showNotification', 'showNotification() must be exposed.'); |
| + |
| + return registration.showNotification(scope, { |
| + body: 'Hello, world!', |
| + icon: '/icon.png' |
| + }); |
| + }).then(function () { |
| + messagePort.addEventListener('message', function(event) { |
| + assert_equals(event.data, 'The notification has been clicked on.'); |
| + test.done(); |
| + }); |
| + |
| + testRunner.simulateWebNotificationClick(scope); |
| + |
| + }).catch(unreached_rejection(test)); |
| + |
| + }, 'Clicking on a notification displayed through showNotification() fires a Service Worker event.'); |
| + </script> |
| + </body> |
| +</html> |