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

Unified Diff: LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-no-permission.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-service-worker-no-permission.html
diff --git a/LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-no-permission.html b/LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-no-permission.html
new file mode 100644
index 0000000000000000000000000000000000000000..3abbced552d460ab6eb9861f886956ca44775914
--- /dev/null
+++ b/LayoutTests/http/tests/notifications/serviceworkerregistration-service-worker-no-permission.html
@@ -0,0 +1,49 @@
+<!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 when used in a Service Worker
+ // rejects when no permission has been granted. This test requires the test runner.
+
+ async_test(function(test) {
+ var scope = 'resources/scope/serviceworkerregistration-service-worker-click',
+ script = 'resources/instrumentation-service-worker.js';
+
+ testRunner.grantWebNotificationPermission(location.origin, false);
+ getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) {
+ // (1) Tell the Service Worker to display a Web Notification.
+ workerInfo.port.postMessage({
+ command: 'show',
+
+ title: 'My Notification',
+ options: { body: 'Hello, world!' }
+ });
+
+ workerInfo.port.addEventListener('message', function(event) {
+ if (typeof event.data != 'object' || !event.data.command) {
+ assert_unreached('Invalid message from the Service Worker.');
+ return;
+ }
+
+ // (2) Listen for confirmation from the Service Worker that the
+ // notification could not be displayed because of a permission error.
+ assert_equals(event.data.command, 'show');
+
+ assert_false(event.data.success);
+ assert_equals(event.data.message, 'No notification permission has been granted for this origin.');
+
+ test.done();
+ });
+ }).catch(unreached_rejection(test));
+
+ }, 'showNotification() must reject if no Web Notification permission has been granted.');
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698