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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/resources/sw-test-helpers.js

Issue 2877543003: [ServiceWorker] Allow waitUntil to be called multiple times asynchronously (Closed)
Patch Set: Address comments from falken@ Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Test helper that is meant as a mini test framework to be used from a service 1 // Test helper that is meant as a mini test framework to be used from a service
2 // worker that runs some tests and send results back to its client. 2 // worker that runs some tests and send results back to its client.
3 // 3 //
4 // A simple usage of this framework would consist of calling initialize() to 4 // A simple usage of this framework would consist of calling initialize() to
5 // setup then runNextTestOrQuit() in order to start running the methods defined 5 // setup then runNextTestOrQuit() in order to start running the methods defined
6 // by TESTS. Then, tests can start sending messages back to the client using 6 // by TESTS. Then, tests can start sending messages back to the client using
7 // postMessage(). 7 // postMessage().
8 // 8 //
9 // Example: 9 // Example:
10 // var TESTS = [ 10 // var TESTS = [
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // object. 54 // object.
55 self.synthesizeNotificationClick = function() { 55 self.synthesizeNotificationClick = function() {
56 var promise = new Promise(function(resolve) { 56 var promise = new Promise(function(resolve) {
57 var title = "fake notification"; 57 var title = "fake notification";
58 registration.showNotification(title).then(function() { 58 registration.showNotification(title).then(function() {
59 client.postMessage({type: 'click', title: title}); 59 client.postMessage({type: 'click', title: title});
60 }); 60 });
61 61
62 var handler = function(e) { 62 var handler = function(e) {
63 resolve(e); 63 resolve(e);
64 // To allow waitUntil to be called inside execution of the microtask
65 // enqueued by above resolve function.
66 e.waitUntil(Promise.resolve());
64 e.notification.close(); 67 e.notification.close();
65 self.removeEventListener('notificationclick', handler); 68 self.removeEventListener('notificationclick', handler);
66 }; 69 };
67 70
68 self.addEventListener('notificationclick', handler); 71 self.addEventListener('notificationclick', handler);
69 }); 72 });
70 73
71 return promise; 74 return promise;
72 } 75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698