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

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

Issue 1907443007: Use promises in notifications tests and enable controlling the page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Address peter's comments. Created 4 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: third_party/WebKit/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js b/third_party/WebKit/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js
deleted file mode 100644
index 6a1991e0a9be2c4549bbee3fc016dbd1b42af670..0000000000000000000000000000000000000000
--- a/third_party/WebKit/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js
+++ /dev/null
@@ -1,110 +0,0 @@
-importScripts('/resources/testharness-helpers.js');
-
-// For copying Notification.data. Currently a deep copy algorithm is used. Note
-// that the robustness of this function (and also |assert_object_equals| in
-// testharness.js) affects the types of possible testing can be done.
-// TODO(peter): change this to a structured clone algorithm.
-function cloneObject(src) {
- if (typeof src != 'object' || src === null)
- return src;
- var dst = Array.isArray(src) ? [] : {};
- for (var property in src) {
- if (src.hasOwnProperty(property))
- dst[property] = cloneObject(src[property]);
- }
- return dst;
-}
-
-// Copies the serializable attributes of |notification|.
-function cloneNotification(notification) {
- var copiedNotification = JSON.parse(stringifyDOMObject(notification));
- copiedNotification.data = cloneObject(notification.data);
- return copiedNotification;
-}
-
-// Allows a document to exercise the Notifications API within a service worker by sending commands.
-var messagePort = null;
-
-addEventListener('message', function(workerEvent) {
- messagePort = workerEvent.data;
-
- // Listen to incoming commands on the message port.
- messagePort.onmessage = function(event) {
- if (typeof event.data != 'object' || !event.data.command)
- return;
-
- switch (event.data.command) {
- case 'permission':
- messagePort.postMessage({ command: event.data.command,
- value: Notification.permission });
- break;
-
- case 'show':
- registration.showNotification(event.data.title, event.data.options).then(function() {
- messagePort.postMessage({ command: event.data.command,
- success: true });
- }, function(error) {
- messagePort.postMessage({ command: event.data.command,
- success: false,
- message: error.message });
- });
- 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;
-
- case 'request-permission-exists':
- messagePort.postMessage({ command: event.data.command,
- value: 'requestPermission' in Notification });
- break;
-
- default:
- messagePort.postMessage({ command: 'error', message: 'Invalid command: ' + event.data.command });
- break;
- }
- };
-
- // Notify the controller that the worker is now available.
- messagePort.postMessage('ready');
-});
-
-addEventListener('notificationclick', function(event) {
- var notificationCopy = cloneNotification(event.notification);
-
- // Notifications containing "ACTION:CLOSE" in their message will be closed
- // immediately by the Service Worker.
- if (event.notification.body.indexOf('ACTION:CLOSE') != -1)
- event.notification.close();
-
- // Notifications containing "ACTION:OPENWINDOW" in their message will attempt
- // to open a new window for an example URL.
- if (event.notification.body.indexOf('ACTION:OPENWINDOW') != -1)
- event.waitUntil(clients.openWindow('https://example.com/'));
-
- messagePort.postMessage({ command: 'click',
- notification: notificationCopy,
- action: event.action });
-});
-
-addEventListener('notificationclose', function(event) {
- var notificationCopy = cloneNotification(event.notification);
- messagePort.postMessage({ command: 'close',
- notification: notificationCopy });
-});

Powered by Google App Engine
This is Rietveld 408576698