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

Unified Diff: LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js

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
« no previous file with comments | « no previous file | LayoutTests/http/tests/notifications/serviceworkerregistration-get.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js
diff --git a/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js b/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js
index d77c1408235f5b5e45bd96b2d87510e98ea2fdff..868ab02e449bfb78927520dd7fdf8cec52124e18 100644
--- a/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js
+++ b/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js
@@ -1,5 +1,10 @@
importScripts('/resources/testharness-helpers.js');
+// Copies the serializable attributes of |notification|.
+function cloneNotification(notification) {
+ return JSON.parse(stringifyDOMObject(notification));
+}
+
// Allows a document to exercise the Notifications API within a service worker by sending commands.
var messagePort = null;
@@ -28,6 +33,26 @@ addEventListener('message', function(workerEvent) {
});
break;
+ case 'get':
+ var filter = {};
+ if (typeof (event.data.filter) !== 'undefined')
+ filter = event.data.filter;
+
+ registration.getNotifications(filter).then(function(notifications) {
+ var clonedNotifications = [];
+ for (var notification of notifications)
+ clonedNotifications.push(cloneNotification(notification));
+
+ messagePort.postMessage({ command: event.data.command,
+ success: true,
+ notifications: clonedNotifications });
+ }, function(error) {
+ messagePort.postMessage({ command: event.data.command,
+ success: false,
+ message: error.message });
+ });
+ break;
+
default:
messagePort.postMessage({ command: 'error', message: 'Invalid command: ' + event.data.command });
break;
@@ -39,8 +64,7 @@ addEventListener('message', function(workerEvent) {
});
addEventListener('notificationclick', function(event) {
- // Copies the serializable attributes of the Notification instance on |event|.
- var notificationCopy = JSON.parse(stringifyDOMObject(event.notification));
+ var notificationCopy = cloneNotification(event.notification);
// Notifications containing "ACTION:CLOSE" in their message will be closed
// immediately by the Service Worker.
« no previous file with comments | « no previous file | LayoutTests/http/tests/notifications/serviceworkerregistration-get.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698