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

Unified Diff: LayoutTests/http/tests/notifications/serviceworkerregistration-document-close.html

Issue 868053003: Expose ServiceWorkerRegistration.showNotification() in Service Workers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/notifications/serviceworkerregistration-document-close.html
diff --git a/LayoutTests/http/tests/notifications/serviceworkerregistration-document-close.html b/LayoutTests/http/tests/notifications/serviceworkerregistration-document-close.html
new file mode 100644
index 0000000000000000000000000000000000000000..f03b1d3ae3038423398c4b0dadc2ed2816137cad
--- /dev/null
+++ b/LayoutTests/http/tests/notifications/serviceworkerregistration-document-close.html
@@ -0,0 +1,57 @@
+<!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, that the
+ // notificationclick event gets fired on the Service Worker when we simulate a
+ // click on it, and the notification can then be closed. This test requires
+ // the test runner.
+ async_test(function(test) {
+ var scope = 'resources/scope/serviceworkerregistration-document-close',
+ 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: 'ACTION:CLOSE',
+ 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);
+
+ // FIXME: The notification has now been closed by the Service Worker. In
+ // order to verify that this works correctly, we need to support the
+ // Notification.get() getter, which is not implemented yet.
+
+ test.done();
+ });
+ }).catch(unreached_rejection(test));
+
+ }, 'Clicking on a notification displayed through showNotification() fires a Service Worker event, and can be closed there.');
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698