Index: LayoutTests/http/tests/notifications/serviceworkerregistration-document-click.html |
diff --git a/LayoutTests/http/tests/notifications/serviceworkerregistration-document-click.html b/LayoutTests/http/tests/notifications/serviceworkerregistration-document-click.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..92e74ba7f59cbf62ba4883b3f1b8e3654c852da1 |
--- /dev/null |
+++ b/LayoutTests/http/tests/notifications/serviceworkerregistration-document-click.html |
@@ -0,0 +1,53 @@ |
+<!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> |
+ <script src="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/serviceworkerregistration-document-click', |
+ script = 'resources/instrumentation-service-worker.js'; |
+ |
+ testRunner.grantWebNotificationPermission(location.origin, true); |
+ |
+ var workerInfo = null; |
+ getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(info) { |
+ workerInfo = info; |
+ |
+ // (1) Display a Web Notification from the document. |
+ assert_inherits(workerInfo.registration, 'showNotification', 'showNotification() must be exposed.'); |
+ return workerInfo.registration.showNotification(scope, { |
+ body: 'Hello, world!', |
+ icon: '/icon.png' |
+ }); |
+ }).then(function() { |
+ // (2) Simulate a click on the notification that has been displayed. |
+ testRunner.simulateWebNotificationClick(scope); |
+ |
+ workerInfo.port.addEventListener('message', function(event) { |
+ if (typeof event.data != 'object' || !event.data.command) { |
+ assert_unreached('Received an invalid message from the Service Worker.'); |
+ return; |
+ } |
+ |
+ // (3) Verify that the click event was received by the Service Worker. |
+ assert_equals(event.data.command, 'click'); |
+ assert_equals(event.data.notification.title, scope); |
+ |
+ test.done(); |
+ }); |
+ }).catch(unreached_rejection(test)); |
+ |
+ }, 'Clicking on a notification displayed through showNotification() fires a Service Worker event.'); |
+ </script> |
+ </body> |
+</html> |