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

Unified Diff: LayoutTests/http/tests/notifications/serviceworkerregistration-get-from-service-worker.html

Issue 1056573002: Introduce layout tests for SWR.getNotifications() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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-get-from-service-worker.html
diff --git a/LayoutTests/http/tests/notifications/serviceworkerregistration-get-from-service-worker.html b/LayoutTests/http/tests/notifications/serviceworkerregistration-get-from-service-worker.html
new file mode 100644
index 0000000000000000000000000000000000000000..14c09084e3cae7b9cc466149de32157f77933347
--- /dev/null
+++ b/LayoutTests/http/tests/notifications/serviceworkerregistration-get-from-service-worker.html
@@ -0,0 +1,62 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Notifications: ServiceWorkerRegistration.getNotifications() when created by the Service Worker.</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 getNotifications() function when used in a document returns
+ // an array of the notifications which were previously displayed by the
+ // Service Worker.
+ async_test(function(test) {
+ var scope = 'resources/scope/' + location.pathname,
+ script = 'resources/instrumentation-service-worker.js';
+
+ testRunner.grantWebNotificationPermission(location.origin, true);
+
+ var info = null;
+ getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) {
+ info = workerInfo;
+
+ // (1) Tell the Service Worker to display a new Notification and wait for it
+ // to have been displayed to the user.
+ info.port.postMessage({
+ command: 'show',
+
+ title: scope,
+ options: { body: 'Hello, world!' }
+ });
+
+ return new Promise(function(resolve) {
+ info.port.addEventListener('message', function(event) {
+ if (typeof event.data != 'object' || !event.data.command) {
+ assert_unreached('Invalid message from the Service Worker.');
+ return;
+ }
+
+ assert_equals(event.data.command, 'show');
+ resolve();
+ });
+ });
+ }).then(function() {
+ // (2) Get a list of all notifications in the document.
+ return info.registration.getNotifications();
+ }).then(function(notifications) {
+ // (3) Verify that there's only one notification: the one we just showed.
+ assert_equals(notifications.length, 1);
+
+ assert_equals(notifications[0].title, scope);
+ assert_equals(notifications[0].body, 'Hello, world!');
+
+ test.done();
+
+ }).catch(unreached_rejection(test));
+
+ }, 'ServiceWorkerRegistration.getNotifications() when created by a Service Worker.');
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698