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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/notifications/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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/http/tests/notifications/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/instrumentation-service-worker.js
similarity index 81%
rename from third_party/WebKit/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js
rename to third_party/WebKit/LayoutTests/http/tests/notifications/instrumentation-service-worker.js
index 6a1991e0a9be2c4549bbee3fc016dbd1b42af670..16c6b8231636f6e2b9dd2e796a3c6e9cee9e4636 100644
--- a/third_party/WebKit/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js
+++ b/third_party/WebKit/LayoutTests/http/tests/notifications/instrumentation-service-worker.js
@@ -25,11 +25,22 @@ function cloneNotification(notification) {
// Allows a document to exercise the Notifications API within a service worker by sending commands.
var messagePort = null;
-addEventListener('message', function(workerEvent) {
+// All urls of requests that have been routed through the fetch event handler.
+var fetchHistory = [];
+
+addEventListener('install', event => {
+ event.waitUntil(skipWaiting());
+});
+
+addEventListener('activate', event => {
+ event.waitUntil(clients.claim());
+});
+
+addEventListener('message', workerEvent => {
messagePort = workerEvent.data;
// Listen to incoming commands on the message port.
- messagePort.onmessage = function(event) {
+ messagePort.onmessage = event => {
if (typeof event.data != 'object' || !event.data.command)
return;
@@ -40,22 +51,27 @@ addEventListener('message', function(workerEvent) {
break;
case 'show':
- registration.showNotification(event.data.title, event.data.options).then(function() {
+ registration.showNotification(event.data.title, event.data.options).then(() => {
messagePort.postMessage({ command: event.data.command,
success: true });
- }, function(error) {
+ }, error => {
messagePort.postMessage({ command: event.data.command,
success: false,
message: error.message });
});
break;
+ case 'get-fetch-history':
+ messagePort.postMessage({ command: event.data.command,
+ fetchHistory: fetchHistory });
+ break;
+
case 'get':
var filter = {};
if (typeof (event.data.filter) !== 'undefined')
filter = event.data.filter;
- registration.getNotifications(filter).then(function(notifications) {
+ registration.getNotifications(filter).then(notifications => {
var clonedNotifications = [];
for (var notification of notifications)
clonedNotifications.push(cloneNotification(notification));
@@ -63,7 +79,7 @@ addEventListener('message', function(workerEvent) {
messagePort.postMessage({ command: event.data.command,
success: true,
notifications: clonedNotifications });
- }, function(error) {
+ }, error => {
messagePort.postMessage({ command: event.data.command,
success: false,
message: error.message });
@@ -85,7 +101,7 @@ addEventListener('message', function(workerEvent) {
messagePort.postMessage('ready');
});
-addEventListener('notificationclick', function(event) {
+addEventListener('notificationclick', event => {
var notificationCopy = cloneNotification(event.notification);
// Notifications containing "ACTION:CLOSE" in their message will be closed
@@ -103,8 +119,13 @@ addEventListener('notificationclick', function(event) {
action: event.action });
});
-addEventListener('notificationclose', function(event) {
+addEventListener('notificationclose', event => {
var notificationCopy = cloneNotification(event.notification);
messagePort.postMessage({ command: 'close',
notification: notificationCopy });
});
+
+addEventListener('fetch', event => {
+ fetchHistory.push(event.request.url);
+ event.respondWith(fetch(event.request));
+});
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698